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