blob: dadf61f62da1f5a925de897357a15d112b295495 [file] [log] [blame]
[email protected]daa9e382012-01-06 00:30:341// Copyright (c) 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]aca02cf2010-05-03 18:56:0110#endif // OS_WIN
11
[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"
[email protected]8a53ee042009-01-21 16:41:3318#include "base/logging.h"
[email protected]49098f702011-10-13 03:47:1819#include "base/metrics/field_trial.h"
[email protected]835d7c82010-10-14 04:38:3820#include "base/metrics/histogram.h"
[email protected]b02d0382009-11-30 21:19:5021#include "base/path_service.h"
[email protected]b5febf72012-07-29 18:10:0922#include "base/process_info.h"
[email protected]0af8f132011-07-16 01:37:0223#include "base/string_number_conversions.h"
[email protected]b6a4ac2b2011-10-17 20:05:4824#include "base/string_util.h"
[email protected]5a17d492011-10-24 19:37:0325#include "base/stringprintf.h"
[email protected]34b99632011-01-01 01:01:0626#include "base/threading/thread.h"
27#include "base/threading/thread_restrictions.h"
[email protected]7f070d42011-03-09 20:25:3228#include "base/time.h"
[email protected]6524385ef2010-08-18 06:34:1329#include "base/utf_string_conversions.h"
[email protected]1a3aba82010-11-08 23:52:5430#include "chrome/app/chrome_command_ids.h"
[email protected]77a91c72012-08-13 16:19:3431#include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h"
[email protected]ea9edcb02011-09-23 22:05:0432#include "chrome/browser/autofill/personal_data_manager_factory.h"
[email protected]a07676b22011-06-17 16:36:5333#include "chrome/browser/background/background_contents_service.h"
[email protected]4fdf6742012-01-10 20:14:3634#include "chrome/browser/background/background_contents_service_factory.h"
[email protected]a9afddb2009-02-12 17:49:4235#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]b3ac5c82009-10-08 20:56:5436#include "chrome/browser/bookmarks/bookmark_utils.h"
[email protected]5c238752009-06-13 10:29:0737#include "chrome/browser/browser_process.h"
[email protected]c61db1d2009-02-06 03:39:1838#include "chrome/browser/browser_shutdown.h"
[email protected]40d59ce52009-03-06 23:20:1439#include "chrome/browser/character_encoding.h"
[email protected]0f083402011-11-22 02:59:0140#include "chrome/browser/chrome_page_zoom.h"
[email protected]55c87fa2011-10-15 07:28:2841#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]7ae9c322012-07-17 23:46:4442#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]7d189022011-08-25 22:54:2043#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
44#include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h"
[email protected]dce502762011-07-20 08:53:4945#include "chrome/browser/debugger/devtools_toggle_action.h"
46#include "chrome/browser/debugger/devtools_window.h"
[email protected]7fb4bbb2012-05-27 18:06:2247#include "chrome/browser/download/download_crx_util.h"
[email protected]59560e0b2009-06-04 03:30:2248#include "chrome/browser/download/download_item_model.h"
[email protected]9bb54ee2011-10-12 17:43:3549#include "chrome/browser/download/download_service.h"
50#include "chrome/browser/download/download_service_factory.h"
[email protected]a1bc3b82012-04-19 19:32:2051#include "chrome/browser/download/download_shelf.h"
[email protected]59560e0b2009-06-04 03:30:2252#include "chrome/browser/download/download_started_animation.h"
[email protected]a53209b2012-01-20 16:48:1653#include "chrome/browser/download/download_util.h"
[email protected]9c1662b2012-03-06 15:44:3354#include "chrome/browser/extensions/browser_extension_window_controller.h"
[email protected]49098f702011-10-13 03:47:1855#include "chrome/browser/extensions/default_apps_trial.h"
[email protected]10abd192010-09-30 02:03:4956#include "chrome/browser/extensions/extension_prefs.h"
[email protected]eaa7dd182010-12-14 11:09:0057#include "chrome/browser/extensions/extension_service.h"
[email protected]a6394ae2012-07-16 20:58:4358#include "chrome/browser/extensions/tab_helper.h"
[email protected]b375c5d2011-05-03 21:15:0459#include "chrome/browser/favicon/favicon_tab_helper.h"
[email protected]3a29a6e2011-08-24 18:26:2160#include "chrome/browser/file_select_helper.h"
[email protected]820735792010-07-29 23:40:0161#include "chrome/browser/first_run/first_run.h"
[email protected]f7578f52010-08-30 22:22:4962#include "chrome/browser/google/google_url_tracker.h"
[email protected]7e204122011-09-01 18:56:2163#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]65c81142012-07-31 19:44:4364#include "chrome/browser/intents/device_attached_intent_source.h"
[email protected]7d189022011-08-25 22:54:2065#include "chrome/browser/intents/register_intent_handler_infobar_delegate.h"
[email protected]59d73ec2012-09-01 02:24:2766#include "chrome/browser/intents/web_intents_reporting.h"
[email protected]8f0bbd62012-02-22 03:37:1867#include "chrome/browser/intents/web_intents_util.h"
[email protected]2e6389f2012-05-18 19:41:2568#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]4afde5c2012-06-25 17:00:5369#include "chrome/browser/media/media_stream_devices_controller.h"
[email protected]a239c3f2009-02-17 22:13:1970#include "chrome/browser/net/url_fixer_upper.h"
[email protected]2c4fb7b2011-04-02 06:33:2971#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]14a000d2010-04-29 21:44:2472#include "chrome/browser/platform_util.h"
[email protected]4e94ab32011-08-05 05:28:2773#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]37858e52010-08-26 00:22:0274#include "chrome/browser/prefs/pref_service.h"
[email protected]02337592010-09-27 18:38:2575#include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h"
[email protected]0996e9b2011-08-26 17:59:0176#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]8ecad5e2010-12-02 21:18:3377#include "chrome/browser/profiles/profile.h"
[email protected]5e919242012-02-13 23:59:3578#include "chrome/browser/profiles/profile_destroyer.h"
[email protected]5a17d492011-10-24 19:37:0379#include "chrome/browser/profiles/profile_manager.h"
[email protected]a7be6982011-12-12 21:53:5780#include "chrome/browser/profiles/profile_metrics.h"
[email protected]67baffc82011-12-19 18:03:0781#include "chrome/browser/repost_form_warning_controller.h"
[email protected]85e921fb82009-02-11 23:19:4482#include "chrome/browser/sessions/session_service.h"
[email protected]92371eb2011-04-28 11:50:1583#include "chrome/browser/sessions/session_service_factory.h"
[email protected]bde40b822012-08-30 17:28:5684#include "chrome/browser/sessions/session_tab_helper.h"
[email protected]c61db1d2009-02-06 03:39:1885#include "chrome/browser/sessions/session_types.h"
[email protected]92926d92010-09-02 18:35:0686#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]92371eb2011-04-28 11:50:1587#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]066629f2009-10-17 00:28:1388#include "chrome/browser/sync/profile_sync_service.h"
[email protected]5e61afb92012-01-27 20:09:1389#include "chrome/browser/sync/profile_sync_service_factory.h"
[email protected]40f047972009-11-25 03:54:4090#include "chrome/browser/sync/sync_ui_util.h"
[email protected]2c4fb7b2011-04-02 06:33:2991#include "chrome/browser/tab_contents/background_contents.h"
[email protected]4fdf6742012-01-10 20:14:3692#include "chrome/browser/tab_contents/retargeting_details.h"
[email protected]1ab4ddf2011-07-21 04:48:0493#include "chrome/browser/tab_contents/tab_util.h"
[email protected]ffa6f592011-06-24 22:03:5794#include "chrome/browser/themes/theme_service.h"
95#include "chrome/browser/themes/theme_service_factory.h"
[email protected]82194b5fb2012-05-22 23:53:0796#include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h"
[email protected]35699d572011-05-11 19:46:1497#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
[email protected]5d98294912012-06-27 22:57:4098#include "chrome/browser/ui/browser_command_controller.h"
[email protected]a37d4b02012-06-25 21:56:1099#include "chrome/browser/ui/browser_commands.h"
[email protected]ef557022012-03-16 10:05:33100#include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
[email protected]55452902011-06-01 21:57:47101#include "chrome/browser/ui/browser_dialogs.h"
[email protected]d8748142012-05-16 21:13:43102#include "chrome/browser/ui/browser_finder.h"
[email protected]7acfaf92012-07-11 15:51:59103#include "chrome/browser/ui/browser_instant_controller.h"
[email protected]6768ac02011-04-06 17:41:04104#include "chrome/browser/ui/browser_list.h"
[email protected]fcca741b2011-06-17 22:46:37105#include "chrome/browser/ui/browser_navigator.h"
[email protected]fb7da4132011-03-15 15:51:00106#include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
[email protected]855370052012-07-10 19:30:32107#include "chrome/browser/ui/browser_tab_strip_model_delegate.h"
[email protected]52877dbc62012-06-29 22:22:03108#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]ef557022012-03-16 10:05:33109#include "chrome/browser/ui/browser_toolbar_model_delegate.h"
[email protected]2cd4fde2012-06-26 03:10:26110#include "chrome/browser/ui/browser_ui_prefs.h"
[email protected]00070c732011-04-09 15:31:33111#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:12112#include "chrome/browser/ui/chrome_pages.h"
[email protected]6e1fcd12012-07-02 17:14:20113#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]a44657202012-01-09 05:48:31114#include "chrome/browser/ui/extensions/shell_window.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]9d5c059a82012-06-29 20:13:07118#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
[email protected]1ba55cf2012-06-29 19:11:39119#include "chrome/browser/ui/global_error/global_error.h"
120#include "chrome/browser/ui/global_error/global_error_service.h"
121#include "chrome/browser/ui/global_error/global_error_service_factory.h"
[email protected]8be45842012-04-13 19:49:29122#include "chrome/browser/ui/hung_plugin_tab_helper.h"
[email protected]943b8612011-08-31 21:07:13123#include "chrome/browser/ui/intents/web_intent_picker_controller.h"
[email protected]f13b4202012-06-12 23:53:23124#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]6a3ec2312010-12-02 19:30:19125#include "chrome/browser/ui/omnibox/location_bar.h"
[email protected]fe90ca8e2011-04-08 20:40:43126#include "chrome/browser/ui/panels/panel.h"
127#include "chrome/browser/ui/panels/panel_manager.h"
[email protected]e3a5d5b2012-06-22 17:56:46128#include "chrome/browser/ui/search/search.h"
129#include "chrome/browser/ui/search/search_delegate.h"
130#include "chrome/browser/ui/search/search_model.h"
[email protected]5d9cace72012-06-21 16:07:12131#include "chrome/browser/ui/singleton_tabs.h"
[email protected]6a3ec2312010-12-02 19:30:19132#include "chrome/browser/ui/status_bubble.h"
[email protected]3da95a102011-11-30 21:47:45133#include "chrome/browser/ui/sync/browser_synced_window_delegate.h"
[email protected]51d83bdf2011-12-09 16:09:29134#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
[email protected]3d61dd02012-06-07 00:05:53135#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]9a800652010-12-02 17:08:44136#include "chrome/browser/ui/tabs/dock_info.h"
[email protected]6a3ec2312010-12-02 19:30:19137#include "chrome/browser/ui/tabs/tab_menu_model.h"
[email protected]b56e2e32012-05-11 21:18:04138#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]f9b6c092012-07-09 19:32:28139#include "chrome/browser/ui/unload_controller.h"
[email protected]f847e6082011-03-24 00:08:26140#include "chrome/browser/ui/web_applications/web_app_ui.h"
[email protected]65549182012-02-25 00:45:40141#include "chrome/browser/ui/webui/signin/login_ui_service.h"
142#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
[email protected]03639422012-06-28 19:03:37143#include "chrome/browser/ui/window_sizer/window_sizer.h"
[email protected]b1b73942010-05-26 20:11:54144#include "chrome/browser/upgrade_detector.h"
[email protected]86b54012009-11-19 09:18:50145#include "chrome/browser/web_applications/web_app.h"
[email protected]d938aed92009-01-22 19:49:33146#include "chrome/common/chrome_constants.h"
[email protected]432115822011-07-10 15:52:27147#include "chrome/common/chrome_notification_types.h"
[email protected]d938aed92009-01-22 19:49:33148#include "chrome/common/chrome_switches.h"
[email protected]7d189022011-08-25 22:54:20149#include "chrome/common/custom_handlers/protocol_handler.h"
[email protected]5b1a0e22009-05-26 19:00:58150#include "chrome/common/extensions/extension.h"
[email protected]46fd1ea42011-02-16 15:59:33151#include "chrome/common/extensions/extension_constants.h"
[email protected]8a53ee042009-01-21 16:41:33152#include "chrome/common/pref_names.h"
[email protected]7664ab32011-02-01 23:35:25153#include "chrome/common/profiling.h"
[email protected]b5febf72012-07-29 18:10:09154#include "chrome/common/startup_metric_utils.h"
[email protected]b689fce72009-03-17 22:45:34155#include "chrome/common/url_constants.h"
[email protected]bb461532010-11-26 21:50:23156#include "chrome/common/web_apps.h"
[email protected]da8543762012-03-20 08:52:20157#include "content/public/browser/color_chooser.h"
[email protected]0e12d7d2011-12-01 16:21:44158#include "content/public/browser/devtools_manager.h"
[email protected]e582fdd2011-12-20 16:48:17159#include "content/public/browser/download_item.h"
160#include "content/public/browser/download_manager.h"
[email protected]cadaec52012-02-08 21:53:13161#include "content/public/browser/interstitial_page.h"
[email protected]d9083482012-01-06 00:38:46162#include "content/public/browser/invalidate_type.h"
[email protected]cdcb1dee2012-01-04 00:46:20163#include "content/public/browser/navigation_controller.h"
[email protected]022af742011-12-28 18:37:25164#include "content/public/browser/navigation_entry.h"
[email protected]7f6f44c2011-12-14 13:23:38165#include "content/public/browser/notification_details.h"
166#include "content/public/browser/notification_service.h"
[email protected]3a5180ae2011-12-21 02:39:38167#include "content/public/browser/plugin_service.h"
[email protected]9c1662b2012-03-06 15:44:33168#include "content/public/browser/render_process_host.h"
169#include "content/public/browser/render_view_host.h"
[email protected]b6583592012-01-25 19:52:33170#include "content/public/browser/site_instance.h"
[email protected]7f6f44c2011-12-14 13:23:38171#include "content/public/browser/user_metrics.h"
[email protected]d9083482012-01-06 00:38:46172#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10173#include "content/public/browser/web_contents_view.h"
[email protected]0d9989d2011-12-21 20:26:00174#include "content/public/browser/web_intents_dispatcher.h"
[email protected]4573fbd2011-10-31 20:25:18175#include "content/public/common/content_restriction.h"
[email protected]c08950d22011-10-13 22:20:29176#include "content/public/common/content_switches.h"
[email protected]0f083402011-11-22 02:59:01177#include "content/public/common/page_zoom.h"
[email protected]cadaec52012-02-08 21:53:13178#include "content/public/common/renderer_preferences.h"
[email protected]a3e18c42009-03-04 23:36:05179#include "grit/chromium_strings.h"
180#include "grit/generated_resources.h"
181#include "grit/locale_settings.h"
[email protected]2a281332012-07-11 22:20:23182#include "grit/theme_resources.h"
[email protected]8a53ee042009-01-21 16:41:33183#include "net/base/net_util.h"
[email protected]be28b5f42012-07-20 11:31:25184#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]4d7c4ef2012-03-16 01:47:12185#include "net/cookies/cookie_monster.h"
[email protected]8a53ee042009-01-21 16:41:33186#include "net/url_request/url_request_context.h"
[email protected]f67678062011-01-07 17:33:39187#include "ui/base/animation/animation.h"
[email protected]53f04c82012-07-26 02:31:09188#include "ui/base/dialogs/selected_file_info.h"
[email protected]c051a1b2011-01-21 23:30:17189#include "ui/base/l10n/l10n_util.h"
[email protected]08397d52011-02-05 01:53:38190#include "ui/gfx/point.h"
[email protected]ce9751942011-09-21 01:57:24191#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:36192#include "webkit/glue/web_intent_service_data.h"
[email protected]4a19be92011-09-22 14:25:02193#include "webkit/glue/webkit_glue.h"
[email protected]d938aed92009-01-22 19:49:33194#include "webkit/glue/window_open_disposition.h"
[email protected]3a5180ae2011-12-21 02:39:38195#include "webkit/plugins/webplugininfo.h"
[email protected]8a53ee042009-01-21 16:41:33196
197#if defined(OS_WIN)
[email protected]77cbe50e2012-06-14 02:44:38198#include "base/win/metro.h"
[email protected]36d5e5592010-11-15 20:45:59199#include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h"
[email protected]12f520c2010-01-06 18:11:15200#include "chrome/browser/shell_integration.h"
[email protected]b17d41c2011-02-17 22:09:59201#include "chrome/browser/ssl/ssl_error_info.h"
[email protected]a5d1e1e2010-09-23 19:34:12202#include "chrome/browser/task_manager/task_manager.h"
[email protected]6a3ec2312010-12-02 19:30:19203#include "chrome/browser/ui/view_ids.h"
[email protected]dcd57762011-06-25 12:18:51204#include "ui/base/win/shell.h"
[email protected]8a53ee042009-01-21 16:41:33205#endif // OS_WIN
[email protected]e1acf6f2008-10-27 20:43:33206
[email protected]b7969202010-05-14 21:29:26207#if defined(OS_CHROMEOS)
[email protected]361c2012012-09-05 16:31:13208#include "chrome/browser/chromeos/gdata/drive_file_system_util.h"
[email protected]eab8c0f2011-11-18 22:33:50209#endif
210
[email protected]dc04be7c2012-03-15 23:57:49211#if defined(USE_ASH)
[email protected]bafda132012-02-16 19:32:51212#include "ash/ash_switches.h"
[email protected]c2f0a892012-01-24 22:19:21213#endif
214
[email protected]8a53ee042009-01-21 16:41:33215using base::TimeDelta;
[email protected]b87ee522012-05-18 15:16:54216using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50217using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23218using content::NavigationEntry;
[email protected]e5d549d2011-12-28 01:29:20219using content::OpenURLParams;
[email protected]3a5180ae2011-12-21 02:39:38220using content::PluginService;
[email protected]e5d549d2011-12-28 01:29:20221using content::Referrer;
[email protected]b6583592012-01-25 19:52:33222using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38223using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09224using content::WebContents;
[email protected]1c321ee2012-05-21 03:02:34225using extensions::Extension;
[email protected]20c07f8e2012-05-31 08:43:14226using ui::WebDialogDelegate;
initial.commit09911bf2008-07-26 23:55:29227
[email protected]36b6dcb2008-11-12 01:19:57228///////////////////////////////////////////////////////////////////////////////
initial.commit09911bf2008-07-26 23:55:29229
[email protected]505323e22009-01-24 02:47:58230namespace {
231
[email protected]91a79232010-11-10 18:15:08232// The URL to be loaded to display the "Report a broken page" form.
233const char kBrokenPageUrl[] =
[email protected]95fc6f92011-04-13 00:37:20234 "https://www.google.com/support/chrome/bin/request.py?contact_type="
[email protected]91a79232010-11-10 18:15:08235 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2";
236
237// The URL for the privacy dashboard.
238const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard";
239
240// How long we wait before updating the browser chrome while loading a page.
241const int kUIUpdateCoalescingTimeMS = 200;
242
[email protected]0da58292012-03-22 20:37:21243bool AllowPanels(const std::string& app_name) {
[email protected]cae97652012-04-20 03:12:12244 return PanelManager::ShouldUsePanels(
245 web_app::GetExtensionIdFromApplicationName(app_name));
[email protected]0da58292012-03-22 20:37:21246}
247
[email protected]a4fe67012012-07-25 20:14:29248BrowserWindow* CreateBrowserWindow(Browser* browser) {
249#if !defined(USE_ASH)
250 if (browser->is_type_panel())
251 return PanelManager::GetInstance()->CreatePanel(browser)->browser_window();
252#endif
253 return BrowserWindow::CreateBrowserWindow(browser);
254}
255
[email protected]56073dc2012-08-10 16:59:06256#if defined(OS_CHROMEOS)
257chrome::HostDesktopType kDefaultHostDesktopType = chrome::HOST_DESKTOP_TYPE_ASH;
258#else
259chrome::HostDesktopType kDefaultHostDesktopType =
260 chrome::HOST_DESKTOP_TYPE_NATIVE;
261#endif
262
263
[email protected]505323e22009-01-24 02:47:58264} // namespace
265
[email protected]b35b26b32011-05-05 20:35:14266////////////////////////////////////////////////////////////////////////////////
267// Browser, CreateParams:
268
[email protected]da22aa62012-04-04 18:54:35269Browser::CreateParams::CreateParams()
270 : type(TYPE_TABBED),
271 profile(NULL),
[email protected]56073dc2012-08-10 16:59:06272 host_desktop_type(kDefaultHostDesktopType),
[email protected]a4fe67012012-07-25 20:14:29273 app_type(APP_TYPE_HOST),
[email protected]da22aa62012-04-04 18:54:35274 initial_show_state(ui::SHOW_STATE_DEFAULT),
[email protected]a4fe67012012-07-25 20:14:29275 is_session_restore(false),
276 window(NULL) {
277}
278
279Browser::CreateParams::CreateParams(Profile* profile)
[email protected]56073dc2012-08-10 16:59:06280 : type(TYPE_TABBED),
281 profile(profile),
282 host_desktop_type(kDefaultHostDesktopType),
283 app_type(APP_TYPE_HOST),
284 initial_show_state(ui::SHOW_STATE_DEFAULT),
285 is_session_restore(false),
286 window(NULL) {
[email protected]da22aa62012-04-04 18:54:35287}
288
[email protected]b35b26b32011-05-05 20:35:14289Browser::CreateParams::CreateParams(Type type, Profile* profile)
290 : type(type),
[email protected]a636d8e52012-02-28 15:40:41291 profile(profile),
[email protected]56073dc2012-08-10 16:59:06292 host_desktop_type(kDefaultHostDesktopType),
293 app_type(APP_TYPE_HOST),
294 initial_show_state(ui::SHOW_STATE_DEFAULT),
295 is_session_restore(false),
296 window(NULL) {
297}
298
299Browser::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]0da58292012-03-22 20:37:21305 app_type(APP_TYPE_HOST),
[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(
313 Type type,
314 const std::string& app_name,
315 const gfx::Rect& window_bounds,
316 Profile* profile) {
317 DCHECK(type != TYPE_TABBED);
318 DCHECK(!app_name.empty());
319
320 if (type == TYPE_PANEL && !AllowPanels(app_name))
321 type = TYPE_POPUP;
322
323 CreateParams params(type, profile);
324 params.app_name = app_name;
325 params.app_type = APP_TYPE_CHILD;
326 params.initial_bounds = window_bounds;
327
328 return params;
329}
330
331// static
332Browser::CreateParams Browser::CreateParams::CreateForDevTools(
333 Profile* profile) {
334 CreateParams params(TYPE_POPUP, profile);
335 params.app_name = DevToolsWindow::kDevToolsApp;
336 return params;
337}
338
[email protected]36b6dcb2008-11-12 01:19:57339///////////////////////////////////////////////////////////////////////////////
340// Browser, Constructors, Creation, Showing:
initial.commit09911bf2008-07-26 23:55:29341
[email protected]a4fe67012012-07-25 20:14:29342Browser::Browser(const CreateParams& params)
343 : type_(params.type),
344 profile_(params.profile),
[email protected]f3e99e32008-07-30 04:48:39345 window_(NULL),
[email protected]ecc523f62010-09-28 22:45:40346 ALLOW_THIS_IN_INITIALIZER_LIST(
[email protected]855370052012-07-10 19:30:32347 tab_strip_model_delegate_(
348 new chrome::BrowserTabStripModelDelegate(this))),
349 ALLOW_THIS_IN_INITIALIZER_LIST(
350 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(),
[email protected]a4fe67012012-07-25 20:14:29351 params.profile))),
352 app_name_(params.app_name),
353 app_type_(params.app_type),
[email protected]15952e462008-11-14 00:29:05354 chrome_updater_factory_(this),
[email protected]69444cc2009-04-09 20:40:06355 cancel_download_confirmation_state_(NOT_PROMPTED),
[email protected]a4fe67012012-07-25 20:14:29356 override_bounds_(params.initial_bounds),
357 initial_show_state_(params.initial_show_state),
358 is_session_restore_(params.is_session_restore),
[email protected]56073dc2012-08-10 16:59:06359 host_desktop_type_(params.host_desktop_type),
[email protected]f9b6c092012-07-09 19:32:28360 ALLOW_THIS_IN_INITIALIZER_LIST(
361 unload_controller_(new chrome::UnloadController(this))),
[email protected]24f1477532011-11-22 22:55:36362 weak_factory_(this),
[email protected]fb7da4132011-03-15 15:51:00363 ALLOW_THIS_IN_INITIALIZER_LIST(
[email protected]ef557022012-03-16 10:05:33364 content_setting_bubble_model_delegate_(
365 new BrowserContentSettingBubbleModelDelegate(this))),
366 ALLOW_THIS_IN_INITIALIZER_LIST(
367 toolbar_model_delegate_(
368 new BrowserToolbarModelDelegate(this))),
369 ALLOW_THIS_IN_INITIALIZER_LIST(
[email protected]fb7da4132011-03-15 15:51:00370 tab_restore_service_delegate_(
[email protected]09b29342011-06-24 19:18:48371 new BrowserTabRestoreServiceDelegate(this))),
[email protected]afefa74e2011-07-26 05:04:23372 ALLOW_THIS_IN_INITIALIZER_LIST(
373 synced_window_delegate_(
374 new BrowserSyncedWindowDelegate(this))),
[email protected]8a5e0ca2011-08-25 06:30:47375 bookmark_bar_state_(BookmarkBar::HIDDEN),
[email protected]5d98294912012-06-27 22:57:40376 ALLOW_THIS_IN_INITIALIZER_LIST(
377 command_controller_(new chrome::BrowserCommandController(this))),
[email protected]2f516c792011-09-19 22:22:09378 window_has_shown_(false) {
[email protected]a4fe67012012-07-25 20:14:29379 if (!app_name_.empty())
380 chrome::RegisterAppPrefs(app_name_, profile_);
[email protected]2fc15ae2012-05-06 00:01:37381 tab_strip_model_->AddObserver(this);
382
[email protected]ef557022012-03-16 10:05:33383 toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get()));
[email protected]e3a5d5b2012-06-22 17:56:46384 search_model_.reset(new chrome::search::SearchModel(NULL));
385 search_delegate_.reset(
[email protected]51a53e8f62012-08-28 03:08:56386 new chrome::search::SearchDelegate(search_model_.get(),
387 toolbar_model_.get()));
[email protected]ef557022012-03-16 10:05:33388
[email protected]432115822011-07-10 15:52:27389 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED,
[email protected]ad50def52011-10-19 23:17:07390 content::NotificationService::AllSources());
[email protected]432115822011-07-10 15:52:27391 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
[email protected]a93089b12011-11-22 20:47:38392 content::Source<Profile>(profile_->GetOriginalProfile()));
[email protected]432115822011-07-10 15:52:27393 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]a93089b12011-11-22 20:47:38394 content::Source<Profile>(profile_->GetOriginalProfile()));
[email protected]432115822011-07-10 15:52:27395 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
[email protected]a93089b12011-11-22 20:47:38396 content::Source<Profile>(profile_->GetOriginalProfile()));
[email protected]432115822011-07-10 15:52:27397 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07398 content::NotificationService::AllSources());
[email protected]6b40bb582012-03-15 20:50:38399#if defined(ENABLE_THEMES)
[email protected]ffa6f592011-06-24 22:03:57400 registrar_.Add(
[email protected]432115822011-07-10 15:52:27401 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
[email protected]6c2381d2011-10-19 02:52:53402 content::Source<ThemeService>(
403 ThemeServiceFactory::GetForProfile(profile_)));
[email protected]6b40bb582012-03-15 20:50:38404#endif
[email protected]ea049a02011-12-25 21:37:09405 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
[email protected]ad50def52011-10-19 23:17:07406 content::NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29407
[email protected]97b46382011-05-02 13:23:04408 profile_pref_registrar_.Init(profile_->GetPrefs());
409 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this);
[email protected]3710d0002011-10-11 00:35:00410 profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this);
[email protected]6c6b02d2011-09-02 03:36:47411 profile_pref_registrar_.Add(prefs::kHomePage, this);
[email protected]9e823662010-10-13 23:36:00412
initial.commit09911bf2008-07-26 23:55:29413 BrowserList::AddBrowser(this);
414
[email protected]97b46382011-05-02 13:23:04415 // NOTE: These prefs all need to be explicitly destroyed in the destructor
416 // or you'll get a nasty surprise when you run the incognito tests.
initial.commit09911bf2008-07-26 23:55:29417 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector,
418 profile_->GetPrefs(), NULL);
[email protected]281918912010-05-27 22:05:13419
[email protected]7acfaf92012-07-11 15:51:59420 instant_controller_.reset(new chrome::BrowserInstantController(this));
[email protected]e545cb22012-08-27 23:31:23421
422#if 0
423 // Disabled for M22. See http://crbug.com/144326.
[email protected]65c81142012-07-31 19:44:43424 device_attached_intent_source_.reset(
425 new DeviceAttachedIntentSource(this, (this)));
[email protected]e545cb22012-08-27 23:31:23426#endif
[email protected]07d490bc2011-03-07 17:05:26427
[email protected]09b29342011-06-24 19:18:48428 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT);
[email protected]a7be6982011-12-12 21:53:57429
[email protected]a4fe67012012-07-25 20:14:29430 FilePath profile_path = profile_->GetPath();
[email protected]a7be6982011-12-12 21:53:57431 ProfileMetrics::LogProfileLaunch(profile_path);
[email protected]a4fe67012012-07-25 20:14:29432
433 window_ = params.window ? params.window : CreateBrowserWindow(this);
434
435 // TODO(beng): move to BrowserFrameWin.
436#if defined(OS_WIN) && !defined(USE_AURA)
437 // Set the app user model id for this application to that of the application
438 // name. See http://crbug.com/7028.
439 ui::win::SetAppIdForWindow(
440 is_app() && !is_type_panel() ?
441 ShellIntegration::GetAppModelIdForProfile(UTF8ToWide(app_name_),
442 profile_->GetPath()) :
443 ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()),
444 window()->GetNativeWindow());
445
446 if (is_type_panel()) {
447 ui::win::SetAppIconForWindow(ShellIntegration::GetChromiumIconPath(),
448 window()->GetNativeWindow());
449 }
450#endif
451
452 // Create the extension window controller before sending notifications.
453 extension_window_controller_.reset(
454 new BrowserExtensionWindowController(this));
455
456 // TODO(beng): Move BrowserList::AddBrowser() to the end of this function and
457 // replace uses of this with BL's notifications.
458 content::NotificationService::current()->Notify(
459 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
460 content::Source<Browser>(this),
461 content::NotificationService::NoDetails());
462
463 // TODO(beng): move to ChromeBrowserMain:
464 PrefService* local_state = g_browser_process->local_state();
465 if (local_state && local_state->FindPreference(
466 prefs::kAutofillPersonalDataManagerFirstRun) &&
467 local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) {
468 // Notify PDM that this is a first run.
469#if defined(OS_WIN)
470 ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_));
471#endif // defined(OS_WIN)
472 // Reset the preference so we don't call it again for subsequent windows.
473 local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun);
474 }
475
[email protected]6fb528e2012-08-01 20:32:33476 fullscreen_controller_.reset(new FullscreenController(this));
initial.commit09911bf2008-07-26 23:55:29477}
478
479Browser::~Browser() {
[email protected]2fc15ae2012-05-06 00:01:37480 // The tab strip should not have any tabs at this point.
481 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers())
482 DCHECK(tab_strip_model_->empty());
483 tab_strip_model_->RemoveObserver(this);
484
initial.commit09911bf2008-07-26 23:55:29485 BrowserList::RemoveBrowser(this);
486
[email protected]bdc6ccd12012-03-20 22:06:13487 SessionService* session_service =
488 SessionServiceFactory::GetForProfile(profile_);
489 if (session_service)
490 session_service->WindowClosed(session_id_);
491
492 TabRestoreService* tab_restore_service =
493 TabRestoreServiceFactory::GetForProfile(profile());
494 if (tab_restore_service)
495 tab_restore_service->BrowserClosed(tab_restore_service_delegate());
496
[email protected]7be64502011-05-03 17:51:47497#if !defined(OS_MACOSX)
[email protected]d8748142012-05-16 21:13:43498 if (!browser::GetBrowserCount(profile_)) {
initial.commit09911bf2008-07-26 23:55:29499 // We're the last browser window with this profile. We need to nuke the
500 // TabRestoreService, which will start the shutdown of the
501 // NavigationControllers and allow for proper shutdown. If we don't do this
502 // chrome won't shutdown cleanly, and may end up crashing when some
503 // thread tries to use the IO thread (or another thread) that is no longer
504 // valid.
[email protected]fbc947b2009-06-19 13:28:24505 // This isn't a valid assumption for Mac OS, as it stays running after
506 // the last browser has closed. The Mac equivalent is in its app
507 // controller.
[email protected]92371eb2011-04-28 11:50:15508 TabRestoreServiceFactory::ResetForProfile(profile_);
initial.commit09911bf2008-07-26 23:55:29509 }
[email protected]fbc947b2009-06-19 13:28:24510#endif
initial.commit09911bf2008-07-26 23:55:29511
[email protected]97b46382011-05-02 13:23:04512 profile_pref_registrar_.RemoveAll();
[email protected]97b46382011-05-02 13:23:04513
[email protected]9a8c4022011-01-25 14:25:33514 encoding_auto_detect_.Destroy();
[email protected]9a8c4022011-01-25 14:25:33515
[email protected]5d98294912012-06-27 22:57:40516 command_controller_.reset();
517
initial.commit09911bf2008-07-26 23:55:29518 if (profile_->IsOffTheRecord() &&
[email protected]474e5db2011-08-12 13:02:23519 !BrowserList::IsOffTheRecordSessionActiveForProfile(profile_)) {
[email protected]5e919242012-02-13 23:59:35520 // An incognito profile is no longer needed, this indirectly frees
521 // its cache and cookies once it gets destroyed at the appropriate time.
[email protected]4dffabe2012-05-19 14:37:06522 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_);
initial.commit09911bf2008-07-26 23:55:29523 }
524
525 // There may be pending file dialogs, we need to tell them that we've gone
526 // away so they don't try and call back to us.
527 if (select_file_dialog_.get())
528 select_file_dialog_->ListenerDestroyed();
529}
530
[email protected]36b6dcb2008-11-12 01:19:57531///////////////////////////////////////////////////////////////////////////////
[email protected]5c238752009-06-13 10:29:07532// Getters & Setters
533
[email protected]b77cb302009-10-29 04:09:17534FindBarController* Browser::GetFindBarController() {
535 if (!find_bar_controller_.get()) {
[email protected]632983f2011-08-08 22:51:24536 FindBar* find_bar = window_->CreateFindBar();
[email protected]b77cb302009-10-29 04:09:17537 find_bar_controller_.reset(new FindBarController(find_bar));
538 find_bar->SetFindBarController(find_bar_controller_.get());
[email protected]52877dbc62012-06-29 22:22:03539 find_bar_controller_->ChangeTabContents(chrome::GetActiveTabContents(this));
[email protected]b77cb302009-10-29 04:09:17540 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
541 }
542 return find_bar_controller_.get();
543}
544
[email protected]24db8a072009-10-29 20:35:37545bool Browser::HasFindBarController() const {
546 return find_bar_controller_.get() != NULL;
547}
548
[email protected]b35b26b32011-05-05 20:35:14549bool Browser::is_app() const {
550 return !app_name_.empty();
551}
552
553bool Browser::is_devtools() const {
554 return app_name_ == DevToolsWindow::kDevToolsApp;
555}
556
[email protected]5c238752009-06-13 10:29:07557///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:57558// Browser, State Storage and Retrieval for UI:
559
[email protected]9b125b732012-08-17 04:43:55560gfx::Image Browser::GetCurrentPageIcon() const {
[email protected]52877dbc62012-06-29 22:22:03561 TabContents* contents = chrome::GetActiveTabContents(this);
[email protected]ce5348a82008-12-18 18:36:23562 // |contents| can be NULL since GetCurrentPageIcon() is called by the window
563 // during the window's creation (before tabs have been added).
[email protected]61720892012-08-03 19:35:33564 return contents ?
[email protected]9b125b732012-08-17 04:43:55565 contents->favicon_tab_helper()->GetFavicon() : gfx::Image();
[email protected]36b6dcb2008-11-12 01:19:57566}
567
[email protected]731f8a42009-07-20 22:07:32568string16 Browser::GetWindowTitleForCurrentTab() const {
[email protected]52877dbc62012-06-29 22:22:03569 WebContents* contents = chrome::GetActiveWebContents(this);
[email protected]dda5dfa32009-07-10 00:33:29570 string16 title;
[email protected]c7c42332008-11-15 01:10:54571
[email protected]731f8a42009-07-20 22:07:32572 // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the
573 // window during the window's creation (before tabs have been added).
[email protected]36b6dcb2008-11-12 01:19:57574 if (contents) {
[email protected]dda5dfa32009-07-10 00:33:29575 title = contents->GetTitle();
[email protected]36b6dcb2008-11-12 01:19:57576 FormatTitleForDisplay(&title);
577 }
578 if (title.empty())
[email protected]51d83bdf2011-12-09 16:09:29579 title = CoreTabHelper::GetDefaultTitle();
[email protected]36b6dcb2008-11-12 01:19:57580
[email protected]cae97652012-04-20 03:12:12581#if defined(OS_MACOSX) || defined(USE_ASH)
582 // On Mac or Ash, we don't want to suffix the page title with
[email protected]22a3daa2009-11-09 22:03:33583 // the application name.
[email protected]d904bc82009-07-07 00:41:04584 return title;
[email protected]7be64502011-05-03 17:51:47585#else
[email protected]edb5e6a2009-04-08 23:46:17586 int string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT;
[email protected]dff529732010-04-01 23:50:55587 // Don't append the app name to window titles on app frames and app popups
[email protected]b35b26b32011-05-05 20:35:14588 if (is_app())
[email protected]edb5e6a2009-04-08 23:46:17589 string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT_NO_LOGO;
[email protected]dda5dfa32009-07-10 00:33:29590 return l10n_util::GetStringFUTF16(string_id, title);
[email protected]57e68dba2009-05-15 21:30:50591#endif
[email protected]36b6dcb2008-11-12 01:19:57592}
593
594// static
[email protected]dda5dfa32009-07-10 00:33:29595void Browser::FormatTitleForDisplay(string16* title) {
[email protected]36b6dcb2008-11-12 01:19:57596 size_t current_index = 0;
597 size_t match_index;
[email protected]57ecc4b2010-08-11 03:02:51598 while ((match_index = title->find(L'\n', current_index)) != string16::npos) {
[email protected]810a52ef2010-01-08 01:22:15599 title->replace(match_index, 1, string16());
[email protected]36b6dcb2008-11-12 01:19:57600 current_index = match_index;
601 }
602}
603
604///////////////////////////////////////////////////////////////////////////////
605// Browser, OnBeforeUnload handling:
606
607bool Browser::ShouldCloseWindow() {
[email protected]69444cc2009-04-09 20:40:06608 if (!CanCloseWithInProgressDownloads())
609 return false;
610
[email protected]f9b6c092012-07-09 19:32:28611 return unload_controller_->ShouldCloseWindow();
612}
[email protected]69444cc2009-04-09 20:40:06613
[email protected]f9b6c092012-07-09 19:32:28614bool Browser::IsAttemptingToCloseBrowser() const {
615 return unload_controller_->is_attempting_to_close_browser();
[email protected]36b6dcb2008-11-12 01:19:57616}
617
618void Browser::OnWindowClosing() {
619 if (!ShouldCloseWindow())
620 return;
621
[email protected]c984d9f2010-07-20 20:52:20622 // Application should shutdown on last window close if the user is explicitly
623 // trying to quit, or if there is nothing keeping the browser alive (such as
624 // AppController on the Mac, or BackgroundContentsService for background
625 // pages).
626 bool should_quit_if_last_browser =
[email protected]2e6389f2012-05-18 19:41:25627 browser_shutdown::IsTryingToQuit() || !browser::WillKeepAlive();
[email protected]7dc8c6b2010-04-09 17:02:50628
[email protected]1e0c7402012-07-27 10:48:15629 if (should_quit_if_last_browser && BrowserList::size() == 1)
[email protected]36b6dcb2008-11-12 01:19:57630 browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE);
631
[email protected]92371eb2011-04-28 11:50:15632 // Don't use GetForProfileIfExisting here, we want to force creation of the
[email protected]36b6dcb2008-11-12 01:19:57633 // session service so that user can restore what was open.
[email protected]92371eb2011-04-28 11:50:15634 SessionService* session_service =
635 SessionServiceFactory::GetForProfile(profile());
[email protected]36b6dcb2008-11-12 01:19:57636 if (session_service)
637 session_service->WindowClosing(session_id());
638
[email protected]92371eb2011-04-28 11:50:15639 TabRestoreService* tab_restore_service =
640 TabRestoreServiceFactory::GetForProfile(profile());
[email protected]a636d8e52012-02-28 15:40:41641
642#if defined(USE_AURA)
643 if (tab_restore_service && is_app())
644 tab_restore_service->BrowserClosing(tab_restore_service_delegate());
645#endif
646
[email protected]b35b26b32011-05-05 20:35:14647 if (tab_restore_service && is_type_tabbed() && tab_count())
[email protected]fb7da4132011-03-15 15:51:00648 tab_restore_service->BrowserClosing(tab_restore_service_delegate());
[email protected]d8375fd2008-11-25 22:45:39649
[email protected]911f8152010-03-18 16:46:40650 // TODO(sky): convert session/tab restore to use notification.
[email protected]ad50def52011-10-19 23:17:07651 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27652 chrome::NOTIFICATION_BROWSER_CLOSING,
[email protected]6c2381d2011-10-19 02:52:53653 content::Source<Browser>(this),
[email protected]1e0c7402012-07-27 10:48:15654 content::NotificationService::NoDetails());
[email protected]911f8152010-03-18 16:46:40655
[email protected]52877dbc62012-06-29 22:22:03656 chrome::CloseAllTabs(this);
[email protected]36b6dcb2008-11-12 01:19:57657}
658
[email protected]28788c7d2011-05-20 23:03:45659void Browser::OnWindowActivated() {
660 // On some platforms we want to automatically reload tabs that are
661 // killed when the user selects them.
[email protected]52877dbc62012-06-29 22:22:03662 WebContents* contents = chrome::GetActiveWebContents(this);
[email protected]be1f56ab2011-12-22 06:55:31663 if (contents && contents->GetCrashedStatus() ==
[email protected]28788c7d2011-05-20 23:03:45664 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) {
665 if (CommandLine::ForCurrentProcess()->HasSwitch(
666 switches::kReloadKilledTabs)) {
[email protected]a37d4b02012-06-25 21:56:10667 chrome::Reload(this, CURRENT_TAB);
[email protected]28788c7d2011-05-20 23:03:45668 }
669 }
670}
671
[email protected]69444cc2009-04-09 20:40:06672////////////////////////////////////////////////////////////////////////////////
673// In-progress download termination handling:
674
675void Browser::InProgressDownloadResponse(bool cancel_downloads) {
676 if (cancel_downloads) {
677 cancel_download_confirmation_state_ = RESPONSE_RECEIVED;
[email protected]a37d4b02012-06-25 21:56:10678 chrome::CloseWindow(this);
[email protected]69444cc2009-04-09 20:40:06679 return;
680 }
681
682 // Sets the confirmation state to NOT_PROMPTED so that if the user tries to
683 // close again we'll show the warning again.
684 cancel_download_confirmation_state_ = NOT_PROMPTED;
685
686 // Show the download page so the user can figure-out what downloads are still
687 // in-progress.
[email protected]5d9cace72012-06-21 16:07:12688 chrome::ShowDownloads(this);
[email protected]69444cc2009-04-09 20:40:06689}
690
[email protected]5a17d492011-10-24 19:37:03691Browser::DownloadClosePreventionType Browser::OkToCloseWithInProgressDownloads(
692 int* num_downloads_blocking) const {
693 DCHECK(num_downloads_blocking);
694 *num_downloads_blocking = 0;
695
[email protected]f9b6c092012-07-09 19:32:28696 if (IsAttemptingToCloseBrowser())
[email protected]5a17d492011-10-24 19:37:03697 return DOWNLOAD_CLOSE_OK;
698
699 // If we're not running a full browser process with a profile manager
700 // (testing), it's ok to close the browser.
701 if (!g_browser_process->profile_manager())
702 return DOWNLOAD_CLOSE_OK;
703
704 int total_download_count = DownloadService::DownloadCountAllProfiles();
705 if (total_download_count == 0)
706 return DOWNLOAD_CLOSE_OK; // No downloads; can definitely close.
707
708 // Figure out how many windows are open total, and associated with this
709 // profile, that are relevant for the ok-to-close decision.
710 int profile_window_count = 0;
711 int total_window_count = 0;
712 for (BrowserList::const_iterator iter = BrowserList::begin();
713 iter != BrowserList::end(); ++iter) {
714 // Don't count this browser window or any other in the process of closing.
715 Browser* const browser = *iter;
[email protected]f9b6c092012-07-09 19:32:28716 // Window closing may be delayed, and windows that are in the process of
717 // closing don't count against our totals.
718 if (browser == this || browser->IsAttemptingToCloseBrowser())
[email protected]5a17d492011-10-24 19:37:03719 continue;
720
721 if ((*iter)->profile() == profile())
722 profile_window_count++;
723 total_window_count++;
724 }
725
726 // If there aren't any other windows, we're at browser shutdown,
727 // which would cancel all current downloads.
728 if (total_window_count == 0) {
729 *num_downloads_blocking = total_download_count;
730 return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN;
731 }
732
733 // If there aren't any other windows on our profile, and we're an incognito
734 // profile, and there are downloads associated with that profile,
735 // those downloads would be cancelled by our window (-> profile) close.
736 DownloadService* download_service =
737 DownloadServiceFactory::GetForProfile(profile());
738 if (profile_window_count == 0 && download_service->DownloadCount() > 0 &&
739 profile()->IsOffTheRecord()) {
740 *num_downloads_blocking = download_service->DownloadCount();
741 return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE;
742 }
743
744 // Those are the only conditions under which we will block shutdown.
745 return DOWNLOAD_CLOSE_OK;
746}
747
[email protected]69444cc2009-04-09 20:40:06748////////////////////////////////////////////////////////////////////////////////
[email protected]c848d3d92010-09-16 21:57:45749// Browser, TabStripModel pass-thrus:
750
751int Browser::tab_count() const {
[email protected]2fc15ae2012-05-06 00:01:37752 return tab_strip_model_->count();
[email protected]c848d3d92010-09-16 21:57:45753}
754
[email protected]1ea49d52011-04-12 17:44:44755int Browser::active_index() const {
[email protected]2fc15ae2012-05-06 00:01:37756 return tab_strip_model_->active_index();
[email protected]c848d3d92010-09-16 21:57:45757}
758
[email protected]c848d3d92010-09-16 21:57:45759////////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:57760// Browser, Tab adding/showing functions:
761
[email protected]227393e2011-06-29 21:28:39762void Browser::WindowFullscreenStateChanged() {
[email protected]01a5a762011-11-21 05:40:55763 fullscreen_controller_->WindowFullscreenStateChanged();
[email protected]5d98294912012-06-27 22:57:40764 command_controller_->FullscreenStateChanged();
[email protected]9adb8b12011-12-09 06:49:13765 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN);
[email protected]ae2622c2009-07-30 23:47:58766}
767
[email protected]36b6dcb2008-11-12 01:19:57768///////////////////////////////////////////////////////////////////////////////
769// Browser, Assorted browser commands:
770
[email protected]41d9faf2012-02-28 23:46:02771void Browser::ToggleFullscreenModeWithExtension(const GURL& extension_url) {
772 fullscreen_controller_->ToggleFullscreenModeWithExtension(extension_url);
[email protected]9282cea2009-02-18 18:49:00773}
774
[email protected]d3766932011-08-04 22:18:23775#if defined(OS_MACOSX)
[email protected]184717d52012-02-22 04:46:16776void Browser::TogglePresentationMode() {
777 fullscreen_controller_->TogglePresentationMode();
[email protected]d3766932011-08-04 22:18:23778}
779#endif
780
[email protected]a3e18c42009-03-04 23:36:05781bool Browser::SupportsWindowFeature(WindowFeature feature) const {
[email protected]018cf362010-05-05 22:43:22782 return SupportsWindowFeatureImpl(feature, true);
783}
[email protected]f5bf8ccf2010-02-05 18:19:25784
[email protected]018cf362010-05-05 22:43:22785bool Browser::CanSupportWindowFeature(WindowFeature feature) const {
786 return SupportsWindowFeatureImpl(feature, false);
[email protected]a3e18c42009-03-04 23:36:05787}
788
[email protected]fbd77592008-11-12 20:50:27789void Browser::ToggleEncodingAutoDetect() {
[email protected]7f6f44c2011-12-14 13:23:38790 content::RecordAction(UserMetricsAction("AutoDetectChange"));
[email protected]fbd77592008-11-12 20:50:27791 encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue());
[email protected]a697f4c2009-09-14 22:30:18792 // If "auto detect" is turned on, then any current override encoding
793 // is cleared. This also implicitly performs a reload.
794 // OTOH, if "auto detect" is turned off, we don't change the currently
795 // active encoding.
796 if (encoding_auto_detect_.GetValue()) {
[email protected]52877dbc62012-06-29 22:22:03797 WebContents* contents = chrome::GetActiveWebContents(this);
[email protected]a697f4c2009-09-14 22:30:18798 if (contents)
[email protected]b2fe07d12010-02-09 14:38:08799 contents->ResetOverrideEncoding();
[email protected]a697f4c2009-09-14 22:30:18800 }
[email protected]fbd77592008-11-12 20:50:27801}
802
803void Browser::OverrideEncoding(int encoding_id) {
[email protected]7f6f44c2011-12-14 13:23:38804 content::RecordAction(UserMetricsAction("OverrideEncoding"));
[email protected]41fc0322009-09-04 22:23:40805 const std::string selected_encoding =
[email protected]fbd77592008-11-12 20:50:27806 CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id);
[email protected]52877dbc62012-06-29 22:22:03807 WebContents* contents = chrome::GetActiveWebContents(this);
[email protected]57c6a652009-05-04 07:58:34808 if (!selected_encoding.empty() && contents)
[email protected]b2fe07d12010-02-09 14:38:08809 contents->SetOverrideEncoding(selected_encoding);
[email protected]fbd77592008-11-12 20:50:27810 // Update the list of recently selected encodings.
[email protected]41fc0322009-09-04 22:23:40811 std::string new_selected_encoding_list;
[email protected]ddd231e2010-06-29 20:35:19812 if (CharacterEncoding::UpdateRecentlySelectedEncoding(
813 profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding),
[email protected]41fc0322009-09-04 22:23:40814 encoding_id,
815 &new_selected_encoding_list)) {
[email protected]fbd77592008-11-12 20:50:27816 profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding,
[email protected]ddd231e2010-06-29 20:35:19817 new_selected_encoding_list);
[email protected]fbd77592008-11-12 20:50:27818 }
[email protected]36b6dcb2008-11-12 01:19:57819}
820
[email protected]84214982008-12-10 18:49:10821void Browser::OpenFile() {
[email protected]7f6f44c2011-12-14 13:23:38822 content::RecordAction(UserMetricsAction("OpenFile"));
[email protected]92f54082012-07-31 01:43:14823 select_file_dialog_ = ui::SelectFileDialog::Create(
[email protected]6e1fcd12012-07-02 17:14:20824 this, new ChromeSelectFilePolicy(
825 chrome::GetActiveWebContents(this)));
[email protected]84214982008-12-10 18:49:10826
[email protected]35896a32010-06-09 08:42:51827 const FilePath directory = profile_->last_selected_directory();
828
[email protected]84214982008-12-10 18:49:10829 // TODO(beng): figure out how to juggle this.
[email protected]90556dd2012-06-07 20:26:18830 gfx::NativeWindow parent_window = window_->GetNativeWindow();
[email protected]92f54082012-07-31 01:43:14831 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE,
[email protected]35896a32010-06-09 08:42:51832 string16(), directory,
[email protected]b949f1112009-04-12 20:03:08833 NULL, 0, FILE_PATH_LITERAL(""),
[email protected]d56bcd22009-03-16 19:51:56834 parent_window, NULL);
[email protected]84214982008-12-10 18:49:10835}
836
[email protected]92655362012-04-20 21:33:17837void Browser::UpdateDownloadShelfVisibility(bool visible) {
838 if (GetStatusBubble())
839 GetStatusBubble()->UpdateDownloadShelfVisibility(visible);
840}
841
[email protected]36b6dcb2008-11-12 01:19:57842///////////////////////////////////////////////////////////////////////////////
843
844// static
[email protected]d9083482012-01-06 00:38:46845bool Browser::RunUnloadEventsHelper(WebContents* contents) {
[email protected]075969d2012-04-17 20:05:55846 // If the WebContents is not connected yet, then there's no unload
847 // handler we can fire even if the WebContents has an unload listener.
[email protected]ecc523f62010-09-28 22:45:40848 // One case where we hit this is in a tab that has an infinite loop
849 // before load.
[email protected]5aab5e22010-12-08 22:13:29850 if (contents->NeedToFireBeforeUnload()) {
[email protected]ecc523f62010-09-28 22:45:40851 // If the page has unload listeners, then we tell the renderer to fire
852 // them. Once they have fired, we'll get a message back saying whether
853 // to proceed closing the page or not, which sends us back to this method
[email protected]5aab5e22010-12-08 22:13:29854 // with the NeedToFireBeforeUnload bit cleared.
[email protected]151a63d2011-12-20 22:32:52855 contents->GetRenderViewHost()->FirePageBeforeUnload(false);
[email protected]ecc523f62010-09-28 22:45:40856 return true;
857 }
858 return false;
859}
860
861// static
[email protected]1d3e9172012-06-12 02:59:13862void Browser::JSOutOfMemoryHelper(WebContents* web_contents) {
863 TabContents* tab_contents = TabContents::FromWebContents(web_contents);
[email protected]3d61dd02012-06-07 00:05:53864 if (!tab_contents)
[email protected]2a6bc3e2011-12-28 23:51:33865 return;
866
[email protected]3d61dd02012-06-07 00:05:53867 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
[email protected]2a6bc3e2011-12-28 23:51:33868 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate(
869 infobar_helper,
870 NULL,
871 l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
872 true));
[email protected]7d189022011-08-25 22:54:20873}
874
875// static
[email protected]1d3e9172012-06-12 02:59:13876void Browser::RegisterProtocolHandlerHelper(WebContents* web_contents,
[email protected]7d189022011-08-25 22:54:20877 const std::string& protocol,
878 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:36879 const string16& title,
[email protected]7ae9c322012-07-17 23:46:44880 bool user_gesture,
881 BrowserWindow* window) {
[email protected]1d3e9172012-06-12 02:59:13882 TabContents* tab_contents = TabContents::FromWebContents(web_contents);
[email protected]3d61dd02012-06-07 00:05:53883 if (!tab_contents || tab_contents->profile()->IsOffTheRecord())
[email protected]7d189022011-08-25 22:54:20884 return;
885
[email protected]7d189022011-08-25 22:54:20886 ProtocolHandler handler =
887 ProtocolHandler::CreateProtocolHandler(protocol, url, title);
888
889 ProtocolHandlerRegistry* registry =
[email protected]3d61dd02012-06-07 00:05:53890 tab_contents->profile()->GetProtocolHandlerRegistry();
[email protected]7ae9c322012-07-17 23:46:44891 TabSpecificContentSettings* content_settings =
892 tab_contents->content_settings();
[email protected]7d189022011-08-25 22:54:20893
[email protected]96affbc82012-07-23 18:04:42894 if (registry->SilentlyHandleRegisterHandlerRequest(handler))
895 return;
896
[email protected]7ae9c322012-07-17 23:46:44897 if (!user_gesture && window) {
898 content_settings->set_pending_protocol_handler(handler);
899 content_settings->set_previous_protocol_handler(
900 registry->GetHandlerFor(handler.protocol()));
901 window->GetLocationBar()->UpdateContentSettingsIcons();
[email protected]3fa5e192012-07-15 00:40:34902 return;
[email protected]7ae9c322012-07-17 23:46:44903 }
904
905 // Make sure content-setting icon is turned off in case the page does
906 // ungestured and gestured RPH calls.
907 if (window) {
908 content_settings->ClearPendingProtocolHandler();
909 window->GetLocationBar()->UpdateContentSettingsIcons();
910 }
[email protected]3fa5e192012-07-15 00:40:34911
[email protected]96affbc82012-07-23 18:04:42912 content::RecordAction(
913 UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown"));
914 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
[email protected]d3ddb6d2012-01-06 02:51:17915
[email protected]96affbc82012-07-23 18:04:42916 RegisterProtocolHandlerInfoBarDelegate* rph_delegate =
917 new RegisterProtocolHandlerInfoBarDelegate(infobar_helper,
918 registry,
919 handler);
[email protected]d3ddb6d2012-01-06 02:51:17920
[email protected]d715fb802012-08-20 16:34:13921 for (size_t i = 0; i < infobar_helper->GetInfoBarCount(); i++) {
[email protected]96affbc82012-07-23 18:04:42922 InfoBarDelegate* delegate = infobar_helper->GetInfoBarDelegateAt(i);
923 RegisterProtocolHandlerInfoBarDelegate* cast_delegate =
924 delegate->AsRegisterProtocolHandlerInfoBarDelegate();
925 if (cast_delegate != NULL && cast_delegate->IsReplacedBy(rph_delegate)) {
926 infobar_helper->ReplaceInfoBar(cast_delegate, rph_delegate);
927 rph_delegate = NULL;
928 break;
[email protected]d3ddb6d2012-01-06 02:51:17929 }
[email protected]7d189022011-08-25 22:54:20930 }
[email protected]96affbc82012-07-23 18:04:42931
932 if (rph_delegate != NULL)
933 infobar_helper->AddInfoBar(rph_delegate);
[email protected]7d189022011-08-25 22:54:20934}
935
936// static
[email protected]1d3e9172012-06-12 02:59:13937void Browser::FindReplyHelper(WebContents* web_contents,
[email protected]b888919c2011-09-02 00:32:16938 int request_id,
939 int number_of_matches,
940 const gfx::Rect& selection_rect,
941 int active_match_ordinal,
942 bool final_update) {
[email protected]1d3e9172012-06-12 02:59:13943 TabContents* tab_contents = TabContents::FromWebContents(web_contents);
[email protected]3d61dd02012-06-07 00:05:53944 if (!tab_contents || !tab_contents->find_tab_helper())
[email protected]b888919c2011-09-02 00:32:16945 return;
946
[email protected]3d61dd02012-06-07 00:05:53947 tab_contents->find_tab_helper()->HandleFindReply(request_id,
948 number_of_matches,
949 selection_rect,
950 active_match_ordinal,
951 final_update);
[email protected]b888919c2011-09-02 00:32:16952}
953
[email protected]c55d3d122012-07-10 16:53:41954// static
955void Browser::RequestMediaAccessPermissionHelper(
956 content::WebContents* web_contents,
957 const content::MediaStreamRequest* request,
958 const content::MediaResponseCallback& callback) {
959 TabContents* tab = TabContents::FromWebContents(web_contents);
960
961 scoped_ptr<MediaStreamDevicesController>
962 controller(new MediaStreamDevicesController(tab->profile(),
963 request,
964 callback));
965 if (!controller->DismissInfoBarAndTakeActionOnSettings()) {
966 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
967 InfoBarDelegate* old_infobar = NULL;
[email protected]d715fb802012-08-20 16:34:13968 for (size_t i = 0; i < infobar_helper->GetInfoBarCount(); ++i) {
[email protected]c55d3d122012-07-10 16:53:41969 old_infobar = infobar_helper->GetInfoBarDelegateAt(i)->
970 AsMediaStreamInfoBarDelegate();
971 if (old_infobar)
972 break;
973 }
974
975 InfoBarDelegate* infobar =
976 new MediaStreamInfoBarDelegate(infobar_helper, controller.release());
977 if (old_infobar)
978 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
979 else
980 infobar_helper->AddInfoBar(infobar);
981 }
982}
983
[email protected]3d61dd02012-06-07 00:05:53984void Browser::UpdateUIForNavigationInTab(TabContents* contents,
[email protected]ef557022012-03-16 10:05:33985 content::PageTransition transition,
986 bool user_initiated) {
[email protected]2fc15ae2012-05-06 00:01:37987 tab_strip_model_->TabNavigating(contents, transition);
[email protected]ef557022012-03-16 10:05:33988
[email protected]52877dbc62012-06-29 22:22:03989 bool contents_is_selected = contents == chrome::GetActiveTabContents(this);
[email protected]ef557022012-03-16 10:05:33990 if (user_initiated && contents_is_selected && window()->GetLocationBar()) {
991 // Forcibly reset the location bar if the url is going to change in the
992 // current tab, since otherwise it won't discard any ongoing user edits,
993 // since it doesn't realize this is a user-initiated action.
994 window()->GetLocationBar()->Revert();
995 }
996
997 if (GetStatusBubble())
998 GetStatusBubble()->Hide();
999
1000 // Update the location bar. This is synchronous. We specifically don't
1001 // update the load state since the load hasn't started yet and updating it
1002 // will put it out of sync with the actual state like whether we're
1003 // displaying a favicon, which controls the throbber. If we updated it here,
1004 // the throbber will show the default favicon for a split second when
1005 // navigating away from the new tab page.
1006 ScheduleUIUpdate(contents->web_contents(), content::INVALIDATE_TYPE_URL);
1007
[email protected]e1f288d2012-05-23 19:36:101008 if (contents_is_selected)
[email protected]ef557022012-03-16 10:05:331009 contents->web_contents()->Focus();
1010}
1011
1012///////////////////////////////////////////////////////////////////////////////
1013// Browser, PageNavigator implementation:
1014
1015WebContents* Browser::OpenURL(const OpenURLParams& params) {
1016 return OpenURLFromTab(NULL, params);
1017}
1018
[email protected]485fba42009-03-24 23:27:291019///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:571020// Browser, TabStripModelObserver implementation:
1021
[email protected]3d61dd02012-06-07 00:05:531022void Browser::TabInsertedAt(TabContents* contents,
[email protected]36b6dcb2008-11-12 01:19:571023 int index,
1024 bool foreground) {
[email protected]6451fe92012-08-30 18:37:261025 SetAsDelegate(contents->web_contents(), this);
[email protected]bde40b822012-08-30 17:28:561026 contents->session_tab_helper()->SetWindowID(session_id());
[email protected]e524ff92011-03-30 13:26:581027
[email protected]c37e3b62010-01-22 00:15:171028 SyncHistoryWithTabs(index);
[email protected]36b6dcb2008-11-12 01:19:571029
[email protected]159f7762008-12-19 14:58:271030 // Make sure the loading state is updated correctly, otherwise the throbber
1031 // won't start if the page is loading.
[email protected]2a6bc3e2011-12-28 23:51:331032 LoadingStateChanged(contents->web_contents());
[email protected]159f7762008-12-19 14:58:271033
[email protected]432115822011-07-10 15:52:271034 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED,
[email protected]fbc5e5f92012-01-02 06:08:321035 content::Source<WebContents>(contents->web_contents()));
[email protected]e397a4472011-12-21 21:47:501036
1037 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED,
[email protected]fbc5e5f92012-01-02 06:08:321038 content::Source<WebContents>(contents->web_contents()));
[email protected]36b6dcb2008-11-12 01:19:571039}
1040
[email protected]f2cc7382010-10-15 18:03:051041void Browser::TabClosingAt(TabStripModel* tab_strip_model,
[email protected]3d61dd02012-06-07 00:05:531042 TabContents* contents,
[email protected]f2cc7382010-10-15 18:03:051043 int index) {
[email protected]d9083482012-01-06 00:38:461044 fullscreen_controller_->OnTabClosing(contents->web_contents());
[email protected]ad50def52011-10-19 23:17:071045 content::NotificationService::current()->Notify(
[email protected]884033e2012-04-16 19:38:421046 chrome::NOTIFICATION_TAB_CLOSING,
[email protected]c5eed492012-01-04 17:07:501047 content::Source<NavigationController>(
[email protected]cca0f1e2012-01-03 18:27:461048 &contents->web_contents()->GetController()),
[email protected]ad50def52011-10-19 23:17:071049 content::NotificationService::NoDetails());
[email protected]36b6dcb2008-11-12 01:19:571050
[email protected]075969d2012-04-17 20:05:551051 // Sever the WebContents' connection back to us.
[email protected]6451fe92012-08-30 18:37:261052 SetAsDelegate(contents->web_contents(), NULL);
[email protected]36b6dcb2008-11-12 01:19:571053}
1054
[email protected]3d61dd02012-06-07 00:05:531055void Browser::TabDetachedAt(TabContents* contents, int index) {
[email protected]c37e3b62010-01-22 00:15:171056 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH);
[email protected]36b6dcb2008-11-12 01:19:571057}
1058
[email protected]3d61dd02012-06-07 00:05:531059void Browser::TabDeactivated(TabContents* contents) {
[email protected]01a5a762011-11-21 05:40:551060 fullscreen_controller_->OnTabDeactivated(contents);
[email protected]e3a5d5b2012-06-22 17:56:461061 search_delegate_->OnTabDeactivated(contents);
1062
[email protected]85ff2c42009-05-29 21:22:031063 // Save what the user's currently typing, so it can be restored when we
1064 // switch back to this tab.
[email protected]83a2610a2012-01-05 01:00:271065 window_->GetLocationBar()->SaveStateToContents(contents->web_contents());
[email protected]85ff2c42009-05-29 21:22:031066}
1067
[email protected]3d61dd02012-06-07 00:05:531068void Browser::ActiveTabChanged(TabContents* old_contents,
1069 TabContents* new_contents,
[email protected]3aca95d42011-05-24 22:06:541070 int index,
1071 bool user_gesture) {
[email protected]a8f024392011-01-13 21:50:161072 // On some platforms we want to automatically reload tabs that are
1073 // killed when the user selects them.
[email protected]9d7518f2012-04-17 02:15:201074 bool did_reload = false;
[email protected]d9083482012-01-06 00:38:461075 if (user_gesture && new_contents->web_contents()->GetCrashedStatus() ==
[email protected]a8f024392011-01-13 21:50:161076 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) {
1077 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
[email protected]f8a35772011-02-02 23:17:561078 if (parsed_command_line.HasSwitch(switches::kReloadKilledTabs)) {
[email protected]734d26692012-03-26 18:00:251079 LOG(WARNING) << "Reloading killed tab at " << index;
[email protected]d6d4dae2012-04-18 17:47:321080 static int reload_count = 0;
[email protected]24c463a2012-04-20 22:33:501081 UMA_HISTOGRAM_CUSTOM_COUNTS(
1082 "Tabs.SadTab.ReloadCount", ++reload_count, 1, 1000, 50);
[email protected]a37d4b02012-06-25 21:56:101083 chrome::Reload(this, CURRENT_TAB);
[email protected]9d7518f2012-04-17 02:15:201084 did_reload = true;
[email protected]f8a35772011-02-02 23:17:561085 }
[email protected]a8f024392011-01-13 21:50:161086 }
1087
[email protected]002efb042011-10-07 17:30:241088 // Discarded tabs always get reloaded.
[email protected]52877dbc62012-06-29 22:22:031089 if (!did_reload && tab_strip_model_->IsTabDiscarded(index)) {
[email protected]d6d4dae2012-04-18 17:47:321090 LOG(WARNING) << "Reloading discarded tab at " << index;
1091 static int reload_count = 0;
[email protected]24c463a2012-04-20 22:33:501092 UMA_HISTOGRAM_CUSTOM_COUNTS(
1093 "Tabs.Discard.ReloadCount", ++reload_count, 1, 1000, 50);
[email protected]a37d4b02012-06-25 21:56:101094 chrome::Reload(this, CURRENT_TAB);
[email protected]002efb042011-10-07 17:30:241095 }
1096
[email protected]36b6dcb2008-11-12 01:19:571097 // If we have any update pending, do it now.
[email protected]24f1477532011-11-22 22:55:361098 if (chrome_updater_factory_.HasWeakPtrs() && old_contents)
[email protected]36b6dcb2008-11-12 01:19:571099 ProcessPendingUIUpdates();
1100
[email protected]36b6dcb2008-11-12 01:19:571101 // Propagate the profile to the location bar.
1102 UpdateToolbar(true);
1103
[email protected]e3a5d5b2012-06-22 17:56:461104 // Propagate tab state to toolbar, tab-strip, etc.
1105 UpdateSearchState(new_contents);
1106
[email protected]943d8122010-06-11 02:13:451107 // Update reload/stop state.
[email protected]5d98294912012-06-27 22:57:401108 command_controller_->LoadingStateChanged(
1109 new_contents->web_contents()->IsLoading(), true);
[email protected]36b6dcb2008-11-12 01:19:571110
[email protected]84214982008-12-10 18:49:101111 // Update commands to reflect current state.
[email protected]5d98294912012-06-27 22:57:401112 command_controller_->TabStateChanged();
[email protected]36b6dcb2008-11-12 01:19:571113
1114 // Reset the status bubble.
[email protected]be3877f2009-01-14 15:51:101115 StatusBubble* status_bubble = GetStatusBubble();
1116 if (status_bubble) {
1117 status_bubble->Hide();
[email protected]36b6dcb2008-11-12 01:19:571118
[email protected]be3877f2009-01-14 15:51:101119 // Show the loading state (if any).
[email protected]51d83bdf2011-12-09 16:09:291120 status_bubble->SetStatus(
[email protected]52877dbc62012-06-29 22:22:031121 chrome::GetActiveTabContents(this)->core_tab_helper()->GetStatusText());
[email protected]be3877f2009-01-14 15:51:101122 }
[email protected]36b6dcb2008-11-12 01:19:571123
[email protected]24db8a072009-10-29 20:35:371124 if (HasFindBarController()) {
[email protected]9c318862011-02-01 22:27:241125 find_bar_controller_->ChangeTabContents(new_contents);
[email protected]b77cb302009-10-29 04:09:171126 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
[email protected]4801ecc2009-04-05 04:52:581127 }
1128
[email protected]36b6dcb2008-11-12 01:19:571129 // Update sessions. Don't force creation of sessions. If sessions doesn't
1130 // exist, the change will be picked up by sessions when created.
[email protected]92371eb2011-04-28 11:50:151131 SessionService* session_service =
1132 SessionServiceFactory::GetForProfileIfExisting(profile_);
[email protected]2fc15ae2012-05-06 00:01:371133 if (session_service && !tab_strip_model_->closing_all()) {
[email protected]41f022e2012-01-31 05:56:401134 session_service->SetSelectedTabInWindow(session_id(), active_index());
[email protected]36b6dcb2008-11-12 01:19:571135 }
[email protected]09b29342011-06-24 19:18:481136
1137 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH);
[email protected]36b6dcb2008-11-12 01:19:571138}
1139
[email protected]3d61dd02012-06-07 00:05:531140void Browser::TabMoved(TabContents* contents,
[email protected]36b6dcb2008-11-12 01:19:571141 int from_index,
[email protected]1a242c32010-02-02 21:20:541142 int to_index) {
[email protected]36b6dcb2008-11-12 01:19:571143 DCHECK(from_index >= 0 && to_index >= 0);
1144 // Notify the history service.
1145 SyncHistoryWithTabs(std::min(from_index, to_index));
1146}
1147
[email protected]da25dd52011-01-11 19:06:301148void Browser::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]3d61dd02012-06-07 00:05:531149 TabContents* old_contents,
1150 TabContents* new_contents,
[email protected]8a34e6602010-10-02 17:29:431151 int index) {
[email protected]c37e3b62010-01-22 00:15:171152 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE);
[email protected]41f022e2012-01-31 05:56:401153 TabInsertedAt(new_contents, index, (index == active_index()));
[email protected]c37e3b62010-01-22 00:15:171154
[email protected]a26023822011-12-29 00:23:551155 int entry_count =
[email protected]d9083482012-01-06 00:38:461156 new_contents->web_contents()->GetController().GetEntryCount();
[email protected]c37e3b62010-01-22 00:15:171157 if (entry_count > 0) {
1158 // Send out notification so that observers are updated appropriately.
[email protected]d9083482012-01-06 00:38:461159 new_contents->web_contents()->GetController().NotifyEntryChanged(
1160 new_contents->web_contents()->GetController().GetEntryAtIndex(
[email protected]4a63e242011-12-12 15:23:081161 entry_count - 1),
[email protected]c37e3b62010-01-22 00:15:171162 entry_count - 1);
1163 }
[email protected]47e020a2010-10-15 14:43:371164
[email protected]92371eb2011-04-28 11:50:151165 SessionService* session_service =
1166 SessionServiceFactory::GetForProfile(profile());
[email protected]47e020a2010-10-15 14:43:371167 if (session_service) {
1168 // The new_contents may end up with a different navigation stack. Force
1169 // the session service to update itself.
[email protected]52877dbc62012-06-29 22:22:031170 session_service->TabRestored(new_contents,
1171 tab_strip_model_->IsTabPinned(index));
[email protected]47e020a2010-10-15 14:43:371172 }
[email protected]2914600d2011-01-31 23:25:141173
[email protected]a0262432012-04-13 15:48:091174 content::DevToolsManager::GetInstance()->ContentsReplaced(
[email protected]d9083482012-01-06 00:38:461175 old_contents->web_contents(), new_contents->web_contents());
[email protected]c37e3b62010-01-22 00:15:171176}
1177
[email protected]3d61dd02012-06-07 00:05:531178void Browser::TabPinnedStateChanged(TabContents* contents, int index) {
[email protected]92371eb2011-04-28 11:50:151179 SessionService* session_service =
1180 SessionServiceFactory::GetForProfileIfExisting(profile());
[email protected]5c0e6482009-07-14 20:20:091181 if (session_service) {
1182 session_service->SetPinnedState(
1183 session_id(),
[email protected]bde40b822012-08-30 17:28:561184 chrome::GetTabContentsAt(this, index)->session_tab_helper()->
[email protected]52877dbc62012-06-29 22:22:031185 session_id(),
1186 tab_strip_model_->IsTabPinned(index));
[email protected]5c0e6482009-07-14 20:20:091187 }
1188}
1189
[email protected]36b6dcb2008-11-12 01:19:571190void Browser::TabStripEmpty() {
1191 // Close the frame after we return to the message loop (not immediately,
1192 // otherwise it will destroy this object before the stack has a chance to
1193 // cleanly unwind.)
1194 // Note: This will be called several times if TabStripEmpty is called several
1195 // times. This is because it does not close the window if tabs are
1196 // still present.
[email protected]0586b0e2010-02-12 21:38:371197 MessageLoop::current()->PostTask(
[email protected]24f1477532011-11-22 22:55:361198 FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr()));
[email protected]36b6dcb2008-11-12 01:19:571199}
1200
[email protected]b3996ba2012-08-08 00:39:131201bool Browser::PreHandleKeyboardEvent(content::WebContents* source,
1202 const NativeWebKeyboardEvent& event,
[email protected]fc761142012-06-08 04:49:201203 bool* is_keyboard_shortcut) {
1204 // Escape exits tabbed fullscreen mode.
1205 // TODO(koz): Write a test for this http://crbug.com/100441.
1206 if (event.windowsKeyCode == 27 &&
1207 fullscreen_controller_->HandleUserPressedEscape()) {
1208 return true;
1209 }
1210 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1211}
1212
[email protected]b3996ba2012-08-08 00:39:131213void Browser::HandleKeyboardEvent(content::WebContents* source,
1214 const NativeWebKeyboardEvent& event) {
[email protected]fc761142012-06-08 04:49:201215 window()->HandleKeyboardEvent(event);
1216}
1217
[email protected]92655362012-04-20 21:33:171218bool Browser::TabsNeedBeforeUnloadFired() {
[email protected]f9b6c092012-07-09 19:32:281219 return unload_controller_->TabsNeedBeforeUnloadFired();
[email protected]92655362012-04-20 21:33:171220}
1221
[email protected]d013f142012-04-27 17:31:141222bool Browser::IsMouseLocked() const {
1223 return fullscreen_controller_->IsMouseLocked();
[email protected]92655362012-04-20 21:33:171224}
1225
1226void Browser::OnWindowDidShow() {
1227 if (window_has_shown_)
1228 return;
1229 window_has_shown_ = true;
1230
[email protected]b5febf72012-07-29 18:10:091231// CurrentProcessInfo::CreationTime() is currently only implemented on Mac and
1232// Windows.
1233#if defined(OS_MACOSX) || defined(OS_WIN)
1234 // Measure the latency from startup till the first browser window becomes
1235 // visible.
1236 static bool is_first_browser_window = true;
1237 if (is_first_browser_window &&
1238 !startup_metric_utils::WasNonBrowserUIDisplayed()) {
1239 is_first_browser_window = false;
1240 const base::Time* process_creation_time =
1241 base::CurrentProcessInfo::CreationTime();
1242
1243 if (process_creation_time) {
1244 UMA_HISTOGRAM_LONG_TIMES(
1245 "Startup.BrowserWindowDisplay",
1246 base::Time::Now() - *process_creation_time);
1247 }
1248 }
1249#endif // OS_MACOSX || OS_WIN
1250
[email protected]92655362012-04-20 21:33:171251 // Nothing to do for non-tabbed windows.
1252 if (!is_type_tabbed())
1253 return;
1254
1255 // Show any pending global error bubble.
1256 GlobalErrorService* service =
1257 GlobalErrorServiceFactory::GetForProfile(profile());
1258 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView();
1259 if (error)
1260 error->ShowBubbleView(this);
1261}
1262
1263void Browser::ShowFirstRunBubble() {
1264 window()->GetLocationBar()->ShowFirstRunBubble();
1265}
1266
1267///////////////////////////////////////////////////////////////////////////////
[email protected]674bc592011-12-20 23:00:421268// Browser, content::WebContentsDelegate implementation:
initial.commit09911bf2008-07-26 23:55:291269
[email protected]e5d549d2011-12-28 01:29:201270WebContents* Browser::OpenURLFromTab(WebContents* source,
[email protected]00c37fc2011-08-02 00:22:501271 const OpenURLParams& params) {
[email protected]78e2edc2012-07-01 23:32:281272 chrome::NavigateParams nav_params(this, params.url, params.transition);
[email protected]52877dbc62012-06-29 22:22:031273 nav_params.source_contents = chrome::GetTabContentsAt(this,
[email protected]e52d0a42012-06-08 22:44:161274 tab_strip_model_->GetIndexOfWebContents(source));
[email protected]cb8fb01a2011-12-05 21:01:141275 nav_params.referrer = params.referrer;
[email protected]00c37fc2011-08-02 00:22:501276 nav_params.disposition = params.disposition;
1277 nav_params.tabstrip_add_types = TabStripModel::ADD_NONE;
[email protected]78e2edc2012-07-01 23:32:281278 nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]00c37fc2011-08-02 00:22:501279 nav_params.user_gesture = true;
1280 nav_params.override_encoding = params.override_encoding;
[email protected]e47ae9472011-10-13 19:48:341281 nav_params.is_renderer_initiated = params.is_renderer_initiated;
[email protected]4ad5d77d2011-12-03 02:00:481282 nav_params.transferred_global_request_id =
1283 params.transferred_global_request_id;
[email protected]78e2edc2012-07-01 23:32:281284 chrome::Navigate(&nav_params);
[email protected]00c37fc2011-08-02 00:22:501285
1286 return nav_params.target_contents ?
[email protected]d9083482012-01-06 00:38:461287 nav_params.target_contents->web_contents() : NULL;
initial.commit09911bf2008-07-26 23:55:291288}
1289
[email protected]2a6bc3e2011-12-28 23:51:331290void Browser::NavigationStateChanged(const WebContents* source,
initial.commit09911bf2008-07-26 23:55:291291 unsigned changed_flags) {
initial.commit09911bf2008-07-26 23:55:291292 // Only update the UI when something visible has changed.
[email protected]e83f1682008-09-07 23:57:401293 if (changed_flags)
initial.commit09911bf2008-07-26 23:55:291294 ScheduleUIUpdate(source, changed_flags);
1295
[email protected]83c2e232011-10-07 21:36:461296 // We can synchronously update commands since they will only change once per
1297 // navigation, so we don't have to worry about flickering. We do, however,
1298 // need to update the command state early on load to always present usable
1299 // actions in the face of slow-to-commit pages.
[email protected]d9083482012-01-06 00:38:461300 if (changed_flags & (content::INVALIDATE_TYPE_URL |
1301 content::INVALIDATE_TYPE_LOAD))
[email protected]5d98294912012-06-27 22:57:401302 command_controller_->TabStateChanged();
initial.commit09911bf2008-07-26 23:55:291303}
1304
[email protected]2a6bc3e2011-12-28 23:51:331305void Browser::AddNewContents(WebContents* source,
1306 WebContents* new_contents,
initial.commit09911bf2008-07-26 23:55:291307 WindowOpenDisposition disposition,
1308 const gfx::Rect& initial_pos,
[email protected]eda238a12012-09-07 23:44:001309 bool user_gesture,
1310 bool* was_blocked) {
[email protected]52877dbc62012-06-29 22:22:031311 chrome::AddWebContents(this, source, new_contents, disposition, initial_pos,
[email protected]eda238a12012-09-07 23:44:001312 user_gesture, was_blocked);
initial.commit09911bf2008-07-26 23:55:291313}
1314
[email protected]2a6bc3e2011-12-28 23:51:331315void Browser::ActivateContents(WebContents* contents) {
[email protected]52877dbc62012-06-29 22:22:031316 chrome::ActivateTabAt(this, tab_strip_model_->GetIndexOfWebContents(contents),
1317 false);
[email protected]f3e99e32008-07-30 04:48:391318 window_->Activate();
initial.commit09911bf2008-07-26 23:55:291319}
1320
[email protected]2a6bc3e2011-12-28 23:51:331321void Browser::DeactivateContents(WebContents* contents) {
[email protected]ea42e7782010-08-23 23:58:121322 window_->Deactivate();
1323}
1324
[email protected]2a6bc3e2011-12-28 23:51:331325void Browser::LoadingStateChanged(WebContents* source) {
[email protected]2fc15ae2012-05-06 00:01:371326 window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading());
[email protected]f3e99e32008-07-30 04:48:391327 window_->UpdateTitleBar();
initial.commit09911bf2008-07-26 23:55:291328
[email protected]52877dbc62012-06-29 22:22:031329 WebContents* selected_contents = chrome::GetActiveWebContents(this);
[email protected]3c9e1872010-11-18 16:17:491330 if (source == selected_contents) {
[email protected]f5d978c2011-07-21 14:43:511331 bool is_loading = source->IsLoading();
[email protected]5d98294912012-06-27 22:57:401332 command_controller_->LoadingStateChanged(is_loading, false);
[email protected]43d259d2010-09-03 21:37:461333 if (GetStatusBubble()) {
[email protected]0dd3a0ab2011-02-18 08:17:441334 GetStatusBubble()->SetStatus(
[email protected]52877dbc62012-06-29 22:22:031335 chrome::GetActiveTabContents(this)->core_tab_helper()->
1336 GetStatusText());
[email protected]43d259d2010-09-03 21:37:461337 }
initial.commit09911bf2008-07-26 23:55:291338 }
1339}
1340
[email protected]a81343d232011-12-27 07:39:201341void Browser::CloseContents(WebContents* source) {
[email protected]f9b6c092012-07-09 19:32:281342 if (unload_controller_->CanCloseContents(source))
1343 chrome::CloseWebContents(this, source);
initial.commit09911bf2008-07-26 23:55:291344}
1345
[email protected]2a6bc3e2011-12-28 23:51:331346void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) {
[email protected]b35b26b32011-05-05 20:35:141347 if (!IsPopupOrPanel(source)) {
initial.commit09911bf2008-07-26 23:55:291348 NOTREACHED() << "moving invalid browser type";
1349 return;
1350 }
[email protected]e561e202010-03-24 17:57:121351 window_->SetBounds(pos);
initial.commit09911bf2008-07-26 23:55:291352}
1353
[email protected]2a6bc3e2011-12-28 23:51:331354bool Browser::IsPopupOrPanel(const WebContents* source) const {
initial.commit09911bf2008-07-26 23:55:291355 // A non-tabbed BROWSER is an unconstrained popup.
[email protected]b35b26b32011-05-05 20:35:141356 return is_type_popup() || is_type_panel();
initial.commit09911bf2008-07-26 23:55:291357}
1358
[email protected]2a6bc3e2011-12-28 23:51:331359void Browser::UpdateTargetURL(WebContents* source, int32 page_id,
[email protected]d952a052011-09-06 18:42:451360 const GURL& url) {
[email protected]be3877f2009-01-14 15:51:101361 if (!GetStatusBubble())
1362 return;
1363
[email protected]52877dbc62012-06-29 22:22:031364 if (source == chrome::GetActiveWebContents(this)) {
[email protected]36b6dcb2008-11-12 01:19:571365 PrefService* prefs = profile_->GetPrefs();
[email protected]65233052011-08-22 19:02:481366 GetStatusBubble()->SetURL(url, prefs->GetString(prefs::kAcceptLanguages));
[email protected]36b6dcb2008-11-12 01:19:571367 }
1368}
1369
[email protected]92655362012-04-20 21:33:171370void Browser::ContentsMouseEvent(
1371 WebContents* source, const gfx::Point& location, bool motion) {
1372 if (!GetStatusBubble())
1373 return;
1374
[email protected]52877dbc62012-06-29 22:22:031375 if (source == chrome::GetActiveWebContents(this)) {
[email protected]92655362012-04-20 21:33:171376 GetStatusBubble()->MouseMoved(location, !motion);
1377 if (!motion)
1378 GetStatusBubble()->SetURL(GURL(), std::string());
1379 }
[email protected]3a6a3b62009-05-27 21:36:201380}
1381
[email protected]36b6dcb2008-11-12 01:19:571382void Browser::ContentsZoomChange(bool zoom_in) {
[email protected]5d98294912012-06-27 22:57:401383 chrome::ExecuteCommand(this, zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS);
[email protected]36b6dcb2008-11-12 01:19:571384}
1385
[email protected]2a6bc3e2011-12-28 23:51:331386void Browser::WebContentsFocused(WebContents* contents) {
1387 window_->WebContentsFocused(contents);
[email protected]7e383692009-06-12 19:14:541388}
1389
[email protected]b3996ba2012-08-08 00:39:131390bool Browser::TakeFocus(content::WebContents* source,
1391 bool reverse) {
[email protected]ad50def52011-10-19 23:17:071392 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271393 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
[email protected]6c2381d2011-10-19 02:52:531394 content::Source<Browser>(this),
[email protected]ad50def52011-10-19 23:17:071395 content::NotificationService::NoDetails());
[email protected]130efb02009-09-18 18:54:351396 return false;
1397}
1398
[email protected]36b6dcb2008-11-12 01:19:571399bool Browser::IsApplication() const {
[email protected]b35b26b32011-05-05 20:35:141400 return is_app();
[email protected]36b6dcb2008-11-12 01:19:571401}
1402
[email protected]b7a756d42012-01-23 18:08:171403gfx::Rect Browser::GetRootWindowResizerRect() const {
1404 return window_->GetRootWindowResizerRect();
1405}
1406
[email protected]1d3e9172012-06-12 02:59:131407void Browser::BeforeUnloadFired(WebContents* web_contents,
[email protected]36b6dcb2008-11-12 01:19:571408 bool proceed,
1409 bool* proceed_to_fire_unload) {
[email protected]f9b6c092012-07-09 19:32:281410 *proceed_to_fire_unload =
1411 unload_controller_->BeforeUnloadFired(web_contents, proceed);
[email protected]36b6dcb2008-11-12 01:19:571412}
1413
[email protected]a26dc362010-04-23 01:48:581414void Browser::SetFocusToLocationBar(bool select_all) {
[email protected]1a380622009-02-17 17:33:131415 // Two differences between this and FocusLocationBar():
1416 // (1) This doesn't get recorded in user metrics, since it's called
1417 // internally.
1418 // (2) This checks whether the location bar can be focused, and if not, clears
1419 // the focus. FocusLocationBar() is only reached when the location bar is
1420 // focusable, but this may be reached at other times, e.g. while in
1421 // fullscreen mode, where we need to leave focus in a consistent state.
[email protected]a26dc362010-04-23 01:48:581422 window_->SetFocusToLocationBar(select_all);
[email protected]4bcefee2009-01-29 15:57:571423}
1424
[email protected]7d5925a2009-03-03 02:59:121425void Browser::RenderWidgetShowing() {
1426 window_->DisableInactiveFrame();
1427}
[email protected]a239c3f2009-02-17 22:13:191428
[email protected]0a2aeb82009-05-15 21:52:481429int Browser::GetExtraRenderViewHeight() const {
1430 return window_->GetExtraRenderViewHeight();
1431}
1432
[email protected]2a6bc3e2011-12-28 23:51:331433void Browser::OnStartDownload(WebContents* source,
[email protected]e582fdd2011-12-20 16:48:171434 content::DownloadItem* download) {
[email protected]1d3e9172012-06-12 02:59:131435 TabContents* tab_contents = TabContents::FromWebContents(source);
[email protected]2ae41f9d2012-06-11 20:13:381436 TabContents* constrained = GetConstrainingTabContents(tab_contents);
[email protected]3d61dd02012-06-07 00:05:531437 if (constrained != tab_contents) {
[email protected]686493142011-07-15 21:47:221438 // Download in a constrained popup is shown in the tab that opened it.
[email protected]d9083482012-01-06 00:38:461439 WebContents* constrained_tab = constrained->web_contents();
[email protected]6934a702011-12-20 00:04:511440 constrained_tab->GetDelegate()->OnStartDownload(constrained_tab, download);
[email protected]686493142011-07-15 21:47:221441 return;
1442 }
1443
1444 if (!window())
1445 return;
1446
[email protected]27c14f02012-06-22 17:29:581447 // GetDownloadShelf creates the download shelf if it was not yet created.
1448 DownloadShelf* shelf = window()->GetDownloadShelf();
1449 shelf->AddDownload(new DownloadItemModel(download));
1450 // Don't show the animation for "Save file" downloads.
1451 // For non-theme extensions, we don't show the download animation.
1452 // Show animation in same window as the download shelf. Download shelf
1453 // may not be in the same window that initiated the download, e.g.
1454 // Panels.
1455 // Don't show the animation if the selected tab is not visible (i.e. the
1456 // window is minimized, we're in a unit test, etc.).
[email protected]52877dbc62012-06-29 22:22:031457 WebContents* shelf_tab = chrome::GetActiveWebContents(shelf->browser());
[email protected]27c14f02012-06-22 17:29:581458 if ((download->GetTotalBytes() > 0) &&
1459 !download_crx_util::IsExtensionDownload(*download) &&
1460 platform_util::IsVisible(shelf_tab->GetNativeView()) &&
1461 ui::Animation::ShouldRenderRichAnimation()) {
1462 DownloadStartedAnimation::Show(shelf_tab);
[email protected]a0e4b072011-08-17 01:47:071463 }
[email protected]686493142011-07-15 21:47:221464
1465 // If the download occurs in a new tab, close it.
[email protected]f5fa20e2011-12-21 22:35:561466 if (source->GetController().IsInitialNavigation() && tab_count() > 1)
[email protected]686493142011-07-15 21:47:221467 CloseContents(source);
1468}
1469
[email protected]2a6bc3e2011-12-28 23:51:331470void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) {
[email protected]1788e772010-12-15 16:40:501471 DCHECK(source);
[email protected]52877dbc62012-06-29 22:22:031472 TabContents* tab_contents = chrome::GetTabContentsAt(this,
[email protected]e52d0a42012-06-08 22:44:161473 tab_strip_model_->GetIndexOfWebContents(source));
[email protected]2cd4fde2012-06-26 03:10:261474 chrome::ViewSource(this, tab_contents);
[email protected]77d8d622010-12-15 10:30:121475}
1476
[email protected]2a6bc3e2011-12-28 23:51:331477void Browser::ViewSourceForFrame(WebContents* source,
[email protected]932b7a12011-03-09 12:50:271478 const GURL& frame_url,
1479 const std::string& frame_content_state) {
1480 DCHECK(source);
[email protected]52877dbc62012-06-29 22:22:031481 TabContents* tab_contents = chrome::GetTabContentsAt(this,
[email protected]e52d0a42012-06-08 22:44:161482 tab_strip_model_->GetIndexOfWebContents(source));
[email protected]2cd4fde2012-06-26 03:10:261483 chrome::ViewSource(this, tab_contents, frame_url, frame_content_state);
[email protected]932b7a12011-03-09 12:50:271484}
1485
[email protected]4fdf6742012-01-10 20:14:361486void Browser::ShowRepostFormWarningDialog(WebContents* source) {
[email protected]87586fb72012-07-02 13:15:021487 chrome::ShowTabModalConfirmDialog(new RepostFormWarningController(source),
1488 TabContents::FromWebContents(source));
[email protected]14f3408a2009-08-31 20:53:531489}
1490
[email protected]ec0b6c42010-08-26 03:16:581491bool Browser::ShouldAddNavigationToHistory(
1492 const history::HistoryAddPageArgs& add_page_args,
[email protected]610cbb82011-10-18 16:35:081493 content::NavigationType navigation_type) {
[email protected]2e29d922009-10-22 22:13:351494 // Don't update history if running as app.
1495 return !IsApplication();
1496}
1497
[email protected]4fdf6742012-01-10 20:14:361498bool Browser::ShouldCreateWebContents(
1499 WebContents* web_contents,
1500 int route_id,
1501 WindowContainerType window_container_type,
[email protected]03b6d552012-03-29 04:03:011502 const string16& frame_name,
1503 const GURL& target_url) {
[email protected]4fdf6742012-01-10 20:14:361504 if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1505 // If a BackgroundContents is created, suppress the normal WebContents.
1506 return !MaybeCreateBackgroundContents(
[email protected]03b6d552012-03-29 04:03:011507 route_id, web_contents, frame_name, target_url);
[email protected]4fdf6742012-01-10 20:14:361508 }
1509
1510 return true;
1511}
1512
1513void Browser::WebContentsCreated(WebContents* source_contents,
1514 int64 source_frame_id,
1515 const GURL& target_url,
1516 WebContents* new_contents) {
[email protected]6451fe92012-08-30 18:37:261517 // Adopt the WebContents now, so all observers are in place, as the network
[email protected]3d61dd02012-06-07 00:05:531518 // requests for its initial navigation will start immediately. The WebContents
1519 // will later be inserted into this browser using Browser::Navigate via
[email protected]6451fe92012-08-30 18:37:261520 // AddNewContents.
1521 AdoptAsTabContents(new_contents);
[email protected]4fdf6742012-01-10 20:14:361522
1523 // Notify.
1524 RetargetingDetails details;
1525 details.source_web_contents = source_contents;
1526 details.source_frame_id = source_frame_id;
1527 details.target_url = target_url;
1528 details.target_web_contents = new_contents;
1529 details.not_yet_in_tabstrip = true;
1530 content::NotificationService::current()->Notify(
1531 chrome::NOTIFICATION_RETARGETING,
1532 content::Source<Profile>(profile_),
1533 content::Details<RetargetingDetails>(&details));
[email protected]80c7b802011-10-28 19:59:081534}
1535
[email protected]2a6bc3e2011-12-28 23:51:331536void Browser::ContentRestrictionsChanged(WebContents* source) {
[email protected]5d98294912012-06-27 22:57:401537 command_controller_->ContentRestrictionsChanged();
[email protected]9e823662010-10-13 23:36:001538}
1539
[email protected]2a6bc3e2011-12-28 23:51:331540void Browser::RendererUnresponsive(WebContents* source) {
[email protected]c19d9542011-11-15 22:26:421541 // Ignore hangs if print preview is open.
[email protected]1d3e9172012-06-12 02:59:131542 TabContents* tab_contents = TabContents::FromWebContents(source);
[email protected]3d61dd02012-06-07 00:05:531543 if (tab_contents) {
[email protected]c19d9542011-11-15 22:26:421544 printing::PrintPreviewTabController* controller =
1545 printing::PrintPreviewTabController::GetInstance();
1546 if (controller) {
[email protected]3d61dd02012-06-07 00:05:531547 TabContents* preview_tab =
1548 controller->GetPrintPreviewForTab(tab_contents);
1549 if (preview_tab && preview_tab != tab_contents) {
[email protected]c19d9542011-11-15 22:26:421550 return;
1551 }
1552 }
1553 }
1554
[email protected]87586fb72012-07-02 13:15:021555 chrome::ShowHungRendererDialog(source);
[email protected]55452902011-06-01 21:57:471556}
1557
[email protected]2a6bc3e2011-12-28 23:51:331558void Browser::RendererResponsive(WebContents* source) {
[email protected]87586fb72012-07-02 13:15:021559 chrome::HideHungRendererDialog(source);
[email protected]55452902011-06-01 21:57:471560}
1561
[email protected]2a6bc3e2011-12-28 23:51:331562void Browser::WorkerCrashed(WebContents* source) {
[email protected]1d3e9172012-06-12 02:59:131563 TabContents* tab_contents = TabContents::FromWebContents(source);
[email protected]3d61dd02012-06-07 00:05:531564 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
[email protected]95a33ed62011-09-30 15:07:081565 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate(
1566 infobar_helper,
1567 NULL,
1568 l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]55452902011-06-01 21:57:471569 true));
[email protected]0dd3a0ab2011-02-18 08:17:441570}
1571
[email protected]1d3e9172012-06-12 02:59:131572void Browser::DidNavigateMainFramePostCommit(WebContents* web_contents) {
[email protected]52877dbc62012-06-29 22:22:031573 if (web_contents == chrome::GetActiveWebContents(this))
[email protected]09b29342011-06-24 19:18:481574 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
[email protected]93f230e02011-06-01 14:40:001575}
1576
[email protected]1d3e9172012-06-12 02:59:131577void Browser::DidNavigateToPendingEntry(WebContents* web_contents) {
[email protected]52877dbc62012-06-29 22:22:031578 if (web_contents == chrome::GetActiveWebContents(this))
[email protected]09b29342011-06-24 19:18:481579 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
[email protected]93f230e02011-06-01 14:40:001580}
1581
[email protected]3ab9cb82011-06-03 18:02:071582content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() {
1583 return GetJavaScriptDialogCreatorInstance();
1584}
1585
[email protected]1d3e9172012-06-12 02:59:131586content::ColorChooser* Browser::OpenColorChooser(WebContents* web_contents,
[email protected]da8543762012-03-20 08:52:201587 int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321588 SkColor color) {
[email protected]da8543762012-03-20 08:52:201589#if defined(OS_WIN)
1590 // On Windows, only create a color chooser if one doesn't exist, because we
1591 // can't close the old color chooser dialog.
1592 if (!color_chooser_.get())
[email protected]1d3e9172012-06-12 02:59:131593 color_chooser_.reset(content::ColorChooser::Create(color_chooser_id,
1594 web_contents,
[email protected]da8543762012-03-20 08:52:201595 color));
1596#else
1597 if (color_chooser_.get())
1598 color_chooser_->End();
[email protected]1d3e9172012-06-12 02:59:131599 color_chooser_.reset(content::ColorChooser::Create(color_chooser_id,
1600 web_contents,
[email protected]da8543762012-03-20 08:52:201601 color));
1602#endif
1603 return color_chooser_.get();
1604}
1605
1606void Browser::DidEndColorChooser() {
1607 color_chooser_.reset();
1608}
1609
[email protected]1d3e9172012-06-12 02:59:131610void Browser::RunFileChooser(WebContents* web_contents,
[email protected]8caadeb2011-11-22 02:45:231611 const content::FileChooserParams& params) {
[email protected]1d3e9172012-06-12 02:59:131612 FileSelectHelper::RunFileChooser(web_contents, params);
[email protected]3a29a6e2011-08-24 18:26:211613}
1614
[email protected]1d3e9172012-06-12 02:59:131615void Browser::EnumerateDirectory(WebContents* web_contents,
[email protected]33f8ad52012-05-22 18:10:131616 int request_id,
[email protected]3a29a6e2011-08-24 18:26:211617 const FilePath& path) {
[email protected]1d3e9172012-06-12 02:59:131618 FileSelectHelper::EnumerateDirectory(web_contents, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211619}
1620
[email protected]1d3e9172012-06-12 02:59:131621void Browser::ToggleFullscreenModeForTab(WebContents* web_contents,
[email protected]01a5a762011-11-21 05:40:551622 bool enter_fullscreen) {
[email protected]1d3e9172012-06-12 02:59:131623 fullscreen_controller_->ToggleFullscreenModeForTab(web_contents,
1624 enter_fullscreen);
[email protected]8a5e0ca2011-08-25 06:30:471625}
1626
[email protected]1d3e9172012-06-12 02:59:131627bool Browser::IsFullscreenForTabOrPending(
1628 const WebContents* web_contents) const {
1629 return fullscreen_controller_->IsFullscreenForTabOrPending(web_contents);
[email protected]5d5f7af2011-10-01 01:38:121630}
1631
[email protected]1d3e9172012-06-12 02:59:131632void Browser::JSOutOfMemory(WebContents* web_contents) {
1633 JSOutOfMemoryHelper(web_contents);
[email protected]7d189022011-08-25 22:54:201634}
1635
[email protected]1d3e9172012-06-12 02:59:131636void Browser::RegisterProtocolHandler(WebContents* web_contents,
[email protected]7d189022011-08-25 22:54:201637 const std::string& protocol,
1638 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:361639 const string16& title,
1640 bool user_gesture) {
[email protected]1d3e9172012-06-12 02:59:131641 RegisterProtocolHandlerHelper(
[email protected]7ae9c322012-07-17 23:46:441642 web_contents, protocol, url, title, user_gesture, window());
[email protected]7d189022011-08-25 22:54:201643}
1644
[email protected]3a3b75a2012-06-01 08:38:361645void Browser::RegisterIntentHandler(
[email protected]1d3e9172012-06-12 02:59:131646 WebContents* web_contents,
[email protected]3a3b75a2012-06-01 08:38:361647 const webkit_glue::WebIntentServiceData& data,
1648 bool user_gesture) {
[email protected]1d3e9172012-06-12 02:59:131649 RegisterIntentHandlerHelper(web_contents, data, user_gesture);
[email protected]7d189022011-08-25 22:54:201650}
1651
[email protected]0d9989d2011-12-21 20:26:001652void Browser::WebIntentDispatch(
[email protected]1d3e9172012-06-12 02:59:131653 WebContents* web_contents,
1654 content::WebIntentsDispatcher* intents_dispatcher) {
[email protected]59d73ec2012-09-01 02:24:271655 if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) {
1656 web_intents::RecordIntentsDispatchDisabled();
[email protected]828e61af2011-09-14 19:45:061657 return;
[email protected]59d73ec2012-09-01 02:24:271658 }
[email protected]828e61af2011-09-14 19:45:061659
[email protected]59d73ec2012-09-01 02:24:271660 web_intents::RecordIntentDispatchRequested();
[email protected]86238d22012-05-22 20:00:111661
[email protected]bd52a982012-06-26 23:34:291662 if (!web_contents) {
1663 // Intent is system-caused and the picker will show over the currently
1664 // active web contents.
[email protected]52877dbc62012-06-29 22:22:031665 web_contents = chrome::GetActiveWebContents(this);
[email protected]bd52a982012-06-26 23:34:291666 }
[email protected]1d3e9172012-06-12 02:59:131667 TabContents* tab_contents = TabContents::FromWebContents(web_contents);
[email protected]3d61dd02012-06-07 00:05:531668 tab_contents->web_intent_picker_controller()->SetIntentsDispatcher(
1669 intents_dispatcher);
1670 tab_contents->web_intent_picker_controller()->ShowDialog(
[email protected]0d9989d2011-12-21 20:26:001671 intents_dispatcher->GetIntent().action,
1672 intents_dispatcher->GetIntent().type);
[email protected]b888919c2011-09-02 00:32:161673}
1674
[email protected]2a6bc3e2011-12-28 23:51:331675void Browser::UpdatePreferredSize(WebContents* source,
[email protected]0548c5352011-09-07 00:33:331676 const gfx::Size& pref_size) {
1677 window_->UpdatePreferredSize(source, pref_size);
1678}
1679
[email protected]61e2b3cc2012-03-02 16:13:341680void Browser::ResizeDueToAutoResize(WebContents* source,
1681 const gfx::Size& new_size) {
1682 window_->ResizeDueToAutoResize(source, new_size);
1683}
1684
[email protected]1d3e9172012-06-12 02:59:131685void Browser::FindReply(WebContents* web_contents,
[email protected]92655362012-04-20 21:33:171686 int request_id,
1687 int number_of_matches,
1688 const gfx::Rect& selection_rect,
1689 int active_match_ordinal,
1690 bool final_update) {
[email protected]1d3e9172012-06-12 02:59:131691 FindReplyHelper(web_contents, request_id, number_of_matches, selection_rect,
[email protected]92655362012-04-20 21:33:171692 active_match_ordinal, final_update);
1693}
1694
[email protected]1d3e9172012-06-12 02:59:131695void Browser::RequestToLockMouse(WebContents* web_contents,
[email protected]a9c81f02012-06-01 00:15:441696 bool user_gesture,
1697 bool last_unlocked_by_target) {
[email protected]1d3e9172012-06-12 02:59:131698 fullscreen_controller_->RequestToLockMouse(web_contents,
[email protected]a9c81f02012-06-01 00:15:441699 user_gesture,
1700 last_unlocked_by_target);
[email protected]55c87fa2011-10-15 07:28:281701}
1702
[email protected]5ef8e372011-10-18 04:25:551703void Browser::LostMouseLock() {
[email protected]01a5a762011-11-21 05:40:551704 fullscreen_controller_->LostMouseLock();
[email protected]5ef8e372011-10-18 04:25:551705}
1706
[email protected]f13b4202012-06-12 23:53:231707void Browser::RequestMediaAccessPermission(
1708 content::WebContents* web_contents,
1709 const content::MediaStreamRequest* request,
1710 const content::MediaResponseCallback& callback) {
[email protected]c55d3d122012-07-10 16:53:411711 RequestMediaAccessPermissionHelper(web_contents, request, callback);
[email protected]f13b4202012-06-12 23:53:231712}
1713
[email protected]36b6dcb2008-11-12 01:19:571714///////////////////////////////////////////////////////////////////////////////
[email protected]51d83bdf2011-12-09 16:09:291715// Browser, CoreTabHelperDelegate implementation:
[email protected]a0366a52011-02-04 20:04:211716
[email protected]3d61dd02012-06-07 00:05:531717void Browser::SwapTabContents(TabContents* old_tab_contents,
1718 TabContents* new_tab_contents) {
[email protected]2fc15ae2012-05-06 00:01:371719 int index = tab_strip_model_->GetIndexOfTabContents(old_tab_contents);
[email protected]92655362012-04-20 21:33:171720 DCHECK_NE(TabStripModel::kNoTab, index);
[email protected]2fc15ae2012-05-06 00:01:371721 tab_strip_model_->ReplaceTabContentsAt(index, new_tab_contents);
[email protected]92655362012-04-20 21:33:171722}
1723
[email protected]e1461952012-06-14 21:05:351724bool Browser::CanReloadContents(TabContents* source) const {
[email protected]5d98294912012-06-27 22:57:401725 return chrome::CanReload(this);
[email protected]e1461952012-06-14 21:05:351726}
1727
1728bool Browser::CanSaveContents(TabContents* source) const {
[email protected]5d98294912012-06-27 22:57:401729 return chrome::CanSavePage(this);
[email protected]e1461952012-06-14 21:05:351730}
1731
[email protected]92655362012-04-20 21:33:171732///////////////////////////////////////////////////////////////////////////////
1733// Browser, SearchEngineTabHelperDelegate implementation:
1734
[email protected]3613347d2012-04-27 20:27:371735void Browser::ConfirmAddSearchProvider(TemplateURL* template_url,
[email protected]92655362012-04-20 21:33:171736 Profile* profile) {
1737 window()->ConfirmAddSearchProvider(template_url, profile);
1738}
1739
1740///////////////////////////////////////////////////////////////////////////////
1741// Browser, ConstrainedWindowTabHelperDelegate implementation:
1742
[email protected]3d61dd02012-06-07 00:05:531743void Browser::SetTabContentBlocked(TabContents* tab_contents, bool blocked) {
1744 int index = tab_strip_model_->GetIndexOfTabContents(tab_contents);
[email protected]92655362012-04-20 21:33:171745 if (index == TabStripModel::kNoTab) {
1746 NOTREACHED();
1747 return;
1748 }
[email protected]2fc15ae2012-05-06 00:01:371749 tab_strip_model_->SetTabBlocked(index, blocked);
[email protected]5d98294912012-06-27 22:57:401750 command_controller_->PrintingStateChanged();
[email protected]52877dbc62012-06-29 22:22:031751 if (!blocked && chrome::GetActiveTabContents(this) == tab_contents)
[email protected]3d61dd02012-06-07 00:05:531752 tab_contents->web_contents()->Focus();
[email protected]92655362012-04-20 21:33:171753}
1754
1755///////////////////////////////////////////////////////////////////////////////
1756// Browser, BlockedContentTabHelperDelegate implementation:
1757
[email protected]2ae41f9d2012-06-11 20:13:381758TabContents* Browser::GetConstrainingTabContents(TabContents* source) {
[email protected]92655362012-04-20 21:33:171759 return source;
1760}
1761
1762///////////////////////////////////////////////////////////////////////////////
1763// Browser, BookmarkTabHelperDelegate implementation:
1764
[email protected]3d61dd02012-06-07 00:05:531765void Browser::URLStarredChanged(TabContents* source, bool starred) {
[email protected]52877dbc62012-06-29 22:22:031766 if (source == chrome::GetActiveTabContents(this))
[email protected]92655362012-04-20 21:33:171767 window_->SetStarredState(starred);
1768}
1769
1770///////////////////////////////////////////////////////////////////////////////
[email protected]6f80e932012-06-04 19:00:071771// Browser, ZoomObserver implementation:
1772
[email protected]5423c372012-08-22 05:50:161773void Browser::OnZoomChanged(TabContents* source, bool can_show_bubble) {
[email protected]52877dbc62012-06-29 22:22:031774 if (source == chrome::GetActiveTabContents(this)) {
[email protected]6f80e932012-06-04 19:00:071775 // Only show the zoom bubble for zoom changes in the active window.
[email protected]5423c372012-08-22 05:50:161776 window_->ZoomChangedForActiveTab(can_show_bubble && window_->IsActive());
[email protected]6f80e932012-06-04 19:00:071777 }
1778}
1779
1780///////////////////////////////////////////////////////////////////////////////
[email protected]92f54082012-07-31 01:43:141781// Browser, ui::SelectFileDialog::Listener implementation:
[email protected]36b6dcb2008-11-12 01:19:571782
[email protected]561abe62009-04-06 18:08:341783void Browser::FileSelected(const FilePath& path, int index, void* params) {
[email protected]53f04c82012-07-26 02:31:091784 FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params);
1785}
1786
1787void Browser::FileSelectedWithExtraInfo(
1788 const ui::SelectedFileInfo& file_info,
1789 int index,
1790 void* params) {
1791 profile_->set_last_selected_directory(file_info.file_path.DirName());
1792
1793 const FilePath& path = file_info.local_path;
[email protected]72cbd322009-04-07 10:17:121794 GURL file_url = net::FilePathToFileURL(path);
[email protected]b7813a22012-04-04 18:41:021795
1796#if defined(OS_CHROMEOS)
[email protected]06809de2012-09-07 05:51:051797 gdata::util::ModifyDriveFileResourceUrl(profile_, path, &file_url);
[email protected]b7813a22012-04-04 18:41:021798#endif
1799
[email protected]e5d549d2011-12-28 01:29:201800 if (file_url.is_empty())
1801 return;
1802
1803 OpenURL(OpenURLParams(
1804 file_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED,
1805 false));
[email protected]36b6dcb2008-11-12 01:19:571806}
1807
1808///////////////////////////////////////////////////////////////////////////////
[email protected]6c2381d2011-10-19 02:52:531809// Browser, content::NotificationObserver implementation:
[email protected]36b6dcb2008-11-12 01:19:571810
[email protected]432115822011-07-10 15:52:271811void Browser::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:531812 const content::NotificationSource& source,
1813 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:271814 switch (type) {
[email protected]432115822011-07-10 15:52:271815 case content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED:
[email protected]e83f1682008-09-07 23:57:401816 // When the current tab's SSL state changes, we need to update the URL
[email protected]90e8d062008-09-08 02:26:321817 // bar to reflect the new state. Note that it's possible for the selected
1818 // tab contents to be NULL. This is because we listen for all sources
1819 // (NavigationControllers) for convenience, so the notification could
1820 // actually be for a different window while we're doing asynchronous
1821 // closing of this one.
[email protected]52877dbc62012-06-29 22:22:031822 if (chrome::GetActiveWebContents(this) &&
1823 &chrome::GetActiveWebContents(this)->GetController() ==
[email protected]c5eed492012-01-04 17:07:501824 content::Source<NavigationController>(source).ptr())
[email protected]36b6dcb2008-11-12 01:19:571825 UpdateToolbar(false);
[email protected]e83f1682008-09-07 23:57:401826 break;
1827
[email protected]432115822011-07-10 15:52:271828 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
[email protected]ce696a452011-05-31 17:47:361829 if (window()->GetLocationBar())
1830 window()->GetLocationBar()->UpdatePageActions();
[email protected]57f71b92009-09-11 19:31:381831
[email protected]b3f7fe22011-11-11 19:27:561832 // Close any tabs from the unloaded extension, unless it's terminated,
1833 // in which case let the sad tabs remain.
[email protected]1c321ee2012-05-21 03:02:341834 if (content::Details<extensions::UnloadedExtensionInfo>(
1835 details)->reason != extension_misc::UNLOAD_REASON_TERMINATE) {
[email protected]b3f7fe22011-11-11 19:27:561836 const Extension* extension =
[email protected]1c321ee2012-05-21 03:02:341837 content::Details<extensions::UnloadedExtensionInfo>(
1838 details)->extension;
[email protected]2fc15ae2012-05-06 00:01:371839 for (int i = tab_strip_model_->count() - 1; i >= 0; --i) {
[email protected]52877dbc62012-06-29 22:22:031840 WebContents* tc = chrome::GetTabContentsAt(this, i)->web_contents();
[email protected]b3f7fe22011-11-11 19:27:561841 bool close_tab_contents =
1842 tc->GetURL().SchemeIs(chrome::kExtensionScheme) &&
1843 tc->GetURL().host() == extension->id();
1844 // We want to close all panels originated by the unloaded extension.
1845 close_tab_contents = close_tab_contents ||
1846 (type_ == TYPE_PANEL &&
1847 (web_app::GetExtensionIdFromApplicationName(app_name_) ==
[email protected]f9e82d92011-10-29 00:50:451848 extension->id()));
[email protected]52877dbc62012-06-29 22:22:031849 if (close_tab_contents)
1850 chrome::CloseWebContents(this, tc);
[email protected]894bb502009-05-21 22:39:571851 }
1852 }
1853 break;
1854 }
1855
[email protected]432115822011-07-10 15:52:271856 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:531857 Profile* profile = content::Source<Profile>(source).ptr();
[email protected]fe8944f2011-08-30 17:47:321858 if (profile_->IsSameProfile(profile) && window()->GetLocationBar())
[email protected]ce696a452011-05-31 17:47:361859 window()->GetLocationBar()->InvalidatePageActions();
[email protected]371ed7a2009-08-25 15:22:461860 break;
1861 }
1862
[email protected]432115822011-07-10 15:52:271863 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED:
1864 case chrome::NOTIFICATION_EXTENSION_LOADED:
[email protected]1797f4a2011-08-30 18:00:281865 // During window creation on Windows we may end up calling into
1866 // SHAppBarMessage, which internally spawns a nested message loop. This
1867 // makes it possible for us to end up here before window creation has
1868 // completed,at which point window_ is NULL. See 94752 for details.
1869 if (window() && window()->GetLocationBar())
[email protected]ce696a452011-05-31 17:47:361870 window()->GetLocationBar()->UpdatePageActions();
[email protected]0dfe05c2011-02-23 23:03:361871 break;
[email protected]ad0c2e1b2010-01-30 00:00:101872
[email protected]6b40bb582012-03-15 20:50:381873#if defined(ENABLE_THEMES)
[email protected]432115822011-07-10 15:52:271874 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
[email protected]e001d412009-06-26 20:53:251875 window()->UserChangedTheme();
1876 break;
[email protected]6b40bb582012-03-15 20:50:381877#endif
[email protected]e001d412009-06-26 20:53:251878
[email protected]432115822011-07-10 15:52:271879 case chrome::NOTIFICATION_PREF_CHANGED: {
[email protected]6c2381d2011-10-19 02:52:531880 const std::string& pref_name =
1881 *content::Details<std::string>(details).ptr();
[email protected]7acfaf92012-07-11 15:51:591882 if (pref_name == prefs::kDevToolsDisabled) {
[email protected]97b46382011-05-02 13:23:041883 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
[email protected]0e12d7d2011-12-01 16:21:441884 content::DevToolsManager::GetInstance()->CloseAllClientHosts();
[email protected]3710d0002011-10-11 00:35:001885 } else if (pref_name == prefs::kShowBookmarkBar) {
[email protected]3710d0002011-10-11 00:35:001886 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE);
[email protected]6c6b02d2011-09-02 03:36:471887 } else if (pref_name == prefs::kHomePage) {
[email protected]6c2381d2011-10-19 02:52:531888 PrefService* pref_service = content::Source<PrefService>(source).ptr();
[email protected]6c6b02d2011-09-02 03:36:471889 MarkHomePageAsChanged(pref_service);
[email protected]2a7e7c152010-10-01 20:12:091890 } else {
[email protected]b9c505b2010-04-30 15:05:101891 NOTREACHED();
[email protected]2a7e7c152010-10-01 20:12:091892 }
[email protected]b9c505b2010-04-30 15:05:101893 break;
1894 }
1895
[email protected]ea049a02011-12-25 21:37:091896 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: {
1897 WebContents* web_contents = content::Source<WebContents>(source).ptr();
[email protected]52877dbc62012-06-29 22:22:031898 if (web_contents == chrome::GetActiveWebContents(this)) {
[email protected]9a9a9e22011-05-13 22:20:351899 LocationBar* location_bar = window()->GetLocationBar();
1900 if (location_bar)
1901 location_bar->UpdateContentSettingsIcons();
1902 }
1903 break;
1904 }
1905
[email protected]432115822011-07-10 15:52:271906 case content::NOTIFICATION_INTERSTITIAL_ATTACHED:
[email protected]09b29342011-06-24 19:18:481907 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
[email protected]e397a4472011-12-21 21:47:501908 break;
1909
1910 case content::NOTIFICATION_INTERSTITIAL_DETACHED:
1911 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
[email protected]09b29342011-06-24 19:18:481912 break;
1913
[email protected]e83f1682008-09-07 23:57:401914 default:
1915 NOTREACHED() << "Got a notification we didn't register for.";
initial.commit09911bf2008-07-26 23:55:291916 }
1917}
1918
[email protected]d3b98c82010-07-14 07:45:591919///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:571920// Browser, Command and state updating (private):
1921
[email protected]6c6b02d2011-09-02 03:36:471922void Browser::MarkHomePageAsChanged(PrefService* pref_service) {
1923 pref_service->SetBoolean(prefs::kHomePageChanged, true);
[email protected]6c6b02d2011-09-02 03:36:471924}
1925
[email protected]36b6dcb2008-11-12 01:19:571926///////////////////////////////////////////////////////////////////////////////
1927// Browser, UI update coalescing and handling (private):
1928
1929void Browser::UpdateToolbar(bool should_restore_state) {
[email protected]52877dbc62012-06-29 22:22:031930 window_->UpdateToolbar(chrome::GetActiveTabContents(this),
1931 should_restore_state);
initial.commit09911bf2008-07-26 23:55:291932}
1933
[email protected]e3a5d5b2012-06-22 17:56:461934void Browser::UpdateSearchState(TabContents* contents) {
1935 if (chrome::search::IsInstantExtendedAPIEnabled(profile_))
1936 search_delegate_->OnTabActivated(contents);
1937}
1938
[email protected]2a6bc3e2011-12-28 23:51:331939void Browser::ScheduleUIUpdate(const WebContents* source,
[email protected]36b6dcb2008-11-12 01:19:571940 unsigned changed_flags) {
[email protected]a5231662009-09-26 00:56:001941 if (!source)
1942 return;
1943
[email protected]2b4355c2009-04-04 17:55:461944 // Do some synchronous updates.
[email protected]d9083482012-01-06 00:38:461945 if (changed_flags & content::INVALIDATE_TYPE_URL &&
[email protected]52877dbc62012-06-29 22:22:031946 source == chrome::GetActiveWebContents(this)) {
[email protected]36b6dcb2008-11-12 01:19:571947 // Only update the URL for the current tab. Note that we do not update
1948 // the navigation commands since those would have already been updated
1949 // synchronously by NavigationStateChanged.
1950 UpdateToolbar(false);
[email protected]d9083482012-01-06 00:38:461951 changed_flags &= ~content::INVALIDATE_TYPE_URL;
[email protected]36b6dcb2008-11-12 01:19:571952 }
[email protected]d9083482012-01-06 00:38:461953 if (changed_flags & content::INVALIDATE_TYPE_LOAD) {
[email protected]6ebdc9b2010-09-27 16:55:571954 // Update the loading state synchronously. This is so the throbber will
1955 // immediately start/stop, which gives a more snappy feel. We want to do
[email protected]a5231662009-09-26 00:56:001956 // this for any tab so they start & stop quickly.
[email protected]2fc15ae2012-05-06 00:01:371957 tab_strip_model_->UpdateTabContentsStateAt(
[email protected]52877dbc62012-06-29 22:22:031958 chrome::GetIndexOfTab(this, source),
[email protected]6ebdc9b2010-09-27 16:55:571959 TabStripModelObserver::LOADING_ONLY);
[email protected]d9083482012-01-06 00:38:461960 // The status bubble needs to be updated during INVALIDATE_TYPE_LOAD too,
1961 // but we do that asynchronously by not stripping INVALIDATE_TYPE_LOAD from
[email protected]6ebdc9b2010-09-27 16:55:571962 // changed_flags.
[email protected]8030f012009-09-25 18:09:371963 }
1964
[email protected]d9083482012-01-06 00:38:461965 if (changed_flags & content::INVALIDATE_TYPE_TITLE && !source->IsLoading()) {
[email protected]f1cd5e82009-10-23 17:19:031966 // To correctly calculate whether the title changed while not loading
1967 // we need to process the update synchronously. This state only matters for
1968 // the TabStripModel, so we notify the TabStripModel now and notify others
1969 // asynchronously.
[email protected]2fc15ae2012-05-06 00:01:371970 tab_strip_model_->UpdateTabContentsStateAt(
[email protected]52877dbc62012-06-29 22:22:031971 chrome::GetIndexOfTab(this, source),
[email protected]f1cd5e82009-10-23 17:19:031972 TabStripModelObserver::TITLE_NOT_LOADING);
1973 }
1974
[email protected]2b4355c2009-04-04 17:55:461975 // If the only updates were synchronously handled above, we're done.
[email protected]8030f012009-09-25 18:09:371976 if (changed_flags == 0)
[email protected]2b4355c2009-04-04 17:55:461977 return;
[email protected]36b6dcb2008-11-12 01:19:571978
1979 // Save the dirty bits.
[email protected]85354982009-09-25 19:58:401980 scheduled_updates_[source] |= changed_flags;
[email protected]36b6dcb2008-11-12 01:19:571981
[email protected]24f1477532011-11-22 22:55:361982 if (!chrome_updater_factory_.HasWeakPtrs()) {
[email protected]36b6dcb2008-11-12 01:19:571983 // No task currently scheduled, start another.
[email protected]0586b0e2010-02-12 21:38:371984 MessageLoop::current()->PostDelayedTask(
1985 FROM_HERE,
[email protected]24f1477532011-11-22 22:55:361986 base::Bind(&Browser::ProcessPendingUIUpdates,
1987 chrome_updater_factory_.GetWeakPtr()),
[email protected]11d6ab1a2012-01-12 21:37:261988 base::TimeDelta::FromMilliseconds(kUIUpdateCoalescingTimeMS));
[email protected]36b6dcb2008-11-12 01:19:571989 }
1990}
1991
1992void Browser::ProcessPendingUIUpdates() {
1993#ifndef NDEBUG
1994 // Validate that all tabs we have pending updates for exist. This is scary
1995 // because the pending list must be kept in sync with any detached or
[email protected]a5231662009-09-26 00:56:001996 // deleted tabs.
[email protected]85354982009-09-25 19:58:401997 for (UpdateMap::const_iterator i = scheduled_updates_.begin();
1998 i != scheduled_updates_.end(); ++i) {
[email protected]36b6dcb2008-11-12 01:19:571999 bool found = false;
2000 for (int tab = 0; tab < tab_count(); tab++) {
[email protected]52877dbc62012-06-29 22:22:032001 if (chrome::GetWebContentsAt(this, tab) == i->first) {
[email protected]36b6dcb2008-11-12 01:19:572002 found = true;
2003 break;
2004 }
2005 }
2006 DCHECK(found);
2007 }
2008#endif
2009
[email protected]24f1477532011-11-22 22:55:362010 chrome_updater_factory_.InvalidateWeakPtrs();
[email protected]36b6dcb2008-11-12 01:19:572011
[email protected]85354982009-09-25 19:58:402012 for (UpdateMap::const_iterator i = scheduled_updates_.begin();
2013 i != scheduled_updates_.end(); ++i) {
[email protected]36b6dcb2008-11-12 01:19:572014 // Do not dereference |contents|, it may be out-of-date!
[email protected]2a6bc3e2011-12-28 23:51:332015 const WebContents* contents = i->first;
[email protected]85354982009-09-25 19:58:402016 unsigned flags = i->second;
[email protected]36b6dcb2008-11-12 01:19:572017
[email protected]52877dbc62012-06-29 22:22:032018 if (contents == chrome::GetActiveWebContents(this)) {
[email protected]a5231662009-09-26 00:56:002019 // Updates that only matter when the tab is selected go here.
[email protected]f7f3a5f2009-05-01 22:02:342020
[email protected]d9083482012-01-06 00:38:462021 if (flags & content::INVALIDATE_TYPE_PAGE_ACTIONS) {
[email protected]9800de5e2011-03-11 18:19:492022 LocationBar* location_bar = window()->GetLocationBar();
2023 if (location_bar)
2024 location_bar->UpdatePageActions();
2025 }
[email protected]6ebdc9b2010-09-27 16:55:572026 // Updating the URL happens synchronously in ScheduleUIUpdate.
[email protected]d9083482012-01-06 00:38:462027 if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) {
[email protected]52877dbc62012-06-29 22:22:032028 GetStatusBubble()->SetStatus(chrome::GetActiveTabContents(this)->
2029 core_tab_helper()->GetStatusText());
[email protected]0dd3a0ab2011-02-18 08:17:442030 }
[email protected]a5231662009-09-26 00:56:002031
[email protected]d9083482012-01-06 00:38:462032 if (flags & (content::INVALIDATE_TYPE_TAB |
2033 content::INVALIDATE_TYPE_TITLE)) {
[email protected]a5231662009-09-26 00:56:002034 window_->UpdateTitleBar();
2035 }
[email protected]4d34e2e2009-05-26 22:55:282036 }
[email protected]36b6dcb2008-11-12 01:19:572037
[email protected]a5231662009-09-26 00:56:002038 // Updates that don't depend upon the selected state go here.
[email protected]d9083482012-01-06 00:38:462039 if (flags &
2040 (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) {
[email protected]2fc15ae2012-05-06 00:01:372041 tab_strip_model_->UpdateTabContentsStateAt(
[email protected]e52d0a42012-06-08 22:44:162042 tab_strip_model_->GetIndexOfWebContents(contents),
[email protected]f1cd5e82009-10-23 17:19:032043 TabStripModelObserver::ALL);
[email protected]36b6dcb2008-11-12 01:19:572044 }
2045
2046 // We don't need to process INVALIDATE_STATE, since that's not visible.
2047 }
2048
2049 scheduled_updates_.clear();
2050}
2051
[email protected]d9083482012-01-06 00:38:462052void Browser::RemoveScheduledUpdatesFor(WebContents* contents) {
[email protected]36b6dcb2008-11-12 01:19:572053 if (!contents)
2054 return;
2055
[email protected]85354982009-09-25 19:58:402056 UpdateMap::iterator i = scheduled_updates_.find(contents);
2057 if (i != scheduled_updates_.end())
2058 scheduled_updates_.erase(i);
initial.commit09911bf2008-07-26 23:55:292059}
2060
[email protected]d938aed92009-01-22 19:49:332061
[email protected]36b6dcb2008-11-12 01:19:572062///////////////////////////////////////////////////////////////////////////////
2063// Browser, Getters for UI (private):
initial.commit09911bf2008-07-26 23:55:292064
[email protected]36b6dcb2008-11-12 01:19:572065StatusBubble* Browser::GetStatusBubble() {
[email protected]34930432009-11-09 00:12:092066 // In kiosk mode, we want to always hide the status bubble.
2067 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
2068 return NULL;
[email protected]9b032bf2009-07-21 17:34:232069 return window_ ? window_->GetStatusBubble() : NULL;
initial.commit09911bf2008-07-26 23:55:292070}
2071
[email protected]36b6dcb2008-11-12 01:19:572072///////////////////////////////////////////////////////////////////////////////
2073// Browser, Session restore functions (private):
initial.commit09911bf2008-07-26 23:55:292074
2075void Browser::SyncHistoryWithTabs(int index) {
[email protected]92371eb2011-04-28 11:50:152076 SessionService* session_service =
2077 SessionServiceFactory::GetForProfileIfExisting(profile());
initial.commit09911bf2008-07-26 23:55:292078 if (session_service) {
2079 for (int i = index; i < tab_count(); ++i) {
[email protected]52877dbc62012-06-29 22:22:032080 TabContents* tab = chrome::GetTabContentsAt(this, i);
[email protected]81898992011-06-14 22:15:002081 if (tab) {
initial.commit09911bf2008-07-26 23:55:292082 session_service->SetTabIndexInWindow(
[email protected]bde40b822012-08-30 17:28:562083 session_id(), tab->session_tab_helper()->session_id(), i);
[email protected]ecc523f62010-09-28 22:45:402084 session_service->SetPinnedState(
2085 session_id(),
[email protected]bde40b822012-08-30 17:28:562086 tab->session_tab_helper()->session_id(),
[email protected]52877dbc62012-06-29 22:22:032087 tab_strip_model_->IsTabPinned(i));
initial.commit09911bf2008-07-26 23:55:292088 }
2089 }
2090 }
2091}
2092
[email protected]36b6dcb2008-11-12 01:19:572093///////////////////////////////////////////////////////////////////////////////
[email protected]69444cc2009-04-09 20:40:062094// Browser, In-progress download termination handling (private):
2095
[email protected]b6a4ac2b2011-10-17 20:05:482096bool Browser::CanCloseWithInProgressDownloads() {
[email protected]5a17d492011-10-24 19:37:032097 // If we've prompted, we need to hear from the user before we
2098 // can close.
2099 if (cancel_download_confirmation_state_ != NOT_PROMPTED)
2100 return cancel_download_confirmation_state_ != WAITING_FOR_RESPONSE;
2101
2102 int num_downloads_blocking;
2103 if (DOWNLOAD_CLOSE_OK ==
2104 OkToCloseWithInProgressDownloads(&num_downloads_blocking))
[email protected]446295a2010-04-19 23:43:002105 return true;
2106
[email protected]5a17d492011-10-24 19:37:032107 // Closing this window will kill some downloads; prompt to make sure
2108 // that's ok.
[email protected]69444cc2009-04-09 20:40:062109 cancel_download_confirmation_state_ = WAITING_FOR_RESPONSE;
2110 window_->ConfirmBrowserCloseWithPendingDownloads();
2111
2112 // Return false so the browser does not close. We'll close if the user
2113 // confirms in the dialog.
2114 return false;
2115}
2116
2117///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:572118// Browser, Assorted utility functions (private):
initial.commit09911bf2008-07-26 23:55:292119
[email protected]36b6dcb2008-11-12 01:19:572120void Browser::CloseFrame() {
2121 window_->Close();
initial.commit09911bf2008-07-26 23:55:292122}
2123
[email protected]3d61dd02012-06-07 00:05:532124void Browser::TabDetachedAtImpl(TabContents* contents, int index,
[email protected]c37e3b62010-01-22 00:15:172125 DetachType type) {
2126 if (type == DETACH_TYPE_DETACH) {
[email protected]56580852010-11-17 16:09:152127 // Save the current location bar state, but only if the tab being detached
2128 // is the selected tab. Because saving state can conditionally revert the
2129 // location bar, saving the current tab's location bar state to a
2130 // non-selected tab can corrupt both tabs.
[email protected]52877dbc62012-06-29 22:22:032131 if (contents == chrome::GetActiveTabContents(this)) {
[email protected]9800de5e2011-03-11 18:19:492132 LocationBar* location_bar = window()->GetLocationBar();
2133 if (location_bar)
[email protected]83a2610a2012-01-05 01:00:272134 location_bar->SaveStateToContents(contents->web_contents());
[email protected]9800de5e2011-03-11 18:19:492135 }
[email protected]c37e3b62010-01-22 00:15:172136
[email protected]2fc15ae2012-05-06 00:01:372137 if (!tab_strip_model_->closing_all())
[email protected]c37e3b62010-01-22 00:15:172138 SyncHistoryWithTabs(0);
2139 }
2140
[email protected]6451fe92012-08-30 18:37:262141 SetAsDelegate(contents->web_contents(), NULL);
[email protected]d9083482012-01-06 00:38:462142 RemoveScheduledUpdatesFor(contents->web_contents());
[email protected]c37e3b62010-01-22 00:15:172143
[email protected]41f022e2012-01-31 05:56:402144 if (find_bar_controller_.get() && index == active_index()) {
[email protected]c37e3b62010-01-22 00:15:172145 find_bar_controller_->ChangeTabContents(NULL);
[email protected]ecc523f62010-09-28 22:45:402146 }
[email protected]c37e3b62010-01-22 00:15:172147
[email protected]e3a5d5b2012-06-22 17:56:462148 // Stop observing search model changes for this tab.
2149 search_delegate_->OnTabDetached(contents);
2150
[email protected]432115822011-07-10 15:52:272151 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED,
[email protected]fbc5e5f92012-01-02 06:08:322152 content::Source<WebContents>(contents->web_contents()));
[email protected]e397a4472011-12-21 21:47:502153 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED,
[email protected]4b19ea52012-01-02 20:15:252154 content::Source<WebContents>(contents->web_contents()));
[email protected]c37e3b62010-01-22 00:15:172155}
2156
[email protected]92655362012-04-20 21:33:172157bool Browser::SupportsWindowFeatureImpl(WindowFeature feature,
2158 bool check_fullscreen) const {
2159 // On Mac, fullscreen mode has most normal things (in a slide-down panel). On
2160 // other platforms, we hide some controls when in fullscreen mode.
2161 bool hide_ui_for_fullscreen = false;
2162#if !defined(OS_MACOSX)
2163 hide_ui_for_fullscreen = check_fullscreen && window_ &&
2164 window_->IsFullscreen();
2165#endif
2166
2167 unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF;
2168
2169 if (is_type_tabbed())
2170 features |= FEATURE_BOOKMARKBAR;
2171
2172 if (!hide_ui_for_fullscreen) {
2173 if (!is_type_tabbed())
2174 features |= FEATURE_TITLEBAR;
2175
2176 if (is_type_tabbed())
2177 features |= FEATURE_TABSTRIP;
2178
2179 if (is_type_tabbed())
2180 features |= FEATURE_TOOLBAR;
2181
2182 if (!is_app())
2183 features |= FEATURE_LOCATIONBAR;
2184 }
2185 return !!(features & feature);
2186}
2187
[email protected]09b29342011-06-24 19:18:482188void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) {
2189 BookmarkBar::State state;
[email protected]227393e2011-06-29 21:28:392190 // The bookmark bar is hidden in fullscreen mode, unless on the new tab page.
[email protected]3710d0002011-10-11 00:35:002191 if (browser_defaults::bookmarks_enabled &&
2192 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) &&
[email protected]227393e2011-06-29 21:28:392193 (!window_ || !window_->IsFullscreen())) {
[email protected]09b29342011-06-24 19:18:482194 state = BookmarkBar::SHOW;
2195 } else {
[email protected]52877dbc62012-06-29 22:22:032196 TabContents* tab = chrome::GetActiveTabContents(this);
[email protected]09b29342011-06-24 19:18:482197 if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar())
2198 state = BookmarkBar::DETACHED;
2199 else
2200 state = BookmarkBar::HIDDEN;
2201 }
[email protected]2d4e43a02012-06-26 00:11:552202
2203 // Only allow the bookmark bar to be shown in default mode.
2204 if (!search_model_->mode().is_default())
2205 state = BookmarkBar::HIDDEN;
2206
[email protected]09b29342011-06-24 19:18:482207 if (state == bookmark_bar_state_)
2208 return;
2209
2210 bookmark_bar_state_ = state;
2211
2212 if (!window_)
2213 return; // This is called from the constructor when window_ is NULL.
2214
2215 if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) {
2216 // Don't notify BrowserWindow on a tab switch as at the time this is invoked
2217 // BrowserWindow hasn't yet switched tabs. The BrowserWindow implementations
2218 // end up querying state once they process the tab switch.
2219 return;
2220 }
2221
2222 BookmarkBar::AnimateChangeType animate_type =
2223 (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE) ?
2224 BookmarkBar::ANIMATE_STATE_CHANGE :
2225 BookmarkBar::DONT_ANIMATE_STATE_CHANGE;
2226 window_->BookmarkBarStateChanged(animate_type);
2227}
[email protected]2e2cacc2011-07-12 21:54:262228
[email protected]92655362012-04-20 21:33:172229bool Browser::MaybeCreateBackgroundContents(int route_id,
2230 WebContents* opener_web_contents,
2231 const string16& frame_name,
2232 const GURL& target_url) {
2233 GURL opener_url = opener_web_contents->GetURL();
2234 ExtensionService* extensions_service = profile_->GetExtensionService();
2235
2236 if (!opener_url.is_valid() ||
2237 frame_name.empty() ||
2238 !extensions_service ||
2239 !extensions_service->is_ready())
2240 return false;
2241
2242 // Only hosted apps have web extents, so this ensures that only hosted apps
2243 // can create BackgroundContents. We don't have to check for background
2244 // permission as that is checked in RenderMessageFilter when the CreateWindow
2245 // message is processed.
2246 const Extension* extension =
2247 extensions_service->extensions()->GetHostedAppByURL(
2248 ExtensionURLInfo(opener_url));
2249 if (!extension)
2250 return false;
2251
2252 // No BackgroundContents allowed if BackgroundContentsService doesn't exist.
2253 BackgroundContentsService* service =
2254 BackgroundContentsServiceFactory::GetForProfile(profile_);
2255 if (!service)
2256 return false;
2257
2258 // Ensure that we're trying to open this from the extension's process.
2259 SiteInstance* opener_site_instance = opener_web_contents->GetSiteInstance();
2260 extensions::ProcessMap* process_map = extensions_service->process_map();
2261 if (!opener_site_instance->GetProcess() ||
2262 !process_map->Contains(
2263 extension->id(), opener_site_instance->GetProcess()->GetID())) {
2264 return false;
2265 }
2266
2267 // Only allow a single background contents per app.
2268 bool allow_js_access = extension->allow_background_js_access();
2269 BackgroundContents* existing =
2270 service->GetAppBackgroundContents(ASCIIToUTF16(extension->id()));
2271 if (existing) {
2272 // For non-scriptable background contents, ignore the request altogether,
2273 // (returning true, so that a regular WebContents isn't created either).
2274 if (!allow_js_access)
2275 return true;
2276 // For scriptable background pages, if one already exists, close it (even
2277 // if it was specified in the manifest).
2278 DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url;
2279 delete existing;
2280 }
2281
2282 // If script access is not allowed, create the the background contents in a
2283 // new SiteInstance, so that a separate process is used.
2284 scoped_refptr<content::SiteInstance> site_instance =
2285 allow_js_access ?
2286 opener_site_instance :
2287 content::SiteInstance::Create(opener_web_contents->GetBrowserContext());
2288
2289 // Passed all the checks, so this should be created as a BackgroundContents.
2290 BackgroundContents* contents = service->CreateBackgroundContents(
2291 site_instance,
2292 route_id,
2293 profile_,
2294 frame_name,
2295 ASCIIToUTF16(extension->id()));
2296
2297 // When a separate process is used, the original renderer cannot access the
2298 // new window later, thus we need to navigate the window now.
2299 if (contents && !allow_js_access) {
2300 contents->web_contents()->GetController().LoadURL(
2301 target_url,
2302 content::Referrer(),
2303 content::PAGE_TRANSITION_LINK,
2304 std::string()); // No extra headers.
2305 }
2306
2307 return contents != NULL;
[email protected]afcb43562011-09-02 23:33:382308}