blob: c633924e5aae024f4cd0273fab00bd4581f21fe9 [file] [log] [blame]
[email protected]e41982a72012-11-20 07:16:511// Copyright 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]7b5dc002010-11-16 23:08:105#include "chrome/browser/ui/browser.h"
[email protected]c61db1d2009-02-06 03:39:186
[email protected]aca02cf2010-05-03 18:56:017#if defined(OS_WIN)
[email protected]541434c2011-06-25 01:38:598#include <windows.h>
[email protected]dcd57762011-06-25 12:18:519#include <shellapi.h>
[email protected]9c55de82012-11-01 21:03:5210#endif // defined(OS_WIN)
[email protected]aca02cf2010-05-03 18:56:0111
[email protected]5dcbc02f2010-01-26 22:32:0612#include <algorithm>
13#include <string>
14
[email protected]b02d0382009-11-30 21:19:5015#include "base/base_paths.h"
[email protected]24f1477532011-11-22 22:55:3616#include "base/bind.h"
[email protected]8a53ee042009-01-21 16:41:3317#include "base/command_line.h"
skyostil380bb2222015-06-12 12:07:0518#include "base/location.h"
[email protected]8a53ee042009-01-21 16:41:3319#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3820#include "base/metrics/histogram.h"
[email protected]3853a4c2013-02-11 17:15:5721#include "base/prefs/pref_service.h"
[email protected]d09a4ce1c2013-07-24 17:37:0222#include "base/process/process_info.h"
erikchen174b78c62015-03-11 22:02:5423#include "base/profiler/scoped_tracker.h"
skyostil380bb2222015-06-12 12:07:0524#include "base/single_thread_task_runner.h"
[email protected]3ea1b182013-02-08 22:38:4125#include "base/strings/string_number_conversions.h"
[email protected]11521182013-06-11 04:06:3626#include "base/strings/string_util.h"
27#include "base/strings/stringprintf.h"
[email protected]5846d582013-06-08 16:02:1228#include "base/strings/utf_string_conversions.h"
skyostil380bb2222015-06-12 12:07:0529#include "base/thread_task_runner_handle.h"
[email protected]34b99632011-01-01 01:01:0630#include "base/threading/thread.h"
31#include "base/threading/thread_restrictions.h"
[email protected]bd64063d2013-06-28 15:16:2232#include "base/time/time.h"
[email protected]1a3aba82010-11-08 23:52:5433#include "chrome/app/chrome_command_ids.h"
[email protected]8e837ec2013-01-31 01:48:3334#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]ea9edcb02011-09-23 22:05:0435#include "chrome/browser/autofill/personal_data_manager_factory.h"
avi71d0f762014-12-15 16:08:4736#include "chrome/browser/background/background_contents.h"
[email protected]a07676b22011-06-17 16:36:5337#include "chrome/browser/background/background_contents_service.h"
[email protected]4fdf6742012-01-10 20:14:3638#include "chrome/browser/background/background_contents_service_factory.h"
[email protected]5c238752009-06-13 10:29:0739#include "chrome/browser/browser_process.h"
[email protected]c61db1d2009-02-06 03:39:1840#include "chrome/browser/browser_shutdown.h"
[email protected]40d59ce52009-03-06 23:20:1441#include "chrome/browser/character_encoding.h"
[email protected]dcc8fbc2013-07-12 00:54:0942#include "chrome/browser/chrome_notification_types.h"
[email protected]7ae9c322012-07-17 23:46:4443#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]7d189022011-08-25 22:54:2044#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]8a39b472013-04-04 17:07:4245#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
[email protected]f1d20572014-02-14 01:27:1446#include "chrome/browser/custom_handlers/register_protocol_handler_permission_request.h"
[email protected]5fec4702013-11-20 04:37:3847#include "chrome/browser/defaults.h"
[email protected]70019152012-12-19 11:44:1948#include "chrome/browser/devtools/devtools_toggle_action.h"
49#include "chrome/browser/devtools/devtools_window.h"
[email protected]9bb54ee2011-10-12 17:43:3550#include "chrome/browser/download/download_service.h"
51#include "chrome/browser/download/download_service_factory.h"
[email protected]63d1f9b2014-07-05 19:09:0352#include "chrome/browser/extensions/api/tabs/tabs_event_router.h"
53#include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
[email protected]9c1662b2012-03-06 15:44:3354#include "chrome/browser/extensions/browser_extension_window_controller.h"
[email protected]eaa7dd182010-12-14 11:09:0055#include "chrome/browser/extensions/extension_service.h"
benwells919e79b2015-03-19 04:58:1956#include "chrome/browser/extensions/extension_ui_util.h"
benwells39f23ae2014-08-27 08:01:5257#include "chrome/browser/extensions/extension_util.h"
[email protected]a6394ae2012-07-16 20:58:4358#include "chrome/browser/extensions/tab_helper.h"
[email protected]3a29a6e2011-08-24 18:26:2159#include "chrome/browser/file_select_helper.h"
[email protected]820735792010-07-29 23:40:0160#include "chrome/browser/first_run/first_run.h"
jitendra.ks30f03392015-01-28 09:47:1861#include "chrome/browser/history/top_sites_factory.h"
[email protected]4a8adfa02013-03-19 22:37:4662#include "chrome/browser/infobars/infobar_service.h"
[email protected]2e6389f2012-05-18 19:41:2563#include "chrome/browser/lifetime/application_lifetime.h"
georgesak6fc95e92015-10-26 21:27:0664#include "chrome/browser/memory/tab_manager_web_contents_data.h"
[email protected]2c4fb7b2011-04-02 06:33:2965#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]8c8fc292012-11-23 18:57:1666#include "chrome/browser/pepper_broker_infobar_delegate.h"
[email protected]4e94ab32011-08-05 05:28:2767#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]8ecad5e2010-12-02 21:18:3368#include "chrome/browser/profiles/profile.h"
[email protected]5e919242012-02-13 23:59:3569#include "chrome/browser/profiles/profile_destroyer.h"
[email protected]a7be6982011-12-12 21:53:5770#include "chrome/browser/profiles/profile_metrics.h"
mlerman2c1c3782015-04-23 18:37:4371#include "chrome/browser/profiles/profiles_state.h"
[email protected]67baffc82011-12-19 18:03:0772#include "chrome/browser/repost_form_warning_controller.h"
[email protected]a7b8e43d2013-03-18 18:52:4373#include "chrome/browser/search/search.h"
georgesak5582cbe2015-05-22 22:08:0774#include "chrome/browser/sessions/session_restore.h"
[email protected]85e921fb82009-02-11 23:19:4475#include "chrome/browser/sessions/session_service.h"
[email protected]92371eb2011-04-28 11:50:1576#include "chrome/browser/sessions/session_service_factory.h"
[email protected]bde40b822012-08-30 17:28:5677#include "chrome/browser/sessions/session_tab_helper.h"
[email protected]92371eb2011-04-28 11:50:1578#include "chrome/browser/sessions/tab_restore_service_factory.h"
estark880a5a42015-11-30 18:21:2179#include "chrome/browser/ssl/chrome_security_state_model_client.h"
estarkb190625f2015-09-16 19:07:4180#include "chrome/browser/ssl/security_state_model.h"
[email protected]5e61afb92012-01-27 20:09:1381#include "chrome/browser/sync/profile_sync_service_factory.h"
[email protected]40f047972009-11-25 03:54:4082#include "chrome/browser/sync/sync_ui_util.h"
[email protected]4fdf6742012-01-10 20:14:3683#include "chrome/browser/tab_contents/retargeting_details.h"
[email protected]1ab4ddf2011-07-21 04:48:0484#include "chrome/browser/tab_contents/tab_util.h"
afakhry8394f942015-07-09 18:46:0985#include "chrome/browser/task_management/web_contents_tags.h"
[email protected]ffa6f592011-06-24 22:03:5786#include "chrome/browser/themes/theme_service.h"
87#include "chrome/browser/themes/theme_service_factory.h"
[email protected]255ab972014-06-04 12:14:2288#include "chrome/browser/translate/chrome_translate_client.h"
[email protected]b4db6d42014-06-07 04:36:5889#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
[email protected]5635e6142013-07-18 08:10:4090#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
[email protected]35699d572011-05-11 19:46:1491#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
[email protected]4db2e912014-03-04 07:08:5892#include "chrome/browser/ui/bookmarks/bookmark_utils.h"
[email protected]5d98294912012-06-27 22:57:4093#include "chrome/browser/ui/browser_command_controller.h"
[email protected]a37d4b02012-06-25 21:56:1094#include "chrome/browser/ui/browser_commands.h"
[email protected]ef557022012-03-16 10:05:3395#include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
[email protected]55452902011-06-01 21:57:4796#include "chrome/browser/ui/browser_dialogs.h"
[email protected]d8748142012-05-16 21:13:4397#include "chrome/browser/ui/browser_finder.h"
[email protected]7acfaf92012-07-11 15:51:5998#include "chrome/browser/ui/browser_instant_controller.h"
[email protected]3539929f2013-02-01 05:59:1499#include "chrome/browser/ui/browser_iterator.h"
[email protected]6768ac02011-04-06 17:41:04100#include "chrome/browser/ui/browser_list.h"
blundellbde024d2015-09-30 13:47:07101#include "chrome/browser/ui/browser_live_tab_context.h"
[email protected]fcca741b2011-06-17 22:46:37102#include "chrome/browser/ui/browser_navigator.h"
thestige80821242015-09-30 23:46:08103#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]855370052012-07-10 19:30:32104#include "chrome/browser/ui/browser_tab_strip_model_delegate.h"
[email protected]52877dbc62012-06-29 22:22:03105#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]ef557022012-03-16 10:05:33106#include "chrome/browser/ui/browser_toolbar_model_delegate.h"
[email protected]2cd4fde2012-06-26 03:10:26107#include "chrome/browser/ui/browser_ui_prefs.h"
[email protected]00070c732011-04-09 15:31:33108#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:12109#include "chrome/browser/ui/chrome_pages.h"
[email protected]6e1fcd12012-07-02 17:14:20110#include "chrome/browser/ui/chrome_select_file_policy.h"
sriramsr3e76a412014-12-18 19:25:29111#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
sriramsra41db562015-01-26 22:45:04112#include "chrome/browser/ui/exclusive_access/mouse_lock_controller.h"
benwells11bd6ed2015-06-05 04:20:41113#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
[email protected]88c92012013-07-02 11:56:34114#include "chrome/browser/ui/fast_unload_controller.h"
[email protected]45300ad42010-12-02 15:51:14115#include "chrome/browser/ui/find_bar/find_bar.h"
116#include "chrome/browser/ui/find_bar/find_bar_controller.h"
[email protected]c90c6ca2011-02-16 20:11:38117#include "chrome/browser/ui/find_bar/find_tab_helper.h"
[email protected]1ba55cf2012-06-29 19:11:39118#include "chrome/browser/ui/global_error/global_error.h"
119#include "chrome/browser/ui/global_error/global_error_service.h"
120#include "chrome/browser/ui/global_error/global_error_service_factory.h"
[email protected]d57ce6a2014-07-03 15:39:23121#include "chrome/browser/ui/location_bar/location_bar.h"
[email protected]859ec322013-09-13 16:24:56122#include "chrome/browser/ui/media_utils.h"
[email protected]e3a5d5b2012-06-22 17:56:46123#include "chrome/browser/ui/search/search_delegate.h"
124#include "chrome/browser/ui/search/search_model.h"
[email protected]549f62b2013-10-26 12:54:42125#include "chrome/browser/ui/search/search_tab_helper.h"
[email protected]27e5b3912012-12-16 00:45:37126#include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
[email protected]f9253672014-07-31 03:35:38127#include "chrome/browser/ui/settings_window_manager.h"
[email protected]5d9cace72012-06-21 16:07:12128#include "chrome/browser/ui/singleton_tabs.h"
[email protected]6a3ec2312010-12-02 19:30:19129#include "chrome/browser/ui/status_bubble.h"
[email protected]3da95a102011-11-30 21:47:45130#include "chrome/browser/ui/sync/browser_synced_window_delegate.h"
[email protected]51d83bdf2011-12-09 16:09:29131#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
andresantoso063151d2014-12-18 22:37:55132#include "chrome/browser/ui/tab_dialogs.h"
[email protected]e0bc75d52014-01-30 23:42:59133#include "chrome/browser/ui/tab_helpers.h"
[email protected]51296c62012-09-26 13:02:44134#include "chrome/browser/ui/tab_modal_confirm_dialog.h"
[email protected]6a3ec2312010-12-02 19:30:19135#include "chrome/browser/ui/tabs/tab_menu_model.h"
[email protected]b56e2e32012-05-11 21:18:04136#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]82808d02014-04-10 00:10:59137#include "chrome/browser/ui/tabs/tab_strip_model_utils.h"
jared.sohna1409622015-08-08 07:16:14138#include "chrome/browser/ui/tabs/tab_utils.h"
[email protected]736d00322012-10-11 21:32:41139#include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
[email protected]f9b6c092012-07-09 19:32:28140#include "chrome/browser/ui/unload_controller.h"
[email protected]edc3af82013-12-12 21:24:07141#include "chrome/browser/ui/validation_message_bubble.h"
[email protected]f1d20572014-02-14 01:27:14142#include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
[email protected]65549182012-02-25 00:45:40143#include "chrome/browser/ui/webui/signin/login_ui_service.h"
144#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
[email protected]03639422012-06-28 19:03:37145#include "chrome/browser/ui/window_sizer/window_sizer.h"
[email protected]b1b73942010-05-26 20:11:54146#include "chrome/browser/upgrade_detector.h"
[email protected]d938aed92009-01-22 19:49:33147#include "chrome/common/chrome_constants.h"
148#include "chrome/common/chrome_switches.h"
[email protected]7d189022011-08-25 22:54:20149#include "chrome/common/custom_handlers/protocol_handler.h"
[email protected]8a53ee042009-01-21 16:41:33150#include "chrome/common/pref_names.h"
[email protected]7664ab32011-02-01 23:35:25151#include "chrome/common/profiling.h"
[email protected]c3917742012-11-21 01:51:14152#include "chrome/common/search_types.h"
[email protected]c744f7d22013-04-12 20:29:04153#include "chrome/common/url_constants.h"
thestig884a1602014-08-27 01:29:39154#include "chrome/grit/chromium_strings.h"
155#include "chrome/grit/generated_resources.h"
thestigaeddd322014-08-27 06:58:39156#include "chrome/grit/locale_settings.h"
oshimaf65398422014-11-18 23:30:42157#include "components/app_modal/javascript_dialog_manager.h"
[email protected]a90c8ca2014-05-20 17:16:04158#include "components/bookmarks/browser/bookmark_model.h"
159#include "components/bookmarks/browser/bookmark_utils.h"
brettwe1f0af8b2015-10-09 21:30:46160#include "components/bookmarks/common/bookmark_pref_names.h"
blundell7282b512015-11-09 07:21:11161#include "components/browser_sync/browser/profile_sync_service.h"
mukai8eaec822014-10-25 17:53:16162#include "components/content_settings/core/browser/host_content_settings_map.h"
sdefresne455826972015-04-10 15:25:15163#include "components/favicon/content/content_favicon_driver.h"
sdefresne0da3bc02015-01-29 18:26:35164#include "components/history/core/browser/top_sites.h"
[email protected]720b10492014-07-23 08:48:40165#include "components/search/search.h"
blundell47c6d8a2015-09-24 11:06:40166#include "components/sessions/core/session_types.h"
blundella08c5dd2015-09-18 06:14:16167#include "components/sessions/core/tab_restore_service.h"
fdoray45c02c162015-11-09 20:14:30168#include "components/startup_metric_utils/browser/startup_metric_utils.h"
pkastingcc29d20e2015-02-25 06:05:53169#include "components/translate/core/browser/language_state.h"
wjmaclean7f63c6b2014-12-09 14:59:55170#include "components/ui/zoom/zoom_controller.h"
[email protected]e41d0082013-05-16 04:37:54171#include "components/web_modal/web_contents_modal_dialog_manager.h"
[email protected]b50452f2014-08-18 12:31:44172#include "content/public/browser/devtools_agent_host.h"
[email protected]cadaec52012-02-08 21:53:13173#include "content/public/browser/interstitial_page.h"
[email protected]d9083482012-01-06 00:38:46174#include "content/public/browser/invalidate_type.h"
[email protected]cdcb1dee2012-01-04 00:46:20175#include "content/public/browser/navigation_controller.h"
[email protected]022af742011-12-28 18:37:25176#include "content/public/browser/navigation_entry.h"
[email protected]7f6f44c2011-12-14 13:23:38177#include "content/public/browser/notification_details.h"
178#include "content/public/browser/notification_service.h"
[email protected]3a5180ae2011-12-21 02:39:38179#include "content/public/browser/plugin_service.h"
[email protected]9c1662b2012-03-06 15:44:33180#include "content/public/browser/render_process_host.h"
181#include "content/public/browser/render_view_host.h"
avif9ab5d942015-10-15 14:05:44182#include "content/public/browser/render_widget_host.h"
[email protected]edc3af82013-12-12 21:24:07183#include "content/public/browser/render_widget_host_view.h"
estark5ea80e52015-06-19 18:43:12184#include "content/public/browser/security_style_explanation.h"
185#include "content/public/browser/security_style_explanations.h"
[email protected]b6583592012-01-25 19:52:33186#include "content/public/browser/site_instance.h"
[email protected]7f6f44c2011-12-14 13:23:38187#include "content/public/browser/user_metrics.h"
[email protected]d9083482012-01-06 00:38:46188#include "content/public/browser/web_contents.h"
[email protected]c08950d22011-10-13 22:20:29189#include "content/public/common/content_switches.h"
[email protected]0f083402011-11-22 02:59:01190#include "content/public/common/page_zoom.h"
[email protected]cadaec52012-02-08 21:53:13191#include "content/public/common/renderer_preferences.h"
estark36948be2015-08-05 21:41:25192#include "content/public/common/ssl_status.h"
[email protected]d7bd3e52013-07-21 04:29:20193#include "content/public/common/webplugininfo.h"
[email protected]489db0842014-01-22 18:20:03194#include "extensions/browser/extension_prefs.h"
jitendra.ksa0055532014-10-07 05:54:46195#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:24196#include "extensions/browser/extension_system.h"
[email protected]885c0e92012-11-13 20:27:42197#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:41198#include "extensions/common/extension.h"
[email protected]558878cc82013-11-09 01:25:51199#include "extensions/common/manifest_handlers/background_info.h"
[email protected]d96cf752014-04-09 04:05:28200#include "net/base/filename_util.h"
[email protected]be28b5f42012-07-20 11:31:25201#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]4d7c4ef2012-03-16 01:47:12202#include "net/cookies/cookie_monster.h"
[email protected]8a53ee042009-01-21 16:41:33203#include "net/url_request/url_request_context.h"
[email protected]453c1b22013-07-23 09:31:48204#include "third_party/WebKit/public/web/WebWindowFeatures.h"
[email protected]c051a1b2011-01-21 23:30:17205#include "ui/base/l10n/l10n_util.h"
[email protected]f47621b2013-01-22 20:50:33206#include "ui/base/window_open_disposition.h"
tfarina655f81d2014-12-23 02:38:50207#include "ui/gfx/geometry/point.h"
[email protected]4344a3c2013-01-17 23:49:20208#include "ui/shell_dialogs/selected_file_info.h"
[email protected]8a53ee042009-01-21 16:41:33209
210#if defined(OS_WIN)
[email protected]77cbe50e2012-06-14 02:44:38211#include "base/win/metro.h"
[email protected]a5d1e1e2010-09-23 19:34:12212#include "chrome/browser/task_manager/task_manager.h"
[email protected]6a3ec2312010-12-02 19:30:19213#include "chrome/browser/ui/view_ids.h"
[email protected]526a16b2013-06-20 11:44:33214#include "components/autofill/core/browser/autofill_ie_toolbar_import_win.h"
mfomitchevf09a66bb2014-10-02 02:20:54215#include "ui/base/touch/touch_device.h"
[email protected]dcd57762011-06-25 12:18:51216#include "ui/base/win/shell.h"
[email protected]8a53ee042009-01-21 16:41:33217#endif // OS_WIN
[email protected]e1acf6f2008-10-27 20:43:33218
[email protected]b7969202010-05-14 21:29:26219#if defined(OS_CHROMEOS)
hirono90949af2014-09-25 04:23:37220#include "chrome/browser/chromeos/fileapi/external_file_url_util.h"
[email protected]eab8c0f2011-11-18 22:33:50221#endif
222
[email protected]dc04be7c2012-03-15 23:57:49223#if defined(USE_ASH)
[email protected]bafda132012-02-16 19:32:51224#include "ash/ash_switches.h"
thestig028978692015-10-08 07:39:40225#include "ash/shell.h"
[email protected]c2f0a892012-01-24 22:19:21226#endif
227
[email protected]8a53ee042009-01-21 16:41:33228using base::TimeDelta;
[email protected]e6e30ac2014-01-13 21:24:39229using base::UserMetricsAction;
[email protected]b87ee522012-05-18 15:16:54230using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50231using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23232using content::NavigationEntry;
[email protected]e5d549d2011-12-28 01:29:20233using content::OpenURLParams;
[email protected]3a5180ae2011-12-21 02:39:38234using content::PluginService;
[email protected]e5d549d2011-12-28 01:29:20235using content::Referrer;
[email protected]edc3af82013-12-12 21:24:07236using content::RenderWidgetHostView;
[email protected]b6583592012-01-25 19:52:33237using content::SiteInstance;
[email protected]ea049a02011-12-25 21:37:09238using content::WebContents;
[email protected]1c321ee52012-05-21 03:02:34239using extensions::Extension;
[email protected]20c07f8e2012-05-31 08:43:14240using ui::WebDialogDelegate;
[email protected]e41d0082013-05-16 04:37:54241using web_modal::WebContentsModalDialogManager;
[email protected]a1221aea2013-11-07 01:31:30242using blink::WebWindowFeatures;
initial.commit09911bf2008-07-26 23:55:29243
[email protected]36b6dcb2008-11-12 01:19:57244///////////////////////////////////////////////////////////////////////////////
initial.commit09911bf2008-07-26 23:55:29245
[email protected]505323e22009-01-24 02:47:58246namespace {
247
[email protected]91a79232010-11-10 18:15:08248// How long we wait before updating the browser chrome while loading a page.
249const int kUIUpdateCoalescingTimeMS = 200;
250
[email protected]a4fe67012012-07-25 20:14:29251BrowserWindow* CreateBrowserWindow(Browser* browser) {
[email protected]a4fe67012012-07-25 20:14:29252 return BrowserWindow::CreateBrowserWindow(browser);
253}
254
[email protected]88c92012013-07-02 11:56:34255// Is the fast tab unload experiment enabled?
256bool IsFastTabUnloadEnabled() {
avi556c05022014-12-22 23:31:43257 return base::CommandLine::ForCurrentProcess()->HasSwitch(
258 switches::kEnableFastUnload);
[email protected]88c92012013-07-02 11:56:34259}
260
estarkb190625f2015-09-16 19:07:41261// Note: This is a lossy operation. Not all of the policies that can be
262// expressed by a SecurityLevel (a //chrome concept) can be expressed by
263// a content::SecurityStyle.
264content::SecurityStyle SecurityLevelToSecurityStyle(
265 SecurityStateModel::SecurityLevel security_level) {
266 switch (security_level) {
267 case SecurityStateModel::NONE:
268 return content::SECURITY_STYLE_UNAUTHENTICATED;
269 case SecurityStateModel::SECURITY_WARNING:
270 case SecurityStateModel::SECURITY_POLICY_WARNING:
271 return content::SECURITY_STYLE_WARNING;
272 case SecurityStateModel::EV_SECURE:
273 case SecurityStateModel::SECURE:
274 return content::SECURITY_STYLE_AUTHENTICATED;
275 case SecurityStateModel::SECURITY_ERROR:
276 return content::SECURITY_STYLE_AUTHENTICATION_BROKEN;
277 }
278
279 NOTREACHED();
280 return content::SECURITY_STYLE_UNKNOWN;
281}
282
[email protected]505323e22009-01-24 02:47:58283} // namespace
284
[email protected]b35b26b32011-05-05 20:35:14285////////////////////////////////////////////////////////////////////////////////
286// Browser, CreateParams:
287
[email protected]196578252012-12-06 23:54:20288Browser::CreateParams::CreateParams(Profile* profile,
289 chrome::HostDesktopType host_desktop_type)
290 : type(TYPE_TABBED),
291 profile(profile),
292 host_desktop_type(host_desktop_type),
[email protected]d2202e22014-04-14 20:20:53293 trusted_source(false),
[email protected]196578252012-12-06 23:54:20294 initial_show_state(ui::SHOW_STATE_DEFAULT),
295 is_session_restore(false),
296 window(NULL) {
297}
298
[email protected]56073dc2012-08-10 16:59:06299Browser::CreateParams::CreateParams(Type type,
300 Profile* profile,
301 chrome::HostDesktopType host_desktop_type)
302 : type(type),
303 profile(profile),
304 host_desktop_type(host_desktop_type),
[email protected]d2202e22014-04-14 20:20:53305 trusted_source(false),
[email protected]a636d8e52012-02-28 15:40:41306 initial_show_state(ui::SHOW_STATE_DEFAULT),
[email protected]a4fe67012012-07-25 20:14:29307 is_session_restore(false),
308 window(NULL) {
[email protected]b35b26b32011-05-05 20:35:14309}
310
[email protected]da22aa62012-04-04 18:54:35311// static
312Browser::CreateParams Browser::CreateParams::CreateForApp(
[email protected]da22aa62012-04-04 18:54:35313 const std::string& app_name,
[email protected]d2202e22014-04-14 20:20:53314 bool trusted_source,
[email protected]da22aa62012-04-04 18:54:35315 const gfx::Rect& window_bounds,
[email protected]2b09ae552013-02-23 06:38:03316 Profile* profile,
317 chrome::HostDesktopType host_desktop_type) {
[email protected]da22aa62012-04-04 18:54:35318 DCHECK(!app_name.empty());
319
[email protected]d2202e22014-04-14 20:20:53320 CreateParams params(TYPE_POPUP, profile, host_desktop_type);
[email protected]da22aa62012-04-04 18:54:35321 params.app_name = app_name;
[email protected]d2202e22014-04-14 20:20:53322 params.trusted_source = trusted_source;
[email protected]da22aa62012-04-04 18:54:35323 params.initial_bounds = window_bounds;
324
325 return params;
326}
327
328// static
329Browser::CreateParams Browser::CreateParams::CreateForDevTools(
[email protected]2b09ae552013-02-23 06:38:03330 Profile* profile,
331 chrome::HostDesktopType host_desktop_type) {
332 CreateParams params(TYPE_POPUP, profile, host_desktop_type);
[email protected]da22aa62012-04-04 18:54:35333 params.app_name = DevToolsWindow::kDevToolsApp;
[email protected]d2202e22014-04-14 20:20:53334 params.trusted_source = true;
[email protected]da22aa62012-04-04 18:54:35335 return params;
336}
337
[email protected]20ca0382013-02-28 19:50:07338////////////////////////////////////////////////////////////////////////////////
339// Browser, InterstitialObserver:
340
341class Browser::InterstitialObserver : public content::WebContentsObserver {
342 public:
343 InterstitialObserver(Browser* browser, content::WebContents* web_contents)
344 : WebContentsObserver(web_contents),
345 browser_(browser) {
346 }
347
dcheng5dd5ff62014-10-21 12:42:38348 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07349 browser_->UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
350 }
351
dcheng5dd5ff62014-10-21 12:42:38352 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07353 browser_->UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
354 }
355
356 private:
357 Browser* browser_;
358
359 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
360};
361
[email protected]36b6dcb2008-11-12 01:19:57362///////////////////////////////////////////////////////////////////////////////
363// Browser, Constructors, Creation, Showing:
initial.commit09911bf2008-07-26 23:55:29364
[email protected]a4fe67012012-07-25 20:14:29365Browser::Browser(const CreateParams& params)
jitendra.ksa0055532014-10-07 05:54:46366 : extension_registry_observer_(this),
367 type_(params.type),
[email protected]a4fe67012012-07-25 20:14:29368 profile_(params.profile),
[email protected]f3e99e32008-07-30 04:48:39369 window_(NULL),
[email protected]d4b2d232013-04-30 21:14:23370 tab_strip_model_delegate_(new chrome::BrowserTabStripModelDelegate(this)),
jitendra.ksa0055532014-10-07 05:54:46371 tab_strip_model_(
372 new TabStripModel(tab_strip_model_delegate_.get(), params.profile)),
[email protected]a4fe67012012-07-25 20:14:29373 app_name_(params.app_name),
[email protected]d2202e22014-04-14 20:20:53374 is_trusted_source_(params.trusted_source),
[email protected]69444cc2009-04-09 20:40:06375 cancel_download_confirmation_state_(NOT_PROMPTED),
[email protected]a4fe67012012-07-25 20:14:29376 override_bounds_(params.initial_bounds),
377 initial_show_state_(params.initial_show_state),
378 is_session_restore_(params.is_session_restore),
jitendra.ksa0055532014-10-07 05:54:46379 host_desktop_type_(
380 BrowserWindow::AdjustHostDesktopType(params.host_desktop_type)),
[email protected]d4b2d232013-04-30 21:14:23381 content_setting_bubble_model_delegate_(
382 new BrowserContentSettingBubbleModelDelegate(this)),
383 toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)),
blundellbde024d2015-09-30 13:47:07384 live_tab_context_(new BrowserLiveTabContext(this)),
[email protected]d4b2d232013-04-30 21:14:23385 synced_window_delegate_(new BrowserSyncedWindowDelegate(this)),
[email protected]8a5e0ca2011-08-25 06:30:47386 bookmark_bar_state_(BookmarkBar::HIDDEN),
[email protected]338416c02014-05-13 16:47:06387 command_controller_(new chrome::BrowserCommandController(this)),
[email protected]07f0f2cf2013-10-09 03:43:18388 window_has_shown_(false),
anujk.sharma62e915a2014-12-11 19:23:16389 chrome_updater_factory_(this),
mohan.reddy1f994392014-09-17 05:30:05390 weak_factory_(this) {
[email protected]3d0294ef2013-06-04 19:19:06391 // If this causes a crash then a window is being opened using a profile type
392 // that is disallowed by policy. The crash prevents the disabled window type
393 // from opening at all, but the path that triggered it should be fixed.
394 CHECK(IncognitoModePrefs::CanOpenBrowser(profile_));
[email protected]d5838dd2014-01-08 02:46:33395 CHECK(!profile_->IsGuestSession() || profile_->IsOffTheRecord())
396 << "Only off the record browser may be opened in guest mode";
mlerman7831f57d2015-05-25 11:40:15397 DCHECK(!profile_->IsSystemProfile())
398 << "The system profile should never have a real browser.";
399 // TODO(mlerman): After this hits stable channel, see if there are counts
400 // for this metric. If not, change the DCHECK above to a CHECK.
401 if (profile_->IsSystemProfile())
402 content::RecordAction(base::UserMetricsAction("BrowserForSystemProfile"));
[email protected]3d0294ef2013-06-04 19:19:06403
[email protected]88c92012013-07-02 11:56:34404 // TODO(jeremy): Move to initializer list once flag is removed.
405 if (IsFastTabUnloadEnabled())
406 fast_unload_controller_.reset(new chrome::FastUnloadController(this));
407 else
408 unload_controller_.reset(new chrome::UnloadController(this));
409
[email protected]2fc15ae2012-05-06 00:01:37410 tab_strip_model_->AddObserver(this);
411
[email protected]736d00322012-10-11 21:32:41412 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get()));
[email protected]165fe422013-03-27 06:34:03413 search_model_.reset(new SearchModel());
[email protected]a40be8b2013-08-22 20:12:14414 search_delegate_.reset(new SearchDelegate(search_model_.get()));
[email protected]ef557022012-03-16 10:05:33415
jitendra.ksa0055532014-10-07 05:54:46416 extension_registry_observer_.Add(
417 extensions::ExtensionRegistry::Get(profile_));
[email protected]adf5a102014-07-31 12:44:06418 registrar_.Add(this,
419 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07420 content::NotificationService::AllSources());
[email protected]6b40bb582012-03-15 20:50:38421#if defined(ENABLE_THEMES)
[email protected]ffa6f592011-06-24 22:03:57422 registrar_.Add(
[email protected]432115822011-07-10 15:52:27423 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
[email protected]6c2381d2011-10-19 02:52:53424 content::Source<ThemeService>(
425 ThemeServiceFactory::GetForProfile(profile_)));
[email protected]6b40bb582012-03-15 20:50:38426#endif
[email protected]ea049a02011-12-25 21:37:09427 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
[email protected]ad50def52011-10-19 23:17:07428 content::NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29429
[email protected]97b46382011-05-02 13:23:04430 profile_pref_registrar_.Init(profile_->GetPrefs());
[email protected]c31813a2012-11-15 18:47:26431 profile_pref_registrar_.Add(
432 prefs::kDevToolsDisabled,
433 base::Bind(&Browser::OnDevToolsDisabledChanged, base::Unretained(this)));
434 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32435 bookmarks::prefs::kShowBookmarkBar,
[email protected]c31813a2012-11-15 18:47:26436 base::Bind(&Browser::UpdateBookmarkBarState, base::Unretained(this),
437 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE));
[email protected]9e823662010-10-13 23:36:00438
[email protected]97b46382011-05-02 13:23:04439 // NOTE: These prefs all need to be explicitly destroyed in the destructor
440 // or you'll get a nasty surprise when you run the incognito tests.
initial.commit09911bf2008-07-26 23:55:29441 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector,
[email protected]96a5c342012-12-04 18:14:02442 profile_->GetPrefs());
[email protected]281918912010-05-27 22:05:13443
sdefresne51bbec7b2015-08-03 14:18:13444 if (search::IsInstantExtendedAPIEnabled() && is_type_tabbed())
[email protected]165fe422013-03-27 06:34:03445 instant_controller_.reset(new BrowserInstantController(this));
[email protected]df25eb9f2012-09-13 17:43:23446
benwells11bd6ed2015-06-05 04:20:41447 if (extensions::HostedAppBrowserController::IsForHostedApp(this)) {
448 hosted_app_controller_.reset(
449 new extensions::HostedAppBrowserController(this));
benwellsa2a8a9f72015-04-07 07:09:54450 }
451
[email protected]09b29342011-06-24 19:18:48452 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT);
[email protected]a7be6982011-12-12 21:53:57453
[email protected]26e92df2013-04-11 16:05:21454 ProfileMetrics::LogProfileLaunch(profile_);
[email protected]a4fe67012012-07-25 20:14:29455
456 window_ = params.window ? params.window : CreateBrowserWindow(this);
457
benwells11bd6ed2015-06-05 04:20:41458 if (hosted_app_controller_)
459 hosted_app_controller_->UpdateLocationBarVisibility(false);
benwellsa2a8a9f72015-04-07 07:09:54460
[email protected]a4fe67012012-07-25 20:14:29461 // Create the extension window controller before sending notifications.
462 extension_window_controller_.reset(
463 new BrowserExtensionWindowController(this));
464
[email protected]7d52ea4c62013-11-13 03:52:14465 SessionService* session_service =
466 SessionServiceFactory::GetForProfileForSessionRestore(profile_);
467 if (session_service)
468 session_service->WindowOpened(this);
469
[email protected]a4fe67012012-07-25 20:14:29470 // TODO(beng): move to ChromeBrowserMain:
[email protected]dfcc05f2013-02-21 14:12:16471 if (first_run::ShouldDoPersonalDataManagerFirstRun()) {
[email protected]a4fe67012012-07-25 20:14:29472#if defined(OS_WIN)
[email protected]dfcc05f2013-02-21 14:12:16473 // Notify PDM that this is a first run.
[email protected]bfd4b812013-04-11 02:02:11474 ImportAutofillDataWin(
475 autofill::PersonalDataManagerFactory::GetForProfile(profile_));
[email protected]a4fe67012012-07-25 20:14:29476#endif // defined(OS_WIN)
[email protected]a4fe67012012-07-25 20:14:29477 }
478
sriramsr39b6b7872015-03-04 00:03:32479 exclusive_access_manager_.reset(
480 new ExclusiveAccessManager(window_->GetExclusiveAccessContext()));
[email protected]010152f2014-07-15 00:16:47481
jackhou75d58b12015-07-07 08:16:01482 // TODO(beng): Move BrowserList::AddBrowser() to the end of this function and
483 // replace uses of this with BL's notifications.
484 BrowserList::AddBrowser(this);
485 content::NotificationService::current()->Notify(
486 chrome::NOTIFICATION_BROWSER_WINDOW_READY, content::Source<Browser>(this),
487 content::NotificationService::NoDetails());
initial.commit09911bf2008-07-26 23:55:29488}
489
490Browser::~Browser() {
[email protected]ebe07772014-05-22 04:16:06491 // Stop observing notifications before continuing with destruction. Profile
492 // destruction will unload extensions and reentrant calls to Browser:: should
493 // be avoided while it is being torn down.
494 registrar_.RemoveAll();
jitendra.ksa0055532014-10-07 05:54:46495 extension_registry_observer_.RemoveAll();
[email protected]ebe07772014-05-22 04:16:06496
[email protected]2fc15ae2012-05-06 00:01:37497 // The tab strip should not have any tabs at this point.
[email protected]050e77182014-03-25 15:29:16498 DCHECK(tab_strip_model_->empty());
[email protected]2fc15ae2012-05-06 00:01:37499 tab_strip_model_->RemoveObserver(this);
hcarmonaaa431c02015-08-28 18:45:57500 bubble_manager_.reset();
[email protected]2fc15ae2012-05-06 00:01:37501
[email protected]557c4e22012-12-18 18:30:55502 // Destroy the BrowserCommandController before removing the browser, so that
503 // it doesn't act on any notifications that are sent as a result of removing
504 // the browser.
505 command_controller_.reset();
initial.commit09911bf2008-07-26 23:55:29506 BrowserList::RemoveBrowser(this);
507
[email protected]bdc6ccd12012-03-20 22:06:13508 SessionService* session_service =
509 SessionServiceFactory::GetForProfile(profile_);
510 if (session_service)
511 session_service->WindowClosed(session_id_);
512
blundell74001adc2015-09-18 11:04:25513 sessions::TabRestoreService* tab_restore_service =
[email protected]bdc6ccd12012-03-20 22:06:13514 TabRestoreServiceFactory::GetForProfile(profile());
515 if (tab_restore_service)
blundellbde024d2015-09-30 13:47:07516 tab_restore_service->BrowserClosed(live_tab_context());
[email protected]bdc6ccd12012-03-20 22:06:13517
[email protected]7be64502011-05-03 17:51:47518#if !defined(OS_MACOSX)
[email protected]c987a242013-02-28 01:17:41519 if (!chrome::GetTotalBrowserCountForProfile(profile_)) {
initial.commit09911bf2008-07-26 23:55:29520 // We're the last browser window with this profile. We need to nuke the
521 // TabRestoreService, which will start the shutdown of the
522 // NavigationControllers and allow for proper shutdown. If we don't do this
523 // chrome won't shutdown cleanly, and may end up crashing when some
524 // thread tries to use the IO thread (or another thread) that is no longer
525 // valid.
[email protected]fbc947b2009-06-19 13:28:24526 // This isn't a valid assumption for Mac OS, as it stays running after
527 // the last browser has closed. The Mac equivalent is in its app
528 // controller.
[email protected]92371eb2011-04-28 11:50:15529 TabRestoreServiceFactory::ResetForProfile(profile_);
initial.commit09911bf2008-07-26 23:55:29530 }
[email protected]fbc947b2009-06-19 13:28:24531#endif
initial.commit09911bf2008-07-26 23:55:29532
[email protected]97b46382011-05-02 13:23:04533 profile_pref_registrar_.RemoveAll();
[email protected]97b46382011-05-02 13:23:04534
[email protected]9a8c4022011-01-25 14:25:33535 encoding_auto_detect_.Destroy();
[email protected]9a8c4022011-01-25 14:25:33536
[email protected]fb0f9ebc2013-05-22 06:25:42537 // Destroy BrowserExtensionWindowController before the incognito profile
538 // is destroyed to make sure the chrome.windows.onRemoved event is sent.
539 extension_window_controller_.reset();
540
[email protected]6af41782013-06-22 13:49:11541 // Destroy BrowserInstantController before the incongnito profile is destroyed
542 // because the InstantController destructor depends on this profile.
543 instant_controller_.reset();
544
initial.commit09911bf2008-07-26 23:55:29545 if (profile_->IsOffTheRecord() &&
[email protected]474e5db2011-08-12 13:02:23546 !BrowserList::IsOffTheRecordSessionActiveForProfile(profile_)) {
mlerman67fa17a2015-02-13 21:59:22547 if (profile_->IsGuestSession()) {
548// ChromeOS handles guest data independently.
549#if !defined(OS_CHROMEOS)
550 // Clear all browsing data once a Guest Session completes. The Guest
551 // profile has BrowserContextKeyedServices that the Incognito profile
552 // doesn't, so the ProfileDestroyer can't delete it properly.
553 // TODO(mlerman): Delete the guest using an improved ProfileDestroyer.
mlerman2c1c3782015-04-23 18:37:43554 profiles::RemoveBrowsingDataForProfile(profile_->GetPath());
mlerman67fa17a2015-02-13 21:59:22555#endif
556 } else {
557 // An incognito profile is no longer needed, this indirectly frees
558 // its cache and cookies once it gets destroyed at the appropriate time.
559 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_);
560 }
initial.commit09911bf2008-07-26 23:55:29561 }
562
563 // There may be pending file dialogs, we need to tell them that we've gone
564 // away so they don't try and call back to us.
565 if (select_file_dialog_.get())
566 select_file_dialog_->ListenerDestroyed();
[email protected]5fec4702013-11-20 04:37:38567
568 int num_downloads;
569 if (OkToCloseWithInProgressDownloads(&num_downloads) ==
570 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN &&
571 !browser_defaults::kBrowserAliveWithNoWindows) {
572 DownloadService::CancelAllDownloads();
573 }
initial.commit09911bf2008-07-26 23:55:29574}
575
[email protected]36b6dcb2008-11-12 01:19:57576///////////////////////////////////////////////////////////////////////////////
[email protected]5c238752009-06-13 10:29:07577// Getters & Setters
578
hcarmonaaa431c02015-08-28 18:45:57579ChromeBubbleManager* Browser::GetBubbleManager() {
580 if (!bubble_manager_)
581 bubble_manager_.reset(new ChromeBubbleManager(tab_strip_model_.get()));
582 return bubble_manager_.get();
583}
584
[email protected]b77cb302009-10-29 04:09:17585FindBarController* Browser::GetFindBarController() {
586 if (!find_bar_controller_.get()) {
[email protected]632983f2011-08-08 22:51:24587 FindBar* find_bar = window_->CreateFindBar();
[email protected]b77cb302009-10-29 04:09:17588 find_bar_controller_.reset(new FindBarController(find_bar));
589 find_bar->SetFindBarController(find_bar_controller_.get());
[email protected]0d56fa7212012-11-15 23:34:02590 find_bar_controller_->ChangeWebContents(
591 tab_strip_model_->GetActiveWebContents());
andresantoso6a7691b2014-12-10 23:37:41592 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect());
[email protected]b77cb302009-10-29 04:09:17593 }
594 return find_bar_controller_.get();
595}
596
[email protected]24db8a072009-10-29 20:35:37597bool Browser::HasFindBarController() const {
598 return find_bar_controller_.get() != NULL;
599}
600
[email protected]b35b26b32011-05-05 20:35:14601bool Browser::is_app() const {
602 return !app_name_.empty();
603}
604
605bool Browser::is_devtools() const {
606 return app_name_ == DevToolsWindow::kDevToolsApp;
607}
608
[email protected]5c238752009-06-13 10:29:07609///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:57610// Browser, State Storage and Retrieval for UI:
611
[email protected]9b125b732012-08-17 04:43:55612gfx::Image Browser::GetCurrentPageIcon() const {
[email protected]0d56fa7212012-11-15 23:34:02613 WebContents* web_contents = tab_strip_model_->GetActiveWebContents();
[email protected]502b5612012-10-02 01:33:10614 // |web_contents| can be NULL since GetCurrentPageIcon() is called by the
615 // window during the window's creation (before tabs have been added).
sdefresne455826972015-04-10 15:25:15616 favicon::FaviconDriver* favicon_driver =
617 web_contents
618 ? favicon::ContentFaviconDriver::FromWebContents(web_contents)
619 : nullptr;
620 return favicon_driver ? favicon_driver->GetFavicon() : gfx::Image();
[email protected]36b6dcb2008-11-12 01:19:57621}
622
[email protected]dcd0249872013-12-06 23:58:45623base::string16 Browser::GetWindowTitleForCurrentTab() const {
[email protected]0d56fa7212012-11-15 23:34:02624 WebContents* contents = tab_strip_model_->GetActiveWebContents();
[email protected]dcd0249872013-12-06 23:58:45625 base::string16 title;
[email protected]c7c42332008-11-15 01:10:54626
[email protected]731f8a42009-07-20 22:07:32627 // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the
628 // window during the window's creation (before tabs have been added).
[email protected]36b6dcb2008-11-12 01:19:57629 if (contents) {
benwells502df692014-12-02 20:41:45630 // The web app frame uses the host instead of the title.
631 if (ShouldUseWebAppFrame())
[email protected]f53ec988d2014-08-22 01:38:09632 return base::UTF8ToUTF16(contents->GetURL().host());
[email protected]f53ec988d2014-08-22 01:38:09633
[email protected]dda5dfa32009-07-10 00:33:29634 title = contents->GetTitle();
[email protected]36b6dcb2008-11-12 01:19:57635 FormatTitleForDisplay(&title);
636 }
637 if (title.empty())
[email protected]51d83bdf2011-12-09 16:09:29638 title = CoreTabHelper::GetDefaultTitle();
[email protected]36b6dcb2008-11-12 01:19:57639
[email protected]82b9ed82012-11-15 02:43:18640#if defined(OS_MACOSX)
641 // On Mac, we don't want to suffix the page title with
[email protected]22a3daa2009-11-09 22:03:33642 // the application name.
[email protected]d904bc82009-07-07 00:41:04643 return title;
[email protected]82b9ed82012-11-15 02:43:18644#elif defined(USE_ASH)
645 // On Ash, we don't want to suffix the page title with the application name,
646 // but on Windows, where USE_ASH can also be true, we still want the prefix
647 // on desktop.
648 if (host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH)
649 return title;
650#endif
[email protected]dff529732010-04-01 23:50:55651 // Don't append the app name to window titles on app frames and app popups
[email protected]9c55de82012-11-01 21:03:52652 return is_app() ?
653 title :
654 l10n_util::GetStringFUTF16(IDS_BROWSER_WINDOW_TITLE_FORMAT, title);
[email protected]36b6dcb2008-11-12 01:19:57655}
656
657// static
[email protected]dcd0249872013-12-06 23:58:45658void Browser::FormatTitleForDisplay(base::string16* title) {
[email protected]36b6dcb2008-11-12 01:19:57659 size_t current_index = 0;
660 size_t match_index;
[email protected]dcd0249872013-12-06 23:58:45661 while ((match_index = title->find(L'\n', current_index)) !=
662 base::string16::npos) {
663 title->replace(match_index, 1, base::string16());
[email protected]36b6dcb2008-11-12 01:19:57664 current_index = match_index;
665 }
666}
667
668///////////////////////////////////////////////////////////////////////////////
669// Browser, OnBeforeUnload handling:
670
671bool Browser::ShouldCloseWindow() {
[email protected]69444cc2009-04-09 20:40:06672 if (!CanCloseWithInProgressDownloads())
673 return false;
674
[email protected]88c92012013-07-02 11:56:34675 if (IsFastTabUnloadEnabled())
676 return fast_unload_controller_->ShouldCloseWindow();
[email protected]f9b6c092012-07-09 19:32:28677 return unload_controller_->ShouldCloseWindow();
678}
[email protected]69444cc2009-04-09 20:40:06679
[email protected]2e9d79f2013-08-16 05:45:56680bool Browser::CallBeforeUnloadHandlers(
681 const base::Callback<void(bool)>& on_close_confirmed) {
[email protected]edfca702013-08-16 08:58:14682 cancel_download_confirmation_state_ = RESPONSE_RECEIVED;
[email protected]2e9d79f2013-08-16 05:45:56683 if (IsFastTabUnloadEnabled()) {
684 return fast_unload_controller_->CallBeforeUnloadHandlers(
685 on_close_confirmed);
686 }
687 return unload_controller_->CallBeforeUnloadHandlers(on_close_confirmed);
688}
689
690void Browser::ResetBeforeUnloadHandlers() {
[email protected]edfca702013-08-16 08:58:14691 cancel_download_confirmation_state_ = NOT_PROMPTED;
[email protected]2e9d79f2013-08-16 05:45:56692 if (IsFastTabUnloadEnabled())
693 fast_unload_controller_->ResetBeforeUnloadHandlers();
694 else
695 unload_controller_->ResetBeforeUnloadHandlers();
696}
697
[email protected]88c92012013-07-02 11:56:34698bool Browser::HasCompletedUnloadProcessing() const {
699 DCHECK(IsFastTabUnloadEnabled());
700 return fast_unload_controller_->HasCompletedUnloadProcessing();
701}
702
[email protected]f9b6c092012-07-09 19:32:28703bool Browser::IsAttemptingToCloseBrowser() const {
[email protected]88c92012013-07-02 11:56:34704 if (IsFastTabUnloadEnabled())
705 return fast_unload_controller_->is_attempting_to_close_browser();
[email protected]f9b6c092012-07-09 19:32:28706 return unload_controller_->is_attempting_to_close_browser();
[email protected]36b6dcb2008-11-12 01:19:57707}
708
709void Browser::OnWindowClosing() {
710 if (!ShouldCloseWindow())
711 return;
712
[email protected]c984d9f2010-07-20 20:52:20713 // Application should shutdown on last window close if the user is explicitly
714 // trying to quit, or if there is nothing keeping the browser alive (such as
715 // AppController on the Mac, or BackgroundContentsService for background
716 // pages).
717 bool should_quit_if_last_browser =
[email protected]313fce12013-01-30 17:09:04718 browser_shutdown::IsTryingToQuit() || !chrome::WillKeepAlive();
[email protected]7dc8c6b2010-04-09 17:02:50719
thestig028978692015-10-08 07:39:40720 if (should_quit_if_last_browser && ShouldStartShutdown())
[email protected]36b6dcb2008-11-12 01:19:57721 browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE);
722
[email protected]92371eb2011-04-28 11:50:15723 // Don't use GetForProfileIfExisting here, we want to force creation of the
[email protected]36b6dcb2008-11-12 01:19:57724 // session service so that user can restore what was open.
[email protected]92371eb2011-04-28 11:50:15725 SessionService* session_service =
726 SessionServiceFactory::GetForProfile(profile());
[email protected]36b6dcb2008-11-12 01:19:57727 if (session_service)
728 session_service->WindowClosing(session_id());
729
blundell74001adc2015-09-18 11:04:25730 sessions::TabRestoreService* tab_restore_service =
[email protected]92371eb2011-04-28 11:50:15731 TabRestoreServiceFactory::GetForProfile(profile());
[email protected]a636d8e52012-02-28 15:40:41732
733#if defined(USE_AURA)
[email protected]d019fa582013-11-04 23:45:49734 if (tab_restore_service && is_app() && !is_devtools())
blundellbde024d2015-09-30 13:47:07735 tab_restore_service->BrowserClosing(live_tab_context());
[email protected]a636d8e52012-02-28 15:40:41736#endif
737
[email protected]e0448872013-01-11 19:35:02738 if (tab_restore_service && is_type_tabbed() && tab_strip_model_->count())
blundellbde024d2015-09-30 13:47:07739 tab_restore_service->BrowserClosing(live_tab_context());
[email protected]d8375fd2008-11-25 22:45:39740
[email protected]911f8152010-03-18 16:46:40741 // TODO(sky): convert session/tab restore to use notification.
[email protected]ad50def52011-10-19 23:17:07742 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27743 chrome::NOTIFICATION_BROWSER_CLOSING,
[email protected]6c2381d2011-10-19 02:52:53744 content::Source<Browser>(this),
[email protected]1e0c7402012-07-27 10:48:15745 content::NotificationService::NoDetails());
[email protected]ed1bb7202013-06-21 05:16:44746
[email protected]88c92012013-07-02 11:56:34747 if (!IsFastTabUnloadEnabled())
748 tab_strip_model_->CloseAllTabs();
[email protected]36b6dcb2008-11-12 01:19:57749}
750
[email protected]69444cc2009-04-09 20:40:06751////////////////////////////////////////////////////////////////////////////////
752// In-progress download termination handling:
753
754void Browser::InProgressDownloadResponse(bool cancel_downloads) {
755 if (cancel_downloads) {
756 cancel_download_confirmation_state_ = RESPONSE_RECEIVED;
[email protected]a37d4b02012-06-25 21:56:10757 chrome::CloseWindow(this);
[email protected]69444cc2009-04-09 20:40:06758 return;
759 }
760
761 // Sets the confirmation state to NOT_PROMPTED so that if the user tries to
762 // close again we'll show the warning again.
763 cancel_download_confirmation_state_ = NOT_PROMPTED;
764
765 // Show the download page so the user can figure-out what downloads are still
766 // in-progress.
[email protected]5d9cace72012-06-21 16:07:12767 chrome::ShowDownloads(this);
[email protected]674b65fb2014-02-19 02:43:42768
769 // Reset UnloadController::is_attempting_to_close_browser_ so that we don't
770 // prompt every time any tab is closed. http://crbug.com/305516
771 if (IsFastTabUnloadEnabled())
772 fast_unload_controller_->CancelWindowClose();
773 else
774 unload_controller_->CancelWindowClose();
[email protected]69444cc2009-04-09 20:40:06775}
776
[email protected]5a17d492011-10-24 19:37:03777Browser::DownloadClosePreventionType Browser::OkToCloseWithInProgressDownloads(
778 int* num_downloads_blocking) const {
779 DCHECK(num_downloads_blocking);
780 *num_downloads_blocking = 0;
781
[email protected]5a17d492011-10-24 19:37:03782 // If we're not running a full browser process with a profile manager
783 // (testing), it's ok to close the browser.
784 if (!g_browser_process->profile_manager())
785 return DOWNLOAD_CLOSE_OK;
786
[email protected]422a7d12013-10-21 12:10:42787 int total_download_count =
788 DownloadService::NonMaliciousDownloadCountAllProfiles();
[email protected]5a17d492011-10-24 19:37:03789 if (total_download_count == 0)
790 return DOWNLOAD_CLOSE_OK; // No downloads; can definitely close.
791
792 // Figure out how many windows are open total, and associated with this
793 // profile, that are relevant for the ok-to-close decision.
794 int profile_window_count = 0;
795 int total_window_count = 0;
[email protected]3539929f2013-02-01 05:59:14796 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
[email protected]5a17d492011-10-24 19:37:03797 // Don't count this browser window or any other in the process of closing.
[email protected]3539929f2013-02-01 05:59:14798 Browser* const browser = *it;
[email protected]f9b6c092012-07-09 19:32:28799 // Window closing may be delayed, and windows that are in the process of
800 // closing don't count against our totals.
801 if (browser == this || browser->IsAttemptingToCloseBrowser())
[email protected]5a17d492011-10-24 19:37:03802 continue;
803
[email protected]3539929f2013-02-01 05:59:14804 if (it->profile() == profile())
[email protected]5a17d492011-10-24 19:37:03805 profile_window_count++;
806 total_window_count++;
807 }
808
809 // If there aren't any other windows, we're at browser shutdown,
810 // which would cancel all current downloads.
811 if (total_window_count == 0) {
812 *num_downloads_blocking = total_download_count;
813 return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN;
814 }
815
816 // If there aren't any other windows on our profile, and we're an incognito
817 // profile, and there are downloads associated with that profile,
818 // those downloads would be cancelled by our window (-> profile) close.
819 DownloadService* download_service =
[email protected]423939d2013-07-31 20:00:08820 DownloadServiceFactory::GetForBrowserContext(profile());
[email protected]d07d63fc2013-07-18 19:44:54821 if ((profile_window_count == 0) &&
[email protected]422a7d12013-10-21 12:10:42822 (download_service->NonMaliciousDownloadCount() > 0) &&
[email protected]5a17d492011-10-24 19:37:03823 profile()->IsOffTheRecord()) {
[email protected]422a7d12013-10-21 12:10:42824 *num_downloads_blocking = download_service->NonMaliciousDownloadCount();
[email protected]5a17d492011-10-24 19:37:03825 return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE;
826 }
827
828 // Those are the only conditions under which we will block shutdown.
829 return DOWNLOAD_CLOSE_OK;
830}
831
[email protected]69444cc2009-04-09 20:40:06832////////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:57833// Browser, Tab adding/showing functions:
834
[email protected]227393e2011-06-29 21:28:39835void Browser::WindowFullscreenStateChanged() {
sriramsra41db562015-01-26 22:45:04836 exclusive_access_manager_->fullscreen_controller()
837 ->WindowFullscreenStateChanged();
[email protected]5d98294912012-06-27 22:57:40838 command_controller_->FullscreenStateChanged();
[email protected]9adb8b12011-12-09 06:49:13839 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN);
[email protected]ae2622c2009-07-30 23:47:58840}
841
[email protected]36b6dcb2008-11-12 01:19:57842///////////////////////////////////////////////////////////////////////////////
843// Browser, Assorted browser commands:
844
[email protected]41d9faf2012-02-28 23:46:02845void Browser::ToggleFullscreenModeWithExtension(const GURL& extension_url) {
sriramsra41db562015-01-26 22:45:04846 exclusive_access_manager_->fullscreen_controller()
847 ->ToggleBrowserFullscreenModeWithExtension(extension_url);
[email protected]9282cea2009-02-18 18:49:00848}
849
[email protected]a3e18c42009-03-04 23:36:05850bool Browser::SupportsWindowFeature(WindowFeature feature) const {
[email protected]018cf362010-05-05 22:43:22851 return SupportsWindowFeatureImpl(feature, true);
852}
[email protected]f5bf8ccf2010-02-05 18:19:25853
[email protected]018cf362010-05-05 22:43:22854bool Browser::CanSupportWindowFeature(WindowFeature feature) const {
855 return SupportsWindowFeatureImpl(feature, false);
[email protected]a3e18c42009-03-04 23:36:05856}
857
[email protected]fbd77592008-11-12 20:50:27858void Browser::ToggleEncodingAutoDetect() {
[email protected]7f6f44c2011-12-14 13:23:38859 content::RecordAction(UserMetricsAction("AutoDetectChange"));
[email protected]fbd77592008-11-12 20:50:27860 encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue());
[email protected]a697f4c2009-09-14 22:30:18861 // If "auto detect" is turned on, then any current override encoding
862 // is cleared. This also implicitly performs a reload.
863 // OTOH, if "auto detect" is turned off, we don't change the currently
864 // active encoding.
865 if (encoding_auto_detect_.GetValue()) {
[email protected]0d56fa7212012-11-15 23:34:02866 WebContents* contents = tab_strip_model_->GetActiveWebContents();
[email protected]a697f4c2009-09-14 22:30:18867 if (contents)
[email protected]b2fe07d12010-02-09 14:38:08868 contents->ResetOverrideEncoding();
[email protected]a697f4c2009-09-14 22:30:18869 }
[email protected]fbd77592008-11-12 20:50:27870}
871
872void Browser::OverrideEncoding(int encoding_id) {
[email protected]7f6f44c2011-12-14 13:23:38873 content::RecordAction(UserMetricsAction("OverrideEncoding"));
[email protected]41fc0322009-09-04 22:23:40874 const std::string selected_encoding =
[email protected]fbd77592008-11-12 20:50:27875 CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id);
[email protected]0d56fa7212012-11-15 23:34:02876 WebContents* contents = tab_strip_model_->GetActiveWebContents();
[email protected]57c6a652009-05-04 07:58:34877 if (!selected_encoding.empty() && contents)
[email protected]b2fe07d12010-02-09 14:38:08878 contents->SetOverrideEncoding(selected_encoding);
[email protected]fbd77592008-11-12 20:50:27879 // Update the list of recently selected encodings.
[email protected]41fc0322009-09-04 22:23:40880 std::string new_selected_encoding_list;
[email protected]ddd231e2010-06-29 20:35:19881 if (CharacterEncoding::UpdateRecentlySelectedEncoding(
882 profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding),
[email protected]41fc0322009-09-04 22:23:40883 encoding_id,
884 &new_selected_encoding_list)) {
[email protected]fbd77592008-11-12 20:50:27885 profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding,
[email protected]ddd231e2010-06-29 20:35:19886 new_selected_encoding_list);
[email protected]fbd77592008-11-12 20:50:27887 }
[email protected]36b6dcb2008-11-12 01:19:57888}
889
[email protected]84214982008-12-10 18:49:10890void Browser::OpenFile() {
[email protected]7f6f44c2011-12-14 13:23:38891 content::RecordAction(UserMetricsAction("OpenFile"));
[email protected]92f54082012-07-31 01:43:14892 select_file_dialog_ = ui::SelectFileDialog::Create(
[email protected]6e1fcd12012-07-02 17:14:20893 this, new ChromeSelectFilePolicy(
[email protected]0d56fa7212012-11-15 23:34:02894 tab_strip_model_->GetActiveWebContents()));
[email protected]84214982008-12-10 18:49:10895
[email protected]650b2d52013-02-10 03:41:45896 const base::FilePath directory = profile_->last_selected_directory();
[email protected]35896a32010-06-09 08:42:51897
[email protected]84214982008-12-10 18:49:10898 // TODO(beng): figure out how to juggle this.
[email protected]90556dd2012-06-07 20:26:18899 gfx::NativeWindow parent_window = window_->GetNativeWindow();
[email protected]479cce782012-09-15 20:15:53900 ui::SelectFileDialog::FileTypeInfo file_types;
[email protected]599538b2013-02-20 14:15:14901 file_types.support_drive = true;
[email protected]92f54082012-07-31 01:43:14902 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE,
[email protected]dcd0249872013-12-06 23:58:45903 base::string16(),
[email protected]007b3f82013-04-09 08:46:45904 directory,
905 &file_types,
906 0,
907 base::FilePath::StringType(),
908 parent_window,
909 NULL);
[email protected]84214982008-12-10 18:49:10910}
911
[email protected]92655362012-04-20 21:33:17912void Browser::UpdateDownloadShelfVisibility(bool visible) {
913 if (GetStatusBubble())
914 GetStatusBubble()->UpdateDownloadShelfVisibility(visible);
915}
916
[email protected]36b6dcb2008-11-12 01:19:57917///////////////////////////////////////////////////////////////////////////////
918
[email protected]e232c992012-12-06 12:43:20919void Browser::UpdateUIForNavigationInTab(WebContents* contents,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35920 ui::PageTransition transition,
[email protected]ef557022012-03-16 10:05:33921 bool user_initiated) {
[email protected]e232c992012-12-06 12:43:20922 tab_strip_model_->TabNavigating(contents, transition);
[email protected]ef557022012-03-16 10:05:33923
[email protected]0d56fa7212012-11-15 23:34:02924 bool contents_is_selected =
[email protected]e232c992012-12-06 12:43:20925 contents == tab_strip_model_->GetActiveWebContents();
[email protected]ef557022012-03-16 10:05:33926 if (user_initiated && contents_is_selected && window()->GetLocationBar()) {
927 // Forcibly reset the location bar if the url is going to change in the
928 // current tab, since otherwise it won't discard any ongoing user edits,
929 // since it doesn't realize this is a user-initiated action.
930 window()->GetLocationBar()->Revert();
931 }
932
933 if (GetStatusBubble())
934 GetStatusBubble()->Hide();
935
936 // Update the location bar. This is synchronous. We specifically don't
937 // update the load state since the load hasn't started yet and updating it
938 // will put it out of sync with the actual state like whether we're
939 // displaying a favicon, which controls the throbber. If we updated it here,
940 // the throbber will show the default favicon for a split second when
941 // navigating away from the new tab page.
[email protected]e232c992012-12-06 12:43:20942 ScheduleUIUpdate(contents, content::INVALIDATE_TYPE_URL);
[email protected]ef557022012-03-16 10:05:33943
[email protected]e1f288d2012-05-23 19:36:10944 if (contents_is_selected)
[email protected]fc2b46b2014-05-03 16:33:45945 contents->SetInitialFocus();
[email protected]ef557022012-03-16 10:05:33946}
947
948///////////////////////////////////////////////////////////////////////////////
949// Browser, PageNavigator implementation:
950
951WebContents* Browser::OpenURL(const OpenURLParams& params) {
952 return OpenURLFromTab(NULL, params);
953}
954
[email protected]485fba42009-03-24 23:27:29955///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:57956// Browser, TabStripModelObserver implementation:
957
[email protected]409ea2972012-11-10 19:54:43958void Browser::TabInsertedAt(WebContents* contents,
[email protected]36b6dcb2008-11-12 01:19:57959 int index,
960 bool foreground) {
[email protected]63d1f9b2014-07-05 19:09:03961 SetAsDelegate(contents, true);
[email protected]010152f2014-07-15 00:16:47962
[email protected]50a9a76b2012-09-12 14:19:36963 SessionTabHelper* session_tab_helper =
[email protected]409ea2972012-11-10 19:54:43964 SessionTabHelper::FromWebContents(contents);
[email protected]50a9a76b2012-09-12 14:19:36965 session_tab_helper->SetWindowID(session_id());
[email protected]e524ff92011-03-30 13:26:58966
[email protected]fb312eb2012-09-24 23:21:10967 content::NotificationService::current()->Notify(
968 chrome::NOTIFICATION_TAB_PARENTED,
[email protected]409ea2972012-11-10 19:54:43969 content::Source<content::WebContents>(contents),
[email protected]fb312eb2012-09-24 23:21:10970 content::NotificationService::NoDetails());
971
[email protected]c37e3b62010-01-22 00:15:17972 SyncHistoryWithTabs(index);
[email protected]36b6dcb2008-11-12 01:19:57973
[email protected]159f7762008-12-19 14:58:27974 // Make sure the loading state is updated correctly, otherwise the throbber
975 // won't start if the page is loading.
[email protected]e3b10d12014-03-28 16:06:09976 LoadingStateChanged(contents, true);
[email protected]159f7762008-12-19 14:58:27977
[email protected]20ca0382013-02-28 19:50:07978 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]e397a4472011-12-21 21:47:50979
[email protected]40600152012-09-26 10:04:31980 SessionService* session_service =
981 SessionServiceFactory::GetForProfile(profile_);
[email protected]d4c9caa2013-04-22 18:30:32982 if (session_service) {
[email protected]409ea2972012-11-10 19:54:43983 session_service->TabInserted(contents);
[email protected]d4c9caa2013-04-22 18:30:32984 int new_active_index = tab_strip_model_->active_index();
985 if (index < new_active_index)
986 session_service->SetSelectedTabInWindow(session_id(),
987 new_active_index);
988 }
[email protected]36b6dcb2008-11-12 01:19:57989}
990
[email protected]f2cc7382010-10-15 18:03:05991void Browser::TabClosingAt(TabStripModel* tab_strip_model,
[email protected]0be097d2012-11-10 00:20:16992 WebContents* contents,
[email protected]f2cc7382010-10-15 18:03:05993 int index) {
sriramsra41db562015-01-26 22:45:04994 exclusive_access_manager_->OnTabClosing(contents);
[email protected]40600152012-09-26 10:04:31995 SessionService* session_service =
996 SessionServiceFactory::GetForProfile(profile_);
997 if (session_service)
[email protected]0be097d2012-11-10 00:20:16998 session_service->TabClosing(contents);
[email protected]ad50def52011-10-19 23:17:07999 content::NotificationService::current()->Notify(
[email protected]884033e2012-04-16 19:38:421000 chrome::NOTIFICATION_TAB_CLOSING,
[email protected]0be097d2012-11-10 00:20:161001 content::Source<NavigationController>(&contents->GetController()),
[email protected]ad50def52011-10-19 23:17:071002 content::NotificationService::NoDetails());
[email protected]36b6dcb2008-11-12 01:19:571003
[email protected]075969d2012-04-17 20:05:551004 // Sever the WebContents' connection back to us.
[email protected]63d1f9b2014-07-05 19:09:031005 SetAsDelegate(contents, false);
[email protected]36b6dcb2008-11-12 01:19:571006}
1007
[email protected]e89cfcb2012-11-11 14:47:241008void Browser::TabDetachedAt(WebContents* contents, int index) {
[email protected]d4c9caa2013-04-22 18:30:321009 // TabDetachedAt is called before TabStripModel has updated the
1010 // active index.
1011 int old_active_index = tab_strip_model_->active_index();
1012 if (index < old_active_index && !tab_strip_model_->closing_all()) {
1013 SessionService* session_service =
1014 SessionServiceFactory::GetForProfileIfExisting(profile_);
1015 if (session_service)
1016 session_service->SetSelectedTabInWindow(session_id(),
1017 old_active_index - 1);
1018 }
[email protected]010152f2014-07-15 00:16:471019
[email protected]c37e3b62010-01-22 00:15:171020 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH);
[email protected]36b6dcb2008-11-12 01:19:571021}
1022
[email protected]023c01cc2012-11-12 15:41:111023void Browser::TabDeactivated(WebContents* contents) {
sriramsra41db562015-01-26 22:45:041024 exclusive_access_manager_->OnTabDeactivated(contents);
[email protected]023c01cc2012-11-12 15:41:111025 search_delegate_->OnTabDeactivated(contents);
[email protected]549f62b2013-10-26 12:54:421026 SearchTabHelper::FromWebContents(contents)->OnTabDeactivated();
[email protected]e3a5d5b2012-06-22 17:56:461027
[email protected]85ff2c42009-05-29 21:22:031028 // Save what the user's currently typing, so it can be restored when we
1029 // switch back to this tab.
[email protected]023c01cc2012-11-12 15:41:111030 window_->GetLocationBar()->SaveStateToContents(contents);
[email protected]3d6a8952012-12-14 03:18:071031
1032 if (instant_controller_)
1033 instant_controller_->TabDeactivated(contents);
[email protected]85ff2c42009-05-29 21:22:031034}
1035
[email protected]8e707792012-11-13 10:32:121036void Browser::ActiveTabChanged(WebContents* old_contents,
1037 WebContents* new_contents,
[email protected]3aca95d42011-05-24 22:06:541038 int index,
[email protected]5f2de242013-04-05 02:06:071039 int reason) {
[email protected]d500b1c32013-03-12 06:26:081040 content::RecordAction(UserMetricsAction("ActiveTabChanged"));
1041
[email protected]da9ac4ee2013-10-02 12:19:051042 // Update the bookmark state, since the BrowserWindow may query it during
1043 // OnActiveTabChanged() below.
1044 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH);
1045
1046 // Let the BrowserWindow do its handling. On e.g. views this changes the
1047 // focused object, which should happen before we update the toolbar below,
[email protected]08726d5e2013-09-24 21:52:551048 // since the omnibox expects the correct element to already be focused when it
1049 // is updated.
1050 window_->OnActiveTabChanged(old_contents, new_contents, index, reason);
1051
sriramsra41db562015-01-26 22:45:041052 exclusive_access_manager_->OnTabDetachedFromView(old_contents);
[email protected]949f62a32014-02-13 00:53:101053
[email protected]002efb042011-10-07 17:30:241054 // Discarded tabs always get reloaded.
georgesak6fc95e92015-10-26 21:27:061055 // TODO(georgesak): Validate the usefulness of this. And if needed then move
1056 // to TabManager.
georgesakf6877bd2015-10-30 16:10:361057 if (g_browser_process->GetTabManager()->IsTabDiscarded(new_contents))
[email protected]a37d4b02012-06-25 21:56:101058 chrome::Reload(this, CURRENT_TAB);
[email protected]002efb042011-10-07 17:30:241059
[email protected]36b6dcb2008-11-12 01:19:571060 // If we have any update pending, do it now.
[email protected]24f1477532011-11-22 22:55:361061 if (chrome_updater_factory_.HasWeakPtrs() && old_contents)
[email protected]36b6dcb2008-11-12 01:19:571062 ProcessPendingUIUpdates();
1063
[email protected]36b6dcb2008-11-12 01:19:571064 // Propagate the profile to the location bar.
[email protected]9bc3f242013-04-05 23:27:361065 UpdateToolbar((reason & CHANGE_REASON_REPLACED) == 0);
[email protected]36b6dcb2008-11-12 01:19:571066
sdefresne51bbec7b2015-08-03 14:18:131067 if (search::IsInstantExtendedAPIEnabled())
[email protected]8845bb42013-10-29 00:36:291068 search_delegate_->OnTabActivated(new_contents);
[email protected]e3a5d5b2012-06-22 17:56:461069
[email protected]943d8122010-06-11 02:13:451070 // Update reload/stop state.
[email protected]8e707792012-11-13 10:32:121071 command_controller_->LoadingStateChanged(new_contents->IsLoading(), true);
[email protected]36b6dcb2008-11-12 01:19:571072
[email protected]84214982008-12-10 18:49:101073 // Update commands to reflect current state.
[email protected]5d98294912012-06-27 22:57:401074 command_controller_->TabStateChanged();
[email protected]36b6dcb2008-11-12 01:19:571075
1076 // Reset the status bubble.
[email protected]be3877f2009-01-14 15:51:101077 StatusBubble* status_bubble = GetStatusBubble();
1078 if (status_bubble) {
1079 status_bubble->Hide();
[email protected]36b6dcb2008-11-12 01:19:571080
[email protected]be3877f2009-01-14 15:51:101081 // Show the loading state (if any).
[email protected]0d56fa7212012-11-15 23:34:021082 status_bubble->SetStatus(CoreTabHelper::FromWebContents(
1083 tab_strip_model_->GetActiveWebContents())->GetStatusText());
[email protected]be3877f2009-01-14 15:51:101084 }
[email protected]36b6dcb2008-11-12 01:19:571085
[email protected]826eabe12013-09-30 20:33:381086 if (HasFindBarController()) {
1087 find_bar_controller_->ChangeWebContents(new_contents);
andresantoso6a7691b2014-12-10 23:37:411088 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect());
[email protected]826eabe12013-09-30 20:33:381089 }
1090
georgesak5582cbe2015-05-22 22:08:071091 // Update sessions (selected tab index and last active time). Don't force
1092 // creation of sessions. If sessions doesn't exist, the change will be picked
1093 // up by sessions when created.
[email protected]92371eb2011-04-28 11:50:151094 SessionService* session_service =
1095 SessionServiceFactory::GetForProfileIfExisting(profile_);
[email protected]2fc15ae2012-05-06 00:01:371096 if (session_service && !tab_strip_model_->closing_all()) {
[email protected]04e3ead52013-01-14 01:09:201097 session_service->SetSelectedTabInWindow(session_id(),
1098 tab_strip_model_->active_index());
georgesak5582cbe2015-05-22 22:08:071099 if (SessionRestore::GetSmartRestoreMode() ==
1100 SessionRestore::SMART_RESTORE_MODE_MRU) {
1101 SessionTabHelper* session_tab_helper =
1102 SessionTabHelper::FromWebContents(new_contents);
1103 session_service->SetLastActiveTime(session_id(),
1104 session_tab_helper->session_id(),
1105 base::TimeTicks::Now());
1106 }
[email protected]36b6dcb2008-11-12 01:19:571107 }
[email protected]09b29342011-06-24 19:18:481108
[email protected]8845bb42013-10-29 00:36:291109 // This needs to be called after notifying SearchDelegate.
[email protected]e41982a72012-11-20 07:16:511110 if (instant_controller_)
1111 instant_controller_->ActiveTabChanged();
[email protected]10090d52013-07-25 20:41:371112
[email protected]b4db6d42014-06-07 04:36:581113 autofill::ChromeAutofillClient::FromWebContents(new_contents)->TabActivated();
[email protected]549f62b2013-10-26 12:54:421114 SearchTabHelper::FromWebContents(new_contents)->OnTabActivated();
[email protected]36b6dcb2008-11-12 01:19:571115}
1116
[email protected]3abdff22012-11-13 10:28:451117void Browser::TabMoved(WebContents* contents,
[email protected]36b6dcb2008-11-12 01:19:571118 int from_index,
[email protected]1a242c32010-02-02 21:20:541119 int to_index) {
[email protected]36b6dcb2008-11-12 01:19:571120 DCHECK(from_index >= 0 && to_index >= 0);
1121 // Notify the history service.
1122 SyncHistoryWithTabs(std::min(from_index, to_index));
1123}
1124
[email protected]da25dd52011-01-11 19:06:301125void Browser::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]b624ddc2012-11-15 18:04:131126 WebContents* old_contents,
1127 WebContents* new_contents,
[email protected]8a34e6602010-10-02 17:29:431128 int index) {
[email protected]b624ddc2012-11-15 18:04:131129 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE);
sriramsra41db562015-01-26 22:45:041130 exclusive_access_manager_->OnTabClosing(old_contents);
[email protected]40600152012-09-26 10:04:311131 SessionService* session_service =
1132 SessionServiceFactory::GetForProfile(profile_);
1133 if (session_service)
[email protected]b624ddc2012-11-15 18:04:131134 session_service->TabClosing(old_contents);
[email protected]04e3ead52013-01-14 01:09:201135 TabInsertedAt(new_contents,
1136 index,
1137 (index == tab_strip_model_->active_index()));
[email protected]c37e3b62010-01-22 00:15:171138
creisf82a92ee2015-10-19 19:59:081139 if (!new_contents->GetController().IsInitialBlankNavigation()) {
[email protected]c37e3b62010-01-22 00:15:171140 // Send out notification so that observers are updated appropriately.
creisf82a92ee2015-10-19 19:59:081141 int entry_count = new_contents->GetController().GetEntryCount();
[email protected]b624ddc2012-11-15 18:04:131142 new_contents->GetController().NotifyEntryChanged(
avi47179332015-05-20 21:01:111143 new_contents->GetController().GetEntryAtIndex(entry_count - 1));
[email protected]c37e3b62010-01-22 00:15:171144 }
[email protected]47e020a2010-10-15 14:43:371145
[email protected]47e020a2010-10-15 14:43:371146 if (session_service) {
1147 // The new_contents may end up with a different navigation stack. Force
1148 // the session service to update itself.
[email protected]52877dbc62012-06-29 22:22:031149 session_service->TabRestored(new_contents,
1150 tab_strip_model_->IsTabPinned(index));
[email protected]47e020a2010-10-15 14:43:371151 }
[email protected]c37e3b62010-01-22 00:15:171152}
1153
[email protected]2c7dba42012-11-09 17:05:421154void Browser::TabPinnedStateChanged(WebContents* contents, int index) {
[email protected]92371eb2011-04-28 11:50:151155 SessionService* session_service =
1156 SessionServiceFactory::GetForProfileIfExisting(profile());
[email protected]5c0e6482009-07-14 20:20:091157 if (session_service) {
[email protected]50a9a76b2012-09-12 14:19:361158 SessionTabHelper* session_tab_helper =
[email protected]2c7dba42012-11-09 17:05:421159 SessionTabHelper::FromWebContents(contents);
1160 session_service->SetPinnedState(session_id(),
1161 session_tab_helper->session_id(),
1162 tab_strip_model_->IsTabPinned(index));
[email protected]5c0e6482009-07-14 20:20:091163 }
1164}
1165
[email protected]36b6dcb2008-11-12 01:19:571166void Browser::TabStripEmpty() {
1167 // Close the frame after we return to the message loop (not immediately,
1168 // otherwise it will destroy this object before the stack has a chance to
1169 // cleanly unwind.)
1170 // Note: This will be called several times if TabStripEmpty is called several
1171 // times. This is because it does not close the window if tabs are
1172 // still present.
skyostil380bb2222015-06-12 12:07:051173 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]24f1477532011-11-22 22:55:361174 FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr()));
[email protected]e41982a72012-11-20 07:16:511175
1176 // Instant may have visible WebContents that need to be detached before the
1177 // window system closes.
1178 instant_controller_.reset();
[email protected]36b6dcb2008-11-12 01:19:571179}
1180
[email protected]067310262012-11-22 14:30:411181bool Browser::CanOverscrollContent() const {
mfomitchevf09a66bb2014-10-02 02:20:541182#if defined(OS_WIN)
1183 // Don't enable overscroll on Windows machines unless they have a touch
1184 // screen as these machines typically don't have a touchpad capable of
1185 // horizontal scrolling. We are purposefully biased towards "no" here,
1186 // so that we don't waste resources capturing screenshots for horizontal
1187 // overscroll navigation unnecessarily.
afakhry661e756a2015-12-01 23:50:041188 bool allow_overscroll = ui::GetTouchScreensAvailability() ==
1189 ui::TouchScreensAvailability::ENABLED;
mfomitchevf09a66bb2014-10-02 02:20:541190#elif defined(USE_AURA)
1191 bool allow_overscroll = true;
1192#else
1193 bool allow_overscroll = false;
1194#endif
1195
1196 if (!allow_overscroll)
1197 return false;
1198
avi556c05022014-12-22 23:31:431199 const std::string value =
1200 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
1201 switches::kOverscrollHistoryNavigation);
[email protected]b1d5b192014-03-04 05:36:201202 bool overscroll_enabled = value != "0";
[email protected]86f98a22013-03-20 14:35:001203 if (!overscroll_enabled)
1204 return false;
1205 if (is_app() || is_devtools() || !is_type_tabbed())
1206 return false;
1207
1208 // The detached bookmark bar has appearance of floating above the
1209 // web-contents. This does not play nicely with overscroll navigation
1210 // gestures. So disable overscroll navigation when the bookmark bar is in the
[email protected]b1d5b192014-03-04 05:36:201211 // detached state and the overscroll effect moves the layers.
1212 if (value == "1" && bookmark_bar_state_ == BookmarkBar::DETACHED)
[email protected]86f98a22013-03-20 14:35:001213 return false;
1214 return true;
[email protected]067310262012-11-22 14:30:411215}
1216
[email protected]aa62afd2014-04-22 19:22:461217bool Browser::ShouldPreserveAbortedURLs(WebContents* source) {
1218 // Allow failed URLs to stick around in the omnibox on the NTP, but not when
1219 // other pages have committed.
1220 Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext());
1221 if (!profile || !source->GetController().GetLastCommittedEntry())
1222 return false;
1223 GURL committed_url(source->GetController().GetLastCommittedEntry()->GetURL());
sdefresne51bbec7b2015-08-03 14:18:131224 return search::IsNTPURL(committed_url, profile);
[email protected]aa62afd2014-04-22 19:22:461225}
1226
calamity6160055c2015-04-30 06:45:261227void Browser::SetFocusToLocationBar(bool select_all) {
1228 // Two differences between this and FocusLocationBar():
1229 // (1) This doesn't get recorded in user metrics, since it's called
1230 // internally.
1231 // (2) This checks whether the location bar can be focused, and if not, clears
1232 // the focus. FocusLocationBar() is only reached when the location bar is
1233 // focusable, but this may be reached at other times, e.g. while in
1234 // fullscreen mode, where we need to leave focus in a consistent state.
1235 window_->SetFocusToLocationBar(select_all);
1236}
1237
[email protected]b3996ba2012-08-08 00:39:131238bool Browser::PreHandleKeyboardEvent(content::WebContents* source,
1239 const NativeWebKeyboardEvent& event,
[email protected]fc761142012-06-08 04:49:201240 bool* is_keyboard_shortcut) {
sriramsra41db562015-01-26 22:45:041241 // Escape exits tabbed fullscreen mode and mouse lock, and possibly others.
[email protected]fc761142012-06-08 04:49:201242 // TODO(koz): Write a test for this http://crbug.com/100441.
1243 if (event.windowsKeyCode == 27 &&
sriramsra41db562015-01-26 22:45:041244 exclusive_access_manager_->HandleUserPressedEscape()) {
[email protected]fc761142012-06-08 04:49:201245 return true;
1246 }
1247 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1248}
1249
[email protected]b3996ba2012-08-08 00:39:131250void Browser::HandleKeyboardEvent(content::WebContents* source,
1251 const NativeWebKeyboardEvent& event) {
[email protected]93e0baba2014-04-08 20:04:021252 DevToolsWindow* devtools_window =
1253 DevToolsWindow::GetInstanceForInspectedWebContents(source);
1254 bool handled = false;
1255 if (devtools_window)
1256 handled = devtools_window->ForwardKeyboardEvent(event);
1257
1258 if (!handled)
1259 window()->HandleKeyboardEvent(event);
[email protected]fc761142012-06-08 04:49:201260}
1261
[email protected]ed1bb7202013-06-21 05:16:441262bool Browser::TabsNeedBeforeUnloadFired() {
[email protected]88c92012013-07-02 11:56:341263 if (IsFastTabUnloadEnabled())
1264 return fast_unload_controller_->TabsNeedBeforeUnloadFired();
[email protected]ed1bb7202013-06-21 05:16:441265 return unload_controller_->TabsNeedBeforeUnloadFired();
1266}
1267
[email protected]edc3af82013-12-12 21:24:071268void Browser::ShowValidationMessage(content::WebContents* web_contents,
1269 const gfx::Rect& anchor_in_root_view,
[email protected]ebf04a862013-12-17 08:38:581270 const base::string16& main_text,
1271 const base::string16& sub_text) {
andresantoso49f9a7a2015-01-28 00:03:171272 validation_message_bubble_ =
1273 TabDialogs::FromWebContents(web_contents)
1274 ->ShowValidationMessage(anchor_in_root_view, main_text, sub_text);
[email protected]edc3af82013-12-12 21:24:071275}
1276
1277void Browser::HideValidationMessage(content::WebContents* web_contents) {
1278 validation_message_bubble_.reset();
1279}
1280
1281void Browser::MoveValidationMessage(content::WebContents* web_contents,
1282 const gfx::Rect& anchor_in_root_view) {
1283 if (!validation_message_bubble_)
1284 return;
1285 RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
1286 if (rwhv) {
1287 validation_message_bubble_->SetPositionRelativeToAnchor(
1288 rwhv->GetRenderWidgetHost(), anchor_in_root_view);
1289 }
1290}
1291
[email protected]7a0c5aea2014-03-05 17:41:171292bool Browser::PreHandleGestureEvent(content::WebContents* source,
1293 const blink::WebGestureEvent& event) {
1294 // Disable pinch zooming in undocked dev tools window due to poor UX.
1295 if (app_name() == DevToolsWindow::kDevToolsApp)
1296 return event.type == blink::WebGestureEvent::GesturePinchBegin ||
1297 event.type == blink::WebGestureEvent::GesturePinchUpdate ||
1298 event.type == blink::WebGestureEvent::GesturePinchEnd;
1299
1300 return false;
1301}
1302
[email protected]f9253672014-07-31 03:35:381303bool Browser::CanDragEnter(content::WebContents* source,
1304 const content::DropData& data,
1305 blink::WebDragOperationsMask operations_allowed) {
1306 // Disallow drag-and-drop navigation for Settings windows which do not support
1307 // external navigation.
1308 if ((operations_allowed & blink::WebDragOperationLink) &&
1309 chrome::SettingsWindowManager::GetInstance()->IsSettingsBrowser(this)) {
1310 return false;
1311 }
1312 return true;
1313}
1314
estark5ea80e52015-06-19 18:43:121315content::SecurityStyle Browser::GetSecurityStyle(
1316 WebContents* web_contents,
1317 content::SecurityStyleExplanations* security_style_explanations) {
estark880a5a42015-11-30 18:21:211318 ChromeSecurityStateModelClient* model_client =
1319 ChromeSecurityStateModelClient::FromWebContents(web_contents);
1320 DCHECK(model_client);
estarkb190625f2015-09-16 19:07:411321 const SecurityStateModel::SecurityInfo& security_info =
estark880a5a42015-11-30 18:21:211322 model_client->GetSecurityInfo();
estarkb190625f2015-09-16 19:07:411323
1324 const content::SecurityStyle security_style =
1325 SecurityLevelToSecurityStyle(security_info.security_level);
estark5ea80e52015-06-19 18:43:121326
estark3667b7a62015-08-14 16:49:271327 security_style_explanations->ran_insecure_content_style =
estarkb190625f2015-09-16 19:07:411328 SecurityStateModel::kRanInsecureContentStyle;
estark3667b7a62015-08-14 16:49:271329 security_style_explanations->displayed_insecure_content_style =
estarkb190625f2015-09-16 19:07:411330 SecurityStateModel::kDisplayedInsecureContentStyle;
estark3667b7a62015-08-14 16:49:271331
1332 // Check if the page is HTTP; if so, no explanations are needed. Note
1333 // that SECURITY_STYLE_UNAUTHENTICATED does not necessarily mean that
1334 // the page is loaded over HTTP, because the security style merely
1335 // represents how the embedder wishes to display the security state of
1336 // the page, and the embedder can choose to display HTTPS page as HTTP
1337 // if it wants to (for example, displaying deprecated crypto
1338 // algorithms with the same UI treatment as HTTP pages).
1339 security_style_explanations->scheme_is_cryptographic =
1340 security_info.scheme_is_cryptographic;
estarkb190625f2015-09-16 19:07:411341 if (!security_info.scheme_is_cryptographic) {
1342 return security_style;
estark3667b7a62015-08-14 16:49:271343 }
estark5ea80e52015-06-19 18:43:121344
1345 if (security_info.sha1_deprecation_status ==
lgarroncc53de22015-10-05 23:03:171346 SecurityStateModel::DEPRECATED_SHA1_MAJOR) {
estark5ea80e52015-06-19 18:43:121347 security_style_explanations->broken_explanations.push_back(
1348 content::SecurityStyleExplanation(
lgarroncc53de22015-10-05 23:03:171349 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1),
1350 l10n_util::GetStringUTF8(IDS_MAJOR_SHA1_DESCRIPTION),
pfeldman9966039c2015-09-04 16:49:131351 security_info.cert_id));
estark5ea80e52015-06-19 18:43:121352 } else if (security_info.sha1_deprecation_status ==
lgarroncc53de22015-10-05 23:03:171353 SecurityStateModel::DEPRECATED_SHA1_MINOR) {
lgarron8555a6c0f2015-11-19 02:20:261354 security_style_explanations->unauthenticated_explanations.push_back(
estark5ea80e52015-06-19 18:43:121355 content::SecurityStyleExplanation(
lgarroncc53de22015-10-05 23:03:171356 l10n_util::GetStringUTF8(IDS_MINOR_SHA1),
1357 l10n_util::GetStringUTF8(IDS_MINOR_SHA1_DESCRIPTION),
pfeldman9966039c2015-09-04 16:49:131358 security_info.cert_id));
estark5ea80e52015-06-19 18:43:121359 }
1360
estark3667b7a62015-08-14 16:49:271361 security_style_explanations->ran_insecure_content =
1362 security_info.mixed_content_status ==
estarkb190625f2015-09-16 19:07:411363 SecurityStateModel::RAN_MIXED_CONTENT ||
estark3667b7a62015-08-14 16:49:271364 security_info.mixed_content_status ==
estarkb190625f2015-09-16 19:07:411365 SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT;
estark3667b7a62015-08-14 16:49:271366 security_style_explanations->displayed_insecure_content =
1367 security_info.mixed_content_status ==
estarkb190625f2015-09-16 19:07:411368 SecurityStateModel::DISPLAYED_MIXED_CONTENT ||
estark3667b7a62015-08-14 16:49:271369 security_info.mixed_content_status ==
estarkb190625f2015-09-16 19:07:411370 SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT;
estark5ea80e52015-06-19 18:43:121371
1372 if (net::IsCertStatusError(security_info.cert_status)) {
1373 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString(
1374 net::MapCertStatusToNetError(security_info.cert_status)));
1375
1376 content::SecurityStyleExplanation explanation(
1377 l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR),
1378 l10n_util::GetStringFUTF8(
pfeldman9966039c2015-09-04 16:49:131379 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string),
1380 security_info.cert_id);
estark5ea80e52015-06-19 18:43:121381
1382 if (net::IsCertStatusMinorError(security_info.cert_status))
lgarron8555a6c0f2015-11-19 02:20:261383 security_style_explanations->unauthenticated_explanations.push_back(
1384 explanation);
estark5ea80e52015-06-19 18:43:121385 else
1386 security_style_explanations->broken_explanations.push_back(explanation);
estark36948be2015-08-05 21:41:251387 } else {
1388 // If the certificate does not have errors and is not using
1389 // deprecated SHA1, then add an explanation that the certificate is
1390 // valid.
1391 if (security_info.sha1_deprecation_status ==
estarkb190625f2015-09-16 19:07:411392 SecurityStateModel::NO_DEPRECATED_SHA1) {
estark36948be2015-08-05 21:41:251393 security_style_explanations->secure_explanations.push_back(
1394 content::SecurityStyleExplanation(
1395 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE),
1396 l10n_util::GetStringUTF8(
pfeldman9966039c2015-09-04 16:49:131397 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION),
1398 security_info.cert_id));
estark36948be2015-08-05 21:41:251399 }
estark5ea80e52015-06-19 18:43:121400 }
1401
estarkfd5ca022015-10-29 21:07:551402 if (security_info.is_secure_protocol_and_ciphersuite) {
1403 security_style_explanations->secure_explanations.push_back(
1404 content::SecurityStyleExplanation(
1405 l10n_util::GetStringUTF8(IDS_SECURE_PROTOCOL_AND_CIPHERSUITE),
1406 l10n_util::GetStringUTF8(
1407 IDS_SECURE_PROTOCOL_AND_CIPHERSUITE_DESCRIPTION)));
1408 }
1409
estarkb190625f2015-09-16 19:07:411410 return security_style;
lgarron662dd522015-06-08 23:20:011411}
1412
pfeldman61aa8a1592015-09-03 22:08:181413void Browser::ShowCertificateViewerInDevTools(
1414 content::WebContents* web_contents, int cert_id) {
1415 DevToolsWindow* devtools_window =
1416 DevToolsWindow::GetInstanceForInspectedWebContents(web_contents);
1417 if (devtools_window)
1418 devtools_window->ShowCertificateViewer(cert_id);
1419}
1420
[email protected]d013f142012-04-27 17:31:141421bool Browser::IsMouseLocked() const {
sriramsra41db562015-01-26 22:45:041422 return exclusive_access_manager_->mouse_lock_controller()->IsMouseLocked();
[email protected]92655362012-04-20 21:33:171423}
1424
1425void Browser::OnWindowDidShow() {
1426 if (window_has_shown_)
1427 return;
1428 window_has_shown_ = true;
1429
gab4768aee2015-11-11 23:37:191430 startup_metric_utils::RecordBrowserWindowDisplay(base::TimeTicks::Now());
[email protected]b5febf72012-07-29 18:10:091431
[email protected]92655362012-04-20 21:33:171432 // Nothing to do for non-tabbed windows.
1433 if (!is_type_tabbed())
1434 return;
1435
1436 // Show any pending global error bubble.
1437 GlobalErrorService* service =
1438 GlobalErrorServiceFactory::GetForProfile(profile());
1439 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView();
1440 if (error)
1441 error->ShowBubbleView(this);
1442}
1443
1444void Browser::ShowFirstRunBubble() {
1445 window()->GetLocationBar()->ShowFirstRunBubble();
1446}
1447
1448///////////////////////////////////////////////////////////////////////////////
[email protected]674bc592011-12-20 23:00:421449// Browser, content::WebContentsDelegate implementation:
initial.commit09911bf2008-07-26 23:55:291450
[email protected]e5d549d2011-12-28 01:29:201451WebContents* Browser::OpenURLFromTab(WebContents* source,
[email protected]00c37fc2011-08-02 00:22:501452 const OpenURLParams& params) {
dgozman3ef307abb2015-03-03 14:39:501453 if (is_devtools()) {
1454 DevToolsWindow* window = DevToolsWindow::AsDevToolsWindow(source);
1455 DCHECK(window);
1456 return window->OpenURLFromTab(source, params);
1457 }
1458
[email protected]78e2edc2012-07-01 23:32:281459 chrome::NavigateParams nav_params(this, params.url, params.transition);
[email protected]19c64142013-03-06 20:08:531460 FillNavigateParamsFromOpenURLParams(&nav_params, params);
[email protected]e232c992012-12-06 12:43:201461 nav_params.source_contents = source;
[email protected]00c37fc2011-08-02 00:22:501462 nav_params.tabstrip_add_types = TabStripModel::ADD_NONE;
[email protected]dee1b5a02014-04-22 11:21:561463 if (params.user_gesture)
1464 nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]e7f2e7c2013-07-15 09:41:301465 nav_params.user_gesture = params.user_gesture;
1466
[email protected]5635e6142013-07-18 08:10:401467 PopupBlockerTabHelper* popup_blocker_helper = NULL;
[email protected]e7f2e7c2013-07-15 09:41:301468 if (source)
[email protected]5635e6142013-07-18 08:10:401469 popup_blocker_helper = PopupBlockerTabHelper::FromWebContents(source);
[email protected]e7f2e7c2013-07-15 09:41:301470
[email protected]992e2912013-08-19 15:05:241471 if (popup_blocker_helper) {
[email protected]e7f2e7c2013-07-15 09:41:301472 if ((params.disposition == NEW_POPUP ||
1473 params.disposition == NEW_FOREGROUND_TAB ||
[email protected]7f53dff2013-08-05 10:45:501474 params.disposition == NEW_BACKGROUND_TAB ||
1475 params.disposition == NEW_WINDOW) &&
avi556c05022014-12-22 23:31:431476 !params.user_gesture &&
1477 !base::CommandLine::ForCurrentProcess()->HasSwitch(
1478 switches::kDisablePopupBlocking)) {
[email protected]67264062013-07-25 12:39:261479 if (popup_blocker_helper->MaybeBlockPopup(nav_params,
1480 WebWindowFeatures())) {
[email protected]5635e6142013-07-18 08:10:401481 return NULL;
[email protected]67264062013-07-25 12:39:261482 }
[email protected]e7f2e7c2013-07-15 09:41:301483 }
1484 }
1485
[email protected]78e2edc2012-07-01 23:32:281486 chrome::Navigate(&nav_params);
[email protected]00c37fc2011-08-02 00:22:501487
[email protected]e232c992012-12-06 12:43:201488 return nav_params.target_contents;
initial.commit09911bf2008-07-26 23:55:291489}
1490
creiscde28de2014-11-26 17:10:361491void Browser::NavigationStateChanged(WebContents* source,
[email protected]7f924832014-08-09 05:57:221492 content::InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541493 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1494 // is fixed.
1495 tracked_objects::ScopedTracker tracking_profile1(
1496 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1497 "466285 Browser::NavigationStateChanged::ScheduleUIUpdate"));
initial.commit09911bf2008-07-26 23:55:291498 // Only update the UI when something visible has changed.
[email protected]e83f1682008-09-07 23:57:401499 if (changed_flags)
initial.commit09911bf2008-07-26 23:55:291500 ScheduleUIUpdate(source, changed_flags);
1501
erikchen174b78c62015-03-11 22:02:541502 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1503 // is fixed.
1504 tracked_objects::ScopedTracker tracking_profile2(
1505 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1506 "466285 Browser::NavigationStateChanged::TabStateChanged"));
[email protected]83c2e232011-10-07 21:36:461507 // We can synchronously update commands since they will only change once per
1508 // navigation, so we don't have to worry about flickering. We do, however,
1509 // need to update the command state early on load to always present usable
1510 // actions in the face of slow-to-commit pages.
[email protected]d9083482012-01-06 00:38:461511 if (changed_flags & (content::INVALIDATE_TYPE_URL |
1512 content::INVALIDATE_TYPE_LOAD))
[email protected]5d98294912012-06-27 22:57:401513 command_controller_->TabStateChanged();
benwellsa2a8a9f72015-04-07 07:09:541514
benwells11bd6ed2015-06-05 04:20:411515 if (hosted_app_controller_)
1516 hosted_app_controller_->UpdateLocationBarVisibility(true);
initial.commit09911bf2008-07-26 23:55:291517}
1518
estark25f9af12015-09-09 19:37:041519void Browser::VisibleSSLStateChanged(const WebContents* source) {
[email protected]25af6ec2014-06-06 19:35:071520 // When the current tab's SSL state changes, we need to update the URL
1521 // bar to reflect the new state.
1522 DCHECK(source);
1523 if (tab_strip_model_->GetActiveWebContents() == source)
1524 UpdateToolbar(false);
1525}
1526
[email protected]2a6bc3e2011-12-28 23:51:331527void Browser::AddNewContents(WebContents* source,
1528 WebContents* new_contents,
initial.commit09911bf2008-07-26 23:55:291529 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:391530 const gfx::Rect& initial_rect,
[email protected]eda238a12012-09-07 23:44:001531 bool user_gesture,
1532 bool* was_blocked) {
bokan107a47f2015-02-03 23:23:391533 chrome::AddWebContents(this, source, new_contents, disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001534 user_gesture, was_blocked);
initial.commit09911bf2008-07-26 23:55:291535}
1536
[email protected]2a6bc3e2011-12-28 23:51:331537void Browser::ActivateContents(WebContents* contents) {
[email protected]0d56fa7212012-11-15 23:34:021538 tab_strip_model_->ActivateTabAt(
1539 tab_strip_model_->GetIndexOfWebContents(contents), false);
[email protected]f3e99e32008-07-30 04:48:391540 window_->Activate();
initial.commit09911bf2008-07-26 23:55:291541}
1542
[email protected]e3b10d12014-03-28 16:06:091543void Browser::LoadingStateChanged(WebContents* source,
1544 bool to_different_document) {
[email protected]2fc15ae2012-05-06 00:01:371545 window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading());
[email protected]f3e99e32008-07-30 04:48:391546 window_->UpdateTitleBar();
initial.commit09911bf2008-07-26 23:55:291547
[email protected]0d56fa7212012-11-15 23:34:021548 WebContents* selected_contents = tab_strip_model_->GetActiveWebContents();
[email protected]3c9e1872010-11-18 16:17:491549 if (source == selected_contents) {
[email protected]e3b10d12014-03-28 16:06:091550 bool is_loading = source->IsLoading() && to_different_document;
[email protected]5d98294912012-06-27 22:57:401551 command_controller_->LoadingStateChanged(is_loading, false);
[email protected]43d259d2010-09-03 21:37:461552 if (GetStatusBubble()) {
[email protected]0d56fa7212012-11-15 23:34:021553 GetStatusBubble()->SetStatus(CoreTabHelper::FromWebContents(
1554 tab_strip_model_->GetActiveWebContents())->GetStatusText());
[email protected]43d259d2010-09-03 21:37:461555 }
initial.commit09911bf2008-07-26 23:55:291556 }
1557}
1558
[email protected]a81343d232011-12-27 07:39:201559void Browser::CloseContents(WebContents* source) {
[email protected]88c92012013-07-02 11:56:341560 bool can_close_contents;
1561 if (IsFastTabUnloadEnabled())
1562 can_close_contents = fast_unload_controller_->CanCloseContents(source);
1563 else
1564 can_close_contents = unload_controller_->CanCloseContents(source);
1565
1566 if (can_close_contents)
[email protected]81ddd3402012-12-28 00:55:261567 chrome::CloseWebContents(this, source, true);
initial.commit09911bf2008-07-26 23:55:291568}
1569
[email protected]2a6bc3e2011-12-28 23:51:331570void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) {
[email protected]b35b26b32011-05-05 20:35:141571 if (!IsPopupOrPanel(source)) {
initial.commit09911bf2008-07-26 23:55:291572 NOTREACHED() << "moving invalid browser type";
1573 return;
1574 }
[email protected]e561e202010-03-24 17:57:121575 window_->SetBounds(pos);
initial.commit09911bf2008-07-26 23:55:291576}
1577
[email protected]2a6bc3e2011-12-28 23:51:331578bool Browser::IsPopupOrPanel(const WebContents* source) const {
[email protected]7efaed362013-04-04 09:33:321579 return is_type_popup();
initial.commit09911bf2008-07-26 23:55:291580}
1581
avi450ce00e2014-09-24 01:58:521582void Browser::UpdateTargetURL(WebContents* source, const GURL& url) {
[email protected]be3877f2009-01-14 15:51:101583 if (!GetStatusBubble())
1584 return;
1585
[email protected]0d56fa7212012-11-15 23:34:021586 if (source == tab_strip_model_->GetActiveWebContents()) {
[email protected]36b6dcb2008-11-12 01:19:571587 PrefService* prefs = profile_->GetPrefs();
[email protected]65233052011-08-22 19:02:481588 GetStatusBubble()->SetURL(url, prefs->GetString(prefs::kAcceptLanguages));
[email protected]36b6dcb2008-11-12 01:19:571589 }
1590}
1591
[email protected]92655362012-04-20 21:33:171592void Browser::ContentsMouseEvent(
1593 WebContents* source, const gfx::Point& location, bool motion) {
1594 if (!GetStatusBubble())
1595 return;
1596
[email protected]0d56fa7212012-11-15 23:34:021597 if (source == tab_strip_model_->GetActiveWebContents()) {
[email protected]92655362012-04-20 21:33:171598 GetStatusBubble()->MouseMoved(location, !motion);
1599 if (!motion)
1600 GetStatusBubble()->SetURL(GURL(), std::string());
1601 }
[email protected]3a6a3b62009-05-27 21:36:201602}
1603
[email protected]36b6dcb2008-11-12 01:19:571604void Browser::ContentsZoomChange(bool zoom_in) {
[email protected]5d98294912012-06-27 22:57:401605 chrome::ExecuteCommand(this, zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS);
[email protected]36b6dcb2008-11-12 01:19:571606}
1607
[email protected]b3996ba2012-08-08 00:39:131608bool Browser::TakeFocus(content::WebContents* source,
1609 bool reverse) {
[email protected]ad50def52011-10-19 23:17:071610 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271611 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
[email protected]6c2381d2011-10-19 02:52:531612 content::Source<Browser>(this),
[email protected]ad50def52011-10-19 23:17:071613 content::NotificationService::NoDetails());
[email protected]130efb02009-09-18 18:54:351614 return false;
1615}
1616
[email protected]b7a756d42012-01-23 18:08:171617gfx::Rect Browser::GetRootWindowResizerRect() const {
1618 return window_->GetRootWindowResizerRect();
1619}
1620
[email protected]1d3e9172012-06-12 02:59:131621void Browser::BeforeUnloadFired(WebContents* web_contents,
[email protected]36b6dcb2008-11-12 01:19:571622 bool proceed,
1623 bool* proceed_to_fire_unload) {
[email protected]90354712013-11-16 00:06:301624 if (is_devtools() && DevToolsWindow::HandleBeforeUnload(web_contents,
1625 proceed, proceed_to_fire_unload))
1626 return;
1627
[email protected]88c92012013-07-02 11:56:341628 if (IsFastTabUnloadEnabled()) {
1629 *proceed_to_fire_unload =
1630 fast_unload_controller_->BeforeUnloadFired(web_contents, proceed);
1631 } else {
1632 *proceed_to_fire_unload =
1633 unload_controller_->BeforeUnloadFired(web_contents, proceed);
1634 }
[email protected]36b6dcb2008-11-12 01:19:571635}
1636
[email protected]0c9406632013-02-08 01:13:331637bool Browser::ShouldFocusLocationBarByDefault(WebContents* source) {
[email protected]77fd82e52013-03-12 22:24:261638 const content::NavigationEntry* entry =
[email protected]06cb23b2013-12-17 02:56:491639 source->GetController().GetActiveEntry();
[email protected]e4916412013-04-25 20:12:151640 if (entry) {
1641 GURL url = entry->GetURL();
1642 GURL virtual_url = entry->GetVirtualURL();
[email protected]2d9748b22014-02-11 00:17:291643 if ((url.SchemeIs(content::kChromeUIScheme) &&
[email protected]e4916412013-04-25 20:12:151644 url.host() == chrome::kChromeUINewTabHost) ||
[email protected]2d9748b22014-02-11 00:17:291645 (virtual_url.SchemeIs(content::kChromeUIScheme) &&
[email protected]e4916412013-04-25 20:12:151646 virtual_url.host() == chrome::kChromeUINewTabHost)) {
1647 return true;
1648 }
[email protected]c744f7d22013-04-12 20:29:041649 }
1650
sdefresne51bbec7b2015-08-03 14:18:131651 return search::NavEntryIsInstantNTP(source, entry);
[email protected]0c9406632013-02-08 01:13:331652}
1653
[email protected]2a6bc3e2011-12-28 23:51:331654void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) {
[email protected]1788e772010-12-15 16:40:501655 DCHECK(source);
[email protected]ab93b6372012-11-28 05:20:221656 chrome::ViewSource(this, source);
[email protected]77d8d622010-12-15 10:30:121657}
1658
[email protected]2a6bc3e2011-12-28 23:51:331659void Browser::ViewSourceForFrame(WebContents* source,
[email protected]932b7a12011-03-09 12:50:271660 const GURL& frame_url,
[email protected]691aa2f2013-05-28 22:52:041661 const content::PageState& frame_page_state) {
[email protected]932b7a12011-03-09 12:50:271662 DCHECK(source);
[email protected]691aa2f2013-05-28 22:52:041663 chrome::ViewSource(this, source, frame_url, frame_page_state);
[email protected]932b7a12011-03-09 12:50:271664}
1665
[email protected]4fdf6742012-01-10 20:14:361666void Browser::ShowRepostFormWarningDialog(WebContents* source) {
[email protected]51296c62012-09-26 13:02:441667 TabModalConfirmDialog::Create(new RepostFormWarningController(source),
[email protected]70320ab2012-11-02 19:07:161668 source);
[email protected]14f3408a2009-08-31 20:53:531669}
1670
[email protected]4fdf6742012-01-10 20:14:361671bool Browser::ShouldCreateWebContents(
1672 WebContents* web_contents,
dcheng3ce04b62015-10-26 23:30:551673 int32_t route_id,
1674 int32_t main_frame_route_id,
1675 int32_t main_frame_widget_route_id,
[email protected]4fdf6742012-01-10 20:14:361676 WindowContainerType window_container_type,
nasko48321ca32015-07-02 20:44:121677 const std::string& frame_name,
[email protected]4543b67c2013-07-11 18:18:361678 const GURL& target_url,
[email protected]dd6730412013-08-14 15:03:371679 const std::string& partition_id,
1680 content::SessionStorageNamespace* session_storage_namespace) {
[email protected]4fdf6742012-01-10 20:14:361681 if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1682 // If a BackgroundContents is created, suppress the normal WebContents.
dcheng3ce04b62015-10-26 23:30:551683 return !MaybeCreateBackgroundContents(
1684 route_id, main_frame_route_id, main_frame_widget_route_id, web_contents,
1685 frame_name, target_url, partition_id, session_storage_namespace);
[email protected]4fdf6742012-01-10 20:14:361686 }
1687
1688 return true;
1689}
1690
1691void Browser::WebContentsCreated(WebContents* source_contents,
[email protected]a7531d772014-03-25 16:15:071692 int opener_render_frame_id,
nasko48321ca32015-07-02 20:44:121693 const std::string& frame_name,
[email protected]4fdf6742012-01-10 20:14:361694 const GURL& target_url,
1695 WebContents* new_contents) {
[email protected]6451fe92012-08-30 18:37:261696 // Adopt the WebContents now, so all observers are in place, as the network
[email protected]3d61dd02012-06-07 00:05:531697 // requests for its initial navigation will start immediately. The WebContents
1698 // will later be inserted into this browser using Browser::Navigate via
[email protected]6451fe92012-08-30 18:37:261699 // AddNewContents.
[email protected]e0bc75d52014-01-30 23:42:591700 TabHelpers::AttachTabHelpers(new_contents);
[email protected]4fdf6742012-01-10 20:14:361701
afakhry8394f942015-07-09 18:46:091702 // Make the tab show up in the task manager.
1703 task_management::WebContentsTags::CreateForTabContents(new_contents);
1704
[email protected]4fdf6742012-01-10 20:14:361705 // Notify.
1706 RetargetingDetails details;
1707 details.source_web_contents = source_contents;
[email protected]a7531d772014-03-25 16:15:071708 details.source_render_frame_id = opener_render_frame_id;
[email protected]4fdf6742012-01-10 20:14:361709 details.target_url = target_url;
1710 details.target_web_contents = new_contents;
1711 details.not_yet_in_tabstrip = true;
1712 content::NotificationService::current()->Notify(
1713 chrome::NOTIFICATION_RETARGETING,
1714 content::Source<Profile>(profile_),
1715 content::Details<RetargetingDetails>(&details));
[email protected]80c7b802011-10-28 19:59:081716}
1717
[email protected]2a6bc3e2011-12-28 23:51:331718void Browser::RendererUnresponsive(WebContents* source) {
[email protected]a7ed0ca2012-12-06 19:30:061719 // Ignore hangs if a tab is blocked.
1720 int index = tab_strip_model_->GetIndexOfWebContents(source);
1721 DCHECK_NE(TabStripModel::kNoTab, index);
1722 if (tab_strip_model_->IsTabBlocked(index))
1723 return;
[email protected]c19d9542011-11-15 22:26:421724
andresantoso063151d2014-12-18 22:37:551725 TabDialogs::FromWebContents(source)->ShowHungRendererDialog();
[email protected]55452902011-06-01 21:57:471726}
1727
[email protected]2a6bc3e2011-12-28 23:51:331728void Browser::RendererResponsive(WebContents* source) {
andresantoso063151d2014-12-18 22:37:551729 TabDialogs::FromWebContents(source)->HideHungRendererDialog();
[email protected]55452902011-06-01 21:57:471730}
1731
[email protected]1d3e9172012-06-12 02:59:131732void Browser::DidNavigateMainFramePostCommit(WebContents* web_contents) {
[email protected]0d56fa7212012-11-15 23:34:021733 if (web_contents == tab_strip_model_->GetActiveWebContents())
[email protected]09b29342011-06-24 19:18:481734 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
[email protected]93f230e02011-06-01 14:40:001735}
1736
mathiash72a5e462014-11-19 08:18:501737content::JavaScriptDialogManager* Browser::GetJavaScriptDialogManager(
1738 WebContents* source) {
oshima0929be2a2014-11-19 22:21:031739 return app_modal::JavaScriptDialogManager::GetInstance();
[email protected]3ab9cb82011-06-03 18:02:071740}
1741
[email protected]8bc5ff02013-11-29 06:34:031742content::ColorChooser* Browser::OpenColorChooser(
1743 WebContents* web_contents,
1744 SkColor initial_color,
1745 const std::vector<content::ColorSuggestion>& suggestions) {
[email protected]cb805452013-05-22 15:16:211746 return chrome::ShowColorChooser(web_contents, initial_color);
[email protected]da8543762012-03-20 08:52:201747}
1748
[email protected]1d3e9172012-06-12 02:59:131749void Browser::RunFileChooser(WebContents* web_contents,
[email protected]8caadeb2011-11-22 02:45:231750 const content::FileChooserParams& params) {
[email protected]1d3e9172012-06-12 02:59:131751 FileSelectHelper::RunFileChooser(web_contents, params);
[email protected]3a29a6e2011-08-24 18:26:211752}
1753
[email protected]1d3e9172012-06-12 02:59:131754void Browser::EnumerateDirectory(WebContents* web_contents,
[email protected]33f8ad52012-05-22 18:10:131755 int request_id,
[email protected]650b2d52013-02-10 03:41:451756 const base::FilePath& path) {
[email protected]1d3e9172012-06-12 02:59:131757 FileSelectHelper::EnumerateDirectory(web_contents, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211758}
1759
[email protected]4aebbcaa2013-09-17 22:26:491760bool Browser::EmbedsFullscreenWidget() const {
[email protected]40f12b92014-07-15 19:56:111761 return true;
[email protected]4aebbcaa2013-09-17 22:26:491762}
1763
mlamouri7a78d6fd2015-01-17 13:23:531764void Browser::EnterFullscreenModeForTab(WebContents* web_contents,
1765 const GURL& origin) {
sriramsra41db562015-01-26 22:45:041766 exclusive_access_manager_->fullscreen_controller()->EnterFullscreenModeForTab(
1767 web_contents, origin);
mlamouri7a78d6fd2015-01-17 13:23:531768}
1769
1770void Browser::ExitFullscreenModeForTab(WebContents* web_contents) {
sriramsra41db562015-01-26 22:45:041771 exclusive_access_manager_->fullscreen_controller()->ExitFullscreenModeForTab(
1772 web_contents);
[email protected]8a5e0ca2011-08-25 06:30:471773}
1774
[email protected]1d3e9172012-06-12 02:59:131775bool Browser::IsFullscreenForTabOrPending(
1776 const WebContents* web_contents) const {
sriramsra41db562015-01-26 22:45:041777 return exclusive_access_manager_->fullscreen_controller()
1778 ->IsFullscreenForTabOrPending(web_contents);
[email protected]5d5f7af2011-10-01 01:38:121779}
1780
mikhail.pozdnyakov76208cb2015-09-07 10:31:401781blink::WebDisplayMode Browser::GetDisplayMode(
1782 const WebContents* web_contents) const {
1783 if (window_->IsFullscreen())
1784 return blink::WebDisplayModeFullscreen;
1785
1786 if (is_type_popup())
1787 return blink::WebDisplayModeStandalone;
1788
1789 return blink::WebDisplayModeBrowser;
1790}
1791
[email protected]1d3e9172012-06-12 02:59:131792void Browser::RegisterProtocolHandler(WebContents* web_contents,
[email protected]7d189022011-08-25 22:54:201793 const std::string& protocol,
1794 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:361795 bool user_gesture) {
[email protected]a23abe472014-07-29 23:46:311796 content::BrowserContext* context = web_contents->GetBrowserContext();
1797 if (context->IsOffTheRecord())
[email protected]e1ff4a42013-12-16 20:29:011798 return;
1799
1800 ProtocolHandler handler =
[email protected]c125e532014-05-10 20:39:061801 ProtocolHandler::CreateProtocolHandler(protocol, url);
[email protected]e1ff4a42013-12-16 20:29:011802
1803 ProtocolHandlerRegistry* registry =
[email protected]a23abe472014-07-29 23:46:311804 ProtocolHandlerRegistryFactory::GetForBrowserContext(context);
[email protected]e1ff4a42013-12-16 20:29:011805 if (registry->SilentlyHandleRegisterHandlerRequest(handler))
1806 return;
1807
1808 TabSpecificContentSettings* tab_content_settings =
1809 TabSpecificContentSettings::FromWebContents(web_contents);
1810 if (!user_gesture && window_) {
1811 tab_content_settings->set_pending_protocol_handler(handler);
1812 tab_content_settings->set_previous_protocol_handler(
1813 registry->GetHandlerFor(handler.protocol()));
1814 window_->GetLocationBar()->UpdateContentSettingsIcons();
1815 return;
1816 }
1817
1818 // Make sure content-setting icon is turned off in case the page does
1819 // ungestured and gestured RPH calls.
1820 if (window_) {
1821 tab_content_settings->ClearPendingProtocolHandler();
1822 window_->GetLocationBar()->UpdateContentSettingsIcons();
1823 }
1824
[email protected]f1d20572014-02-14 01:27:141825 PermissionBubbleManager* bubble_manager =
1826 PermissionBubbleManager::FromWebContents(web_contents);
estade6d95d1d2015-10-02 18:55:231827 if (bubble_manager) {
[email protected]f1d20572014-02-14 01:27:141828 bubble_manager->AddRequest(
[email protected]d23cdeee2014-03-10 06:39:531829 new RegisterProtocolHandlerPermissionRequest(registry, handler,
1830 url, user_gesture));
[email protected]f1d20572014-02-14 01:27:141831 }
[email protected]7d189022011-08-25 22:54:201832}
1833
[email protected]f5273e52014-07-14 16:30:201834void Browser::UnregisterProtocolHandler(WebContents* web_contents,
1835 const std::string& protocol,
1836 const GURL& url,
1837 bool user_gesture) {
1838 // user_gesture will be used in case we decide to have confirmation bubble
1839 // for user while un-registering the handler.
[email protected]a23abe472014-07-29 23:46:311840 content::BrowserContext* context = web_contents->GetBrowserContext();
1841 if (context->IsOffTheRecord())
[email protected]f5273e52014-07-14 16:30:201842 return;
1843
1844 ProtocolHandler handler =
1845 ProtocolHandler::CreateProtocolHandler(protocol, url);
1846
1847 ProtocolHandlerRegistry* registry =
[email protected]a23abe472014-07-29 23:46:311848 ProtocolHandlerRegistryFactory::GetForBrowserContext(context);
[email protected]f5273e52014-07-14 16:30:201849 registry->RemoveHandler(handler);
1850}
1851
[email protected]2a6bc3e2011-12-28 23:51:331852void Browser::UpdatePreferredSize(WebContents* source,
[email protected]0548c5352011-09-07 00:33:331853 const gfx::Size& pref_size) {
1854 window_->UpdatePreferredSize(source, pref_size);
1855}
1856
[email protected]61e2b3cc2012-03-02 16:13:341857void Browser::ResizeDueToAutoResize(WebContents* source,
1858 const gfx::Size& new_size) {
1859 window_->ResizeDueToAutoResize(source, new_size);
1860}
1861
[email protected]1d3e9172012-06-12 02:59:131862void Browser::FindReply(WebContents* web_contents,
[email protected]92655362012-04-20 21:33:171863 int request_id,
1864 int number_of_matches,
1865 const gfx::Rect& selection_rect,
1866 int active_match_ordinal,
1867 bool final_update) {
[email protected]e1ff4a42013-12-16 20:29:011868 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents);
1869 if (!find_tab_helper)
1870 return;
1871
1872 find_tab_helper->HandleFindReply(request_id,
1873 number_of_matches,
1874 selection_rect,
1875 active_match_ordinal,
1876 final_update);
[email protected]92655362012-04-20 21:33:171877}
1878
[email protected]1d3e9172012-06-12 02:59:131879void Browser::RequestToLockMouse(WebContents* web_contents,
[email protected]a9c81f02012-06-01 00:15:441880 bool user_gesture,
1881 bool last_unlocked_by_target) {
sriramsra41db562015-01-26 22:45:041882 exclusive_access_manager_->mouse_lock_controller()->RequestToLockMouse(
1883 web_contents, user_gesture, last_unlocked_by_target);
[email protected]55c87fa2011-10-15 07:28:281884}
1885
[email protected]5ef8e372011-10-18 04:25:551886void Browser::LostMouseLock() {
sriramsra41db562015-01-26 22:45:041887 exclusive_access_manager_->mouse_lock_controller()->LostMouseLock();
[email protected]5ef8e372011-10-18 04:25:551888}
1889
[email protected]f13b4202012-06-12 23:53:231890void Browser::RequestMediaAccessPermission(
1891 content::WebContents* web_contents,
[email protected]33662e52013-01-07 21:31:091892 const content::MediaStreamRequest& request,
[email protected]f13b4202012-06-12 23:53:231893 const content::MediaResponseCallback& callback) {
[email protected]859ec322013-09-13 16:24:561894 ::RequestMediaAccessPermission(web_contents, profile_, request, callback);
[email protected]f13b4202012-06-12 23:53:231895}
1896
grunell657d4d82014-09-18 00:09:431897bool Browser::CheckMediaAccessPermission(content::WebContents* web_contents,
1898 const GURL& security_origin,
1899 content::MediaStreamType type) {
1900 return ::CheckMediaAccessPermission(web_contents, security_origin, type);
1901}
1902
[email protected]8c8fc292012-11-23 18:57:161903bool Browser::RequestPpapiBrokerPermission(
1904 WebContents* web_contents,
1905 const GURL& url,
[email protected]650b2d52013-02-10 03:41:451906 const base::FilePath& plugin_path,
[email protected]8c8fc292012-11-23 18:57:161907 const base::Callback<void(bool)>& callback) {
[email protected]0be09932013-01-08 02:03:501908 PepperBrokerInfoBarDelegate::Create(web_contents, url, plugin_path, callback);
[email protected]8c8fc292012-11-23 18:57:161909 return true;
1910}
1911
[email protected]fc2b46b2014-05-03 16:33:451912gfx::Size Browser::GetSizeForNewRenderView(WebContents* web_contents) const {
[email protected]dc0fd432013-08-27 15:29:211913 // When navigating away from NTP with unpinned bookmark bar, the bookmark bar
1914 // would disappear on non-NTP pages, resulting in a bigger size for the new
1915 // render view.
[email protected]fc2b46b2014-05-03 16:33:451916 gfx::Size size = web_contents->GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:211917 // Don't change render view size if bookmark bar is currently not detached,
1918 // or there's no pending entry, or navigating to a NTP page.
1919 if (size.IsEmpty() || bookmark_bar_state_ != BookmarkBar::DETACHED)
1920 return size;
1921 const NavigationEntry* pending_entry =
1922 web_contents->GetController().GetPendingEntry();
1923 if (pending_entry &&
sdefresne51bbec7b2015-08-03 14:18:131924 !search::IsNTPURL(pending_entry->GetVirtualURL(), profile_)) {
[email protected]dc0fd432013-08-27 15:29:211925 size.Enlarge(
1926 0, window()->GetRenderViewHeightInsetWithDetachedBookmarkBar());
1927 }
1928 return size;
1929}
1930
[email protected]36b6dcb2008-11-12 01:19:571931///////////////////////////////////////////////////////////////////////////////
[email protected]51d83bdf2011-12-09 16:09:291932// Browser, CoreTabHelperDelegate implementation:
[email protected]a0366a52011-02-04 20:04:211933
[email protected]ece4aca2012-09-19 22:22:581934void Browser::SwapTabContents(content::WebContents* old_contents,
[email protected]9aa1f6282014-01-30 08:47:411935 content::WebContents* new_contents,
1936 bool did_start_load,
1937 bool did_finish_load) {
[email protected]ece4aca2012-09-19 22:22:581938 int index = tab_strip_model_->GetIndexOfWebContents(old_contents);
[email protected]92655362012-04-20 21:33:171939 DCHECK_NE(TabStripModel::kNoTab, index);
[email protected]59fa29fb2012-12-07 22:13:421940 tab_strip_model_->ReplaceWebContentsAt(index, new_contents);
[email protected]92655362012-04-20 21:33:171941}
1942
[email protected]ece4aca2012-09-19 22:22:581943bool Browser::CanReloadContents(content::WebContents* web_contents) const {
[email protected]5d98294912012-06-27 22:57:401944 return chrome::CanReload(this);
[email protected]e1461952012-06-14 21:05:351945}
1946
[email protected]ece4aca2012-09-19 22:22:581947bool Browser::CanSaveContents(content::WebContents* web_contents) const {
[email protected]5d98294912012-06-27 22:57:401948 return chrome::CanSavePage(this);
[email protected]e1461952012-06-14 21:05:351949}
1950
[email protected]92655362012-04-20 21:33:171951///////////////////////////////////////////////////////////////////////////////
1952// Browser, SearchEngineTabHelperDelegate implementation:
1953
[email protected]3613347d2012-04-27 20:27:371954void Browser::ConfirmAddSearchProvider(TemplateURL* template_url,
[email protected]92655362012-04-20 21:33:171955 Profile* profile) {
1956 window()->ConfirmAddSearchProvider(template_url, profile);
1957}
1958
1959///////////////////////////////////////////////////////////////////////////////
[email protected]82808d02014-04-10 00:10:591960// Browser, SearchTabHelperDelegate implementation:
1961
1962void Browser::NavigateOnThumbnailClick(const GURL& url,
1963 WindowOpenDisposition disposition,
1964 content::WebContents* source_contents) {
1965 DCHECK(source_contents);
1966 // We're guaranteed that AUTO_BOOKMARK is the right transition since this only
1967 // gets called to handle clicks in the new tab page (to navigate to most
1968 // visited item URLs) and in the search results page (to navigate to
1969 // privileged destinations (e.g. chrome://URLs)).
1970 //
1971 // TODO(kmadhusu): Page transitions to privileged destinations should be
1972 // marked as "LINK" instead of "AUTO_BOOKMARK"?
1973 chrome::NavigateParams params(this, url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351974 ui::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82808d02014-04-10 00:10:591975 params.referrer = content::Referrer();
1976 params.source_contents = source_contents;
1977 params.disposition = disposition;
1978 params.is_renderer_initiated = false;
1979 params.initiating_profile = profile_;
1980 chrome::Navigate(&params);
1981}
1982
1983void Browser::OnWebContentsInstantSupportDisabled(
1984 const content::WebContents* web_contents) {
1985 DCHECK(web_contents);
1986 if (tab_strip_model_->GetActiveWebContents() == web_contents)
1987 UpdateToolbar(false);
1988}
1989
1990OmniboxView* Browser::GetOmniboxView() {
1991 return window_->GetLocationBar()->GetOmniboxView();
1992}
1993
1994std::set<std::string> Browser::GetOpenUrls() {
jitendra.ks30f03392015-01-28 09:47:181995 scoped_refptr<history::TopSites> top_sites =
1996 TopSitesFactory::GetForProfile(profile_);
[email protected]82808d02014-04-10 00:10:591997 if (!top_sites) // NULL for Incognito profiles.
1998 return std::set<std::string>();
1999
2000 std::set<std::string> open_urls;
2001 chrome::GetOpenUrls(*tab_strip_model_, *top_sites, &open_urls);
2002 return open_urls;
2003}
2004
2005///////////////////////////////////////////////////////////////////////////////
[email protected]e41d0082013-05-16 04:37:542006// Browser, web_modal::WebContentsModalDialogManagerDelegate implementation:
[email protected]92655362012-04-20 21:33:172007
[email protected]c5731a1c2012-12-22 10:18:452008void Browser::SetWebContentsBlocked(content::WebContents* web_contents,
2009 bool blocked) {
[email protected]c6464ad2012-10-03 00:27:282010 int index = tab_strip_model_->GetIndexOfWebContents(web_contents);
[email protected]92655362012-04-20 21:33:172011 if (index == TabStripModel::kNoTab) {
2012 NOTREACHED();
2013 return;
2014 }
[email protected]2fc15ae2012-05-06 00:01:372015 tab_strip_model_->SetTabBlocked(index, blocked);
[email protected]0d56fa7212012-11-15 23:34:022016 if (!blocked && tab_strip_model_->GetActiveWebContents() == web_contents)
[email protected]fc2b46b2014-05-03 16:33:452017 web_contents->Focus();
[email protected]92655362012-04-20 21:33:172018}
2019
[email protected]e41d0082013-05-16 04:37:542020web_modal::WebContentsModalDialogHost*
2021Browser::GetWebContentsModalDialogHost() {
[email protected]7519c522013-04-02 01:07:232022 return window_->GetWebContentsModalDialogHost();
[email protected]6a151762012-10-03 22:33:192023}
2024
[email protected]92655362012-04-20 21:33:172025///////////////////////////////////////////////////////////////////////////////
[email protected]92655362012-04-20 21:33:172026// Browser, BookmarkTabHelperDelegate implementation:
2027
[email protected]1c5119c2012-09-19 00:08:572028void Browser::URLStarredChanged(content::WebContents* web_contents,
2029 bool starred) {
[email protected]0d56fa7212012-11-15 23:34:022030 if (web_contents == tab_strip_model_->GetActiveWebContents())
[email protected]92655362012-04-20 21:33:172031 window_->SetStarredState(starred);
2032}
2033
2034///////////////////////////////////////////////////////////////////////////////
[email protected]6f80e932012-06-04 19:00:072035// Browser, ZoomObserver implementation:
2036
wjmaclean7f63c6b2014-12-09 14:59:552037void Browser::OnZoomChanged(
2038 const ui_zoom::ZoomController::ZoomChangedEventData& data) {
[email protected]63d1f9b2014-07-05 19:09:032039 if (data.web_contents == tab_strip_model_->GetActiveWebContents()) {
wjmacleanff3d0f62015-02-25 19:38:362040 window_->ZoomChangedForActiveTab(data.can_show_bubble);
[email protected]d93dbd12014-08-04 23:42:532041 // Change the zoom commands state based on the zoom state
2042 command_controller_->ZoomStateChanged();
[email protected]6f80e932012-06-04 19:00:072043 }
2044}
2045
2046///////////////////////////////////////////////////////////////////////////////
[email protected]92f54082012-07-31 01:43:142047// Browser, ui::SelectFileDialog::Listener implementation:
[email protected]36b6dcb2008-11-12 01:19:572048
[email protected]650b2d52013-02-10 03:41:452049void Browser::FileSelected(const base::FilePath& path, int index,
2050 void* params) {
[email protected]53f04c82012-07-26 02:31:092051 FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params);
2052}
2053
[email protected]a573bc32013-04-09 15:09:542054void Browser::FileSelectedWithExtraInfo(const ui::SelectedFileInfo& file_info,
2055 int index,
2056 void* params) {
[email protected]53f04c82012-07-26 02:31:092057 profile_->set_last_selected_directory(file_info.file_path.DirName());
2058
[email protected]a573bc32013-04-09 15:09:542059 GURL url = net::FilePathToFileURL(file_info.local_path);
[email protected]b7813a22012-04-04 18:41:022060
2061#if defined(OS_CHROMEOS)
hirono90949af2014-09-25 04:23:372062 const GURL external_url =
2063 chromeos::CreateExternalFileURLFromPath(profile_, file_info.file_path);
2064 if (!external_url.is_empty())
2065 url = external_url;
[email protected]b7813a22012-04-04 18:41:022066#endif
2067
[email protected]a573bc32013-04-09 15:09:542068 if (url.is_empty())
[email protected]e5d549d2011-12-28 01:29:202069 return;
2070
2071 OpenURL(OpenURLParams(
Sylvain Defresnec6ccc77d2014-09-19 10:19:352072 url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
[email protected]36b6dcb2008-11-12 01:19:572073}
2074
2075///////////////////////////////////////////////////////////////////////////////
[email protected]6c2381d2011-10-19 02:52:532076// Browser, content::NotificationObserver implementation:
[email protected]36b6dcb2008-11-12 01:19:572077
[email protected]432115822011-07-10 15:52:272078void Browser::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532079 const content::NotificationSource& source,
2080 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272081 switch (type) {
[email protected]adf5a102014-07-31 12:44:062082 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532083 Profile* profile = content::Source<Profile>(source).ptr();
[email protected]fe8944f2011-08-30 17:47:322084 if (profile_->IsSameProfile(profile) && window()->GetLocationBar())
erikchen545918a2014-12-31 02:34:062085 window()->GetLocationBar()->UpdatePageActions();
[email protected]371ed7a2009-08-25 15:22:462086 break;
2087 }
2088
[email protected]6b40bb582012-03-15 20:50:382089#if defined(ENABLE_THEMES)
[email protected]432115822011-07-10 15:52:272090 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
[email protected]e001d412009-06-26 20:53:252091 window()->UserChangedTheme();
2092 break;
[email protected]6b40bb582012-03-15 20:50:382093#endif
[email protected]e001d412009-06-26 20:53:252094
[email protected]ea049a02011-12-25 21:37:092095 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: {
2096 WebContents* web_contents = content::Source<WebContents>(source).ptr();
[email protected]0d56fa7212012-11-15 23:34:022097 if (web_contents == tab_strip_model_->GetActiveWebContents()) {
[email protected]9a9a9e22011-05-13 22:20:352098 LocationBar* location_bar = window()->GetLocationBar();
2099 if (location_bar)
2100 location_bar->UpdateContentSettingsIcons();
2101 }
2102 break;
2103 }
2104
[email protected]e83f1682008-09-07 23:57:402105 default:
2106 NOTREACHED() << "Got a notification we didn't register for.";
initial.commit09911bf2008-07-26 23:55:292107 }
2108}
2109
thestiga84d8e62014-10-17 22:27:552110#if defined(ENABLE_EXTENSIONS)
[email protected]d3b98c82010-07-14 07:45:592111///////////////////////////////////////////////////////////////////////////////
jitendra.ksa0055532014-10-07 05:54:462112// Browser, extensions::ExtensionRegistryObserver implementation:
2113
2114void Browser::OnExtensionUninstalled(content::BrowserContext* browser_context,
2115 const extensions::Extension* extension,
2116 extensions::UninstallReason reason) {
2117 // During window creation on Windows we may end up calling into
2118 // SHAppBarMessage, which internally spawns a nested message loop.This
2119 // makes it possible for us to end up here before window creation has
2120 // completed, at which point window_ is NULL. See 94752 for details.
2121
2122 if (window() && window()->GetLocationBar())
2123 window()->GetLocationBar()->UpdatePageActions();
2124}
2125
2126void Browser::OnExtensionLoaded(content::BrowserContext* browser_context,
2127 const extensions::Extension* extension) {
wittman76df71db32014-12-18 23:26:582128 command_controller_->ExtensionStateChanged();
jitendra.ksa0055532014-10-07 05:54:462129}
2130
2131void Browser::OnExtensionUnloaded(
2132 content::BrowserContext* browser_context,
2133 const extensions::Extension* extension,
2134 extensions::UnloadedExtensionInfo::Reason reason) {
wittman76df71db32014-12-18 23:26:582135 command_controller_->ExtensionStateChanged();
jitendra.ksa0055532014-10-07 05:54:462136 if (window()->GetLocationBar())
2137 window()->GetLocationBar()->UpdatePageActions();
2138
2139 // Close any tabs from the unloaded extension, unless it's terminated,
2140 // in which case let the sad tabs remain.
jared.sohna1409622015-08-08 07:16:142141 // Also, if tab is muted and the cause is the unloaded extension, unmute it.
jitendra.ksa0055532014-10-07 05:54:462142 if (reason != extensions::UnloadedExtensionInfo::REASON_TERMINATE) {
2143 // Iterate backwards as we may remove items while iterating.
2144 for (int i = tab_strip_model_->count() - 1; i >= 0; --i) {
2145 WebContents* web_contents = tab_strip_model_->GetWebContentsAt(i);
2146 // Two cases are handled here:
2147
2148 // - The scheme check is for when an extension page is loaded in a
2149 // tab, e.g. chrome-extension://id/page.html.
2150 // - The extension_app check is for apps, which can have non-extension
2151 // schemes, e.g. https://mail.google.com if you have the Gmail app
2152 // installed.
2153 if ((web_contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
2154 web_contents->GetURL().host() == extension->id()) ||
2155 (extensions::TabHelper::FromWebContents(web_contents)
2156 ->extension_app() == extension)) {
2157 tab_strip_model_->CloseWebContentsAt(i, TabStripModel::CLOSE_NONE);
jared.sohna1409622015-08-08 07:16:142158 } else {
miu895bb4e2015-08-11 23:03:042159 chrome::UnmuteIfMutedByExtension(web_contents, extension->id());
jitendra.ksa0055532014-10-07 05:54:462160 }
2161 }
2162 }
2163}
thestiga84d8e62014-10-17 22:27:552164#endif // defined(ENABLE_EXTENSIONS)
jitendra.ksa0055532014-10-07 05:54:462165
2166///////////////////////////////////////////////////////////////////////////////
pkastingcc29d20e2015-02-25 06:05:532167// Browser, translate::ContentTranslateDriver::Observer implementation:
2168
2169void Browser::OnIsPageTranslatedChanged(content::WebContents* source) {
2170 DCHECK(source);
2171 if (tab_strip_model_->GetActiveWebContents() == source) {
2172 window_->SetTranslateIconToggled(
2173 ChromeTranslateClient::FromWebContents(
2174 source)->GetLanguageState().IsPageTranslated());
2175 }
2176}
2177
2178void Browser::OnTranslateEnabledChanged(content::WebContents* source) {
2179 DCHECK(source);
2180 if (tab_strip_model_->GetActiveWebContents() == source)
2181 UpdateToolbar(false);
2182}
2183
2184///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:572185// Browser, Command and state updating (private):
2186
[email protected]c31813a2012-11-15 18:47:262187void Browser::OnDevToolsDisabledChanged() {
2188 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
[email protected]b50452f2014-08-18 12:31:442189 content::DevToolsAgentHost::DetachAllClients();
[email protected]c31813a2012-11-15 18:47:262190}
2191
[email protected]36b6dcb2008-11-12 01:19:572192///////////////////////////////////////////////////////////////////////////////
2193// Browser, UI update coalescing and handling (private):
2194
2195void Browser::UpdateToolbar(bool should_restore_state) {
[email protected]2e7fe4312013-08-21 17:19:482196 window_->UpdateToolbar(should_restore_state ?
2197 tab_strip_model_->GetActiveWebContents() : NULL);
initial.commit09911bf2008-07-26 23:55:292198}
2199
creiscde28de2014-11-26 17:10:362200void Browser::ScheduleUIUpdate(WebContents* source,
[email protected]36b6dcb2008-11-12 01:19:572201 unsigned changed_flags) {
[email protected]913664d2013-12-17 11:43:382202 DCHECK(source);
2203 int index = tab_strip_model_->GetIndexOfWebContents(source);
2204 DCHECK_NE(TabStripModel::kNoTab, index);
[email protected]a5231662009-09-26 00:56:002205
erikchen174b78c62015-03-11 22:02:542206 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
2207 // is fixed.
2208 tracked_objects::ScopedTracker tracking_profile1(
2209 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2210 "466285 Browser::ScheduleUIUpdate::Toolbar"));
[email protected]2b4355c2009-04-04 17:55:462211 // Do some synchronous updates.
creiscde28de2014-11-26 17:10:362212 if (changed_flags & content::INVALIDATE_TYPE_URL) {
2213 if (source == tab_strip_model_->GetActiveWebContents()) {
2214 // Only update the URL for the current tab. Note that we do not update
2215 // the navigation commands since those would have already been updated
2216 // synchronously by NavigationStateChanged.
2217 UpdateToolbar(false);
2218 } else {
2219 // Clear the saved tab state for the tab that navigated, so that we don't
2220 // restore any user text after the old URL has been invalidated (e.g.,
2221 // after a new navigation commits in that tab while unfocused).
2222 window_->ResetToolbarTabState(source);
2223 }
[email protected]d9083482012-01-06 00:38:462224 changed_flags &= ~content::INVALIDATE_TYPE_URL;
[email protected]36b6dcb2008-11-12 01:19:572225 }
erikchen174b78c62015-03-11 22:02:542226
2227 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
2228 // is fixed.
2229 tracked_objects::ScopedTracker tracking_profile2(
2230 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2231 "466285 Browser::ScheduleUIUpdate::TabStripModel"));
[email protected]d9083482012-01-06 00:38:462232 if (changed_flags & content::INVALIDATE_TYPE_LOAD) {
[email protected]6ebdc9b2010-09-27 16:55:572233 // Update the loading state synchronously. This is so the throbber will
2234 // immediately start/stop, which gives a more snappy feel. We want to do
[email protected]a5231662009-09-26 00:56:002235 // this for any tab so they start & stop quickly.
[email protected]526b45e2012-11-28 20:22:462236 tab_strip_model_->UpdateWebContentsStateAt(
[email protected]0d56fa7212012-11-15 23:34:022237 tab_strip_model_->GetIndexOfWebContents(source),
[email protected]6ebdc9b2010-09-27 16:55:572238 TabStripModelObserver::LOADING_ONLY);
[email protected]d9083482012-01-06 00:38:462239 // The status bubble needs to be updated during INVALIDATE_TYPE_LOAD too,
2240 // but we do that asynchronously by not stripping INVALIDATE_TYPE_LOAD from
[email protected]6ebdc9b2010-09-27 16:55:572241 // changed_flags.
[email protected]8030f012009-09-25 18:09:372242 }
2243
[email protected]d9083482012-01-06 00:38:462244 if (changed_flags & content::INVALIDATE_TYPE_TITLE && !source->IsLoading()) {
[email protected]f1cd5e82009-10-23 17:19:032245 // To correctly calculate whether the title changed while not loading
2246 // we need to process the update synchronously. This state only matters for
2247 // the TabStripModel, so we notify the TabStripModel now and notify others
2248 // asynchronously.
[email protected]526b45e2012-11-28 20:22:462249 tab_strip_model_->UpdateWebContentsStateAt(
[email protected]0d56fa7212012-11-15 23:34:022250 tab_strip_model_->GetIndexOfWebContents(source),
[email protected]f1cd5e82009-10-23 17:19:032251 TabStripModelObserver::TITLE_NOT_LOADING);
2252 }
2253
[email protected]2b4355c2009-04-04 17:55:462254 // If the only updates were synchronously handled above, we're done.
[email protected]8030f012009-09-25 18:09:372255 if (changed_flags == 0)
[email protected]2b4355c2009-04-04 17:55:462256 return;
[email protected]36b6dcb2008-11-12 01:19:572257
2258 // Save the dirty bits.
[email protected]85354982009-09-25 19:58:402259 scheduled_updates_[source] |= changed_flags;
[email protected]36b6dcb2008-11-12 01:19:572260
[email protected]24f1477532011-11-22 22:55:362261 if (!chrome_updater_factory_.HasWeakPtrs()) {
[email protected]36b6dcb2008-11-12 01:19:572262 // No task currently scheduled, start another.
skyostil380bb2222015-06-12 12:07:052263 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
2264 FROM_HERE, base::Bind(&Browser::ProcessPendingUIUpdates,
2265 chrome_updater_factory_.GetWeakPtr()),
[email protected]11d6ab1a2012-01-12 21:37:262266 base::TimeDelta::FromMilliseconds(kUIUpdateCoalescingTimeMS));
[email protected]36b6dcb2008-11-12 01:19:572267 }
2268}
2269
2270void Browser::ProcessPendingUIUpdates() {
2271#ifndef NDEBUG
2272 // Validate that all tabs we have pending updates for exist. This is scary
2273 // because the pending list must be kept in sync with any detached or
[email protected]a5231662009-09-26 00:56:002274 // deleted tabs.
[email protected]85354982009-09-25 19:58:402275 for (UpdateMap::const_iterator i = scheduled_updates_.begin();
2276 i != scheduled_updates_.end(); ++i) {
[email protected]36b6dcb2008-11-12 01:19:572277 bool found = false;
[email protected]e0448872013-01-11 19:35:022278 for (int tab = 0; tab < tab_strip_model_->count(); tab++) {
[email protected]0d56fa7212012-11-15 23:34:022279 if (tab_strip_model_->GetWebContentsAt(tab) == i->first) {
[email protected]36b6dcb2008-11-12 01:19:572280 found = true;
2281 break;
2282 }
2283 }
2284 DCHECK(found);
2285 }
2286#endif
2287
[email protected]24f1477532011-11-22 22:55:362288 chrome_updater_factory_.InvalidateWeakPtrs();
[email protected]36b6dcb2008-11-12 01:19:572289
robliao1766df52015-03-14 01:06:262290 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185
2291 // is fixed.
2292 tracked_objects::ScopedTracker tracking_profile1(
2293 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2294 "467185 Browser::ProcessPendingUIUpdates1"));
2295
[email protected]85354982009-09-25 19:58:402296 for (UpdateMap::const_iterator i = scheduled_updates_.begin();
2297 i != scheduled_updates_.end(); ++i) {
[email protected]36b6dcb2008-11-12 01:19:572298 // Do not dereference |contents|, it may be out-of-date!
[email protected]2a6bc3e2011-12-28 23:51:332299 const WebContents* contents = i->first;
[email protected]85354982009-09-25 19:58:402300 unsigned flags = i->second;
[email protected]36b6dcb2008-11-12 01:19:572301
[email protected]0d56fa7212012-11-15 23:34:022302 if (contents == tab_strip_model_->GetActiveWebContents()) {
robliao1766df52015-03-14 01:06:262303 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185
2304 // is fixed.
2305 tracked_objects::ScopedTracker tracking_profile2(
2306 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2307 "467185 Browser::ProcessPendingUIUpdates2"));
2308
[email protected]a5231662009-09-26 00:56:002309 // Updates that only matter when the tab is selected go here.
[email protected]f7f3a5f2009-05-01 22:02:342310
[email protected]6ebdc9b2010-09-27 16:55:572311 // Updating the URL happens synchronously in ScheduleUIUpdate.
[email protected]d9083482012-01-06 00:38:462312 if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) {
[email protected]0d56fa7212012-11-15 23:34:022313 GetStatusBubble()->SetStatus(CoreTabHelper::FromWebContents(
2314 tab_strip_model_->GetActiveWebContents())->GetStatusText());
[email protected]0dd3a0ab2011-02-18 08:17:442315 }
[email protected]a5231662009-09-26 00:56:002316
[email protected]d9083482012-01-06 00:38:462317 if (flags & (content::INVALIDATE_TYPE_TAB |
2318 content::INVALIDATE_TYPE_TITLE)) {
[email protected]a5231662009-09-26 00:56:002319 window_->UpdateTitleBar();
2320 }
[email protected]4d34e2e2009-05-26 22:55:282321 }
[email protected]36b6dcb2008-11-12 01:19:572322
[email protected]a5231662009-09-26 00:56:002323 // Updates that don't depend upon the selected state go here.
[email protected]d9083482012-01-06 00:38:462324 if (flags &
2325 (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) {
robliao1766df52015-03-14 01:06:262326 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185
2327 // is fixed.
2328 tracked_objects::ScopedTracker tracking_profile3(
2329 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2330 "467185 Browser::ProcessPendingUIUpdates3"));
[email protected]526b45e2012-11-28 20:22:462331 tab_strip_model_->UpdateWebContentsStateAt(
[email protected]e52d0a42012-06-08 22:44:162332 tab_strip_model_->GetIndexOfWebContents(contents),
[email protected]f1cd5e82009-10-23 17:19:032333 TabStripModelObserver::ALL);
[email protected]36b6dcb2008-11-12 01:19:572334 }
2335
[email protected]13155a22013-03-19 23:33:542336 // Update the bookmark bar. It may happen that the tab is crashed, and if
2337 // so, the bookmark bar should be hidden.
robliao1766df52015-03-14 01:06:262338 if (flags & content::INVALIDATE_TYPE_TAB) {
2339 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185
2340 // is fixed.
2341 tracked_objects::ScopedTracker tracking_profile4(
2342 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2343 "467185 Browser::ProcessPendingUIUpdates4"));
[email protected]13155a22013-03-19 23:33:542344 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
robliao1766df52015-03-14 01:06:262345 }
[email protected]13155a22013-03-19 23:33:542346
[email protected]36b6dcb2008-11-12 01:19:572347 // We don't need to process INVALIDATE_STATE, since that's not visible.
2348 }
2349
2350 scheduled_updates_.clear();
2351}
2352
[email protected]d9083482012-01-06 00:38:462353void Browser::RemoveScheduledUpdatesFor(WebContents* contents) {
[email protected]36b6dcb2008-11-12 01:19:572354 if (!contents)
2355 return;
2356
[email protected]85354982009-09-25 19:58:402357 UpdateMap::iterator i = scheduled_updates_.find(contents);
2358 if (i != scheduled_updates_.end())
2359 scheduled_updates_.erase(i);
initial.commit09911bf2008-07-26 23:55:292360}
2361
[email protected]36b6dcb2008-11-12 01:19:572362///////////////////////////////////////////////////////////////////////////////
2363// Browser, Getters for UI (private):
initial.commit09911bf2008-07-26 23:55:292364
[email protected]36b6dcb2008-11-12 01:19:572365StatusBubble* Browser::GetStatusBubble() {
[email protected]8e837ec2013-01-31 01:48:332366 // In kiosk and exclusive app mode, we want to always hide the status bubble.
2367 if (chrome::IsRunningInAppMode())
[email protected]34930432009-11-09 00:12:092368 return NULL;
[email protected]8e837ec2013-01-31 01:48:332369
[email protected]9b032bf2009-07-21 17:34:232370 return window_ ? window_->GetStatusBubble() : NULL;
initial.commit09911bf2008-07-26 23:55:292371}
2372
[email protected]36b6dcb2008-11-12 01:19:572373///////////////////////////////////////////////////////////////////////////////
2374// Browser, Session restore functions (private):
initial.commit09911bf2008-07-26 23:55:292375
2376void Browser::SyncHistoryWithTabs(int index) {
[email protected]92371eb2011-04-28 11:50:152377 SessionService* session_service =
2378 SessionServiceFactory::GetForProfileIfExisting(profile());
initial.commit09911bf2008-07-26 23:55:292379 if (session_service) {
[email protected]e0448872013-01-11 19:35:022380 for (int i = index; i < tab_strip_model_->count(); ++i) {
[email protected]0d56fa7212012-11-15 23:34:022381 WebContents* web_contents = tab_strip_model_->GetWebContentsAt(i);
[email protected]50a9a76b2012-09-12 14:19:362382 if (web_contents) {
2383 SessionTabHelper* session_tab_helper =
2384 SessionTabHelper::FromWebContents(web_contents);
initial.commit09911bf2008-07-26 23:55:292385 session_service->SetTabIndexInWindow(
[email protected]50a9a76b2012-09-12 14:19:362386 session_id(), session_tab_helper->session_id(), i);
[email protected]ecc523f62010-09-28 22:45:402387 session_service->SetPinnedState(
2388 session_id(),
[email protected]50a9a76b2012-09-12 14:19:362389 session_tab_helper->session_id(),
[email protected]52877dbc62012-06-29 22:22:032390 tab_strip_model_->IsTabPinned(i));
initial.commit09911bf2008-07-26 23:55:292391 }
2392 }
2393 }
2394}
2395
[email protected]36b6dcb2008-11-12 01:19:572396///////////////////////////////////////////////////////////////////////////////
[email protected]69444cc2009-04-09 20:40:062397// Browser, In-progress download termination handling (private):
2398
[email protected]b6a4ac2b2011-10-17 20:05:482399bool Browser::CanCloseWithInProgressDownloads() {
[email protected]5a17d492011-10-24 19:37:032400 // If we've prompted, we need to hear from the user before we
2401 // can close.
2402 if (cancel_download_confirmation_state_ != NOT_PROMPTED)
2403 return cancel_download_confirmation_state_ != WAITING_FOR_RESPONSE;
2404
2405 int num_downloads_blocking;
[email protected]edfca702013-08-16 08:58:142406 Browser::DownloadClosePreventionType dialog_type =
2407 OkToCloseWithInProgressDownloads(&num_downloads_blocking);
2408 if (dialog_type == DOWNLOAD_CLOSE_OK)
[email protected]446295a2010-04-19 23:43:002409 return true;
2410
[email protected]5a17d492011-10-24 19:37:032411 // Closing this window will kill some downloads; prompt to make sure
2412 // that's ok.
[email protected]69444cc2009-04-09 20:40:062413 cancel_download_confirmation_state_ = WAITING_FOR_RESPONSE;
[email protected]edfca702013-08-16 08:58:142414 window_->ConfirmBrowserCloseWithPendingDownloads(
2415 num_downloads_blocking,
2416 dialog_type,
2417 false,
2418 base::Bind(&Browser::InProgressDownloadResponse,
2419 weak_factory_.GetWeakPtr()));
[email protected]69444cc2009-04-09 20:40:062420
2421 // Return false so the browser does not close. We'll close if the user
2422 // confirms in the dialog.
2423 return false;
2424}
2425
2426///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:572427// Browser, Assorted utility functions (private):
initial.commit09911bf2008-07-26 23:55:292428
[email protected]63d1f9b2014-07-05 19:09:032429void Browser::SetAsDelegate(WebContents* web_contents, bool set_delegate) {
2430 Browser* delegate = set_delegate ? this : NULL;
[email protected]27e5b3912012-12-16 00:45:372431 // WebContents...
2432 web_contents->SetDelegate(delegate);
2433
2434 // ...and all the helpers.
[email protected]27e5b3912012-12-16 00:45:372435 BookmarkTabHelper::FromWebContents(web_contents)->set_delegate(delegate);
[email protected]d2b16572013-01-03 00:41:582436 WebContentsModalDialogManager::FromWebContents(web_contents)->
[email protected]5c2c7792013-08-20 18:39:162437 SetDelegate(delegate);
[email protected]27e5b3912012-12-16 00:45:372438 CoreTabHelper::FromWebContents(web_contents)->set_delegate(delegate);
2439 SearchEngineTabHelper::FromWebContents(web_contents)->set_delegate(delegate);
[email protected]82808d02014-04-10 00:10:592440 SearchTabHelper::FromWebContents(web_contents)->set_delegate(delegate);
droger38f0d102014-09-16 15:37:412441 translate::ContentTranslateDriver& content_translate_driver =
2442 ChromeTranslateClient::FromWebContents(web_contents)->translate_driver();
2443 if (delegate) {
wjmaclean7f63c6b2014-12-09 14:59:552444 ui_zoom::ZoomController::FromWebContents(web_contents)->AddObserver(this);
pkastingcc29d20e2015-02-25 06:05:532445 content_translate_driver.AddObserver(this);
droger38f0d102014-09-16 15:37:412446 } else {
pkastingcc29d20e2015-02-25 06:05:532447 ui_zoom::ZoomController::FromWebContents(web_contents)->RemoveObserver(
2448 this);
2449 content_translate_driver.RemoveObserver(this);
droger38f0d102014-09-16 15:37:412450 }
[email protected]27e5b3912012-12-16 00:45:372451}
2452
[email protected]36b6dcb2008-11-12 01:19:572453void Browser::CloseFrame() {
2454 window_->Close();
initial.commit09911bf2008-07-26 23:55:292455}
2456
[email protected]e89cfcb2012-11-11 14:47:242457void Browser::TabDetachedAtImpl(content::WebContents* contents,
2458 int index,
[email protected]c37e3b62010-01-22 00:15:172459 DetachType type) {
2460 if (type == DETACH_TYPE_DETACH) {
[email protected]56580852010-11-17 16:09:152461 // Save the current location bar state, but only if the tab being detached
2462 // is the selected tab. Because saving state can conditionally revert the
2463 // location bar, saving the current tab's location bar state to a
2464 // non-selected tab can corrupt both tabs.
[email protected]0d56fa7212012-11-15 23:34:022465 if (contents == tab_strip_model_->GetActiveWebContents()) {
[email protected]9800de5e2011-03-11 18:19:492466 LocationBar* location_bar = window()->GetLocationBar();
2467 if (location_bar)
[email protected]e89cfcb2012-11-11 14:47:242468 location_bar->SaveStateToContents(contents);
[email protected]9800de5e2011-03-11 18:19:492469 }
[email protected]c37e3b62010-01-22 00:15:172470
[email protected]2fc15ae2012-05-06 00:01:372471 if (!tab_strip_model_->closing_all())
[email protected]c37e3b62010-01-22 00:15:172472 SyncHistoryWithTabs(0);
2473 }
2474
[email protected]63d1f9b2014-07-05 19:09:032475 SetAsDelegate(contents, false);
[email protected]e89cfcb2012-11-11 14:47:242476 RemoveScheduledUpdatesFor(contents);
[email protected]c37e3b62010-01-22 00:15:172477
[email protected]04e3ead52013-01-14 01:09:202478 if (find_bar_controller_.get() && index == tab_strip_model_->active_index()) {
[email protected]ba3d09a12012-11-07 12:13:522479 find_bar_controller_->ChangeWebContents(NULL);
[email protected]ecc523f62010-09-28 22:45:402480 }
[email protected]c37e3b62010-01-22 00:15:172481
[email protected]e3a5d5b2012-06-22 17:56:462482 // Stop observing search model changes for this tab.
[email protected]e89cfcb2012-11-11 14:47:242483 search_delegate_->OnTabDetached(contents);
[email protected]e3a5d5b2012-06-22 17:56:462484
[email protected]20ca0382013-02-28 19:50:072485 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
2486 if (interstitial_observers_[i]->web_contents() != contents)
2487 continue;
2488
2489 delete interstitial_observers_[i];
2490 interstitial_observers_.erase(interstitial_observers_.begin() + i);
2491 return;
2492 }
[email protected]c37e3b62010-01-22 00:15:172493}
2494
benwellsa2a8a9f72015-04-07 07:09:542495bool Browser::SupportsLocationBar() const {
[email protected]d2202e22014-04-14 20:20:532496 // Tabbed browser always show a location bar.
2497 if (is_type_tabbed())
[email protected]8a585cb2014-03-21 17:13:522498 return true;
[email protected]d2202e22014-04-14 20:20:532499
benwells919e79b2015-03-19 04:58:192500 // Non-app windows that aren't tabbed or system windows should always show a
2501 // location bar, unless they are from a trusted source.
2502 if (!is_app())
2503 return !is_trusted_source();
2504
benwells11bd6ed2015-06-05 04:20:412505 if (hosted_app_controller_)
2506 return hosted_app_controller_->SupportsLocationBar();
benwells919e79b2015-03-19 04:58:192507
benwellsa2a8a9f72015-04-07 07:09:542508 return false;
[email protected]8a585cb2014-03-21 17:13:522509}
2510
benwells502df692014-12-02 20:41:452511bool Browser::ShouldUseWebAppFrame() const {
benwells919e79b2015-03-19 04:58:192512 // Only use the web app frame for apps in ash, and only if the web app frame
2513 // is enabled.
benwellsa2a8a9f72015-04-07 07:09:542514 if (!is_app())
benwells502df692014-12-02 20:41:452515 return false;
benwells502df692014-12-02 20:41:452516
benwells11bd6ed2015-06-05 04:20:412517 if (hosted_app_controller_)
2518 return hosted_app_controller_->should_use_web_app_frame();
benwellsa2a8a9f72015-04-07 07:09:542519
2520 return false;
benwells502df692014-12-02 20:41:452521}
2522
[email protected]92655362012-04-20 21:33:172523bool Browser::SupportsWindowFeatureImpl(WindowFeature feature,
2524 bool check_fullscreen) const {
[email protected]c3e32942012-12-11 10:26:202525 bool hide_ui_for_fullscreen = check_fullscreen && ShouldHideUIForFullscreen();
[email protected]92655362012-04-20 21:33:172526
2527 unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF;
2528
2529 if (is_type_tabbed())
2530 features |= FEATURE_BOOKMARKBAR;
2531
2532 if (!hide_ui_for_fullscreen) {
2533 if (!is_type_tabbed())
2534 features |= FEATURE_TITLEBAR;
2535
2536 if (is_type_tabbed())
2537 features |= FEATURE_TABSTRIP;
2538
2539 if (is_type_tabbed())
2540 features |= FEATURE_TOOLBAR;
2541
benwellsa2a8a9f72015-04-07 07:09:542542 if (SupportsLocationBar())
[email protected]92655362012-04-20 21:33:172543 features |= FEATURE_LOCATIONBAR;
benwells502df692014-12-02 20:41:452544
2545 if (ShouldUseWebAppFrame())
2546 features |= FEATURE_WEBAPPFRAME;
[email protected]92655362012-04-20 21:33:172547 }
2548 return !!(features & feature);
2549}
2550
[email protected]09b29342011-06-24 19:18:482551void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) {
robliaoe879c2bb2015-03-21 00:46:372552 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 is
2553 // fixed.
2554 tracked_objects::ScopedTracker tracking_profile1(
2555 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2556 "467185 Browser::UpdateBookmarkBarState1"));
[email protected]09b29342011-06-24 19:18:482557 BookmarkBar::State state;
[email protected]a7666d82014-04-04 21:34:032558 // The bookmark bar is always hidden for Guest Sessions and in fullscreen
2559 // mode, unless on the new tab page.
2560 if (profile_->IsGuestSession()) {
2561 state = BookmarkBar::HIDDEN;
2562 } else if (browser_defaults::bookmarks_enabled &&
tfarina3bddbe112014-08-28 05:29:322563 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) &&
[email protected]c3e32942012-12-11 10:26:202564 !ShouldHideUIForFullscreen()) {
[email protected]04143362012-11-28 14:25:182565 state = BookmarkBar::SHOW;
[email protected]09b29342011-06-24 19:18:482566 } else {
robliaoe879c2bb2015-03-21 00:46:372567 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185
2568 // is fixed.
2569 tracked_objects::ScopedTracker tracking_profile2(
2570 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2571 "467185 Browser::UpdateBookmarkBarState2"));
[email protected]0d56fa7212012-11-15 23:34:022572 WebContents* web_contents = tab_strip_model_->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:572573 BookmarkTabHelper* bookmark_tab_helper =
2574 web_contents ? BookmarkTabHelper::FromWebContents(web_contents) : NULL;
2575 if (bookmark_tab_helper && bookmark_tab_helper->ShouldShowBookmarkBar())
[email protected]09b29342011-06-24 19:18:482576 state = BookmarkBar::DETACHED;
2577 else
2578 state = BookmarkBar::HIDDEN;
2579 }
[email protected]2d4e43a02012-06-26 00:11:552580
[email protected]09b29342011-06-24 19:18:482581 if (state == bookmark_bar_state_)
2582 return;
2583
2584 bookmark_bar_state_ = state;
2585
2586 if (!window_)
2587 return; // This is called from the constructor when window_ is NULL.
2588
2589 if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) {
2590 // Don't notify BrowserWindow on a tab switch as at the time this is invoked
2591 // BrowserWindow hasn't yet switched tabs. The BrowserWindow implementations
2592 // end up querying state once they process the tab switch.
2593 return;
2594 }
2595
robliaoe879c2bb2015-03-21 00:46:372596 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 is
2597 // fixed.
2598 tracked_objects::ScopedTracker tracking_profile3(
2599 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2600 "467185 Browser::UpdateBookmarkBarState3"));
2601
tfarina41f42082014-12-26 14:08:122602 bool should_animate = reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE;
2603 window_->BookmarkBarStateChanged(should_animate ?
[email protected]09b29342011-06-24 19:18:482604 BookmarkBar::ANIMATE_STATE_CHANGE :
[email protected]e2395da2013-01-23 22:05:352605 BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
[email protected]09b29342011-06-24 19:18:482606}
[email protected]2e2cacc2011-07-12 21:54:262607
[email protected]c3e32942012-12-11 10:26:202608bool Browser::ShouldHideUIForFullscreen() const {
[email protected]6a414ff2013-02-27 08:22:542609 // Windows and GTK remove the top controls in fullscreen, but Mac and Ash
2610 // keep the controls in a slide-down panel.
2611 return window_ && window_->ShouldHideUIForFullscreen();
[email protected]c3e32942012-12-11 10:26:202612}
2613
thestig028978692015-10-08 07:39:402614bool Browser::ShouldStartShutdown() const {
2615 if (BrowserList::GetInstance(host_desktop_type())->size() > 1)
2616 return false;
2617#if defined(OS_WIN)
2618 // On Windows 8 the desktop and ASH environments could be active
2619 // at the same time.
2620 // We should not start the shutdown process in the following cases:-
2621 // 1. If the desktop type of the browser going away is ASH and there
2622 // are browser windows open in the desktop.
2623 // 2. If the desktop type of the browser going away is desktop and the ASH
2624 // environment is still active.
2625 if (host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE)
2626 return !ash::Shell::HasInstance();
2627 if (host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH)
2628 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty();
2629#endif
2630 return true;
2631}
2632
[email protected]dd6730412013-08-14 15:03:372633bool Browser::MaybeCreateBackgroundContents(
dcheng3ce04b62015-10-26 23:30:552634 int32_t route_id,
2635 int32_t main_frame_route_id,
2636 int32_t main_frame_widget_route_id,
[email protected]dd6730412013-08-14 15:03:372637 WebContents* opener_web_contents,
nasko48321ca32015-07-02 20:44:122638 const std::string& frame_name,
[email protected]dd6730412013-08-14 15:03:372639 const GURL& target_url,
2640 const std::string& partition_id,
2641 content::SessionStorageNamespace* session_storage_namespace) {
[email protected]92655362012-04-20 21:33:172642 GURL opener_url = opener_web_contents->GetURL();
[email protected]06bdd2b2012-11-30 18:47:132643 ExtensionService* extensions_service =
2644 extensions::ExtensionSystem::Get(profile_)->extension_service();
[email protected]92655362012-04-20 21:33:172645
2646 if (!opener_url.is_valid() ||
2647 frame_name.empty() ||
2648 !extensions_service ||
2649 !extensions_service->is_ready())
2650 return false;
2651
2652 // Only hosted apps have web extents, so this ensures that only hosted apps
2653 // can create BackgroundContents. We don't have to check for background
2654 // permission as that is checked in RenderMessageFilter when the CreateWindow
2655 // message is processed.
reillyga3acbc12014-11-11 23:17:122656 const Extension* extension = extensions::ExtensionRegistry::Get(profile_)
2657 ->enabled_extensions()
2658 .GetHostedAppByURL(opener_url);
[email protected]92655362012-04-20 21:33:172659 if (!extension)
2660 return false;
2661
2662 // No BackgroundContents allowed if BackgroundContentsService doesn't exist.
2663 BackgroundContentsService* service =
2664 BackgroundContentsServiceFactory::GetForProfile(profile_);
2665 if (!service)
2666 return false;
2667
2668 // Ensure that we're trying to open this from the extension's process.
2669 SiteInstance* opener_site_instance = opener_web_contents->GetSiteInstance();
[email protected]fafdc842014-01-17 18:09:082670 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile_);
[email protected]92655362012-04-20 21:33:172671 if (!opener_site_instance->GetProcess() ||
2672 !process_map->Contains(
2673 extension->id(), opener_site_instance->GetProcess()->GetID())) {
2674 return false;
2675 }
2676
2677 // Only allow a single background contents per app.
[email protected]9367eabc2013-03-01 01:29:292678 bool allow_js_access = extensions::BackgroundInfo::AllowJSAccess(extension);
[email protected]92655362012-04-20 21:33:172679 BackgroundContents* existing =
[email protected]1f136902013-12-24 23:26:452680 service->GetAppBackgroundContents(base::ASCIIToUTF16(extension->id()));
[email protected]92655362012-04-20 21:33:172681 if (existing) {
2682 // For non-scriptable background contents, ignore the request altogether,
2683 // (returning true, so that a regular WebContents isn't created either).
2684 if (!allow_js_access)
2685 return true;
2686 // For scriptable background pages, if one already exists, close it (even
2687 // if it was specified in the manifest).
[email protected]92655362012-04-20 21:33:172688 delete existing;
2689 }
2690
2691 // If script access is not allowed, create the the background contents in a
2692 // new SiteInstance, so that a separate process is used.
2693 scoped_refptr<content::SiteInstance> site_instance =
2694 allow_js_access ?
2695 opener_site_instance :
2696 content::SiteInstance::Create(opener_web_contents->GetBrowserContext());
2697
2698 // Passed all the checks, so this should be created as a BackgroundContents.
dcheng3ce04b62015-10-26 23:30:552699 BackgroundContents* contents = service->CreateBackgroundContents(
2700 site_instance.get(), route_id, main_frame_route_id,
2701 main_frame_widget_route_id, profile_, frame_name,
2702 base::ASCIIToUTF16(extension->id()), partition_id,
2703 session_storage_namespace);
[email protected]92655362012-04-20 21:33:172704
2705 // When a separate process is used, the original renderer cannot access the
2706 // new window later, thus we need to navigate the window now.
2707 if (contents && !allow_js_access) {
2708 contents->web_contents()->GetController().LoadURL(
2709 target_url,
2710 content::Referrer(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:352711 ui::PAGE_TRANSITION_LINK,
[email protected]92655362012-04-20 21:33:172712 std::string()); // No extra headers.
2713 }
2714
2715 return contents != NULL;
[email protected]afcb43562011-09-02 23:33:382716}