[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 | |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 7 | #include <stddef.h> |
[email protected] | aca02cf | 2010-05-03 18:56:01 | [diff] [blame] | 8 | |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | #include <string> |
juncai | cd97558 | 2015-12-21 22:58:10 | [diff] [blame] | 11 | #include <utility> |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 12 | |
[email protected] | b02d038 | 2009-11-30 21:19:50 | [diff] [blame] | 13 | #include "base/base_paths.h" |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 14 | #include "base/bind.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 15 | #include "base/command_line.h" |
skyostil | 380bb222 | 2015-06-12 12:07:05 | [diff] [blame] | 16 | #include "base/location.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 17 | #include "base/logging.h" |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 18 | #include "base/macros.h" |
asvitkine | 7503603 | 2016-09-01 20:49:34 | [diff] [blame] | 19 | #include "base/metrics/histogram_macros.h" |
[email protected] | d09a4ce1c | 2013-07-24 17:37:02 | [diff] [blame] | 20 | #include "base/process/process_info.h" |
erikchen | 174b78c6 | 2015-03-11 22:02:54 | [diff] [blame] | 21 | #include "base/profiler/scoped_tracker.h" |
skyostil | 380bb222 | 2015-06-12 12:07:05 | [diff] [blame] | 22 | #include "base/single_thread_task_runner.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 23 | #include "base/strings/string_number_conversions.h" |
[email protected] | 1152118 | 2013-06-11 04:06:36 | [diff] [blame] | 24 | #include "base/strings/string_util.h" |
| 25 | #include "base/strings/stringprintf.h" |
[email protected] | 5846d58 | 2013-06-08 16:02:12 | [diff] [blame] | 26 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 27 | #include "base/threading/thread.h" |
| 28 | #include "base/threading/thread_restrictions.h" |
gab | b15e1907 | 2016-05-11 20:45:41 | [diff] [blame] | 29 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | bd64063d | 2013-06-28 15:16:22 | [diff] [blame] | 30 | #include "base/time/time.h" |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 31 | #include "build/build_config.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 32 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 8e837ec | 2013-01-31 01:48:33 | [diff] [blame] | 33 | #include "chrome/browser/app_mode/app_mode_utils.h" |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 34 | #include "chrome/browser/autofill/personal_data_manager_factory.h" |
avi | 71d0f76 | 2014-12-15 16:08:47 | [diff] [blame] | 35 | #include "chrome/browser/background/background_contents.h" |
[email protected] | a07676b2 | 2011-06-17 16:36:53 | [diff] [blame] | 36 | #include "chrome/browser/background/background_contents_service.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 37 | #include "chrome/browser/background/background_contents_service_factory.h" |
horo | 9638ad27 | 2016-01-25 14:36:45 | [diff] [blame] | 38 | #include "chrome/browser/banners/app_banner_manager_desktop.h" |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 39 | #include "chrome/browser/browser_process.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 40 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | dcc8fbc | 2013-07-12 00:54:09 | [diff] [blame] | 41 | #include "chrome/browser/chrome_notification_types.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] | f1d2057 | 2014-02-14 01:27:14 | [diff] [blame] | 45 | #include "chrome/browser/custom_handlers/register_protocol_handler_permission_request.h" |
[email protected] | 5fec470 | 2013-11-20 04:37:38 | [diff] [blame] | 46 | #include "chrome/browser/defaults.h" |
[email protected] | 7001915 | 2012-12-19 11:44:19 | [diff] [blame] | 47 | #include "chrome/browser/devtools/devtools_toggle_action.h" |
| 48 | #include "chrome/browser/devtools/devtools_window.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] | 63d1f9b | 2014-07-05 19:09:03 | [diff] [blame] | 51 | #include "chrome/browser/extensions/api/tabs/tabs_event_router.h" |
| 52 | #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 53 | #include "chrome/browser/extensions/browser_extension_window_controller.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 54 | #include "chrome/browser/extensions/extension_service.h" |
benwells | 919e79b | 2015-03-19 04:58:19 | [diff] [blame] | 55 | #include "chrome/browser/extensions/extension_ui_util.h" |
benwells | 39f23ae | 2014-08-27 08:01:52 | [diff] [blame] | 56 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | a6394ae | 2012-07-16 20:58:43 | [diff] [blame] | 57 | #include "chrome/browser/extensions/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" |
jitendra.ks | 30f0339 | 2015-01-28 09:47:18 | [diff] [blame] | 60 | #include "chrome/browser/history/top_sites_factory.h" |
[email protected] | 4a8adfa0 | 2013-03-19 22:37:46 | [diff] [blame] | 61 | #include "chrome/browser/infobars/infobar_service.h" |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 62 | #include "chrome/browser/lifetime/application_lifetime.h" |
dgn | 0237778 | 2016-03-12 00:58:38 | [diff] [blame] | 63 | #include "chrome/browser/lifetime/keep_alive_registry.h" |
dgn | fe075c8 | 2016-03-18 11:25:35 | [diff] [blame] | 64 | #include "chrome/browser/lifetime/keep_alive_types.h" |
| 65 | #include "chrome/browser/lifetime/scoped_keep_alive.h" |
georgesak | 6fc95e9 | 2015-10-26 21:27:06 | [diff] [blame] | 66 | #include "chrome/browser/memory/tab_manager_web_contents_data.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 67 | #include "chrome/browser/notifications/notification_ui_manager.h" |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 68 | #include "chrome/browser/pepper_broker_infobar_delegate.h" |
tsergeant | a771c23e | 2016-07-13 04:54:52 | [diff] [blame] | 69 | #include "chrome/browser/permissions/permission_request_manager.h" |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 70 | #include "chrome/browser/prefs/incognito_mode_prefs.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 71 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 5e91924 | 2012-02-13 23:59:35 | [diff] [blame] | 72 | #include "chrome/browser/profiles/profile_destroyer.h" |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 73 | #include "chrome/browser/profiles/profile_metrics.h" |
mlerman | 2c1c378 | 2015-04-23 18:37:43 | [diff] [blame] | 74 | #include "chrome/browser/profiles/profiles_state.h" |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 75 | #include "chrome/browser/repost_form_warning_controller.h" |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 76 | #include "chrome/browser/search/search.h" |
georgesak | 5582cbe | 2015-05-22 22:08:07 | [diff] [blame] | 77 | #include "chrome/browser/sessions/session_restore.h" |
[email protected] | 85e921fb8 | 2009-02-11 23:19:44 | [diff] [blame] | 78 | #include "chrome/browser/sessions/session_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 79 | #include "chrome/browser/sessions/session_service_factory.h" |
[email protected] | bde40b82 | 2012-08-30 17:28:56 | [diff] [blame] | 80 | #include "chrome/browser/sessions/session_tab_helper.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 81 | #include "chrome/browser/sessions/tab_restore_service_factory.h" |
estark | 880a5a4 | 2015-11-30 18:21:21 | [diff] [blame] | 82 | #include "chrome/browser/ssl/chrome_security_state_model_client.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] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 85 | #include "chrome/browser/tab_contents/retargeting_details.h" |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 86 | #include "chrome/browser/tab_contents/tab_util.h" |
avi | 24d693f | 2016-08-06 18:03:52 | [diff] [blame] | 87 | #include "chrome/browser/task_manager/web_contents_tags.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] | 255ab97 | 2014-06-04 12:14:22 | [diff] [blame] | 90 | #include "chrome/browser/translate/chrome_translate_client.h" |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 91 | #include "chrome/browser/ui/autofill/chrome_autofill_client.h" |
[email protected] | 5635e614 | 2013-07-18 08:10:40 | [diff] [blame] | 92 | #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 93 | #include "chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h" |
juncai | cd97558 | 2015-12-21 22:58:10 | [diff] [blame] | 94 | #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 95 | #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
[email protected] | 4db2e91 | 2014-03-04 07:08:58 | [diff] [blame] | 96 | #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 97 | #include "chrome/browser/ui/browser_command_controller.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 98 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 99 | #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 100 | #include "chrome/browser/ui/browser_dialogs.h" |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 101 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | 7acfaf9 | 2012-07-11 15:51:59 | [diff] [blame] | 102 | #include "chrome/browser/ui/browser_instant_controller.h" |
[email protected] | 6768ac0 | 2011-04-06 17:41:04 | [diff] [blame] | 103 | #include "chrome/browser/ui/browser_list.h" |
blundell | bde024d | 2015-09-30 13:47:07 | [diff] [blame] | 104 | #include "chrome/browser/ui/browser_live_tab_context.h" |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 105 | #include "chrome/browser/ui/browser_navigator.h" |
thestig | e8082124 | 2015-09-30 23:46:08 | [diff] [blame] | 106 | #include "chrome/browser/ui/browser_navigator_params.h" |
[email protected] | 85537005 | 2012-07-10 19:30:32 | [diff] [blame] | 107 | #include "chrome/browser/ui/browser_tab_strip_model_delegate.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 108 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 109 | #include "chrome/browser/ui/browser_toolbar_model_delegate.h" |
[email protected] | 2cd4fde | 2012-06-26 03:10:26 | [diff] [blame] | 110 | #include "chrome/browser/ui/browser_ui_prefs.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 111 | #include "chrome/browser/ui/browser_window.h" |
juncai | cd97558 | 2015-12-21 22:58:10 | [diff] [blame] | 112 | #include "chrome/browser/ui/chrome_bubble_manager.h" |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 113 | #include "chrome/browser/ui/chrome_pages.h" |
[email protected] | 6e1fcd1 | 2012-07-02 17:14:20 | [diff] [blame] | 114 | #include "chrome/browser/ui/chrome_select_file_policy.h" |
sriramsr | 3e76a41 | 2014-12-18 19:25:29 | [diff] [blame] | 115 | #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 116 | #include "chrome/browser/ui/exclusive_access/mouse_lock_controller.h" |
benwells | 11bd6ed | 2015-06-05 04:20:41 | [diff] [blame] | 117 | #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" |
[email protected] | 88c9201 | 2013-07-02 11:56:34 | [diff] [blame] | 118 | #include "chrome/browser/ui/fast_unload_controller.h" |
[email protected] | 45300ad4 | 2010-12-02 15:51:14 | [diff] [blame] | 119 | #include "chrome/browser/ui/find_bar/find_bar.h" |
| 120 | #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 121 | #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
[email protected] | 1ba55cf | 2012-06-29 19:11:39 | [diff] [blame] | 122 | #include "chrome/browser/ui/global_error/global_error.h" |
| 123 | #include "chrome/browser/ui/global_error/global_error_service.h" |
| 124 | #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
avi | 6082932 | 2016-09-01 19:47:13 | [diff] [blame] | 125 | #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" |
[email protected] | d57ce6a | 2014-07-03 15:39:23 | [diff] [blame] | 126 | #include "chrome/browser/ui/location_bar/location_bar.h" |
[email protected] | 859ec32 | 2013-09-13 16:24:56 | [diff] [blame] | 127 | #include "chrome/browser/ui/media_utils.h" |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 128 | #include "chrome/browser/ui/search/search_delegate.h" |
| 129 | #include "chrome/browser/ui/search/search_model.h" |
[email protected] | 549f62b | 2013-10-26 12:54:42 | [diff] [blame] | 130 | #include "chrome/browser/ui/search/search_tab_helper.h" |
[email protected] | f925367 | 2014-07-31 03:35:38 | [diff] [blame] | 131 | #include "chrome/browser/ui/settings_window_manager.h" |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 132 | #include "chrome/browser/ui/singleton_tabs.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 133 | #include "chrome/browser/ui/status_bubble.h" |
[email protected] | 3da95a10 | 2011-11-30 21:47:45 | [diff] [blame] | 134 | #include "chrome/browser/ui/sync/browser_synced_window_delegate.h" |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 135 | #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
andresantoso | 063151d | 2014-12-18 22:37:55 | [diff] [blame] | 136 | #include "chrome/browser/ui/tab_dialogs.h" |
[email protected] | e0bc75d5 | 2014-01-30 23:42:59 | [diff] [blame] | 137 | #include "chrome/browser/ui/tab_helpers.h" |
[email protected] | 51296c6 | 2012-09-26 13:02:44 | [diff] [blame] | 138 | #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 139 | #include "chrome/browser/ui/tabs/tab_menu_model.h" |
[email protected] | b56e2e3 | 2012-05-11 21:18:04 | [diff] [blame] | 140 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 82808d0 | 2014-04-10 00:10:59 | [diff] [blame] | 141 | #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" |
jared.sohn | a140962 | 2015-08-08 07:16:14 | [diff] [blame] | 142 | #include "chrome/browser/ui/tabs/tab_utils.h" |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 143 | #include "chrome/browser/ui/unload_controller.h" |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 144 | #include "chrome/browser/ui/validation_message_bubble.h" |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 145 | #include "chrome/browser/ui/website_settings/chooser_bubble_delegate.h" |
[email protected] | 6554918 | 2012-02-25 00:45:40 | [diff] [blame] | 146 | #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 147 | #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
[email protected] | 0363942 | 2012-06-28 19:03:37 | [diff] [blame] | 148 | #include "chrome/browser/ui/window_sizer/window_sizer.h" |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 149 | #include "chrome/browser/upgrade_detector.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 150 | #include "chrome/common/chrome_constants.h" |
| 151 | #include "chrome/common/chrome_switches.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 152 | #include "chrome/common/custom_handlers/protocol_handler.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 153 | #include "chrome/common/pref_names.h" |
[email protected] | 7664ab3 | 2011-02-01 23:35:25 | [diff] [blame] | 154 | #include "chrome/common/profiling.h" |
treib | 4dff7cf | 2016-07-06 08:53:30 | [diff] [blame] | 155 | #include "chrome/common/search/search_types.h" |
[email protected] | c744f7d2 | 2013-04-12 20:29:04 | [diff] [blame] | 156 | #include "chrome/common/url_constants.h" |
thestig | 884a160 | 2014-08-27 01:29:39 | [diff] [blame] | 157 | #include "chrome/grit/chromium_strings.h" |
| 158 | #include "chrome/grit/generated_resources.h" |
thestig | aeddd32 | 2014-08-27 06:58:39 | [diff] [blame] | 159 | #include "chrome/grit/locale_settings.h" |
[email protected] | a90c8ca | 2014-05-20 17:16:04 | [diff] [blame] | 160 | #include "components/bookmarks/browser/bookmark_model.h" |
| 161 | #include "components/bookmarks/browser/bookmark_utils.h" |
brettw | e1f0af8b | 2015-10-09 21:30:46 | [diff] [blame] | 162 | #include "components/bookmarks/common/bookmark_pref_names.h" |
maxbogue | 26f4022 | 2016-09-16 20:22:18 | [diff] [blame] | 163 | #include "components/browser_sync/profile_sync_service.h" |
juncai | cd97558 | 2015-12-21 22:58:10 | [diff] [blame] | 164 | #include "components/bubble/bubble_controller.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 165 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
sdefresne | 45582697 | 2015-04-10 15:25:15 | [diff] [blame] | 166 | #include "components/favicon/content/content_favicon_driver.h" |
sdefresne | 0da3bc0 | 2015-01-29 18:26:35 | [diff] [blame] | 167 | #include "components/history/core/browser/top_sites.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 168 | #include "components/prefs/pref_service.h" |
[email protected] | 720b1049 | 2014-07-23 08:48:40 | [diff] [blame] | 169 | #include "components/search/search.h" |
estark | d9e54fb | 2016-01-11 19:37:12 | [diff] [blame] | 170 | #include "components/security_state/security_state_model.h" |
blundell | 47c6d8a | 2015-09-24 11:06:40 | [diff] [blame] | 171 | #include "components/sessions/core/session_types.h" |
blundell | a08c5dd | 2015-09-18 06:14:16 | [diff] [blame] | 172 | #include "components/sessions/core/tab_restore_service.h" |
fdoray | 45c02c16 | 2015-11-09 20:14:30 | [diff] [blame] | 173 | #include "components/startup_metric_utils/browser/startup_metric_utils.h" |
sdefresne | 3adc092b | 2016-02-04 14:18:36 | [diff] [blame] | 174 | #include "components/toolbar/toolbar_model_impl.h" |
pkasting | cc29d20e | 2015-02-25 06:05:53 | [diff] [blame] | 175 | #include "components/translate/core/browser/language_state.h" |
[email protected] | e41d008 | 2013-05-16 04:37:54 | [diff] [blame] | 176 | #include "components/web_modal/web_contents_modal_dialog_manager.h" |
juncai | a64f769c2 | 2016-06-04 00:55:32 | [diff] [blame] | 177 | #include "components/zoom/zoom_controller.h" |
[email protected] | b50452f | 2014-08-18 12:31:44 | [diff] [blame] | 178 | #include "content/public/browser/devtools_agent_host.h" |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 179 | #include "content/public/browser/interstitial_page.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 180 | #include "content/public/browser/invalidate_type.h" |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 181 | #include "content/public/browser/navigation_controller.h" |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 182 | #include "content/public/browser/navigation_entry.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 183 | #include "content/public/browser/notification_details.h" |
| 184 | #include "content/public/browser/notification_service.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 185 | #include "content/public/browser/plugin_service.h" |
horo | 0ff5dcb | 2016-01-29 10:15:08 | [diff] [blame] | 186 | #include "content/public/browser/render_frame_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 187 | #include "content/public/browser/render_process_host.h" |
| 188 | #include "content/public/browser/render_view_host.h" |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 189 | #include "content/public/browser/render_widget_host.h" |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 190 | #include "content/public/browser/render_widget_host_view.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 191 | #include "content/public/browser/site_instance.h" |
jam | 6d47c345 | 2016-09-09 18:51:01 | [diff] [blame] | 192 | #include "content/public/browser/ssl_status.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 193 | #include "content/public/browser/user_metrics.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 194 | #include "content/public/browser/web_contents.h" |
sdefresne | 4d623d70 | 2016-02-03 20:07:57 | [diff] [blame] | 195 | #include "content/public/common/content_constants.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 196 | #include "content/public/common/content_switches.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 197 | #include "content/public/common/page_zoom.h" |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 198 | #include "content/public/common/renderer_preferences.h" |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 199 | #include "content/public/common/webplugininfo.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 200 | #include "extensions/browser/extension_prefs.h" |
jitendra.ks | a005553 | 2014-10-07 05:54:46 | [diff] [blame] | 201 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 202 | #include "extensions/browser/extension_system.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 203 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 204 | #include "extensions/common/extension.h" |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 205 | #include "extensions/common/manifest_handlers/background_info.h" |
[email protected] | d96cf75 | 2014-04-09 04:05:28 | [diff] [blame] | 206 | #include "net/base/filename_util.h" |
[email protected] | be28b5f4 | 2012-07-20 11:31:25 | [diff] [blame] | 207 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 4d7c4ef | 2012-03-16 01:47:12 | [diff] [blame] | 208 | #include "net/cookies/cookie_monster.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 209 | #include "net/url_request/url_request_context.h" |
[email protected] | 453c1b2 | 2013-07-23 09:31:48 | [diff] [blame] | 210 | #include "third_party/WebKit/public/web/WebWindowFeatures.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 211 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | f47621b | 2013-01-22 20:50:33 | [diff] [blame] | 212 | #include "ui/base/window_open_disposition.h" |
tfarina | 655f81d | 2014-12-23 02:38:50 | [diff] [blame] | 213 | #include "ui/gfx/geometry/point.h" |
[email protected] | 4344a3c | 2013-01-17 23:49:20 | [diff] [blame] | 214 | #include "ui/shell_dialogs/selected_file_info.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 215 | |
| 216 | #if defined(OS_WIN) |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 217 | #include <windows.h> |
| 218 | #include <shellapi.h> |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 219 | #include "chrome/browser/ui/view_ids.h" |
[email protected] | 526a16b | 2013-06-20 11:44:33 | [diff] [blame] | 220 | #include "components/autofill/core/browser/autofill_ie_toolbar_import_win.h" |
mfomitchev | f09a66bb | 2014-10-02 02:20:54 | [diff] [blame] | 221 | #include "ui/base/touch/touch_device.h" |
[email protected] | dcd5776 | 2011-06-25 12:18:51 | [diff] [blame] | 222 | #include "ui/base/win/shell.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 223 | #endif // OS_WIN |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 224 | |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 225 | #if defined(OS_CHROMEOS) |
hirono | 90949af | 2014-09-25 04:23:37 | [diff] [blame] | 226 | #include "chrome/browser/chromeos/fileapi/external_file_url_util.h" |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 227 | #endif |
| 228 | |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 229 | #if defined(USE_ASH) |
brettw | 08fe0e95 | 2016-08-26 21:53:39 | [diff] [blame] | 230 | #include "ash/shell.h" // nogncheck |
[email protected] | c2f0a89 | 2012-01-24 22:19:21 | [diff] [blame] | 231 | #endif |
| 232 | |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 233 | using base::TimeDelta; |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 234 | using base::UserMetricsAction; |
[email protected] | b87ee52 | 2012-05-18 15:16:54 | [diff] [blame] | 235 | using content::NativeWebKeyboardEvent; |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 236 | using content::NavigationController; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 237 | using content::NavigationEntry; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 238 | using content::OpenURLParams; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 239 | using content::PluginService; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 240 | using content::Referrer; |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 241 | using content::RenderWidgetHostView; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 242 | using content::SiteInstance; |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 243 | using content::WebContents; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 244 | using extensions::Extension; |
estark | d9e54fb | 2016-01-11 19:37:12 | [diff] [blame] | 245 | using security_state::SecurityStateModel; |
[email protected] | 20c07f8e | 2012-05-31 08:43:14 | [diff] [blame] | 246 | using ui::WebDialogDelegate; |
[email protected] | e41d008 | 2013-05-16 04:37:54 | [diff] [blame] | 247 | using web_modal::WebContentsModalDialogManager; |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 248 | using blink::WebWindowFeatures; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 249 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 250 | /////////////////////////////////////////////////////////////////////////////// |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 251 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 252 | namespace { |
| 253 | |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 254 | // How long we wait before updating the browser chrome while loading a page. |
| 255 | const int kUIUpdateCoalescingTimeMS = 200; |
| 256 | |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 257 | BrowserWindow* CreateBrowserWindow(Browser* browser) { |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 258 | return BrowserWindow::CreateBrowserWindow(browser); |
| 259 | } |
| 260 | |
[email protected] | 88c9201 | 2013-07-02 11:56:34 | [diff] [blame] | 261 | // Is the fast tab unload experiment enabled? |
| 262 | bool IsFastTabUnloadEnabled() { |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 263 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 264 | switches::kEnableFastUnload); |
[email protected] | 88c9201 | 2013-07-02 11:56:34 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 267 | } // namespace |
| 268 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 269 | //////////////////////////////////////////////////////////////////////////////// |
| 270 | // Browser, CreateParams: |
| 271 | |
scottmg | 85194900 | 2016-02-09 20:09:44 | [diff] [blame] | 272 | Browser::CreateParams::CreateParams(Profile* profile) |
[email protected] | 19657825 | 2012-12-06 23:54:20 | [diff] [blame] | 273 | : type(TYPE_TABBED), |
| 274 | profile(profile), |
[email protected] | d2202e2 | 2014-04-14 20:20:53 | [diff] [blame] | 275 | trusted_source(false), |
[email protected] | 19657825 | 2012-12-06 23:54:20 | [diff] [blame] | 276 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
| 277 | is_session_restore(false), |
scottmg | 85194900 | 2016-02-09 20:09:44 | [diff] [blame] | 278 | window(NULL) {} |
[email protected] | 19657825 | 2012-12-06 23:54:20 | [diff] [blame] | 279 | |
scottmg | 85194900 | 2016-02-09 20:09:44 | [diff] [blame] | 280 | Browser::CreateParams::CreateParams(Type type, Profile* profile) |
[email protected] | 56073dc | 2012-08-10 16:59:06 | [diff] [blame] | 281 | : type(type), |
| 282 | profile(profile), |
[email protected] | d2202e2 | 2014-04-14 20:20:53 | [diff] [blame] | 283 | trusted_source(false), |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 284 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 285 | is_session_restore(false), |
scottmg | 85194900 | 2016-02-09 20:09:44 | [diff] [blame] | 286 | window(NULL) {} |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 287 | |
vmpstr | b8aacbe | 2016-02-26 02:00:48 | [diff] [blame] | 288 | Browser::CreateParams::CreateParams(const CreateParams& other) = default; |
| 289 | |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 290 | // static |
| 291 | Browser::CreateParams Browser::CreateParams::CreateForApp( |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 292 | const std::string& app_name, |
[email protected] | d2202e2 | 2014-04-14 20:20:53 | [diff] [blame] | 293 | bool trusted_source, |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 294 | const gfx::Rect& window_bounds, |
scottmg | 85194900 | 2016-02-09 20:09:44 | [diff] [blame] | 295 | Profile* profile) { |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 296 | DCHECK(!app_name.empty()); |
| 297 | |
scottmg | 85194900 | 2016-02-09 20:09:44 | [diff] [blame] | 298 | CreateParams params(TYPE_POPUP, profile); |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 299 | params.app_name = app_name; |
[email protected] | d2202e2 | 2014-04-14 20:20:53 | [diff] [blame] | 300 | params.trusted_source = trusted_source; |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 301 | params.initial_bounds = window_bounds; |
| 302 | |
| 303 | return params; |
| 304 | } |
| 305 | |
| 306 | // static |
| 307 | Browser::CreateParams Browser::CreateParams::CreateForDevTools( |
scottmg | 85194900 | 2016-02-09 20:09:44 | [diff] [blame] | 308 | Profile* profile) { |
| 309 | CreateParams params(TYPE_POPUP, profile); |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 310 | params.app_name = DevToolsWindow::kDevToolsApp; |
[email protected] | d2202e2 | 2014-04-14 20:20:53 | [diff] [blame] | 311 | params.trusted_source = true; |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 312 | return params; |
| 313 | } |
| 314 | |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 315 | //////////////////////////////////////////////////////////////////////////////// |
| 316 | // Browser, InterstitialObserver: |
| 317 | |
| 318 | class Browser::InterstitialObserver : public content::WebContentsObserver { |
| 319 | public: |
| 320 | InterstitialObserver(Browser* browser, content::WebContents* web_contents) |
| 321 | : WebContentsObserver(web_contents), |
| 322 | browser_(browser) { |
| 323 | } |
| 324 | |
dcheng | 5dd5ff6 | 2014-10-21 12:42:38 | [diff] [blame] | 325 | void DidAttachInterstitialPage() override { |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 326 | browser_->UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
| 327 | } |
| 328 | |
dcheng | 5dd5ff6 | 2014-10-21 12:42:38 | [diff] [blame] | 329 | void DidDetachInterstitialPage() override { |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 330 | browser_->UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
| 331 | } |
| 332 | |
| 333 | private: |
| 334 | Browser* browser_; |
| 335 | |
| 336 | DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); |
| 337 | }; |
| 338 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 339 | /////////////////////////////////////////////////////////////////////////////// |
| 340 | // Browser, Constructors, Creation, Showing: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 341 | |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 342 | Browser::Browser(const CreateParams& params) |
jitendra.ks | a005553 | 2014-10-07 05:54:46 | [diff] [blame] | 343 | : extension_registry_observer_(this), |
| 344 | type_(params.type), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 345 | profile_(params.profile), |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 346 | window_(NULL), |
[email protected] | d4b2d23 | 2013-04-30 21:14:23 | [diff] [blame] | 347 | tab_strip_model_delegate_(new chrome::BrowserTabStripModelDelegate(this)), |
jitendra.ks | a005553 | 2014-10-07 05:54:46 | [diff] [blame] | 348 | tab_strip_model_( |
| 349 | new TabStripModel(tab_strip_model_delegate_.get(), params.profile)), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 350 | app_name_(params.app_name), |
[email protected] | d2202e2 | 2014-04-14 20:20:53 | [diff] [blame] | 351 | is_trusted_source_(params.trusted_source), |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 352 | cancel_download_confirmation_state_(NOT_PROMPTED), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 353 | override_bounds_(params.initial_bounds), |
| 354 | initial_show_state_(params.initial_show_state), |
thomasanderson | 06405c5 | 2016-05-03 22:52:22 | [diff] [blame] | 355 | initial_workspace_(params.initial_workspace), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 356 | is_session_restore_(params.is_session_restore), |
[email protected] | d4b2d23 | 2013-04-30 21:14:23 | [diff] [blame] | 357 | content_setting_bubble_model_delegate_( |
| 358 | new BrowserContentSettingBubbleModelDelegate(this)), |
| 359 | toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)), |
blundell | bde024d | 2015-09-30 13:47:07 | [diff] [blame] | 360 | live_tab_context_(new BrowserLiveTabContext(this)), |
[email protected] | d4b2d23 | 2013-04-30 21:14:23 | [diff] [blame] | 361 | synced_window_delegate_(new BrowserSyncedWindowDelegate(this)), |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 362 | bookmark_bar_state_(BookmarkBar::HIDDEN), |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 363 | command_controller_(new chrome::BrowserCommandController(this)), |
[email protected] | 07f0f2cf | 2013-10-09 03:43:18 | [diff] [blame] | 364 | window_has_shown_(false), |
anujk.sharma | 62e915a | 2014-12-11 19:23:16 | [diff] [blame] | 365 | chrome_updater_factory_(this), |
mohan.reddy | 1f99439 | 2014-09-17 05:30:05 | [diff] [blame] | 366 | weak_factory_(this) { |
[email protected] | 3d0294ef | 2013-06-04 19:19:06 | [diff] [blame] | 367 | // If this causes a crash then a window is being opened using a profile type |
| 368 | // that is disallowed by policy. The crash prevents the disabled window type |
| 369 | // from opening at all, but the path that triggered it should be fixed. |
| 370 | CHECK(IncognitoModePrefs::CanOpenBrowser(profile_)); |
[email protected] | d5838dd | 2014-01-08 02:46:33 | [diff] [blame] | 371 | CHECK(!profile_->IsGuestSession() || profile_->IsOffTheRecord()) |
| 372 | << "Only off the record browser may be opened in guest mode"; |
mlerman | 7831f57d | 2015-05-25 11:40:15 | [diff] [blame] | 373 | DCHECK(!profile_->IsSystemProfile()) |
| 374 | << "The system profile should never have a real browser."; |
| 375 | // TODO(mlerman): After this hits stable channel, see if there are counts |
| 376 | // for this metric. If not, change the DCHECK above to a CHECK. |
| 377 | if (profile_->IsSystemProfile()) |
| 378 | content::RecordAction(base::UserMetricsAction("BrowserForSystemProfile")); |
[email protected] | 3d0294ef | 2013-06-04 19:19:06 | [diff] [blame] | 379 | |
[email protected] | 88c9201 | 2013-07-02 11:56:34 | [diff] [blame] | 380 | // TODO(jeremy): Move to initializer list once flag is removed. |
| 381 | if (IsFastTabUnloadEnabled()) |
| 382 | fast_unload_controller_.reset(new chrome::FastUnloadController(this)); |
| 383 | else |
| 384 | unload_controller_.reset(new chrome::UnloadController(this)); |
| 385 | |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 386 | tab_strip_model_->AddObserver(this); |
| 387 | |
sdefresne | 4d623d70 | 2016-02-03 20:07:57 | [diff] [blame] | 388 | toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get(), |
| 389 | content::kMaxURLDisplayChars)); |
[email protected] | 165fe42 | 2013-03-27 06:34:03 | [diff] [blame] | 390 | search_model_.reset(new SearchModel()); |
[email protected] | a40be8b | 2013-08-22 20:12:14 | [diff] [blame] | 391 | search_delegate_.reset(new SearchDelegate(search_model_.get())); |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 392 | |
jitendra.ks | a005553 | 2014-10-07 05:54:46 | [diff] [blame] | 393 | extension_registry_observer_.Add( |
| 394 | extensions::ExtensionRegistry::Get(profile_)); |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 395 | registrar_.Add(this, |
| 396 | extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 397 | content::NotificationService::AllSources()); |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 398 | #if defined(ENABLE_THEMES) |
[email protected] | ffa6f59 | 2011-06-24 22:03:57 | [diff] [blame] | 399 | registrar_.Add( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 400 | this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 401 | content::Source<ThemeService>( |
| 402 | ThemeServiceFactory::GetForProfile(profile_))); |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 403 | #endif |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 404 | registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 405 | content::NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 406 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 407 | profile_pref_registrar_.Init(profile_->GetPrefs()); |
[email protected] | c31813a | 2012-11-15 18:47:26 | [diff] [blame] | 408 | profile_pref_registrar_.Add( |
| 409 | prefs::kDevToolsDisabled, |
| 410 | base::Bind(&Browser::OnDevToolsDisabledChanged, base::Unretained(this))); |
| 411 | profile_pref_registrar_.Add( |
tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 412 | bookmarks::prefs::kShowBookmarkBar, |
[email protected] | c31813a | 2012-11-15 18:47:26 | [diff] [blame] | 413 | base::Bind(&Browser::UpdateBookmarkBarState, base::Unretained(this), |
| 414 | BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE)); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 415 | |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 416 | if (search::IsInstantExtendedAPIEnabled() && is_type_tabbed()) |
[email protected] | 165fe42 | 2013-03-27 06:34:03 | [diff] [blame] | 417 | instant_controller_.reset(new BrowserInstantController(this)); |
[email protected] | df25eb9f | 2012-09-13 17:43:23 | [diff] [blame] | 418 | |
benwells | 11bd6ed | 2015-06-05 04:20:41 | [diff] [blame] | 419 | if (extensions::HostedAppBrowserController::IsForHostedApp(this)) { |
| 420 | hosted_app_controller_.reset( |
| 421 | new extensions::HostedAppBrowserController(this)); |
benwells | a2a8a9f7 | 2015-04-07 07:09:54 | [diff] [blame] | 422 | } |
| 423 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 424 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 425 | |
[email protected] | 26e92df | 2013-04-11 16:05:21 | [diff] [blame] | 426 | ProfileMetrics::LogProfileLaunch(profile_); |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 427 | |
| 428 | window_ = params.window ? params.window : CreateBrowserWindow(this); |
| 429 | |
benwells | 11bd6ed | 2015-06-05 04:20:41 | [diff] [blame] | 430 | if (hosted_app_controller_) |
| 431 | hosted_app_controller_->UpdateLocationBarVisibility(false); |
benwells | a2a8a9f7 | 2015-04-07 07:09:54 | [diff] [blame] | 432 | |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 433 | // Create the extension window controller before sending notifications. |
| 434 | extension_window_controller_.reset( |
| 435 | new BrowserExtensionWindowController(this)); |
| 436 | |
[email protected] | 7d52ea4c6 | 2013-11-13 03:52:14 | [diff] [blame] | 437 | SessionService* session_service = |
| 438 | SessionServiceFactory::GetForProfileForSessionRestore(profile_); |
| 439 | if (session_service) |
| 440 | session_service->WindowOpened(this); |
| 441 | |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 442 | // TODO(beng): move to ChromeBrowserMain: |
[email protected] | dfcc05f | 2013-02-21 14:12:16 | [diff] [blame] | 443 | if (first_run::ShouldDoPersonalDataManagerFirstRun()) { |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 444 | #if defined(OS_WIN) |
[email protected] | dfcc05f | 2013-02-21 14:12:16 | [diff] [blame] | 445 | // Notify PDM that this is a first run. |
[email protected] | bfd4b81 | 2013-04-11 02:02:11 | [diff] [blame] | 446 | ImportAutofillDataWin( |
| 447 | autofill::PersonalDataManagerFactory::GetForProfile(profile_)); |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 448 | #endif // defined(OS_WIN) |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 449 | } |
| 450 | |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 451 | exclusive_access_manager_.reset( |
| 452 | new ExclusiveAccessManager(window_->GetExclusiveAccessContext())); |
[email protected] | 010152f | 2014-07-15 00:16:47 | [diff] [blame] | 453 | |
jackhou | 75d58b1 | 2015-07-07 08:16:01 | [diff] [blame] | 454 | // TODO(beng): Move BrowserList::AddBrowser() to the end of this function and |
| 455 | // replace uses of this with BL's notifications. |
| 456 | BrowserList::AddBrowser(this); |
| 457 | content::NotificationService::current()->Notify( |
| 458 | chrome::NOTIFICATION_BROWSER_WINDOW_READY, content::Source<Browser>(this), |
| 459 | content::NotificationService::NoDetails()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | Browser::~Browser() { |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 463 | // Stop observing notifications before continuing with destruction. Profile |
| 464 | // destruction will unload extensions and reentrant calls to Browser:: should |
| 465 | // be avoided while it is being torn down. |
| 466 | registrar_.RemoveAll(); |
jitendra.ks | a005553 | 2014-10-07 05:54:46 | [diff] [blame] | 467 | extension_registry_observer_.RemoveAll(); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 468 | |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 469 | // The tab strip should not have any tabs at this point. |
[email protected] | 050e7718 | 2014-03-25 15:29:16 | [diff] [blame] | 470 | DCHECK(tab_strip_model_->empty()); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 471 | tab_strip_model_->RemoveObserver(this); |
hcarmona | aa431c0 | 2015-08-28 18:45:57 | [diff] [blame] | 472 | bubble_manager_.reset(); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 473 | |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 474 | // Destroy the BrowserCommandController before removing the browser, so that |
| 475 | // it doesn't act on any notifications that are sent as a result of removing |
| 476 | // the browser. |
| 477 | command_controller_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 478 | BrowserList::RemoveBrowser(this); |
| 479 | |
[email protected] | bdc6ccd1 | 2012-03-20 22:06:13 | [diff] [blame] | 480 | SessionService* session_service = |
| 481 | SessionServiceFactory::GetForProfile(profile_); |
| 482 | if (session_service) |
| 483 | session_service->WindowClosed(session_id_); |
| 484 | |
blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 485 | sessions::TabRestoreService* tab_restore_service = |
[email protected] | bdc6ccd1 | 2012-03-20 22:06:13 | [diff] [blame] | 486 | TabRestoreServiceFactory::GetForProfile(profile()); |
| 487 | if (tab_restore_service) |
blundell | bde024d | 2015-09-30 13:47:07 | [diff] [blame] | 488 | tab_restore_service->BrowserClosed(live_tab_context()); |
[email protected] | bdc6ccd1 | 2012-03-20 22:06:13 | [diff] [blame] | 489 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 490 | profile_pref_registrar_.RemoveAll(); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 491 | |
[email protected] | fb0f9ebc | 2013-05-22 06:25:42 | [diff] [blame] | 492 | // Destroy BrowserExtensionWindowController before the incognito profile |
| 493 | // is destroyed to make sure the chrome.windows.onRemoved event is sent. |
| 494 | extension_window_controller_.reset(); |
| 495 | |
[email protected] | 6af4178 | 2013-06-22 13:49:11 | [diff] [blame] | 496 | // Destroy BrowserInstantController before the incongnito profile is destroyed |
| 497 | // because the InstantController destructor depends on this profile. |
| 498 | instant_controller_.reset(); |
| 499 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 500 | if (profile_->IsOffTheRecord() && |
trizzofo | 49b95f5 | 2016-07-02 00:26:13 | [diff] [blame] | 501 | !BrowserList::IsIncognitoSessionActiveForProfile(profile_)) { |
mlerman | 67fa17a | 2015-02-13 21:59:22 | [diff] [blame] | 502 | if (profile_->IsGuestSession()) { |
| 503 | // ChromeOS handles guest data independently. |
| 504 | #if !defined(OS_CHROMEOS) |
| 505 | // Clear all browsing data once a Guest Session completes. The Guest |
| 506 | // profile has BrowserContextKeyedServices that the Incognito profile |
| 507 | // doesn't, so the ProfileDestroyer can't delete it properly. |
| 508 | // TODO(mlerman): Delete the guest using an improved ProfileDestroyer. |
mlerman | 2c1c378 | 2015-04-23 18:37:43 | [diff] [blame] | 509 | profiles::RemoveBrowsingDataForProfile(profile_->GetPath()); |
mlerman | 67fa17a | 2015-02-13 21:59:22 | [diff] [blame] | 510 | #endif |
| 511 | } else { |
| 512 | // An incognito profile is no longer needed, this indirectly frees |
| 513 | // its cache and cookies once it gets destroyed at the appropriate time. |
| 514 | ProfileDestroyer::DestroyProfileWhenAppropriate(profile_); |
| 515 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | // There may be pending file dialogs, we need to tell them that we've gone |
| 519 | // away so they don't try and call back to us. |
| 520 | if (select_file_dialog_.get()) |
| 521 | select_file_dialog_->ListenerDestroyed(); |
[email protected] | 5fec470 | 2013-11-20 04:37:38 | [diff] [blame] | 522 | |
| 523 | int num_downloads; |
| 524 | if (OkToCloseWithInProgressDownloads(&num_downloads) == |
| 525 | DOWNLOAD_CLOSE_BROWSER_SHUTDOWN && |
| 526 | !browser_defaults::kBrowserAliveWithNoWindows) { |
| 527 | DownloadService::CancelAllDownloads(); |
| 528 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 529 | } |
| 530 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 531 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 532 | // Getters & Setters |
| 533 | |
hcarmona | aa431c0 | 2015-08-28 18:45:57 | [diff] [blame] | 534 | ChromeBubbleManager* Browser::GetBubbleManager() { |
| 535 | if (!bubble_manager_) |
| 536 | bubble_manager_.reset(new ChromeBubbleManager(tab_strip_model_.get())); |
| 537 | return bubble_manager_.get(); |
| 538 | } |
| 539 | |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 540 | FindBarController* Browser::GetFindBarController() { |
| 541 | if (!find_bar_controller_.get()) { |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 542 | FindBar* find_bar = window_->CreateFindBar(); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 543 | find_bar_controller_.reset(new FindBarController(find_bar)); |
| 544 | find_bar->SetFindBarController(find_bar_controller_.get()); |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 545 | find_bar_controller_->ChangeWebContents( |
| 546 | tab_strip_model_->GetActiveWebContents()); |
andresantoso | 6a7691b | 2014-12-10 23:37:41 | [diff] [blame] | 547 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect()); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 548 | } |
| 549 | return find_bar_controller_.get(); |
| 550 | } |
| 551 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 552 | bool Browser::HasFindBarController() const { |
| 553 | return find_bar_controller_.get() != NULL; |
| 554 | } |
| 555 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 556 | bool Browser::is_app() const { |
| 557 | return !app_name_.empty(); |
| 558 | } |
| 559 | |
| 560 | bool Browser::is_devtools() const { |
| 561 | return app_name_ == DevToolsWindow::kDevToolsApp; |
| 562 | } |
| 563 | |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 564 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 565 | // Browser, State Storage and Retrieval for UI: |
| 566 | |
[email protected] | 9b125b73 | 2012-08-17 04:43:55 | [diff] [blame] | 567 | gfx::Image Browser::GetCurrentPageIcon() const { |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 568 | WebContents* web_contents = tab_strip_model_->GetActiveWebContents(); |
[email protected] | 502b561 | 2012-10-02 01:33:10 | [diff] [blame] | 569 | // |web_contents| can be NULL since GetCurrentPageIcon() is called by the |
| 570 | // window during the window's creation (before tabs have been added). |
sdefresne | 45582697 | 2015-04-10 15:25:15 | [diff] [blame] | 571 | favicon::FaviconDriver* favicon_driver = |
| 572 | web_contents |
| 573 | ? favicon::ContentFaviconDriver::FromWebContents(web_contents) |
| 574 | : nullptr; |
| 575 | return favicon_driver ? favicon_driver->GetFavicon() : gfx::Image(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 576 | } |
| 577 | |
varkha | 48f84c4b | 2016-06-27 18:10:33 | [diff] [blame] | 578 | base::string16 Browser::GetWindowTitleForCurrentTab( |
| 579 | bool include_app_name) const { |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 580 | WebContents* contents = tab_strip_model_->GetActiveWebContents(); |
[email protected] | dcd024987 | 2013-12-06 23:58:45 | [diff] [blame] | 581 | base::string16 title; |
[email protected] | c7c4233 | 2008-11-15 01:10:54 | [diff] [blame] | 582 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 583 | // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the |
| 584 | // window during the window's creation (before tabs have been added). |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 585 | if (contents) { |
benwells | 502df69 | 2014-12-02 20:41:45 | [diff] [blame] | 586 | // The web app frame uses the host instead of the title. |
| 587 | if (ShouldUseWebAppFrame()) |
[email protected] | f53ec988d | 2014-08-22 01:38:09 | [diff] [blame] | 588 | return base::UTF8ToUTF16(contents->GetURL().host()); |
[email protected] | f53ec988d | 2014-08-22 01:38:09 | [diff] [blame] | 589 | |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 590 | title = contents->GetTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 591 | FormatTitleForDisplay(&title); |
| 592 | } |
| 593 | if (title.empty()) |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 594 | title = CoreTabHelper::GetDefaultTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 595 | |
varkha | 48f84c4b | 2016-06-27 18:10:33 | [diff] [blame] | 596 | #if defined(OS_MACOSX) |
| 597 | // On Mac, we don't want to suffix the page title with the application name. |
[email protected] | d904bc8 | 2009-07-07 00:41:04 | [diff] [blame] | 598 | return title; |
[email protected] | 82b9ed8 | 2012-11-15 02:43:18 | [diff] [blame] | 599 | #endif |
varkha | 48f84c4b | 2016-06-27 18:10:33 | [diff] [blame] | 600 | // Include the app name in window titles for tabbed browser windows when |
| 601 | // requested with |include_app_name|. |
| 602 | return (!is_app() && include_app_name) ? |
| 603 | l10n_util::GetStringFUTF16(IDS_BROWSER_WINDOW_TITLE_FORMAT, title): |
| 604 | title; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | // static |
[email protected] | dcd024987 | 2013-12-06 23:58:45 | [diff] [blame] | 608 | void Browser::FormatTitleForDisplay(base::string16* title) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 609 | size_t current_index = 0; |
| 610 | size_t match_index; |
[email protected] | dcd024987 | 2013-12-06 23:58:45 | [diff] [blame] | 611 | while ((match_index = title->find(L'\n', current_index)) != |
| 612 | base::string16::npos) { |
| 613 | title->replace(match_index, 1, base::string16()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 614 | current_index = match_index; |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | /////////////////////////////////////////////////////////////////////////////// |
| 619 | // Browser, OnBeforeUnload handling: |
| 620 | |
| 621 | bool Browser::ShouldCloseWindow() { |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 622 | if (!CanCloseWithInProgressDownloads()) |
| 623 | return false; |
| 624 | |
[email protected] | 88c9201 | 2013-07-02 11:56:34 | [diff] [blame] | 625 | if (IsFastTabUnloadEnabled()) |
| 626 | return fast_unload_controller_->ShouldCloseWindow(); |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 627 | return unload_controller_->ShouldCloseWindow(); |
| 628 | } |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 629 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 630 | bool Browser::CallBeforeUnloadHandlers( |
| 631 | const base::Callback<void(bool)>& on_close_confirmed) { |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 632 | cancel_download_confirmation_state_ = RESPONSE_RECEIVED; |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 633 | if (IsFastTabUnloadEnabled()) { |
| 634 | return fast_unload_controller_->CallBeforeUnloadHandlers( |
| 635 | on_close_confirmed); |
| 636 | } |
| 637 | return unload_controller_->CallBeforeUnloadHandlers(on_close_confirmed); |
| 638 | } |
| 639 | |
| 640 | void Browser::ResetBeforeUnloadHandlers() { |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 641 | cancel_download_confirmation_state_ = NOT_PROMPTED; |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 642 | if (IsFastTabUnloadEnabled()) |
| 643 | fast_unload_controller_->ResetBeforeUnloadHandlers(); |
| 644 | else |
| 645 | unload_controller_->ResetBeforeUnloadHandlers(); |
| 646 | } |
| 647 | |
[email protected] | 88c9201 | 2013-07-02 11:56:34 | [diff] [blame] | 648 | bool Browser::HasCompletedUnloadProcessing() const { |
| 649 | DCHECK(IsFastTabUnloadEnabled()); |
| 650 | return fast_unload_controller_->HasCompletedUnloadProcessing(); |
| 651 | } |
| 652 | |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 653 | bool Browser::IsAttemptingToCloseBrowser() const { |
[email protected] | 88c9201 | 2013-07-02 11:56:34 | [diff] [blame] | 654 | if (IsFastTabUnloadEnabled()) |
| 655 | return fast_unload_controller_->is_attempting_to_close_browser(); |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 656 | return unload_controller_->is_attempting_to_close_browser(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 657 | } |
| 658 | |
changwan | 6ed4d43 | 2016-05-19 22:03:54 | [diff] [blame] | 659 | bool Browser::ShouldRunUnloadListenerBeforeClosing( |
| 660 | content::WebContents* web_contents) { |
| 661 | if (IsFastTabUnloadEnabled()) |
| 662 | return fast_unload_controller_->ShouldRunUnloadEventsHelper(web_contents); |
| 663 | return unload_controller_->ShouldRunUnloadEventsHelper(web_contents); |
| 664 | } |
| 665 | |
| 666 | bool Browser::RunUnloadListenerBeforeClosing( |
| 667 | content::WebContents* web_contents) { |
| 668 | if (IsFastTabUnloadEnabled()) |
| 669 | return fast_unload_controller_->RunUnloadEventsHelper(web_contents); |
| 670 | return unload_controller_->RunUnloadEventsHelper(web_contents); |
| 671 | } |
| 672 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 673 | void Browser::OnWindowClosing() { |
| 674 | if (!ShouldCloseWindow()) |
| 675 | return; |
| 676 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 677 | // Application should shutdown on last window close if the user is explicitly |
| 678 | // trying to quit, or if there is nothing keeping the browser alive (such as |
| 679 | // AppController on the Mac, or BackgroundContentsService for background |
| 680 | // pages). |
| 681 | bool should_quit_if_last_browser = |
dgn | 0237778 | 2016-03-12 00:58:38 | [diff] [blame] | 682 | browser_shutdown::IsTryingToQuit() || |
| 683 | !KeepAliveRegistry::GetInstance()->IsKeepingAlive(); |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 684 | |
thestig | 02897869 | 2015-10-08 07:39:40 | [diff] [blame] | 685 | if (should_quit_if_last_browser && ShouldStartShutdown()) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 686 | browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); |
| 687 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 688 | // Don't use GetForProfileIfExisting here, we want to force creation of the |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 689 | // session service so that user can restore what was open. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 690 | SessionService* session_service = |
| 691 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 692 | if (session_service) |
| 693 | session_service->WindowClosing(session_id()); |
| 694 | |
blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 695 | sessions::TabRestoreService* tab_restore_service = |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 696 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 697 | |
| 698 | #if defined(USE_AURA) |
[email protected] | d019fa58 | 2013-11-04 23:45:49 | [diff] [blame] | 699 | if (tab_restore_service && is_app() && !is_devtools()) |
blundell | bde024d | 2015-09-30 13:47:07 | [diff] [blame] | 700 | tab_restore_service->BrowserClosing(live_tab_context()); |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 701 | #endif |
| 702 | |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 703 | if (tab_restore_service && is_type_tabbed() && tab_strip_model_->count()) |
blundell | bde024d | 2015-09-30 13:47:07 | [diff] [blame] | 704 | tab_restore_service->BrowserClosing(live_tab_context()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 705 | |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 706 | // TODO(sky): convert session/tab restore to use notification. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 707 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 708 | chrome::NOTIFICATION_BROWSER_CLOSING, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 709 | content::Source<Browser>(this), |
[email protected] | 1e0c740 | 2012-07-27 10:48:15 | [diff] [blame] | 710 | content::NotificationService::NoDetails()); |
[email protected] | ed1bb720 | 2013-06-21 05:16:44 | [diff] [blame] | 711 | |
[email protected] | 88c9201 | 2013-07-02 11:56:34 | [diff] [blame] | 712 | if (!IsFastTabUnloadEnabled()) |
| 713 | tab_strip_model_->CloseAllTabs(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 714 | } |
| 715 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 716 | //////////////////////////////////////////////////////////////////////////////// |
| 717 | // In-progress download termination handling: |
| 718 | |
| 719 | void Browser::InProgressDownloadResponse(bool cancel_downloads) { |
| 720 | if (cancel_downloads) { |
| 721 | cancel_download_confirmation_state_ = RESPONSE_RECEIVED; |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 722 | chrome::CloseWindow(this); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 723 | return; |
| 724 | } |
| 725 | |
| 726 | // Sets the confirmation state to NOT_PROMPTED so that if the user tries to |
| 727 | // close again we'll show the warning again. |
| 728 | cancel_download_confirmation_state_ = NOT_PROMPTED; |
| 729 | |
| 730 | // Show the download page so the user can figure-out what downloads are still |
| 731 | // in-progress. |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 732 | chrome::ShowDownloads(this); |
[email protected] | 674b65fb | 2014-02-19 02:43:42 | [diff] [blame] | 733 | |
| 734 | // Reset UnloadController::is_attempting_to_close_browser_ so that we don't |
| 735 | // prompt every time any tab is closed. http://crbug.com/305516 |
| 736 | if (IsFastTabUnloadEnabled()) |
| 737 | fast_unload_controller_->CancelWindowClose(); |
| 738 | else |
| 739 | unload_controller_->CancelWindowClose(); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 740 | } |
| 741 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 742 | Browser::DownloadClosePreventionType Browser::OkToCloseWithInProgressDownloads( |
| 743 | int* num_downloads_blocking) const { |
| 744 | DCHECK(num_downloads_blocking); |
| 745 | *num_downloads_blocking = 0; |
| 746 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 747 | // If we're not running a full browser process with a profile manager |
| 748 | // (testing), it's ok to close the browser. |
| 749 | if (!g_browser_process->profile_manager()) |
| 750 | return DOWNLOAD_CLOSE_OK; |
| 751 | |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 752 | int total_download_count = |
| 753 | DownloadService::NonMaliciousDownloadCountAllProfiles(); |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 754 | if (total_download_count == 0) |
| 755 | return DOWNLOAD_CLOSE_OK; // No downloads; can definitely close. |
| 756 | |
| 757 | // Figure out how many windows are open total, and associated with this |
| 758 | // profile, that are relevant for the ok-to-close decision. |
| 759 | int profile_window_count = 0; |
| 760 | int total_window_count = 0; |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 761 | for (auto* browser : *BrowserList::GetInstance()) { |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 762 | // Don't count this browser window or any other in the process of closing. |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 763 | // Window closing may be delayed, and windows that are in the process of |
| 764 | // closing don't count against our totals. |
| 765 | if (browser == this || browser->IsAttemptingToCloseBrowser()) |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 766 | continue; |
| 767 | |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 768 | if (browser->profile() == profile()) |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 769 | profile_window_count++; |
| 770 | total_window_count++; |
| 771 | } |
| 772 | |
| 773 | // If there aren't any other windows, we're at browser shutdown, |
| 774 | // which would cancel all current downloads. |
| 775 | if (total_window_count == 0) { |
| 776 | *num_downloads_blocking = total_download_count; |
| 777 | return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN; |
| 778 | } |
| 779 | |
| 780 | // If there aren't any other windows on our profile, and we're an incognito |
| 781 | // profile, and there are downloads associated with that profile, |
| 782 | // those downloads would be cancelled by our window (-> profile) close. |
| 783 | DownloadService* download_service = |
[email protected] | 423939d | 2013-07-31 20:00:08 | [diff] [blame] | 784 | DownloadServiceFactory::GetForBrowserContext(profile()); |
[email protected] | d07d63fc | 2013-07-18 19:44:54 | [diff] [blame] | 785 | if ((profile_window_count == 0) && |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 786 | (download_service->NonMaliciousDownloadCount() > 0) && |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 787 | profile()->IsOffTheRecord()) { |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 788 | *num_downloads_blocking = download_service->NonMaliciousDownloadCount(); |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 789 | return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE; |
| 790 | } |
| 791 | |
| 792 | // Those are the only conditions under which we will block shutdown. |
| 793 | return DOWNLOAD_CLOSE_OK; |
| 794 | } |
| 795 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 796 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 797 | // Browser, Tab adding/showing functions: |
| 798 | |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 799 | void Browser::WindowFullscreenStateChanged() { |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 800 | exclusive_access_manager_->fullscreen_controller() |
| 801 | ->WindowFullscreenStateChanged(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 802 | command_controller_->FullscreenStateChanged(); |
[email protected] | 9adb8b1 | 2011-12-09 06:49:13 | [diff] [blame] | 803 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 804 | } |
| 805 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 806 | /////////////////////////////////////////////////////////////////////////////// |
| 807 | // Browser, Assorted browser commands: |
| 808 | |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 809 | void Browser::ToggleFullscreenModeWithExtension(const GURL& extension_url) { |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 810 | exclusive_access_manager_->fullscreen_controller() |
| 811 | ->ToggleBrowserFullscreenModeWithExtension(extension_url); |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 812 | } |
| 813 | |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 814 | bool Browser::SupportsWindowFeature(WindowFeature feature) const { |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 815 | return SupportsWindowFeatureImpl(feature, true); |
| 816 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 817 | |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 818 | bool Browser::CanSupportWindowFeature(WindowFeature feature) const { |
| 819 | return SupportsWindowFeatureImpl(feature, false); |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 820 | } |
| 821 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 822 | void Browser::OpenFile() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 823 | content::RecordAction(UserMetricsAction("OpenFile")); |
[email protected] | 92f5408 | 2012-07-31 01:43:14 | [diff] [blame] | 824 | select_file_dialog_ = ui::SelectFileDialog::Create( |
[email protected] | 6e1fcd1 | 2012-07-02 17:14:20 | [diff] [blame] | 825 | this, new ChromeSelectFilePolicy( |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 826 | tab_strip_model_->GetActiveWebContents())); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 827 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 828 | const base::FilePath directory = profile_->last_selected_directory(); |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 829 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 830 | // TODO(beng): figure out how to juggle this. |
[email protected] | 90556dd | 2012-06-07 20:26:18 | [diff] [blame] | 831 | gfx::NativeWindow parent_window = window_->GetNativeWindow(); |
[email protected] | 479cce78 | 2012-09-15 20:15:53 | [diff] [blame] | 832 | ui::SelectFileDialog::FileTypeInfo file_types; |
hirono | 4d4d339 | 2016-02-04 05:03:50 | [diff] [blame] | 833 | file_types.allowed_paths = ui::SelectFileDialog::FileTypeInfo::ANY_PATH; |
[email protected] | 92f5408 | 2012-07-31 01:43:14 | [diff] [blame] | 834 | select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE, |
[email protected] | dcd024987 | 2013-12-06 23:58:45 | [diff] [blame] | 835 | base::string16(), |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 836 | directory, |
| 837 | &file_types, |
| 838 | 0, |
| 839 | base::FilePath::StringType(), |
| 840 | parent_window, |
| 841 | NULL); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 842 | } |
| 843 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 844 | void Browser::UpdateDownloadShelfVisibility(bool visible) { |
| 845 | if (GetStatusBubble()) |
| 846 | GetStatusBubble()->UpdateDownloadShelfVisibility(visible); |
| 847 | } |
| 848 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 849 | /////////////////////////////////////////////////////////////////////////////// |
| 850 | |
erikchen | 0de48e1 | 2016-08-30 22:46:32 | [diff] [blame] | 851 | void Browser::UpdateUIForNavigationInTab( |
| 852 | WebContents* contents, |
| 853 | ui::PageTransition transition, |
| 854 | chrome::NavigateParams::WindowAction action, |
| 855 | bool user_initiated) { |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 856 | tab_strip_model_->TabNavigating(contents, transition); |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 857 | |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 858 | bool contents_is_selected = |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 859 | contents == tab_strip_model_->GetActiveWebContents(); |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 860 | if (user_initiated && contents_is_selected && window()->GetLocationBar()) { |
| 861 | // Forcibly reset the location bar if the url is going to change in the |
| 862 | // current tab, since otherwise it won't discard any ongoing user edits, |
| 863 | // since it doesn't realize this is a user-initiated action. |
| 864 | window()->GetLocationBar()->Revert(); |
| 865 | } |
| 866 | |
| 867 | if (GetStatusBubble()) |
| 868 | GetStatusBubble()->Hide(); |
| 869 | |
| 870 | // Update the location bar. This is synchronous. We specifically don't |
| 871 | // update the load state since the load hasn't started yet and updating it |
| 872 | // will put it out of sync with the actual state like whether we're |
| 873 | // displaying a favicon, which controls the throbber. If we updated it here, |
| 874 | // the throbber will show the default favicon for a split second when |
| 875 | // navigating away from the new tab page. |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 876 | ScheduleUIUpdate(contents, content::INVALIDATE_TYPE_URL); |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 877 | |
erikchen | 0de48e1 | 2016-08-30 22:46:32 | [diff] [blame] | 878 | if (contents_is_selected && |
| 879 | (window()->IsActive() || action == chrome::NavigateParams::SHOW_WINDOW)) { |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 880 | contents->SetInitialFocus(); |
erikchen | 0de48e1 | 2016-08-30 22:46:32 | [diff] [blame] | 881 | } |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 882 | } |
| 883 | |
anthonyvd | e659ee9 | 2016-02-04 23:16:56 | [diff] [blame] | 884 | void Browser::ShowModalSigninWindow(profiles::BubbleViewMode mode, |
| 885 | signin_metrics::AccessPoint access_point) { |
| 886 | signin_view_controller_.ShowModalSignin(mode, this, access_point); |
| 887 | } |
| 888 | |
| 889 | void Browser::CloseModalSigninWindow() { |
| 890 | signin_view_controller_.CloseModalSignin(); |
| 891 | } |
| 892 | |
| 893 | void Browser::ShowModalSyncConfirmationWindow() { |
| 894 | signin_view_controller_.ShowModalSyncConfirmationDialog(this); |
| 895 | } |
| 896 | |
anthonyvd | 0abc347 | 2016-09-27 15:41:05 | [diff] [blame] | 897 | void Browser::ShowModalSigninErrorWindow() { |
| 898 | signin_view_controller_.ShowModalSigninErrorDialog(this); |
| 899 | } |
| 900 | |
dgn | fe075c8 | 2016-03-18 11:25:35 | [diff] [blame] | 901 | void Browser::RegisterKeepAlive() { |
| 902 | keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::BROWSER, |
| 903 | KeepAliveRestartOption::DISABLED)); |
| 904 | } |
| 905 | void Browser::UnregisterKeepAlive() { |
| 906 | keep_alive_.reset(); |
| 907 | } |
| 908 | |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 909 | /////////////////////////////////////////////////////////////////////////////// |
| 910 | // Browser, PageNavigator implementation: |
| 911 | |
| 912 | WebContents* Browser::OpenURL(const OpenURLParams& params) { |
| 913 | return OpenURLFromTab(NULL, params); |
| 914 | } |
| 915 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 916 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 917 | // Browser, TabStripModelObserver implementation: |
| 918 | |
pmonette | 9119e49 | 2016-09-20 22:14:55 | [diff] [blame] | 919 | void Browser::TabInsertedAt(TabStripModel* tab_strip_model, |
| 920 | WebContents* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 921 | int index, |
| 922 | bool foreground) { |
[email protected] | 63d1f9b | 2014-07-05 19:09:03 | [diff] [blame] | 923 | SetAsDelegate(contents, true); |
[email protected] | 010152f | 2014-07-15 00:16:47 | [diff] [blame] | 924 | |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 925 | SessionTabHelper* session_tab_helper = |
[email protected] | 409ea297 | 2012-11-10 19:54:43 | [diff] [blame] | 926 | SessionTabHelper::FromWebContents(contents); |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 927 | session_tab_helper->SetWindowID(session_id()); |
[email protected] | e524ff9 | 2011-03-30 13:26:58 | [diff] [blame] | 928 | |
[email protected] | fb312eb | 2012-09-24 23:21:10 | [diff] [blame] | 929 | content::NotificationService::current()->Notify( |
| 930 | chrome::NOTIFICATION_TAB_PARENTED, |
[email protected] | 409ea297 | 2012-11-10 19:54:43 | [diff] [blame] | 931 | content::Source<content::WebContents>(contents), |
[email protected] | fb312eb | 2012-09-24 23:21:10 | [diff] [blame] | 932 | content::NotificationService::NoDetails()); |
| 933 | |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 934 | SyncHistoryWithTabs(index); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 935 | |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 936 | // Make sure the loading state is updated correctly, otherwise the throbber |
| 937 | // won't start if the page is loading. |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 938 | LoadingStateChanged(contents, true); |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 939 | |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 940 | interstitial_observers_.push_back(new InterstitialObserver(this, contents)); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 941 | |
[email protected] | 4060015 | 2012-09-26 10:04:31 | [diff] [blame] | 942 | SessionService* session_service = |
| 943 | SessionServiceFactory::GetForProfile(profile_); |
[email protected] | d4c9caa | 2013-04-22 18:30:32 | [diff] [blame] | 944 | if (session_service) { |
[email protected] | 409ea297 | 2012-11-10 19:54:43 | [diff] [blame] | 945 | session_service->TabInserted(contents); |
[email protected] | d4c9caa | 2013-04-22 18:30:32 | [diff] [blame] | 946 | int new_active_index = tab_strip_model_->active_index(); |
| 947 | if (index < new_active_index) |
| 948 | session_service->SetSelectedTabInWindow(session_id(), |
| 949 | new_active_index); |
| 950 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 951 | } |
| 952 | |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 953 | void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
[email protected] | 0be097d | 2012-11-10 00:20:16 | [diff] [blame] | 954 | WebContents* contents, |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 955 | int index) { |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 956 | exclusive_access_manager_->OnTabClosing(contents); |
[email protected] | 4060015 | 2012-09-26 10:04:31 | [diff] [blame] | 957 | SessionService* session_service = |
| 958 | SessionServiceFactory::GetForProfile(profile_); |
| 959 | if (session_service) |
[email protected] | 0be097d | 2012-11-10 00:20:16 | [diff] [blame] | 960 | session_service->TabClosing(contents); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 961 | content::NotificationService::current()->Notify( |
[email protected] | 884033e | 2012-04-16 19:38:42 | [diff] [blame] | 962 | chrome::NOTIFICATION_TAB_CLOSING, |
[email protected] | 0be097d | 2012-11-10 00:20:16 | [diff] [blame] | 963 | content::Source<NavigationController>(&contents->GetController()), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 964 | content::NotificationService::NoDetails()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 965 | |
[email protected] | 075969d | 2012-04-17 20:05:55 | [diff] [blame] | 966 | // Sever the WebContents' connection back to us. |
[email protected] | 63d1f9b | 2014-07-05 19:09:03 | [diff] [blame] | 967 | SetAsDelegate(contents, false); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 968 | } |
| 969 | |
[email protected] | e89cfcb | 2012-11-11 14:47:24 | [diff] [blame] | 970 | void Browser::TabDetachedAt(WebContents* contents, int index) { |
[email protected] | d4c9caa | 2013-04-22 18:30:32 | [diff] [blame] | 971 | // TabDetachedAt is called before TabStripModel has updated the |
| 972 | // active index. |
| 973 | int old_active_index = tab_strip_model_->active_index(); |
| 974 | if (index < old_active_index && !tab_strip_model_->closing_all()) { |
| 975 | SessionService* session_service = |
| 976 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 977 | if (session_service) |
| 978 | session_service->SetSelectedTabInWindow(session_id(), |
| 979 | old_active_index - 1); |
| 980 | } |
[email protected] | 010152f | 2014-07-15 00:16:47 | [diff] [blame] | 981 | |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 982 | TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 983 | } |
| 984 | |
[email protected] | 023c01cc | 2012-11-12 15:41:11 | [diff] [blame] | 985 | void Browser::TabDeactivated(WebContents* contents) { |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 986 | exclusive_access_manager_->OnTabDeactivated(contents); |
[email protected] | 023c01cc | 2012-11-12 15:41:11 | [diff] [blame] | 987 | search_delegate_->OnTabDeactivated(contents); |
[email protected] | 549f62b | 2013-10-26 12:54:42 | [diff] [blame] | 988 | SearchTabHelper::FromWebContents(contents)->OnTabDeactivated(); |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 989 | |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 990 | // Save what the user's currently typing, so it can be restored when we |
| 991 | // switch back to this tab. |
[email protected] | 023c01cc | 2012-11-12 15:41:11 | [diff] [blame] | 992 | window_->GetLocationBar()->SaveStateToContents(contents); |
[email protected] | 3d6a895 | 2012-12-14 03:18:07 | [diff] [blame] | 993 | |
| 994 | if (instant_controller_) |
| 995 | instant_controller_->TabDeactivated(contents); |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 996 | } |
| 997 | |
[email protected] | 8e70779 | 2012-11-13 10:32:12 | [diff] [blame] | 998 | void Browser::ActiveTabChanged(WebContents* old_contents, |
| 999 | WebContents* new_contents, |
[email protected] | 3aca95d4 | 2011-05-24 22:06:54 | [diff] [blame] | 1000 | int index, |
[email protected] | 5f2de24 | 2013-04-05 02:06:07 | [diff] [blame] | 1001 | int reason) { |
[email protected] | d500b1c3 | 2013-03-12 06:26:08 | [diff] [blame] | 1002 | content::RecordAction(UserMetricsAction("ActiveTabChanged")); |
| 1003 | |
[email protected] | da9ac4ee | 2013-10-02 12:19:05 | [diff] [blame] | 1004 | // Update the bookmark state, since the BrowserWindow may query it during |
| 1005 | // OnActiveTabChanged() below. |
| 1006 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); |
| 1007 | |
| 1008 | // Let the BrowserWindow do its handling. On e.g. views this changes the |
| 1009 | // focused object, which should happen before we update the toolbar below, |
[email protected] | 08726d5e | 2013-09-24 21:52:55 | [diff] [blame] | 1010 | // since the omnibox expects the correct element to already be focused when it |
| 1011 | // is updated. |
| 1012 | window_->OnActiveTabChanged(old_contents, new_contents, index, reason); |
| 1013 | |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 1014 | exclusive_access_manager_->OnTabDetachedFromView(old_contents); |
[email protected] | 949f62a3 | 2014-02-13 00:53:10 | [diff] [blame] | 1015 | |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 1016 | // Discarded tabs always get reloaded. |
georgesak | 6fc95e9 | 2015-10-26 21:27:06 | [diff] [blame] | 1017 | // TODO(georgesak): Validate the usefulness of this. And if needed then move |
| 1018 | // to TabManager. |
andersoncss | 23ac43b | 2016-08-16 20:23:02 | [diff] [blame] | 1019 | if (g_browser_process->GetTabManager()->IsTabDiscarded(new_contents)) |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 1020 | chrome::Reload(this, WindowOpenDisposition::CURRENT_TAB); |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 1021 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1022 | // If we have any update pending, do it now. |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1023 | if (chrome_updater_factory_.HasWeakPtrs() && old_contents) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1024 | ProcessPendingUIUpdates(); |
| 1025 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1026 | // Propagate the profile to the location bar. |
[email protected] | 9bc3f24 | 2013-04-05 23:27:36 | [diff] [blame] | 1027 | UpdateToolbar((reason & CHANGE_REASON_REPLACED) == 0); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1028 | |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1029 | if (search::IsInstantExtendedAPIEnabled()) |
[email protected] | 8845bb4 | 2013-10-29 00:36:29 | [diff] [blame] | 1030 | search_delegate_->OnTabActivated(new_contents); |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 1031 | |
[email protected] | 943d812 | 2010-06-11 02:13:45 | [diff] [blame] | 1032 | // Update reload/stop state. |
[email protected] | 8e70779 | 2012-11-13 10:32:12 | [diff] [blame] | 1033 | command_controller_->LoadingStateChanged(new_contents->IsLoading(), true); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1034 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1035 | // Update commands to reflect current state. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1036 | command_controller_->TabStateChanged(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1037 | |
| 1038 | // Reset the status bubble. |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1039 | StatusBubble* status_bubble = GetStatusBubble(); |
| 1040 | if (status_bubble) { |
| 1041 | status_bubble->Hide(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1042 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1043 | // Show the loading state (if any). |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 1044 | status_bubble->SetStatus(CoreTabHelper::FromWebContents( |
| 1045 | tab_strip_model_->GetActiveWebContents())->GetStatusText()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1046 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1047 | |
[email protected] | 826eabe1 | 2013-09-30 20:33:38 | [diff] [blame] | 1048 | if (HasFindBarController()) { |
| 1049 | find_bar_controller_->ChangeWebContents(new_contents); |
andresantoso | 6a7691b | 2014-12-10 23:37:41 | [diff] [blame] | 1050 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect()); |
[email protected] | 826eabe1 | 2013-09-30 20:33:38 | [diff] [blame] | 1051 | } |
| 1052 | |
georgesak | 5582cbe | 2015-05-22 22:08:07 | [diff] [blame] | 1053 | // Update sessions (selected tab index and last active time). Don't force |
| 1054 | // creation of sessions. If sessions doesn't exist, the change will be picked |
| 1055 | // up by sessions when created. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1056 | SessionService* session_service = |
| 1057 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1058 | if (session_service && !tab_strip_model_->closing_all()) { |
[email protected] | 04e3ead5 | 2013-01-14 01:09:20 | [diff] [blame] | 1059 | session_service->SetSelectedTabInWindow(session_id(), |
| 1060 | tab_strip_model_->active_index()); |
chrisha | 0598fc31 | 2016-01-07 20:40:41 | [diff] [blame] | 1061 | SessionTabHelper* session_tab_helper = |
| 1062 | SessionTabHelper::FromWebContents(new_contents); |
| 1063 | session_service->SetLastActiveTime(session_id(), |
| 1064 | session_tab_helper->session_id(), |
| 1065 | base::TimeTicks::Now()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1066 | } |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1067 | |
[email protected] | 8845bb4 | 2013-10-29 00:36:29 | [diff] [blame] | 1068 | // This needs to be called after notifying SearchDelegate. |
[email protected] | e41982a7 | 2012-11-20 07:16:51 | [diff] [blame] | 1069 | if (instant_controller_) |
| 1070 | instant_controller_->ActiveTabChanged(); |
[email protected] | 10090d5 | 2013-07-25 20:41:37 | [diff] [blame] | 1071 | |
[email protected] | 549f62b | 2013-10-26 12:54:42 | [diff] [blame] | 1072 | SearchTabHelper::FromWebContents(new_contents)->OnTabActivated(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1073 | } |
| 1074 | |
[email protected] | 3abdff2 | 2012-11-13 10:28:45 | [diff] [blame] | 1075 | void Browser::TabMoved(WebContents* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1076 | int from_index, |
[email protected] | 1a242c3 | 2010-02-02 21:20:54 | [diff] [blame] | 1077 | int to_index) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1078 | DCHECK(from_index >= 0 && to_index >= 0); |
| 1079 | // Notify the history service. |
| 1080 | SyncHistoryWithTabs(std::min(from_index, to_index)); |
| 1081 | } |
| 1082 | |
[email protected] | da25dd5 | 2011-01-11 19:06:30 | [diff] [blame] | 1083 | void Browser::TabReplacedAt(TabStripModel* tab_strip_model, |
[email protected] | b624ddc | 2012-11-15 18:04:13 | [diff] [blame] | 1084 | WebContents* old_contents, |
| 1085 | WebContents* new_contents, |
[email protected] | 8a34e660 | 2010-10-02 17:29:43 | [diff] [blame] | 1086 | int index) { |
[email protected] | b624ddc | 2012-11-15 18:04:13 | [diff] [blame] | 1087 | TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 1088 | exclusive_access_manager_->OnTabClosing(old_contents); |
[email protected] | 4060015 | 2012-09-26 10:04:31 | [diff] [blame] | 1089 | SessionService* session_service = |
| 1090 | SessionServiceFactory::GetForProfile(profile_); |
| 1091 | if (session_service) |
[email protected] | b624ddc | 2012-11-15 18:04:13 | [diff] [blame] | 1092 | session_service->TabClosing(old_contents); |
pmonette | 9119e49 | 2016-09-20 22:14:55 | [diff] [blame] | 1093 | TabInsertedAt(tab_strip_model, new_contents, index, |
[email protected] | 04e3ead5 | 2013-01-14 01:09:20 | [diff] [blame] | 1094 | (index == tab_strip_model_->active_index())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1095 | |
creis | f82a92ee | 2015-10-19 19:59:08 | [diff] [blame] | 1096 | if (!new_contents->GetController().IsInitialBlankNavigation()) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1097 | // Send out notification so that observers are updated appropriately. |
creis | f82a92ee | 2015-10-19 19:59:08 | [diff] [blame] | 1098 | int entry_count = new_contents->GetController().GetEntryCount(); |
[email protected] | b624ddc | 2012-11-15 18:04:13 | [diff] [blame] | 1099 | new_contents->GetController().NotifyEntryChanged( |
avi | 4717933 | 2015-05-20 21:01:11 | [diff] [blame] | 1100 | new_contents->GetController().GetEntryAtIndex(entry_count - 1)); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1101 | } |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1102 | |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1103 | if (session_service) { |
| 1104 | // The new_contents may end up with a different navigation stack. Force |
| 1105 | // the session service to update itself. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1106 | session_service->TabRestored(new_contents, |
| 1107 | tab_strip_model_->IsTabPinned(index)); |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1108 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1109 | } |
| 1110 | |
pmonette | 9119e49 | 2016-09-20 22:14:55 | [diff] [blame] | 1111 | void Browser::TabPinnedStateChanged(TabStripModel* tab_strip_model, |
| 1112 | WebContents* contents, |
| 1113 | int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1114 | SessionService* session_service = |
| 1115 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1116 | if (session_service) { |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 1117 | SessionTabHelper* session_tab_helper = |
[email protected] | 2c7dba4 | 2012-11-09 17:05:42 | [diff] [blame] | 1118 | SessionTabHelper::FromWebContents(contents); |
| 1119 | session_service->SetPinnedState(session_id(), |
| 1120 | session_tab_helper->session_id(), |
| 1121 | tab_strip_model_->IsTabPinned(index)); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1122 | } |
| 1123 | } |
| 1124 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1125 | void Browser::TabStripEmpty() { |
| 1126 | // Close the frame after we return to the message loop (not immediately, |
| 1127 | // otherwise it will destroy this object before the stack has a chance to |
| 1128 | // cleanly unwind.) |
| 1129 | // Note: This will be called several times if TabStripEmpty is called several |
| 1130 | // times. This is because it does not close the window if tabs are |
| 1131 | // still present. |
skyostil | 380bb222 | 2015-06-12 12:07:05 | [diff] [blame] | 1132 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1133 | FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); |
[email protected] | e41982a7 | 2012-11-20 07:16:51 | [diff] [blame] | 1134 | |
| 1135 | // Instant may have visible WebContents that need to be detached before the |
| 1136 | // window system closes. |
| 1137 | instant_controller_.reset(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1138 | } |
| 1139 | |
[email protected] | 06731026 | 2012-11-22 14:30:41 | [diff] [blame] | 1140 | bool Browser::CanOverscrollContent() const { |
mfomitchev | f09a66bb | 2014-10-02 02:20:54 | [diff] [blame] | 1141 | #if defined(OS_WIN) |
| 1142 | // Don't enable overscroll on Windows machines unless they have a touch |
| 1143 | // screen as these machines typically don't have a touchpad capable of |
| 1144 | // horizontal scrolling. We are purposefully biased towards "no" here, |
| 1145 | // so that we don't waste resources capturing screenshots for horizontal |
| 1146 | // overscroll navigation unnecessarily. |
afakhry | 661e756a | 2015-12-01 23:50:04 | [diff] [blame] | 1147 | bool allow_overscroll = ui::GetTouchScreensAvailability() == |
| 1148 | ui::TouchScreensAvailability::ENABLED; |
mfomitchev | f09a66bb | 2014-10-02 02:20:54 | [diff] [blame] | 1149 | #elif defined(USE_AURA) |
| 1150 | bool allow_overscroll = true; |
| 1151 | #else |
| 1152 | bool allow_overscroll = false; |
| 1153 | #endif |
| 1154 | |
| 1155 | if (!allow_overscroll) |
| 1156 | return false; |
| 1157 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 1158 | const std::string value = |
| 1159 | base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 1160 | switches::kOverscrollHistoryNavigation); |
[email protected] | b1d5b19 | 2014-03-04 05:36:20 | [diff] [blame] | 1161 | bool overscroll_enabled = value != "0"; |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 1162 | if (!overscroll_enabled) |
| 1163 | return false; |
| 1164 | if (is_app() || is_devtools() || !is_type_tabbed()) |
| 1165 | return false; |
| 1166 | |
| 1167 | // The detached bookmark bar has appearance of floating above the |
| 1168 | // web-contents. This does not play nicely with overscroll navigation |
| 1169 | // gestures. So disable overscroll navigation when the bookmark bar is in the |
[email protected] | b1d5b19 | 2014-03-04 05:36:20 | [diff] [blame] | 1170 | // detached state and the overscroll effect moves the layers. |
| 1171 | if (value == "1" && bookmark_bar_state_ == BookmarkBar::DETACHED) |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 1172 | return false; |
| 1173 | return true; |
[email protected] | 06731026 | 2012-11-22 14:30:41 | [diff] [blame] | 1174 | } |
| 1175 | |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 1176 | bool Browser::ShouldPreserveAbortedURLs(WebContents* source) { |
| 1177 | // Allow failed URLs to stick around in the omnibox on the NTP, but not when |
| 1178 | // other pages have committed. |
| 1179 | Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext()); |
| 1180 | if (!profile || !source->GetController().GetLastCommittedEntry()) |
| 1181 | return false; |
| 1182 | GURL committed_url(source->GetController().GetLastCommittedEntry()->GetURL()); |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1183 | return search::IsNTPURL(committed_url, profile); |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 1184 | } |
| 1185 | |
calamity | 6160055c | 2015-04-30 06:45:26 | [diff] [blame] | 1186 | void Browser::SetFocusToLocationBar(bool select_all) { |
| 1187 | // Two differences between this and FocusLocationBar(): |
| 1188 | // (1) This doesn't get recorded in user metrics, since it's called |
| 1189 | // internally. |
| 1190 | // (2) This checks whether the location bar can be focused, and if not, clears |
| 1191 | // the focus. FocusLocationBar() is only reached when the location bar is |
| 1192 | // focusable, but this may be reached at other times, e.g. while in |
| 1193 | // fullscreen mode, where we need to leave focus in a consistent state. |
| 1194 | window_->SetFocusToLocationBar(select_all); |
| 1195 | } |
| 1196 | |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1197 | bool Browser::PreHandleKeyboardEvent(content::WebContents* source, |
| 1198 | const NativeWebKeyboardEvent& event, |
[email protected] | fc76114 | 2012-06-08 04:49:20 | [diff] [blame] | 1199 | bool* is_keyboard_shortcut) { |
mgiuca | 6fb1463 | 2015-12-08 03:59:47 | [diff] [blame] | 1200 | // Forward keyboard events to the manager for fullscreen / mouse lock. This |
| 1201 | // may consume the event (e.g., Esc exits fullscreen mode). |
[email protected] | fc76114 | 2012-06-08 04:49:20 | [diff] [blame] | 1202 | // TODO(koz): Write a test for this http://crbug.com/100441. |
mgiuca | 6fb1463 | 2015-12-08 03:59:47 | [diff] [blame] | 1203 | if (exclusive_access_manager_->HandleUserKeyPress(event)) |
[email protected] | fc76114 | 2012-06-08 04:49:20 | [diff] [blame] | 1204 | return true; |
mgiuca | 6fb1463 | 2015-12-08 03:59:47 | [diff] [blame] | 1205 | |
[email protected] | fc76114 | 2012-06-08 04:49:20 | [diff] [blame] | 1206 | return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 1207 | } |
| 1208 | |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1209 | void Browser::HandleKeyboardEvent(content::WebContents* source, |
| 1210 | const NativeWebKeyboardEvent& event) { |
[email protected] | 93e0baba | 2014-04-08 20:04:02 | [diff] [blame] | 1211 | DevToolsWindow* devtools_window = |
| 1212 | DevToolsWindow::GetInstanceForInspectedWebContents(source); |
| 1213 | bool handled = false; |
| 1214 | if (devtools_window) |
| 1215 | handled = devtools_window->ForwardKeyboardEvent(event); |
| 1216 | |
| 1217 | if (!handled) |
| 1218 | window()->HandleKeyboardEvent(event); |
[email protected] | fc76114 | 2012-06-08 04:49:20 | [diff] [blame] | 1219 | } |
| 1220 | |
[email protected] | ed1bb720 | 2013-06-21 05:16:44 | [diff] [blame] | 1221 | bool Browser::TabsNeedBeforeUnloadFired() { |
[email protected] | 88c9201 | 2013-07-02 11:56:34 | [diff] [blame] | 1222 | if (IsFastTabUnloadEnabled()) |
| 1223 | return fast_unload_controller_->TabsNeedBeforeUnloadFired(); |
[email protected] | ed1bb720 | 2013-06-21 05:16:44 | [diff] [blame] | 1224 | return unload_controller_->TabsNeedBeforeUnloadFired(); |
| 1225 | } |
| 1226 | |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 1227 | void Browser::ShowValidationMessage(content::WebContents* web_contents, |
| 1228 | const gfx::Rect& anchor_in_root_view, |
[email protected] | ebf04a86 | 2013-12-17 08:38:58 | [diff] [blame] | 1229 | const base::string16& main_text, |
| 1230 | const base::string16& sub_text) { |
estade | ba9261e | 2016-06-28 00:47:11 | [diff] [blame] | 1231 | // If the web contents is unparented (e.g. in a blocked popup) it does not |
| 1232 | // make sense to show a validation message. See http://crbug.com/616990 |
| 1233 | if (!web_contents->GetTopLevelNativeWindow()) |
| 1234 | return; |
andresantoso | 49f9a7a | 2015-01-28 00:03:17 | [diff] [blame] | 1235 | validation_message_bubble_ = |
| 1236 | TabDialogs::FromWebContents(web_contents) |
| 1237 | ->ShowValidationMessage(anchor_in_root_view, main_text, sub_text); |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | void Browser::HideValidationMessage(content::WebContents* web_contents) { |
estade | 53f17391 | 2016-04-18 02:22:08 | [diff] [blame] | 1241 | if (validation_message_bubble_) |
| 1242 | validation_message_bubble_->CloseValidationMessage(); |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | void Browser::MoveValidationMessage(content::WebContents* web_contents, |
| 1246 | const gfx::Rect& anchor_in_root_view) { |
| 1247 | if (!validation_message_bubble_) |
| 1248 | return; |
| 1249 | RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); |
| 1250 | if (rwhv) { |
| 1251 | validation_message_bubble_->SetPositionRelativeToAnchor( |
| 1252 | rwhv->GetRenderWidgetHost(), anchor_in_root_view); |
| 1253 | } |
| 1254 | } |
| 1255 | |
[email protected] | 7a0c5aea | 2014-03-05 17:41:17 | [diff] [blame] | 1256 | bool Browser::PreHandleGestureEvent(content::WebContents* source, |
| 1257 | const blink::WebGestureEvent& event) { |
| 1258 | // Disable pinch zooming in undocked dev tools window due to poor UX. |
| 1259 | if (app_name() == DevToolsWindow::kDevToolsApp) |
| 1260 | return event.type == blink::WebGestureEvent::GesturePinchBegin || |
| 1261 | event.type == blink::WebGestureEvent::GesturePinchUpdate || |
| 1262 | event.type == blink::WebGestureEvent::GesturePinchEnd; |
| 1263 | |
| 1264 | return false; |
| 1265 | } |
| 1266 | |
[email protected] | f925367 | 2014-07-31 03:35:38 | [diff] [blame] | 1267 | bool Browser::CanDragEnter(content::WebContents* source, |
| 1268 | const content::DropData& data, |
| 1269 | blink::WebDragOperationsMask operations_allowed) { |
| 1270 | // Disallow drag-and-drop navigation for Settings windows which do not support |
| 1271 | // external navigation. |
| 1272 | if ((operations_allowed & blink::WebDragOperationLink) && |
| 1273 | chrome::SettingsWindowManager::GetInstance()->IsSettingsBrowser(this)) { |
| 1274 | return false; |
| 1275 | } |
| 1276 | return true; |
| 1277 | } |
| 1278 | |
estark | 47ba9c7d | 2016-10-11 15:40:11 | [diff] [blame] | 1279 | blink::WebSecurityStyle Browser::GetSecurityStyle( |
estark | 5ea80e5 | 2015-06-19 18:43:12 | [diff] [blame] | 1280 | WebContents* web_contents, |
| 1281 | content::SecurityStyleExplanations* security_style_explanations) { |
estark | 880a5a4 | 2015-11-30 18:21:21 | [diff] [blame] | 1282 | ChromeSecurityStateModelClient* model_client = |
| 1283 | ChromeSecurityStateModelClient::FromWebContents(web_contents); |
| 1284 | DCHECK(model_client); |
estark | 5186604 | 2016-09-22 20:35:35 | [diff] [blame] | 1285 | security_state::SecurityStateModel::SecurityInfo security_info; |
| 1286 | model_client->GetSecurityInfo(&security_info); |
| 1287 | return model_client->GetSecurityStyle(security_info, |
estark | 09dbe8e | 2016-05-20 23:16:56 | [diff] [blame] | 1288 | security_style_explanations); |
lgarron | 662dd52 | 2015-06-08 23:20:01 | [diff] [blame] | 1289 | } |
| 1290 | |
pfeldman | 61aa8a159 | 2015-09-03 22:08:18 | [diff] [blame] | 1291 | void Browser::ShowCertificateViewerInDevTools( |
jam | 8ae7cad | 2016-09-08 23:55:21 | [diff] [blame] | 1292 | content::WebContents* web_contents, |
| 1293 | scoped_refptr<net::X509Certificate> certificate) { |
pfeldman | 61aa8a159 | 2015-09-03 22:08:18 | [diff] [blame] | 1294 | DevToolsWindow* devtools_window = |
| 1295 | DevToolsWindow::GetInstanceForInspectedWebContents(web_contents); |
| 1296 | if (devtools_window) |
jam | 8ae7cad | 2016-09-08 23:55:21 | [diff] [blame] | 1297 | devtools_window->ShowCertificateViewer(certificate); |
pfeldman | 61aa8a159 | 2015-09-03 22:08:18 | [diff] [blame] | 1298 | } |
| 1299 | |
dcheng | 9603ab9 | 2016-04-08 04:17:32 | [diff] [blame] | 1300 | std::unique_ptr<content::BluetoothChooser> Browser::RunBluetoothChooser( |
jyasskin | 93649a5 | 2016-02-17 19:57:02 | [diff] [blame] | 1301 | content::RenderFrameHost* frame, |
| 1302 | const content::BluetoothChooser::EventHandler& event_handler) { |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 1303 | std::unique_ptr<BluetoothChooserController> bluetooth_chooser_controller( |
| 1304 | new BluetoothChooserController(frame, event_handler)); |
juncai | cd97558 | 2015-12-21 22:58:10 | [diff] [blame] | 1305 | |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 1306 | std::unique_ptr<BluetoothChooserDesktop> bluetooth_chooser_desktop( |
| 1307 | new BluetoothChooserDesktop(bluetooth_chooser_controller.get())); |
| 1308 | |
| 1309 | std::unique_ptr<ChooserBubbleDelegate> chooser_bubble_delegate( |
| 1310 | new ChooserBubbleDelegate(frame, |
| 1311 | std::move(bluetooth_chooser_controller))); |
juncai | cd97558 | 2015-12-21 22:58:10 | [diff] [blame] | 1312 | |
jyasskin | 93649a5 | 2016-02-17 19:57:02 | [diff] [blame] | 1313 | Browser* browser = chrome::FindBrowserWithWebContents( |
| 1314 | WebContents::FromRenderFrameHost(frame)); |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 1315 | BubbleReference bubble_reference = browser->GetBubbleManager()->ShowBubble( |
| 1316 | std::move(chooser_bubble_delegate)); |
juncai | cd97558 | 2015-12-21 22:58:10 | [diff] [blame] | 1317 | |
| 1318 | return std::move(bluetooth_chooser_desktop); |
| 1319 | } |
| 1320 | |
pfeldman | 5f0773a4 | 2016-03-29 16:56:33 | [diff] [blame] | 1321 | void Browser::RequestAppBannerFromDevTools(content::WebContents* web_contents) { |
dominickn | d223e62 | 2016-08-10 04:54:13 | [diff] [blame] | 1322 | banners::AppBannerManagerDesktop::CreateForWebContents(web_contents); |
| 1323 | banners::AppBannerManagerDesktop* manager = |
| 1324 | banners::AppBannerManagerDesktop::FromWebContents(web_contents); |
dominickn | ecc7917 | 2016-06-29 05:04:24 | [diff] [blame] | 1325 | manager->RequestAppBanner(web_contents->GetLastCommittedURL(), true); |
horo | 9638ad27 | 2016-01-25 14:36:45 | [diff] [blame] | 1326 | } |
| 1327 | |
[email protected] | d013f14 | 2012-04-27 17:31:14 | [diff] [blame] | 1328 | bool Browser::IsMouseLocked() const { |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 1329 | return exclusive_access_manager_->mouse_lock_controller()->IsMouseLocked(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | void Browser::OnWindowDidShow() { |
| 1333 | if (window_has_shown_) |
| 1334 | return; |
| 1335 | window_has_shown_ = true; |
| 1336 | |
gab | 4768aee | 2015-11-11 23:37:19 | [diff] [blame] | 1337 | startup_metric_utils::RecordBrowserWindowDisplay(base::TimeTicks::Now()); |
[email protected] | b5febf7 | 2012-07-29 18:10:09 | [diff] [blame] | 1338 | |
warx | 6f9ac8d | 2016-06-10 06:45:50 | [diff] [blame] | 1339 | // Nothing to do for non-tabbed and minimized windows. |
| 1340 | if (!is_type_tabbed() || window_->IsMinimized()) |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1341 | return; |
| 1342 | |
| 1343 | // Show any pending global error bubble. |
| 1344 | GlobalErrorService* service = |
| 1345 | GlobalErrorServiceFactory::GetForProfile(profile()); |
| 1346 | GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
| 1347 | if (error) |
| 1348 | error->ShowBubbleView(this); |
| 1349 | } |
| 1350 | |
| 1351 | void Browser::ShowFirstRunBubble() { |
| 1352 | window()->GetLocationBar()->ShowFirstRunBubble(); |
| 1353 | } |
| 1354 | |
| 1355 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 1356 | // Browser, content::WebContentsDelegate implementation: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1357 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1358 | WebContents* Browser::OpenURLFromTab(WebContents* source, |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1359 | const OpenURLParams& params) { |
dgozman | 3ef307abb | 2015-03-03 14:39:50 | [diff] [blame] | 1360 | if (is_devtools()) { |
| 1361 | DevToolsWindow* window = DevToolsWindow::AsDevToolsWindow(source); |
| 1362 | DCHECK(window); |
| 1363 | return window->OpenURLFromTab(source, params); |
| 1364 | } |
| 1365 | |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 1366 | chrome::NavigateParams nav_params(this, params.url, params.transition); |
[email protected] | 19c6414 | 2013-03-06 20:08:53 | [diff] [blame] | 1367 | FillNavigateParamsFromOpenURLParams(&nav_params, params); |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 1368 | nav_params.source_contents = source; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1369 | nav_params.tabstrip_add_types = TabStripModel::ADD_NONE; |
[email protected] | dee1b5a0 | 2014-04-22 11:21:56 | [diff] [blame] | 1370 | if (params.user_gesture) |
| 1371 | nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 1372 | nav_params.user_gesture = params.user_gesture; |
| 1373 | |
[email protected] | 5635e614 | 2013-07-18 08:10:40 | [diff] [blame] | 1374 | PopupBlockerTabHelper* popup_blocker_helper = NULL; |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 1375 | if (source) |
[email protected] | 5635e614 | 2013-07-18 08:10:40 | [diff] [blame] | 1376 | popup_blocker_helper = PopupBlockerTabHelper::FromWebContents(source); |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 1377 | |
[email protected] | 992e291 | 2013-08-19 15:05:24 | [diff] [blame] | 1378 | if (popup_blocker_helper) { |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 1379 | if ((params.disposition == WindowOpenDisposition::NEW_POPUP || |
| 1380 | params.disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB || |
| 1381 | params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB || |
| 1382 | params.disposition == WindowOpenDisposition::NEW_WINDOW) && |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 1383 | !params.user_gesture && |
| 1384 | !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1385 | switches::kDisablePopupBlocking)) { |
[email protected] | 6726406 | 2013-07-25 12:39:26 | [diff] [blame] | 1386 | if (popup_blocker_helper->MaybeBlockPopup(nav_params, |
| 1387 | WebWindowFeatures())) { |
[email protected] | 5635e614 | 2013-07-18 08:10:40 | [diff] [blame] | 1388 | return NULL; |
[email protected] | 6726406 | 2013-07-25 12:39:26 | [diff] [blame] | 1389 | } |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 1393 | chrome::Navigate(&nav_params); |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1394 | |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 1395 | return nav_params.target_contents; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1396 | } |
| 1397 | |
creis | cde28de | 2014-11-26 17:10:36 | [diff] [blame] | 1398 | void Browser::NavigationStateChanged(WebContents* source, |
[email protected] | 7f92483 | 2014-08-09 05:57:22 | [diff] [blame] | 1399 | content::InvalidateTypes changed_flags) { |
erikchen | 174b78c6 | 2015-03-11 22:02:54 | [diff] [blame] | 1400 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 1401 | // is fixed. |
| 1402 | tracked_objects::ScopedTracker tracking_profile1( |
| 1403 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1404 | "466285 Browser::NavigationStateChanged::ScheduleUIUpdate")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1405 | // Only update the UI when something visible has changed. |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 1406 | if (changed_flags) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1407 | ScheduleUIUpdate(source, changed_flags); |
| 1408 | |
erikchen | 174b78c6 | 2015-03-11 22:02:54 | [diff] [blame] | 1409 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 1410 | // is fixed. |
| 1411 | tracked_objects::ScopedTracker tracking_profile2( |
| 1412 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1413 | "466285 Browser::NavigationStateChanged::TabStateChanged")); |
[email protected] | 83c2e23 | 2011-10-07 21:36:46 | [diff] [blame] | 1414 | // We can synchronously update commands since they will only change once per |
| 1415 | // navigation, so we don't have to worry about flickering. We do, however, |
| 1416 | // need to update the command state early on load to always present usable |
| 1417 | // actions in the face of slow-to-commit pages. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1418 | if (changed_flags & (content::INVALIDATE_TYPE_URL | |
thomasanderson | 9094aa5 | 2016-04-01 17:32:57 | [diff] [blame] | 1419 | content::INVALIDATE_TYPE_LOAD | |
| 1420 | content::INVALIDATE_TYPE_TAB)) |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1421 | command_controller_->TabStateChanged(); |
benwells | a2a8a9f7 | 2015-04-07 07:09:54 | [diff] [blame] | 1422 | |
benwells | 11bd6ed | 2015-06-05 04:20:41 | [diff] [blame] | 1423 | if (hosted_app_controller_) |
| 1424 | hosted_app_controller_->UpdateLocationBarVisibility(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1425 | } |
| 1426 | |
estark | f8b269e5 | 2016-10-17 19:17:14 | [diff] [blame] | 1427 | void Browser::VisibleSSLStateChanged(WebContents* source) { |
[email protected] | 25af6ec | 2014-06-06 19:35:07 | [diff] [blame] | 1428 | // When the current tab's SSL state changes, we need to update the URL |
| 1429 | // bar to reflect the new state. |
| 1430 | DCHECK(source); |
| 1431 | if (tab_strip_model_->GetActiveWebContents() == source) |
| 1432 | UpdateToolbar(false); |
estark | f8b269e5 | 2016-10-17 19:17:14 | [diff] [blame] | 1433 | |
| 1434 | ChromeSecurityStateModelClient* security_model = |
| 1435 | ChromeSecurityStateModelClient::FromWebContents(source); |
| 1436 | security_model->VisibleSSLStateChanged(); |
[email protected] | 25af6ec | 2014-06-06 19:35:07 | [diff] [blame] | 1437 | } |
| 1438 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1439 | void Browser::AddNewContents(WebContents* source, |
| 1440 | WebContents* new_contents, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1441 | WindowOpenDisposition disposition, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 1442 | const gfx::Rect& initial_rect, |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 1443 | bool user_gesture, |
| 1444 | bool* was_blocked) { |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 1445 | chrome::AddWebContents(this, source, new_contents, disposition, initial_rect, |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 1446 | user_gesture, was_blocked); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1447 | } |
| 1448 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1449 | void Browser::ActivateContents(WebContents* contents) { |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 1450 | tab_strip_model_->ActivateTabAt( |
| 1451 | tab_strip_model_->GetIndexOfWebContents(contents), false); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 1452 | window_->Activate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1453 | } |
| 1454 | |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 1455 | void Browser::LoadingStateChanged(WebContents* source, |
| 1456 | bool to_different_document) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1457 | window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading()); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 1458 | window_->UpdateTitleBar(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1459 | |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 1460 | WebContents* selected_contents = tab_strip_model_->GetActiveWebContents(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1461 | if (source == selected_contents) { |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 1462 | bool is_loading = source->IsLoading() && to_different_document; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1463 | command_controller_->LoadingStateChanged(is_loading, false); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 1464 | if (GetStatusBubble()) { |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 1465 | GetStatusBubble()->SetStatus(CoreTabHelper::FromWebContents( |
| 1466 | tab_strip_model_->GetActiveWebContents())->GetStatusText()); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 1467 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1468 | } |
| 1469 | } |
| 1470 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 1471 | void Browser::CloseContents(WebContents* source) { |
[email protected] | 88c9201 | 2013-07-02 11:56:34 | [diff] [blame] | 1472 | bool can_close_contents; |
| 1473 | if (IsFastTabUnloadEnabled()) |
| 1474 | can_close_contents = fast_unload_controller_->CanCloseContents(source); |
| 1475 | else |
| 1476 | can_close_contents = unload_controller_->CanCloseContents(source); |
| 1477 | |
| 1478 | if (can_close_contents) |
[email protected] | 81ddd340 | 2012-12-28 00:55:26 | [diff] [blame] | 1479 | chrome::CloseWebContents(this, source, true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1480 | } |
| 1481 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1482 | void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1483 | if (!IsPopupOrPanel(source)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1484 | NOTREACHED() << "moving invalid browser type"; |
| 1485 | return; |
| 1486 | } |
[email protected] | e561e20 | 2010-03-24 17:57:12 | [diff] [blame] | 1487 | window_->SetBounds(pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1488 | } |
| 1489 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1490 | bool Browser::IsPopupOrPanel(const WebContents* source) const { |
[email protected] | 7efaed36 | 2013-04-04 09:33:32 | [diff] [blame] | 1491 | return is_type_popup(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1492 | } |
| 1493 | |
avi | 450ce00e | 2014-09-24 01:58:52 | [diff] [blame] | 1494 | void Browser::UpdateTargetURL(WebContents* source, const GURL& url) { |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1495 | if (!GetStatusBubble()) |
| 1496 | return; |
| 1497 | |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 1498 | if (source == tab_strip_model_->GetActiveWebContents()) |
| 1499 | GetStatusBubble()->SetURL(url); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1500 | } |
| 1501 | |
mgiuca | 1c92cab4 | 2016-01-07 03:18:27 | [diff] [blame] | 1502 | void Browser::ContentsMouseEvent(WebContents* source, |
| 1503 | const gfx::Point& location, |
| 1504 | bool motion, |
| 1505 | bool exited) { |
mgiuca | ef9a286 | 2016-02-19 03:11:29 | [diff] [blame] | 1506 | exclusive_access_manager_->OnUserInput(); |
| 1507 | |
mgiuca | 1c92cab4 | 2016-01-07 03:18:27 | [diff] [blame] | 1508 | // Mouse motion events update the status bubble, if it exists. |
| 1509 | if (!GetStatusBubble() || (!motion && !exited)) |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1510 | return; |
| 1511 | |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 1512 | if (source == tab_strip_model_->GetActiveWebContents()) { |
mgiuca | 1c92cab4 | 2016-01-07 03:18:27 | [diff] [blame] | 1513 | GetStatusBubble()->MouseMoved(location, exited); |
| 1514 | if (exited) |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 1515 | GetStatusBubble()->SetURL(GURL()); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1516 | } |
[email protected] | 3a6a3b6 | 2009-05-27 21:36:20 | [diff] [blame] | 1517 | } |
| 1518 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1519 | void Browser::ContentsZoomChange(bool zoom_in) { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1520 | chrome::ExecuteCommand(this, zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1521 | } |
| 1522 | |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1523 | bool Browser::TakeFocus(content::WebContents* source, |
| 1524 | bool reverse) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1525 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1526 | chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1527 | content::Source<Browser>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1528 | content::NotificationService::NoDetails()); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 1529 | return false; |
| 1530 | } |
| 1531 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1532 | void Browser::BeforeUnloadFired(WebContents* web_contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1533 | bool proceed, |
| 1534 | bool* proceed_to_fire_unload) { |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 1535 | if (is_devtools() && DevToolsWindow::HandleBeforeUnload(web_contents, |
| 1536 | proceed, proceed_to_fire_unload)) |
| 1537 | return; |
| 1538 | |
[email protected] | 88c9201 | 2013-07-02 11:56:34 | [diff] [blame] | 1539 | if (IsFastTabUnloadEnabled()) { |
| 1540 | *proceed_to_fire_unload = |
| 1541 | fast_unload_controller_->BeforeUnloadFired(web_contents, proceed); |
| 1542 | } else { |
| 1543 | *proceed_to_fire_unload = |
| 1544 | unload_controller_->BeforeUnloadFired(web_contents, proceed); |
| 1545 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1546 | } |
| 1547 | |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 1548 | bool Browser::ShouldFocusLocationBarByDefault(WebContents* source) { |
[email protected] | 77fd82e5 | 2013-03-12 22:24:26 | [diff] [blame] | 1549 | const content::NavigationEntry* entry = |
[email protected] | 06cb23b | 2013-12-17 02:56:49 | [diff] [blame] | 1550 | source->GetController().GetActiveEntry(); |
[email protected] | e491641 | 2013-04-25 20:12:15 | [diff] [blame] | 1551 | if (entry) { |
| 1552 | GURL url = entry->GetURL(); |
| 1553 | GURL virtual_url = entry->GetVirtualURL(); |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 1554 | if ((url.SchemeIs(content::kChromeUIScheme) && |
[email protected] | e491641 | 2013-04-25 20:12:15 | [diff] [blame] | 1555 | url.host() == chrome::kChromeUINewTabHost) || |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 1556 | (virtual_url.SchemeIs(content::kChromeUIScheme) && |
[email protected] | e491641 | 2013-04-25 20:12:15 | [diff] [blame] | 1557 | virtual_url.host() == chrome::kChromeUINewTabHost)) { |
| 1558 | return true; |
| 1559 | } |
[email protected] | c744f7d2 | 2013-04-12 20:29:04 | [diff] [blame] | 1560 | } |
| 1561 | |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1562 | return search::NavEntryIsInstantNTP(source, entry); |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 1563 | } |
| 1564 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1565 | void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 1566 | DCHECK(source); |
[email protected] | ab93b637 | 2012-11-28 05:20:22 | [diff] [blame] | 1567 | chrome::ViewSource(this, source); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 1568 | } |
| 1569 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1570 | void Browser::ViewSourceForFrame(WebContents* source, |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1571 | const GURL& frame_url, |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1572 | const content::PageState& frame_page_state) { |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1573 | DCHECK(source); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1574 | chrome::ViewSource(this, source, frame_url, frame_page_state); |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1575 | } |
| 1576 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1577 | void Browser::ShowRepostFormWarningDialog(WebContents* source) { |
[email protected] | 51296c6 | 2012-09-26 13:02:44 | [diff] [blame] | 1578 | TabModalConfirmDialog::Create(new RepostFormWarningController(source), |
[email protected] | 70320ab | 2012-11-02 19:07:16 | [diff] [blame] | 1579 | source); |
[email protected] | 14f3408a | 2009-08-31 20:53:53 | [diff] [blame] | 1580 | } |
| 1581 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1582 | bool Browser::ShouldCreateWebContents( |
| 1583 | WebContents* web_contents, |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1584 | int32_t route_id, |
| 1585 | int32_t main_frame_route_id, |
| 1586 | int32_t main_frame_widget_route_id, |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1587 | WindowContainerType window_container_type, |
nasko | 48321ca3 | 2015-07-02 20:44:12 | [diff] [blame] | 1588 | const std::string& frame_name, |
[email protected] | 4543b67c | 2013-07-11 18:18:36 | [diff] [blame] | 1589 | const GURL& target_url, |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 1590 | const std::string& partition_id, |
| 1591 | content::SessionStorageNamespace* session_storage_namespace) { |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1592 | if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
| 1593 | // If a BackgroundContents is created, suppress the normal WebContents. |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1594 | return !MaybeCreateBackgroundContents( |
| 1595 | route_id, main_frame_route_id, main_frame_widget_route_id, web_contents, |
| 1596 | frame_name, target_url, partition_id, session_storage_namespace); |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | return true; |
| 1600 | } |
| 1601 | |
| 1602 | void Browser::WebContentsCreated(WebContents* source_contents, |
nasko | e2df1d7 | 2016-10-04 00:20:17 | [diff] [blame] | 1603 | int opener_render_process_id, |
[email protected] | a7531d77 | 2014-03-25 16:15:07 | [diff] [blame] | 1604 | int opener_render_frame_id, |
nasko | 48321ca3 | 2015-07-02 20:44:12 | [diff] [blame] | 1605 | const std::string& frame_name, |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1606 | const GURL& target_url, |
| 1607 | WebContents* new_contents) { |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 1608 | // Adopt the WebContents now, so all observers are in place, as the network |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1609 | // requests for its initial navigation will start immediately. The WebContents |
| 1610 | // will later be inserted into this browser using Browser::Navigate via |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 1611 | // AddNewContents. |
[email protected] | e0bc75d5 | 2014-01-30 23:42:59 | [diff] [blame] | 1612 | TabHelpers::AttachTabHelpers(new_contents); |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1613 | |
afakhry | 8394f94 | 2015-07-09 18:46:09 | [diff] [blame] | 1614 | // Make the tab show up in the task manager. |
avi | 24d693f | 2016-08-06 18:03:52 | [diff] [blame] | 1615 | task_manager::WebContentsTags::CreateForTabContents(new_contents); |
afakhry | 8394f94 | 2015-07-09 18:46:09 | [diff] [blame] | 1616 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1617 | // Notify. |
| 1618 | RetargetingDetails details; |
| 1619 | details.source_web_contents = source_contents; |
nasko | e2df1d7 | 2016-10-04 00:20:17 | [diff] [blame] | 1620 | details.source_render_process_id = opener_render_process_id; |
[email protected] | a7531d77 | 2014-03-25 16:15:07 | [diff] [blame] | 1621 | details.source_render_frame_id = opener_render_frame_id; |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1622 | details.target_url = target_url; |
| 1623 | details.target_web_contents = new_contents; |
| 1624 | details.not_yet_in_tabstrip = true; |
| 1625 | content::NotificationService::current()->Notify( |
| 1626 | chrome::NOTIFICATION_RETARGETING, |
| 1627 | content::Source<Profile>(profile_), |
| 1628 | content::Details<RetargetingDetails>(&details)); |
[email protected] | 80c7b80 | 2011-10-28 19:59:08 | [diff] [blame] | 1629 | } |
| 1630 | |
dtapuska | e99ec6e5 | 2016-10-18 00:15:42 | [diff] [blame] | 1631 | void Browser::RendererUnresponsive( |
| 1632 | WebContents* source, |
| 1633 | const content::WebContentsUnresponsiveState& unresponsive_state) { |
[email protected] | a7ed0ca | 2012-12-06 19:30:06 | [diff] [blame] | 1634 | // Ignore hangs if a tab is blocked. |
| 1635 | int index = tab_strip_model_->GetIndexOfWebContents(source); |
| 1636 | DCHECK_NE(TabStripModel::kNoTab, index); |
| 1637 | if (tab_strip_model_->IsTabBlocked(index)) |
| 1638 | return; |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 1639 | |
dtapuska | e99ec6e5 | 2016-10-18 00:15:42 | [diff] [blame] | 1640 | TabDialogs::FromWebContents(source)->ShowHungRendererDialog( |
| 1641 | unresponsive_state); |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 1642 | } |
| 1643 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1644 | void Browser::RendererResponsive(WebContents* source) { |
andresantoso | 063151d | 2014-12-18 22:37:55 | [diff] [blame] | 1645 | TabDialogs::FromWebContents(source)->HideHungRendererDialog(); |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 1646 | } |
| 1647 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1648 | void Browser::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 1649 | if (web_contents == tab_strip_model_->GetActiveWebContents()) |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1650 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1651 | } |
| 1652 | |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 1653 | content::JavaScriptDialogManager* Browser::GetJavaScriptDialogManager( |
| 1654 | WebContents* source) { |
avi | 6082932 | 2016-09-01 19:47:13 | [diff] [blame] | 1655 | return JavaScriptDialogTabHelper::FromWebContents(source); |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 1656 | } |
| 1657 | |
[email protected] | 8bc5ff0 | 2013-11-29 06:34:03 | [diff] [blame] | 1658 | content::ColorChooser* Browser::OpenColorChooser( |
| 1659 | WebContents* web_contents, |
| 1660 | SkColor initial_color, |
| 1661 | const std::vector<content::ColorSuggestion>& suggestions) { |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 1662 | return chrome::ShowColorChooser(web_contents, initial_color); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1663 | } |
| 1664 | |
nasko | 35169af | 2016-06-10 18:47:13 | [diff] [blame] | 1665 | void Browser::RunFileChooser(content::RenderFrameHost* render_frame_host, |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 1666 | const content::FileChooserParams& params) { |
nasko | 35169af | 2016-06-10 18:47:13 | [diff] [blame] | 1667 | FileSelectHelper::RunFileChooser(render_frame_host, params); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1668 | } |
| 1669 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1670 | void Browser::EnumerateDirectory(WebContents* web_contents, |
[email protected] | 33f8ad5 | 2012-05-22 18:10:13 | [diff] [blame] | 1671 | int request_id, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1672 | const base::FilePath& path) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1673 | FileSelectHelper::EnumerateDirectory(web_contents, request_id, path); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1674 | } |
| 1675 | |
[email protected] | 4aebbcaa | 2013-09-17 22:26:49 | [diff] [blame] | 1676 | bool Browser::EmbedsFullscreenWidget() const { |
[email protected] | 40f12b9 | 2014-07-15 19:56:11 | [diff] [blame] | 1677 | return true; |
[email protected] | 4aebbcaa | 2013-09-17 22:26:49 | [diff] [blame] | 1678 | } |
| 1679 | |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1680 | void Browser::EnterFullscreenModeForTab(WebContents* web_contents, |
| 1681 | const GURL& origin) { |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 1682 | exclusive_access_manager_->fullscreen_controller()->EnterFullscreenModeForTab( |
| 1683 | web_contents, origin); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | void Browser::ExitFullscreenModeForTab(WebContents* web_contents) { |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 1687 | exclusive_access_manager_->fullscreen_controller()->ExitFullscreenModeForTab( |
| 1688 | web_contents); |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1689 | } |
| 1690 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1691 | bool Browser::IsFullscreenForTabOrPending( |
| 1692 | const WebContents* web_contents) const { |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 1693 | return exclusive_access_manager_->fullscreen_controller() |
| 1694 | ->IsFullscreenForTabOrPending(web_contents); |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 1695 | } |
| 1696 | |
mikhail.pozdnyakov | 76208cb | 2015-09-07 10:31:40 | [diff] [blame] | 1697 | blink::WebDisplayMode Browser::GetDisplayMode( |
| 1698 | const WebContents* web_contents) const { |
| 1699 | if (window_->IsFullscreen()) |
| 1700 | return blink::WebDisplayModeFullscreen; |
| 1701 | |
| 1702 | if (is_type_popup()) |
| 1703 | return blink::WebDisplayModeStandalone; |
| 1704 | |
| 1705 | return blink::WebDisplayModeBrowser; |
| 1706 | } |
| 1707 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1708 | void Browser::RegisterProtocolHandler(WebContents* web_contents, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1709 | const std::string& protocol, |
| 1710 | const GURL& url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 1711 | bool user_gesture) { |
[email protected] | a23abe47 | 2014-07-29 23:46:31 | [diff] [blame] | 1712 | content::BrowserContext* context = web_contents->GetBrowserContext(); |
| 1713 | if (context->IsOffTheRecord()) |
[email protected] | e1ff4a4 | 2013-12-16 20:29:01 | [diff] [blame] | 1714 | return; |
| 1715 | |
| 1716 | ProtocolHandler handler = |
[email protected] | c125e53 | 2014-05-10 20:39:06 | [diff] [blame] | 1717 | ProtocolHandler::CreateProtocolHandler(protocol, url); |
[email protected] | e1ff4a4 | 2013-12-16 20:29:01 | [diff] [blame] | 1718 | |
| 1719 | ProtocolHandlerRegistry* registry = |
[email protected] | a23abe47 | 2014-07-29 23:46:31 | [diff] [blame] | 1720 | ProtocolHandlerRegistryFactory::GetForBrowserContext(context); |
[email protected] | e1ff4a4 | 2013-12-16 20:29:01 | [diff] [blame] | 1721 | if (registry->SilentlyHandleRegisterHandlerRequest(handler)) |
| 1722 | return; |
| 1723 | |
| 1724 | TabSpecificContentSettings* tab_content_settings = |
| 1725 | TabSpecificContentSettings::FromWebContents(web_contents); |
| 1726 | if (!user_gesture && window_) { |
| 1727 | tab_content_settings->set_pending_protocol_handler(handler); |
| 1728 | tab_content_settings->set_previous_protocol_handler( |
| 1729 | registry->GetHandlerFor(handler.protocol())); |
| 1730 | window_->GetLocationBar()->UpdateContentSettingsIcons(); |
| 1731 | return; |
| 1732 | } |
| 1733 | |
| 1734 | // Make sure content-setting icon is turned off in case the page does |
| 1735 | // ungestured and gestured RPH calls. |
| 1736 | if (window_) { |
| 1737 | tab_content_settings->ClearPendingProtocolHandler(); |
| 1738 | window_->GetLocationBar()->UpdateContentSettingsIcons(); |
| 1739 | } |
| 1740 | |
tsergeant | a771c23e | 2016-07-13 04:54:52 | [diff] [blame] | 1741 | PermissionRequestManager* permission_request_manager = |
| 1742 | PermissionRequestManager::FromWebContents(web_contents); |
| 1743 | if (permission_request_manager) { |
| 1744 | permission_request_manager->AddRequest( |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 1745 | new RegisterProtocolHandlerPermissionRequest(registry, handler, |
| 1746 | url, user_gesture)); |
[email protected] | f1d2057 | 2014-02-14 01:27:14 | [diff] [blame] | 1747 | } |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1748 | } |
| 1749 | |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 1750 | void Browser::UnregisterProtocolHandler(WebContents* web_contents, |
| 1751 | const std::string& protocol, |
| 1752 | const GURL& url, |
| 1753 | bool user_gesture) { |
| 1754 | // user_gesture will be used in case we decide to have confirmation bubble |
| 1755 | // for user while un-registering the handler. |
[email protected] | a23abe47 | 2014-07-29 23:46:31 | [diff] [blame] | 1756 | content::BrowserContext* context = web_contents->GetBrowserContext(); |
| 1757 | if (context->IsOffTheRecord()) |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 1758 | return; |
| 1759 | |
| 1760 | ProtocolHandler handler = |
| 1761 | ProtocolHandler::CreateProtocolHandler(protocol, url); |
| 1762 | |
| 1763 | ProtocolHandlerRegistry* registry = |
[email protected] | a23abe47 | 2014-07-29 23:46:31 | [diff] [blame] | 1764 | ProtocolHandlerRegistryFactory::GetForBrowserContext(context); |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 1765 | registry->RemoveHandler(handler); |
| 1766 | } |
| 1767 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1768 | void Browser::UpdatePreferredSize(WebContents* source, |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 1769 | const gfx::Size& pref_size) { |
| 1770 | window_->UpdatePreferredSize(source, pref_size); |
| 1771 | } |
| 1772 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1773 | void Browser::ResizeDueToAutoResize(WebContents* source, |
| 1774 | const gfx::Size& new_size) { |
| 1775 | window_->ResizeDueToAutoResize(source, new_size); |
| 1776 | } |
| 1777 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1778 | void Browser::FindReply(WebContents* web_contents, |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1779 | int request_id, |
| 1780 | int number_of_matches, |
| 1781 | const gfx::Rect& selection_rect, |
| 1782 | int active_match_ordinal, |
| 1783 | bool final_update) { |
[email protected] | e1ff4a4 | 2013-12-16 20:29:01 | [diff] [blame] | 1784 | FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents); |
| 1785 | if (!find_tab_helper) |
| 1786 | return; |
| 1787 | |
| 1788 | find_tab_helper->HandleFindReply(request_id, |
| 1789 | number_of_matches, |
| 1790 | selection_rect, |
| 1791 | active_match_ordinal, |
| 1792 | final_update); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1793 | } |
| 1794 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1795 | void Browser::RequestToLockMouse(WebContents* web_contents, |
[email protected] | a9c81f0 | 2012-06-01 00:15:44 | [diff] [blame] | 1796 | bool user_gesture, |
| 1797 | bool last_unlocked_by_target) { |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 1798 | exclusive_access_manager_->mouse_lock_controller()->RequestToLockMouse( |
| 1799 | web_contents, user_gesture, last_unlocked_by_target); |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 1800 | } |
| 1801 | |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 1802 | void Browser::LostMouseLock() { |
sriramsr | a41db56 | 2015-01-26 22:45:04 | [diff] [blame] | 1803 | exclusive_access_manager_->mouse_lock_controller()->LostMouseLock(); |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 1804 | } |
| 1805 | |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 1806 | void Browser::RequestMediaAccessPermission( |
| 1807 | content::WebContents* web_contents, |
[email protected] | 33662e5 | 2013-01-07 21:31:09 | [diff] [blame] | 1808 | const content::MediaStreamRequest& request, |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 1809 | const content::MediaResponseCallback& callback) { |
[email protected] | 859ec32 | 2013-09-13 16:24:56 | [diff] [blame] | 1810 | ::RequestMediaAccessPermission(web_contents, profile_, request, callback); |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 1811 | } |
| 1812 | |
grunell | 657d4d8 | 2014-09-18 00:09:43 | [diff] [blame] | 1813 | bool Browser::CheckMediaAccessPermission(content::WebContents* web_contents, |
| 1814 | const GURL& security_origin, |
| 1815 | content::MediaStreamType type) { |
| 1816 | return ::CheckMediaAccessPermission(web_contents, security_origin, type); |
| 1817 | } |
| 1818 | |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 1819 | bool Browser::RequestPpapiBrokerPermission( |
| 1820 | WebContents* web_contents, |
| 1821 | const GURL& url, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1822 | const base::FilePath& plugin_path, |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 1823 | const base::Callback<void(bool)>& callback) { |
[email protected] | 0be0993 | 2013-01-08 02:03:50 | [diff] [blame] | 1824 | PepperBrokerInfoBarDelegate::Create(web_contents, url, plugin_path, callback); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 1825 | return true; |
| 1826 | } |
| 1827 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1828 | gfx::Size Browser::GetSizeForNewRenderView(WebContents* web_contents) const { |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 1829 | // When navigating away from NTP with unpinned bookmark bar, the bookmark bar |
| 1830 | // would disappear on non-NTP pages, resulting in a bigger size for the new |
| 1831 | // render view. |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1832 | gfx::Size size = web_contents->GetContainerBounds().size(); |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 1833 | // Don't change render view size if bookmark bar is currently not detached, |
| 1834 | // or there's no pending entry, or navigating to a NTP page. |
| 1835 | if (size.IsEmpty() || bookmark_bar_state_ != BookmarkBar::DETACHED) |
| 1836 | return size; |
| 1837 | const NavigationEntry* pending_entry = |
| 1838 | web_contents->GetController().GetPendingEntry(); |
| 1839 | if (pending_entry && |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1840 | !search::IsNTPURL(pending_entry->GetVirtualURL(), profile_)) { |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 1841 | size.Enlarge( |
| 1842 | 0, window()->GetRenderViewHeightInsetWithDetachedBookmarkBar()); |
| 1843 | } |
| 1844 | return size; |
| 1845 | } |
| 1846 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1847 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 1848 | // Browser, CoreTabHelperDelegate implementation: |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 1849 | |
[email protected] | ece4aca | 2012-09-19 22:22:58 | [diff] [blame] | 1850 | void Browser::SwapTabContents(content::WebContents* old_contents, |
[email protected] | 9aa1f628 | 2014-01-30 08:47:41 | [diff] [blame] | 1851 | content::WebContents* new_contents, |
| 1852 | bool did_start_load, |
| 1853 | bool did_finish_load) { |
[email protected] | ece4aca | 2012-09-19 22:22:58 | [diff] [blame] | 1854 | int index = tab_strip_model_->GetIndexOfWebContents(old_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1855 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | 59fa29fb | 2012-12-07 22:13:42 | [diff] [blame] | 1856 | tab_strip_model_->ReplaceWebContentsAt(index, new_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1857 | } |
| 1858 | |
[email protected] | ece4aca | 2012-09-19 22:22:58 | [diff] [blame] | 1859 | bool Browser::CanReloadContents(content::WebContents* web_contents) const { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1860 | return chrome::CanReload(this); |
[email protected] | e146195 | 2012-06-14 21:05:35 | [diff] [blame] | 1861 | } |
| 1862 | |
[email protected] | ece4aca | 2012-09-19 22:22:58 | [diff] [blame] | 1863 | bool Browser::CanSaveContents(content::WebContents* web_contents) const { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1864 | return chrome::CanSavePage(this); |
[email protected] | e146195 | 2012-06-14 21:05:35 | [diff] [blame] | 1865 | } |
| 1866 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1867 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 82808d0 | 2014-04-10 00:10:59 | [diff] [blame] | 1868 | // Browser, SearchTabHelperDelegate implementation: |
| 1869 | |
[email protected] | 82808d0 | 2014-04-10 00:10:59 | [diff] [blame] | 1870 | void Browser::OnWebContentsInstantSupportDisabled( |
| 1871 | const content::WebContents* web_contents) { |
| 1872 | DCHECK(web_contents); |
| 1873 | if (tab_strip_model_->GetActiveWebContents() == web_contents) |
| 1874 | UpdateToolbar(false); |
| 1875 | } |
| 1876 | |
| 1877 | OmniboxView* Browser::GetOmniboxView() { |
| 1878 | return window_->GetLocationBar()->GetOmniboxView(); |
| 1879 | } |
| 1880 | |
| 1881 | std::set<std::string> Browser::GetOpenUrls() { |
jitendra.ks | 30f0339 | 2015-01-28 09:47:18 | [diff] [blame] | 1882 | scoped_refptr<history::TopSites> top_sites = |
| 1883 | TopSitesFactory::GetForProfile(profile_); |
[email protected] | 82808d0 | 2014-04-10 00:10:59 | [diff] [blame] | 1884 | if (!top_sites) // NULL for Incognito profiles. |
| 1885 | return std::set<std::string>(); |
| 1886 | |
| 1887 | std::set<std::string> open_urls; |
| 1888 | chrome::GetOpenUrls(*tab_strip_model_, *top_sites, &open_urls); |
| 1889 | return open_urls; |
| 1890 | } |
| 1891 | |
| 1892 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | e41d008 | 2013-05-16 04:37:54 | [diff] [blame] | 1893 | // Browser, web_modal::WebContentsModalDialogManagerDelegate implementation: |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1894 | |
[email protected] | c5731a1c | 2012-12-22 10:18:45 | [diff] [blame] | 1895 | void Browser::SetWebContentsBlocked(content::WebContents* web_contents, |
| 1896 | bool blocked) { |
[email protected] | c6464ad | 2012-10-03 00:27:28 | [diff] [blame] | 1897 | int index = tab_strip_model_->GetIndexOfWebContents(web_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1898 | if (index == TabStripModel::kNoTab) { |
| 1899 | NOTREACHED(); |
| 1900 | return; |
| 1901 | } |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1902 | tab_strip_model_->SetTabBlocked(index, blocked); |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 1903 | if (!blocked && tab_strip_model_->GetActiveWebContents() == web_contents) |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1904 | web_contents->Focus(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1905 | } |
| 1906 | |
[email protected] | e41d008 | 2013-05-16 04:37:54 | [diff] [blame] | 1907 | web_modal::WebContentsModalDialogHost* |
| 1908 | Browser::GetWebContentsModalDialogHost() { |
[email protected] | 7519c52 | 2013-04-02 01:07:23 | [diff] [blame] | 1909 | return window_->GetWebContentsModalDialogHost(); |
[email protected] | 6a15176 | 2012-10-03 22:33:19 | [diff] [blame] | 1910 | } |
| 1911 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1912 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1913 | // Browser, BookmarkTabHelperDelegate implementation: |
| 1914 | |
[email protected] | 1c5119c | 2012-09-19 00:08:57 | [diff] [blame] | 1915 | void Browser::URLStarredChanged(content::WebContents* web_contents, |
| 1916 | bool starred) { |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 1917 | if (web_contents == tab_strip_model_->GetActiveWebContents()) |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1918 | window_->SetStarredState(starred); |
| 1919 | } |
| 1920 | |
| 1921 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 1922 | // Browser, ZoomObserver implementation: |
| 1923 | |
wjmaclean | 7f63c6b | 2014-12-09 14:59:55 | [diff] [blame] | 1924 | void Browser::OnZoomChanged( |
juncai | a64f769c2 | 2016-06-04 00:55:32 | [diff] [blame] | 1925 | const zoom::ZoomController::ZoomChangedEventData& data) { |
[email protected] | 63d1f9b | 2014-07-05 19:09:03 | [diff] [blame] | 1926 | if (data.web_contents == tab_strip_model_->GetActiveWebContents()) { |
wjmaclean | ff3d0f6 | 2015-02-25 19:38:36 | [diff] [blame] | 1927 | window_->ZoomChangedForActiveTab(data.can_show_bubble); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 1928 | // Change the zoom commands state based on the zoom state |
| 1929 | command_controller_->ZoomStateChanged(); |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 92f5408 | 2012-07-31 01:43:14 | [diff] [blame] | 1934 | // Browser, ui::SelectFileDialog::Listener implementation: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1935 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1936 | void Browser::FileSelected(const base::FilePath& path, int index, |
| 1937 | void* params) { |
[email protected] | 53f04c8 | 2012-07-26 02:31:09 | [diff] [blame] | 1938 | FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params); |
| 1939 | } |
| 1940 | |
[email protected] | a573bc3 | 2013-04-09 15:09:54 | [diff] [blame] | 1941 | void Browser::FileSelectedWithExtraInfo(const ui::SelectedFileInfo& file_info, |
| 1942 | int index, |
| 1943 | void* params) { |
[email protected] | 53f04c8 | 2012-07-26 02:31:09 | [diff] [blame] | 1944 | profile_->set_last_selected_directory(file_info.file_path.DirName()); |
| 1945 | |
[email protected] | a573bc3 | 2013-04-09 15:09:54 | [diff] [blame] | 1946 | GURL url = net::FilePathToFileURL(file_info.local_path); |
[email protected] | b7813a2 | 2012-04-04 18:41:02 | [diff] [blame] | 1947 | |
| 1948 | #if defined(OS_CHROMEOS) |
hirono | 90949af | 2014-09-25 04:23:37 | [diff] [blame] | 1949 | const GURL external_url = |
| 1950 | chromeos::CreateExternalFileURLFromPath(profile_, file_info.file_path); |
| 1951 | if (!external_url.is_empty()) |
| 1952 | url = external_url; |
[email protected] | b7813a2 | 2012-04-04 18:41:02 | [diff] [blame] | 1953 | #endif |
| 1954 | |
[email protected] | a573bc3 | 2013-04-09 15:09:54 | [diff] [blame] | 1955 | if (url.is_empty()) |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1956 | return; |
| 1957 | |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 1958 | OpenURL(OpenURLParams(url, Referrer(), WindowOpenDisposition::CURRENT_TAB, |
| 1959 | ui::PAGE_TRANSITION_TYPED, false)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1963 | // Browser, content::NotificationObserver implementation: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1964 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1965 | void Browser::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1966 | const content::NotificationSource& source, |
| 1967 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1968 | switch (type) { |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1969 | case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1970 | Profile* profile = content::Source<Profile>(source).ptr(); |
[email protected] | fe8944f | 2011-08-30 17:47:32 | [diff] [blame] | 1971 | if (profile_->IsSameProfile(profile) && window()->GetLocationBar()) |
erikchen | 545918a | 2014-12-31 02:34:06 | [diff] [blame] | 1972 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 371ed7a | 2009-08-25 15:22:46 | [diff] [blame] | 1973 | break; |
| 1974 | } |
| 1975 | |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 1976 | #if defined(ENABLE_THEMES) |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1977 | case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 1978 | window()->UserChangedTheme(); |
| 1979 | break; |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 1980 | #endif |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 1981 | |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 1982 | case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { |
| 1983 | WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 1984 | if (web_contents == tab_strip_model_->GetActiveWebContents()) { |
[email protected] | 9a9a9e2 | 2011-05-13 22:20:35 | [diff] [blame] | 1985 | LocationBar* location_bar = window()->GetLocationBar(); |
| 1986 | if (location_bar) |
| 1987 | location_bar->UpdateContentSettingsIcons(); |
| 1988 | } |
| 1989 | break; |
| 1990 | } |
| 1991 | |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 1992 | default: |
| 1993 | NOTREACHED() << "Got a notification we didn't register for."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1994 | } |
| 1995 | } |
| 1996 | |
thestig | a84d8e6 | 2014-10-17 22:27:55 | [diff] [blame] | 1997 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 1998 | /////////////////////////////////////////////////////////////////////////////// |
jitendra.ks | a005553 | 2014-10-07 05:54:46 | [diff] [blame] | 1999 | // Browser, extensions::ExtensionRegistryObserver implementation: |
| 2000 | |
| 2001 | void Browser::OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 2002 | const extensions::Extension* extension, |
| 2003 | extensions::UninstallReason reason) { |
| 2004 | // During window creation on Windows we may end up calling into |
| 2005 | // SHAppBarMessage, which internally spawns a nested message loop.This |
| 2006 | // makes it possible for us to end up here before window creation has |
| 2007 | // completed, at which point window_ is NULL. See 94752 for details. |
| 2008 | |
| 2009 | if (window() && window()->GetLocationBar()) |
| 2010 | window()->GetLocationBar()->UpdatePageActions(); |
| 2011 | } |
| 2012 | |
| 2013 | void Browser::OnExtensionLoaded(content::BrowserContext* browser_context, |
| 2014 | const extensions::Extension* extension) { |
wittman | 76df71db3 | 2014-12-18 23:26:58 | [diff] [blame] | 2015 | command_controller_->ExtensionStateChanged(); |
jitendra.ks | a005553 | 2014-10-07 05:54:46 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | void Browser::OnExtensionUnloaded( |
| 2019 | content::BrowserContext* browser_context, |
| 2020 | const extensions::Extension* extension, |
| 2021 | extensions::UnloadedExtensionInfo::Reason reason) { |
wittman | 76df71db3 | 2014-12-18 23:26:58 | [diff] [blame] | 2022 | command_controller_->ExtensionStateChanged(); |
jitendra.ks | a005553 | 2014-10-07 05:54:46 | [diff] [blame] | 2023 | if (window()->GetLocationBar()) |
| 2024 | window()->GetLocationBar()->UpdatePageActions(); |
| 2025 | |
| 2026 | // Close any tabs from the unloaded extension, unless it's terminated, |
| 2027 | // in which case let the sad tabs remain. |
jared.sohn | a140962 | 2015-08-08 07:16:14 | [diff] [blame] | 2028 | // Also, if tab is muted and the cause is the unloaded extension, unmute it. |
jitendra.ks | a005553 | 2014-10-07 05:54:46 | [diff] [blame] | 2029 | if (reason != extensions::UnloadedExtensionInfo::REASON_TERMINATE) { |
| 2030 | // Iterate backwards as we may remove items while iterating. |
| 2031 | for (int i = tab_strip_model_->count() - 1; i >= 0; --i) { |
| 2032 | WebContents* web_contents = tab_strip_model_->GetWebContentsAt(i); |
| 2033 | // Two cases are handled here: |
| 2034 | |
| 2035 | // - The scheme check is for when an extension page is loaded in a |
| 2036 | // tab, e.g. chrome-extension://id/page.html. |
| 2037 | // - The extension_app check is for apps, which can have non-extension |
| 2038 | // schemes, e.g. https://mail.google.com if you have the Gmail app |
| 2039 | // installed. |
| 2040 | if ((web_contents->GetURL().SchemeIs(extensions::kExtensionScheme) && |
| 2041 | web_contents->GetURL().host() == extension->id()) || |
| 2042 | (extensions::TabHelper::FromWebContents(web_contents) |
| 2043 | ->extension_app() == extension)) { |
| 2044 | tab_strip_model_->CloseWebContentsAt(i, TabStripModel::CLOSE_NONE); |
jared.sohn | a140962 | 2015-08-08 07:16:14 | [diff] [blame] | 2045 | } else { |
miu | 895bb4e | 2015-08-11 23:03:04 | [diff] [blame] | 2046 | chrome::UnmuteIfMutedByExtension(web_contents, extension->id()); |
jitendra.ks | a005553 | 2014-10-07 05:54:46 | [diff] [blame] | 2047 | } |
| 2048 | } |
| 2049 | } |
| 2050 | } |
thestig | a84d8e6 | 2014-10-17 22:27:55 | [diff] [blame] | 2051 | #endif // defined(ENABLE_EXTENSIONS) |
jitendra.ks | a005553 | 2014-10-07 05:54:46 | [diff] [blame] | 2052 | |
| 2053 | /////////////////////////////////////////////////////////////////////////////// |
pkasting | cc29d20e | 2015-02-25 06:05:53 | [diff] [blame] | 2054 | // Browser, translate::ContentTranslateDriver::Observer implementation: |
| 2055 | |
| 2056 | void Browser::OnIsPageTranslatedChanged(content::WebContents* source) { |
| 2057 | DCHECK(source); |
| 2058 | if (tab_strip_model_->GetActiveWebContents() == source) { |
| 2059 | window_->SetTranslateIconToggled( |
| 2060 | ChromeTranslateClient::FromWebContents( |
| 2061 | source)->GetLanguageState().IsPageTranslated()); |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | void Browser::OnTranslateEnabledChanged(content::WebContents* source) { |
| 2066 | DCHECK(source); |
| 2067 | if (tab_strip_model_->GetActiveWebContents() == source) |
| 2068 | UpdateToolbar(false); |
| 2069 | } |
| 2070 | |
| 2071 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2072 | // Browser, Command and state updating (private): |
| 2073 | |
[email protected] | c31813a | 2012-11-15 18:47:26 | [diff] [blame] | 2074 | void Browser::OnDevToolsDisabledChanged() { |
| 2075 | if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
[email protected] | b50452f | 2014-08-18 12:31:44 | [diff] [blame] | 2076 | content::DevToolsAgentHost::DetachAllClients(); |
[email protected] | c31813a | 2012-11-15 18:47:26 | [diff] [blame] | 2077 | } |
| 2078 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2079 | /////////////////////////////////////////////////////////////////////////////// |
| 2080 | // Browser, UI update coalescing and handling (private): |
| 2081 | |
| 2082 | void Browser::UpdateToolbar(bool should_restore_state) { |
[email protected] | 2e7fe431 | 2013-08-21 17:19:48 | [diff] [blame] | 2083 | window_->UpdateToolbar(should_restore_state ? |
| 2084 | tab_strip_model_->GetActiveWebContents() : NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2085 | } |
| 2086 | |
creis | cde28de | 2014-11-26 17:10:36 | [diff] [blame] | 2087 | void Browser::ScheduleUIUpdate(WebContents* source, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2088 | unsigned changed_flags) { |
[email protected] | 913664d | 2013-12-17 11:43:38 | [diff] [blame] | 2089 | DCHECK(source); |
| 2090 | int index = tab_strip_model_->GetIndexOfWebContents(source); |
| 2091 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2092 | |
erikchen | 174b78c6 | 2015-03-11 22:02:54 | [diff] [blame] | 2093 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 2094 | // is fixed. |
| 2095 | tracked_objects::ScopedTracker tracking_profile1( |
| 2096 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2097 | "466285 Browser::ScheduleUIUpdate::Toolbar")); |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 2098 | // Do some synchronous updates. |
creis | cde28de | 2014-11-26 17:10:36 | [diff] [blame] | 2099 | if (changed_flags & content::INVALIDATE_TYPE_URL) { |
| 2100 | if (source == tab_strip_model_->GetActiveWebContents()) { |
| 2101 | // Only update the URL for the current tab. Note that we do not update |
| 2102 | // the navigation commands since those would have already been updated |
| 2103 | // synchronously by NavigationStateChanged. |
| 2104 | UpdateToolbar(false); |
| 2105 | } else { |
| 2106 | // Clear the saved tab state for the tab that navigated, so that we don't |
| 2107 | // restore any user text after the old URL has been invalidated (e.g., |
| 2108 | // after a new navigation commits in that tab while unfocused). |
| 2109 | window_->ResetToolbarTabState(source); |
| 2110 | } |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2111 | changed_flags &= ~content::INVALIDATE_TYPE_URL; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2112 | } |
erikchen | 174b78c6 | 2015-03-11 22:02:54 | [diff] [blame] | 2113 | |
| 2114 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 2115 | // is fixed. |
| 2116 | tracked_objects::ScopedTracker tracking_profile2( |
| 2117 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2118 | "466285 Browser::ScheduleUIUpdate::TabStripModel")); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2119 | if (changed_flags & content::INVALIDATE_TYPE_LOAD) { |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 2120 | // Update the loading state synchronously. This is so the throbber will |
| 2121 | // immediately start/stop, which gives a more snappy feel. We want to do |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2122 | // this for any tab so they start & stop quickly. |
[email protected] | 526b45e | 2012-11-28 20:22:46 | [diff] [blame] | 2123 | tab_strip_model_->UpdateWebContentsStateAt( |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 2124 | tab_strip_model_->GetIndexOfWebContents(source), |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 2125 | TabStripModelObserver::LOADING_ONLY); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2126 | // The status bubble needs to be updated during INVALIDATE_TYPE_LOAD too, |
| 2127 | // but we do that asynchronously by not stripping INVALIDATE_TYPE_LOAD from |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 2128 | // changed_flags. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2129 | } |
| 2130 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2131 | if (changed_flags & content::INVALIDATE_TYPE_TITLE && !source->IsLoading()) { |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 2132 | // To correctly calculate whether the title changed while not loading |
| 2133 | // we need to process the update synchronously. This state only matters for |
| 2134 | // the TabStripModel, so we notify the TabStripModel now and notify others |
| 2135 | // asynchronously. |
[email protected] | 526b45e | 2012-11-28 20:22:46 | [diff] [blame] | 2136 | tab_strip_model_->UpdateWebContentsStateAt( |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 2137 | tab_strip_model_->GetIndexOfWebContents(source), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 2138 | TabStripModelObserver::TITLE_NOT_LOADING); |
| 2139 | } |
| 2140 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 2141 | // If the only updates were synchronously handled above, we're done. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2142 | if (changed_flags == 0) |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 2143 | return; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2144 | |
| 2145 | // Save the dirty bits. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2146 | scheduled_updates_[source] |= changed_flags; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2147 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 2148 | if (!chrome_updater_factory_.HasWeakPtrs()) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2149 | // No task currently scheduled, start another. |
skyostil | 380bb222 | 2015-06-12 12:07:05 | [diff] [blame] | 2150 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 2151 | FROM_HERE, base::Bind(&Browser::ProcessPendingUIUpdates, |
| 2152 | chrome_updater_factory_.GetWeakPtr()), |
[email protected] | 11d6ab1a | 2012-01-12 21:37:26 | [diff] [blame] | 2153 | base::TimeDelta::FromMilliseconds(kUIUpdateCoalescingTimeMS)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | void Browser::ProcessPendingUIUpdates() { |
| 2158 | #ifndef NDEBUG |
| 2159 | // Validate that all tabs we have pending updates for exist. This is scary |
| 2160 | // because the pending list must be kept in sync with any detached or |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2161 | // deleted tabs. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2162 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 2163 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2164 | bool found = false; |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 2165 | for (int tab = 0; tab < tab_strip_model_->count(); tab++) { |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 2166 | if (tab_strip_model_->GetWebContentsAt(tab) == i->first) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2167 | found = true; |
| 2168 | break; |
| 2169 | } |
| 2170 | } |
| 2171 | DCHECK(found); |
| 2172 | } |
| 2173 | #endif |
| 2174 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 2175 | chrome_updater_factory_.InvalidateWeakPtrs(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2176 | |
robliao | 1766df5 | 2015-03-14 01:06:26 | [diff] [blame] | 2177 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 |
| 2178 | // is fixed. |
| 2179 | tracked_objects::ScopedTracker tracking_profile1( |
| 2180 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2181 | "467185 Browser::ProcessPendingUIUpdates1")); |
| 2182 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2183 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 2184 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2185 | // Do not dereference |contents|, it may be out-of-date! |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2186 | const WebContents* contents = i->first; |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2187 | unsigned flags = i->second; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2188 | |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 2189 | if (contents == tab_strip_model_->GetActiveWebContents()) { |
robliao | 1766df5 | 2015-03-14 01:06:26 | [diff] [blame] | 2190 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 |
| 2191 | // is fixed. |
| 2192 | tracked_objects::ScopedTracker tracking_profile2( |
| 2193 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2194 | "467185 Browser::ProcessPendingUIUpdates2")); |
| 2195 | |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2196 | // Updates that only matter when the tab is selected go here. |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 2197 | |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 2198 | // Updating the URL happens synchronously in ScheduleUIUpdate. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2199 | if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) { |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 2200 | GetStatusBubble()->SetStatus(CoreTabHelper::FromWebContents( |
| 2201 | tab_strip_model_->GetActiveWebContents())->GetStatusText()); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 2202 | } |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2203 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2204 | if (flags & (content::INVALIDATE_TYPE_TAB | |
| 2205 | content::INVALIDATE_TYPE_TITLE)) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2206 | window_->UpdateTitleBar(); |
| 2207 | } |
[email protected] | 4d34e2e | 2009-05-26 22:55:28 | [diff] [blame] | 2208 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2209 | |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2210 | // Updates that don't depend upon the selected state go here. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2211 | if (flags & |
| 2212 | (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) { |
robliao | 1766df5 | 2015-03-14 01:06:26 | [diff] [blame] | 2213 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 |
| 2214 | // is fixed. |
| 2215 | tracked_objects::ScopedTracker tracking_profile3( |
| 2216 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2217 | "467185 Browser::ProcessPendingUIUpdates3")); |
[email protected] | 526b45e | 2012-11-28 20:22:46 | [diff] [blame] | 2218 | tab_strip_model_->UpdateWebContentsStateAt( |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 2219 | tab_strip_model_->GetIndexOfWebContents(contents), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 2220 | TabStripModelObserver::ALL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2221 | } |
| 2222 | |
[email protected] | 13155a2 | 2013-03-19 23:33:54 | [diff] [blame] | 2223 | // Update the bookmark bar. It may happen that the tab is crashed, and if |
| 2224 | // so, the bookmark bar should be hidden. |
robliao | 1766df5 | 2015-03-14 01:06:26 | [diff] [blame] | 2225 | if (flags & content::INVALIDATE_TYPE_TAB) { |
| 2226 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 |
| 2227 | // is fixed. |
| 2228 | tracked_objects::ScopedTracker tracking_profile4( |
| 2229 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2230 | "467185 Browser::ProcessPendingUIUpdates4")); |
[email protected] | 13155a2 | 2013-03-19 23:33:54 | [diff] [blame] | 2231 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
robliao | 1766df5 | 2015-03-14 01:06:26 | [diff] [blame] | 2232 | } |
[email protected] | 13155a2 | 2013-03-19 23:33:54 | [diff] [blame] | 2233 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2234 | // We don't need to process INVALIDATE_STATE, since that's not visible. |
| 2235 | } |
| 2236 | |
| 2237 | scheduled_updates_.clear(); |
| 2238 | } |
| 2239 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2240 | void Browser::RemoveScheduledUpdatesFor(WebContents* contents) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2241 | if (!contents) |
| 2242 | return; |
| 2243 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2244 | UpdateMap::iterator i = scheduled_updates_.find(contents); |
| 2245 | if (i != scheduled_updates_.end()) |
| 2246 | scheduled_updates_.erase(i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2247 | } |
| 2248 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2249 | /////////////////////////////////////////////////////////////////////////////// |
| 2250 | // Browser, Getters for UI (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2251 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2252 | StatusBubble* Browser::GetStatusBubble() { |
[email protected] | 8e837ec | 2013-01-31 01:48:33 | [diff] [blame] | 2253 | // In kiosk and exclusive app mode, we want to always hide the status bubble. |
| 2254 | if (chrome::IsRunningInAppMode()) |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 2255 | return NULL; |
[email protected] | 8e837ec | 2013-01-31 01:48:33 | [diff] [blame] | 2256 | |
[email protected] | 9b032bf | 2009-07-21 17:34:23 | [diff] [blame] | 2257 | return window_ ? window_->GetStatusBubble() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2258 | } |
| 2259 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2260 | /////////////////////////////////////////////////////////////////////////////// |
| 2261 | // Browser, Session restore functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2262 | |
| 2263 | void Browser::SyncHistoryWithTabs(int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2264 | SessionService* session_service = |
| 2265 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2266 | if (session_service) { |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 2267 | for (int i = index; i < tab_strip_model_->count(); ++i) { |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 2268 | WebContents* web_contents = tab_strip_model_->GetWebContentsAt(i); |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 2269 | if (web_contents) { |
| 2270 | SessionTabHelper* session_tab_helper = |
| 2271 | SessionTabHelper::FromWebContents(web_contents); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2272 | session_service->SetTabIndexInWindow( |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 2273 | session_id(), session_tab_helper->session_id(), i); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2274 | session_service->SetPinnedState( |
| 2275 | session_id(), |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 2276 | session_tab_helper->session_id(), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2277 | tab_strip_model_->IsTabPinned(i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2278 | } |
| 2279 | } |
| 2280 | } |
| 2281 | } |
| 2282 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2283 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 2284 | // Browser, In-progress download termination handling (private): |
| 2285 | |
[email protected] | b6a4ac2b | 2011-10-17 20:05:48 | [diff] [blame] | 2286 | bool Browser::CanCloseWithInProgressDownloads() { |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 2287 | // If we've prompted, we need to hear from the user before we |
| 2288 | // can close. |
| 2289 | if (cancel_download_confirmation_state_ != NOT_PROMPTED) |
| 2290 | return cancel_download_confirmation_state_ != WAITING_FOR_RESPONSE; |
| 2291 | |
| 2292 | int num_downloads_blocking; |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 2293 | Browser::DownloadClosePreventionType dialog_type = |
| 2294 | OkToCloseWithInProgressDownloads(&num_downloads_blocking); |
| 2295 | if (dialog_type == DOWNLOAD_CLOSE_OK) |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 2296 | return true; |
| 2297 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 2298 | // Closing this window will kill some downloads; prompt to make sure |
| 2299 | // that's ok. |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 2300 | cancel_download_confirmation_state_ = WAITING_FOR_RESPONSE; |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 2301 | window_->ConfirmBrowserCloseWithPendingDownloads( |
| 2302 | num_downloads_blocking, |
| 2303 | dialog_type, |
| 2304 | false, |
| 2305 | base::Bind(&Browser::InProgressDownloadResponse, |
| 2306 | weak_factory_.GetWeakPtr())); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 2307 | |
| 2308 | // Return false so the browser does not close. We'll close if the user |
| 2309 | // confirms in the dialog. |
| 2310 | return false; |
| 2311 | } |
| 2312 | |
| 2313 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2314 | // Browser, Assorted utility functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2315 | |
[email protected] | 63d1f9b | 2014-07-05 19:09:03 | [diff] [blame] | 2316 | void Browser::SetAsDelegate(WebContents* web_contents, bool set_delegate) { |
| 2317 | Browser* delegate = set_delegate ? this : NULL; |
[email protected] | 27e5b391 | 2012-12-16 00:45:37 | [diff] [blame] | 2318 | // WebContents... |
| 2319 | web_contents->SetDelegate(delegate); |
| 2320 | |
| 2321 | // ...and all the helpers. |
[email protected] | 27e5b391 | 2012-12-16 00:45:37 | [diff] [blame] | 2322 | BookmarkTabHelper::FromWebContents(web_contents)->set_delegate(delegate); |
[email protected] | d2b1657 | 2013-01-03 00:41:58 | [diff] [blame] | 2323 | WebContentsModalDialogManager::FromWebContents(web_contents)-> |
[email protected] | 5c2c779 | 2013-08-20 18:39:16 | [diff] [blame] | 2324 | SetDelegate(delegate); |
[email protected] | 27e5b391 | 2012-12-16 00:45:37 | [diff] [blame] | 2325 | CoreTabHelper::FromWebContents(web_contents)->set_delegate(delegate); |
[email protected] | 82808d0 | 2014-04-10 00:10:59 | [diff] [blame] | 2326 | SearchTabHelper::FromWebContents(web_contents)->set_delegate(delegate); |
droger | 38f0d10 | 2014-09-16 15:37:41 | [diff] [blame] | 2327 | translate::ContentTranslateDriver& content_translate_driver = |
| 2328 | ChromeTranslateClient::FromWebContents(web_contents)->translate_driver(); |
| 2329 | if (delegate) { |
juncai | a64f769c2 | 2016-06-04 00:55:32 | [diff] [blame] | 2330 | zoom::ZoomController::FromWebContents(web_contents)->AddObserver(this); |
pkasting | cc29d20e | 2015-02-25 06:05:53 | [diff] [blame] | 2331 | content_translate_driver.AddObserver(this); |
droger | 38f0d10 | 2014-09-16 15:37:41 | [diff] [blame] | 2332 | } else { |
juncai | a64f769c2 | 2016-06-04 00:55:32 | [diff] [blame] | 2333 | zoom::ZoomController::FromWebContents(web_contents)->RemoveObserver(this); |
pkasting | cc29d20e | 2015-02-25 06:05:53 | [diff] [blame] | 2334 | content_translate_driver.RemoveObserver(this); |
droger | 38f0d10 | 2014-09-16 15:37:41 | [diff] [blame] | 2335 | } |
[email protected] | 27e5b391 | 2012-12-16 00:45:37 | [diff] [blame] | 2336 | } |
| 2337 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2338 | void Browser::CloseFrame() { |
| 2339 | window_->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2340 | } |
| 2341 | |
[email protected] | e89cfcb | 2012-11-11 14:47:24 | [diff] [blame] | 2342 | void Browser::TabDetachedAtImpl(content::WebContents* contents, |
| 2343 | int index, |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2344 | DetachType type) { |
| 2345 | if (type == DETACH_TYPE_DETACH) { |
[email protected] | 5658085 | 2010-11-17 16:09:15 | [diff] [blame] | 2346 | // Save the current location bar state, but only if the tab being detached |
| 2347 | // is the selected tab. Because saving state can conditionally revert the |
| 2348 | // location bar, saving the current tab's location bar state to a |
| 2349 | // non-selected tab can corrupt both tabs. |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 2350 | if (contents == tab_strip_model_->GetActiveWebContents()) { |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2351 | LocationBar* location_bar = window()->GetLocationBar(); |
| 2352 | if (location_bar) |
[email protected] | e89cfcb | 2012-11-11 14:47:24 | [diff] [blame] | 2353 | location_bar->SaveStateToContents(contents); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2354 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2355 | |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2356 | if (!tab_strip_model_->closing_all()) |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2357 | SyncHistoryWithTabs(0); |
| 2358 | } |
| 2359 | |
[email protected] | 63d1f9b | 2014-07-05 19:09:03 | [diff] [blame] | 2360 | SetAsDelegate(contents, false); |
[email protected] | e89cfcb | 2012-11-11 14:47:24 | [diff] [blame] | 2361 | RemoveScheduledUpdatesFor(contents); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2362 | |
[email protected] | 04e3ead5 | 2013-01-14 01:09:20 | [diff] [blame] | 2363 | if (find_bar_controller_.get() && index == tab_strip_model_->active_index()) { |
[email protected] | ba3d09a1 | 2012-11-07 12:13:52 | [diff] [blame] | 2364 | find_bar_controller_->ChangeWebContents(NULL); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2365 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2366 | |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 2367 | // Stop observing search model changes for this tab. |
[email protected] | e89cfcb | 2012-11-11 14:47:24 | [diff] [blame] | 2368 | search_delegate_->OnTabDetached(contents); |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 2369 | |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 2370 | for (size_t i = 0; i < interstitial_observers_.size(); i++) { |
| 2371 | if (interstitial_observers_[i]->web_contents() != contents) |
| 2372 | continue; |
| 2373 | |
| 2374 | delete interstitial_observers_[i]; |
| 2375 | interstitial_observers_.erase(interstitial_observers_.begin() + i); |
| 2376 | return; |
| 2377 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2378 | } |
| 2379 | |
benwells | a2a8a9f7 | 2015-04-07 07:09:54 | [diff] [blame] | 2380 | bool Browser::SupportsLocationBar() const { |
[email protected] | d2202e2 | 2014-04-14 20:20:53 | [diff] [blame] | 2381 | // Tabbed browser always show a location bar. |
| 2382 | if (is_type_tabbed()) |
[email protected] | 8a585cb | 2014-03-21 17:13:52 | [diff] [blame] | 2383 | return true; |
[email protected] | d2202e2 | 2014-04-14 20:20:53 | [diff] [blame] | 2384 | |
benwells | 919e79b | 2015-03-19 04:58:19 | [diff] [blame] | 2385 | // Non-app windows that aren't tabbed or system windows should always show a |
| 2386 | // location bar, unless they are from a trusted source. |
| 2387 | if (!is_app()) |
| 2388 | return !is_trusted_source(); |
| 2389 | |
benwells | 11bd6ed | 2015-06-05 04:20:41 | [diff] [blame] | 2390 | if (hosted_app_controller_) |
| 2391 | return hosted_app_controller_->SupportsLocationBar(); |
benwells | 919e79b | 2015-03-19 04:58:19 | [diff] [blame] | 2392 | |
benwells | a2a8a9f7 | 2015-04-07 07:09:54 | [diff] [blame] | 2393 | return false; |
[email protected] | 8a585cb | 2014-03-21 17:13:52 | [diff] [blame] | 2394 | } |
| 2395 | |
benwells | 502df69 | 2014-12-02 20:41:45 | [diff] [blame] | 2396 | bool Browser::ShouldUseWebAppFrame() const { |
benwells | 919e79b | 2015-03-19 04:58:19 | [diff] [blame] | 2397 | // Only use the web app frame for apps in ash, and only if the web app frame |
| 2398 | // is enabled. |
benwells | a2a8a9f7 | 2015-04-07 07:09:54 | [diff] [blame] | 2399 | if (!is_app()) |
benwells | 502df69 | 2014-12-02 20:41:45 | [diff] [blame] | 2400 | return false; |
benwells | 502df69 | 2014-12-02 20:41:45 | [diff] [blame] | 2401 | |
benwells | 11bd6ed | 2015-06-05 04:20:41 | [diff] [blame] | 2402 | if (hosted_app_controller_) |
| 2403 | return hosted_app_controller_->should_use_web_app_frame(); |
benwells | a2a8a9f7 | 2015-04-07 07:09:54 | [diff] [blame] | 2404 | |
| 2405 | return false; |
benwells | 502df69 | 2014-12-02 20:41:45 | [diff] [blame] | 2406 | } |
| 2407 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2408 | bool Browser::SupportsWindowFeatureImpl(WindowFeature feature, |
| 2409 | bool check_fullscreen) const { |
[email protected] | c3e3294 | 2012-12-11 10:26:20 | [diff] [blame] | 2410 | bool hide_ui_for_fullscreen = check_fullscreen && ShouldHideUIForFullscreen(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2411 | |
| 2412 | unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF; |
| 2413 | |
| 2414 | if (is_type_tabbed()) |
| 2415 | features |= FEATURE_BOOKMARKBAR; |
| 2416 | |
| 2417 | if (!hide_ui_for_fullscreen) { |
| 2418 | if (!is_type_tabbed()) |
| 2419 | features |= FEATURE_TITLEBAR; |
| 2420 | |
| 2421 | if (is_type_tabbed()) |
| 2422 | features |= FEATURE_TABSTRIP; |
| 2423 | |
| 2424 | if (is_type_tabbed()) |
| 2425 | features |= FEATURE_TOOLBAR; |
| 2426 | |
benwells | a2a8a9f7 | 2015-04-07 07:09:54 | [diff] [blame] | 2427 | if (SupportsLocationBar()) |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2428 | features |= FEATURE_LOCATIONBAR; |
benwells | 502df69 | 2014-12-02 20:41:45 | [diff] [blame] | 2429 | |
| 2430 | if (ShouldUseWebAppFrame()) |
| 2431 | features |= FEATURE_WEBAPPFRAME; |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2432 | } |
| 2433 | return !!(features & feature); |
| 2434 | } |
| 2435 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2436 | void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { |
robliao | e879c2bb | 2015-03-21 00:46:37 | [diff] [blame] | 2437 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 is |
| 2438 | // fixed. |
| 2439 | tracked_objects::ScopedTracker tracking_profile1( |
| 2440 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2441 | "467185 Browser::UpdateBookmarkBarState1")); |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2442 | BookmarkBar::State state; |
[email protected] | a7666d8 | 2014-04-04 21:34:03 | [diff] [blame] | 2443 | // The bookmark bar is always hidden for Guest Sessions and in fullscreen |
| 2444 | // mode, unless on the new tab page. |
| 2445 | if (profile_->IsGuestSession()) { |
| 2446 | state = BookmarkBar::HIDDEN; |
| 2447 | } else if (browser_defaults::bookmarks_enabled && |
tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 2448 | profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) && |
[email protected] | c3e3294 | 2012-12-11 10:26:20 | [diff] [blame] | 2449 | !ShouldHideUIForFullscreen()) { |
[email protected] | 0414336 | 2012-11-28 14:25:18 | [diff] [blame] | 2450 | state = BookmarkBar::SHOW; |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2451 | } else { |
robliao | e879c2bb | 2015-03-21 00:46:37 | [diff] [blame] | 2452 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 |
| 2453 | // is fixed. |
| 2454 | tracked_objects::ScopedTracker tracking_profile2( |
| 2455 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2456 | "467185 Browser::UpdateBookmarkBarState2")); |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 2457 | WebContents* web_contents = tab_strip_model_->GetActiveWebContents(); |
[email protected] | 1c5119c | 2012-09-19 00:08:57 | [diff] [blame] | 2458 | BookmarkTabHelper* bookmark_tab_helper = |
| 2459 | web_contents ? BookmarkTabHelper::FromWebContents(web_contents) : NULL; |
| 2460 | if (bookmark_tab_helper && bookmark_tab_helper->ShouldShowBookmarkBar()) |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2461 | state = BookmarkBar::DETACHED; |
| 2462 | else |
| 2463 | state = BookmarkBar::HIDDEN; |
| 2464 | } |
[email protected] | 2d4e43a0 | 2012-06-26 00:11:55 | [diff] [blame] | 2465 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2466 | if (state == bookmark_bar_state_) |
| 2467 | return; |
| 2468 | |
| 2469 | bookmark_bar_state_ = state; |
| 2470 | |
| 2471 | if (!window_) |
| 2472 | return; // This is called from the constructor when window_ is NULL. |
| 2473 | |
| 2474 | if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) { |
| 2475 | // Don't notify BrowserWindow on a tab switch as at the time this is invoked |
| 2476 | // BrowserWindow hasn't yet switched tabs. The BrowserWindow implementations |
| 2477 | // end up querying state once they process the tab switch. |
| 2478 | return; |
| 2479 | } |
| 2480 | |
robliao | e879c2bb | 2015-03-21 00:46:37 | [diff] [blame] | 2481 | // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 is |
| 2482 | // fixed. |
| 2483 | tracked_objects::ScopedTracker tracking_profile3( |
| 2484 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2485 | "467185 Browser::UpdateBookmarkBarState3")); |
| 2486 | |
tfarina | 41f4208 | 2014-12-26 14:08:12 | [diff] [blame] | 2487 | bool should_animate = reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE; |
| 2488 | window_->BookmarkBarStateChanged(should_animate ? |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2489 | BookmarkBar::ANIMATE_STATE_CHANGE : |
[email protected] | e2395da | 2013-01-23 22:05:35 | [diff] [blame] | 2490 | BookmarkBar::DONT_ANIMATE_STATE_CHANGE); |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2491 | } |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 2492 | |
[email protected] | c3e3294 | 2012-12-11 10:26:20 | [diff] [blame] | 2493 | bool Browser::ShouldHideUIForFullscreen() const { |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 2494 | // Windows and GTK remove the top controls in fullscreen, but Mac and Ash |
| 2495 | // keep the controls in a slide-down panel. |
| 2496 | return window_ && window_->ShouldHideUIForFullscreen(); |
[email protected] | c3e3294 | 2012-12-11 10:26:20 | [diff] [blame] | 2497 | } |
| 2498 | |
thestig | 02897869 | 2015-10-08 07:39:40 | [diff] [blame] | 2499 | bool Browser::ShouldStartShutdown() const { |
scottmg | 0d8e4ab | 2016-01-28 00:34:55 | [diff] [blame] | 2500 | return BrowserList::GetInstance()->size() <= 1; |
thestig | 02897869 | 2015-10-08 07:39:40 | [diff] [blame] | 2501 | } |
| 2502 | |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 2503 | bool Browser::MaybeCreateBackgroundContents( |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2504 | int32_t route_id, |
| 2505 | int32_t main_frame_route_id, |
| 2506 | int32_t main_frame_widget_route_id, |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 2507 | WebContents* opener_web_contents, |
nasko | 48321ca3 | 2015-07-02 20:44:12 | [diff] [blame] | 2508 | const std::string& frame_name, |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 2509 | const GURL& target_url, |
| 2510 | const std::string& partition_id, |
| 2511 | content::SessionStorageNamespace* session_storage_namespace) { |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2512 | GURL opener_url = opener_web_contents->GetURL(); |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 2513 | ExtensionService* extensions_service = |
| 2514 | extensions::ExtensionSystem::Get(profile_)->extension_service(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2515 | |
| 2516 | if (!opener_url.is_valid() || |
| 2517 | frame_name.empty() || |
| 2518 | !extensions_service || |
| 2519 | !extensions_service->is_ready()) |
| 2520 | return false; |
| 2521 | |
| 2522 | // Only hosted apps have web extents, so this ensures that only hosted apps |
| 2523 | // can create BackgroundContents. We don't have to check for background |
| 2524 | // permission as that is checked in RenderMessageFilter when the CreateWindow |
| 2525 | // message is processed. |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 2526 | const Extension* extension = extensions::ExtensionRegistry::Get(profile_) |
| 2527 | ->enabled_extensions() |
| 2528 | .GetHostedAppByURL(opener_url); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2529 | if (!extension) |
| 2530 | return false; |
| 2531 | |
| 2532 | // No BackgroundContents allowed if BackgroundContentsService doesn't exist. |
| 2533 | BackgroundContentsService* service = |
| 2534 | BackgroundContentsServiceFactory::GetForProfile(profile_); |
| 2535 | if (!service) |
| 2536 | return false; |
| 2537 | |
| 2538 | // Ensure that we're trying to open this from the extension's process. |
| 2539 | SiteInstance* opener_site_instance = opener_web_contents->GetSiteInstance(); |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 2540 | extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile_); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2541 | if (!opener_site_instance->GetProcess() || |
| 2542 | !process_map->Contains( |
| 2543 | extension->id(), opener_site_instance->GetProcess()->GetID())) { |
| 2544 | return false; |
| 2545 | } |
| 2546 | |
| 2547 | // Only allow a single background contents per app. |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 2548 | bool allow_js_access = extensions::BackgroundInfo::AllowJSAccess(extension); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2549 | BackgroundContents* existing = |
[email protected] | 1f13690 | 2013-12-24 23:26:45 | [diff] [blame] | 2550 | service->GetAppBackgroundContents(base::ASCIIToUTF16(extension->id())); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2551 | if (existing) { |
| 2552 | // For non-scriptable background contents, ignore the request altogether, |
| 2553 | // (returning true, so that a regular WebContents isn't created either). |
| 2554 | if (!allow_js_access) |
| 2555 | return true; |
| 2556 | // For scriptable background pages, if one already exists, close it (even |
| 2557 | // if it was specified in the manifest). |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2558 | delete existing; |
| 2559 | } |
| 2560 | |
| 2561 | // If script access is not allowed, create the the background contents in a |
| 2562 | // new SiteInstance, so that a separate process is used. |
| 2563 | scoped_refptr<content::SiteInstance> site_instance = |
| 2564 | allow_js_access ? |
| 2565 | opener_site_instance : |
| 2566 | content::SiteInstance::Create(opener_web_contents->GetBrowserContext()); |
| 2567 | |
| 2568 | // Passed all the checks, so this should be created as a BackgroundContents. |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2569 | BackgroundContents* contents = service->CreateBackgroundContents( |
| 2570 | site_instance.get(), route_id, main_frame_route_id, |
| 2571 | main_frame_widget_route_id, profile_, frame_name, |
| 2572 | base::ASCIIToUTF16(extension->id()), partition_id, |
| 2573 | session_storage_namespace); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2574 | |
| 2575 | // When a separate process is used, the original renderer cannot access the |
| 2576 | // new window later, thus we need to navigate the window now. |
| 2577 | if (contents && !allow_js_access) { |
| 2578 | contents->web_contents()->GetController().LoadURL( |
| 2579 | target_url, |
| 2580 | content::Referrer(), |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 2581 | ui::PAGE_TRANSITION_LINK, |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2582 | std::string()); // No extra headers. |
| 2583 | } |
| 2584 | |
| 2585 | return contents != NULL; |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 2586 | } |