blob: ce7a5dc2a49086c927522347258f7127ddc9c675 [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]9c55de82012-11-01 21:03:5210#endif // defined(OS_WIN)
[email protected]aca02cf2010-05-03 18:56:0111
[email protected]5dcbc02f2010-01-26 22:32:0612#include <algorithm>
13#include <string>
14
[email protected]b02d0382009-11-30 21:19:5015#include "base/base_paths.h"
[email protected]24f1477532011-11-22 22:55:3616#include "base/bind.h"
[email protected]8a53ee042009-01-21 16:41:3317#include "base/command_line.h"
[email protected]8a53ee042009-01-21 16:41:3318#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/histogram.h"
[email protected]b02d0382009-11-30 21:19:5020#include "base/path_service.h"
[email protected]b5febf72012-07-29 18:10:0921#include "base/process_info.h"
[email protected]0af8f132011-07-16 01:37:0222#include "base/string_number_conversions.h"
[email protected]b6a4ac2b2011-10-17 20:05:4823#include "base/string_util.h"
[email protected]5a17d492011-10-24 19:37:0324#include "base/stringprintf.h"
[email protected]34b99632011-01-01 01:01:0625#include "base/threading/thread.h"
26#include "base/threading/thread_restrictions.h"
[email protected]7f070d42011-03-09 20:25:3227#include "base/time.h"
[email protected]6524385ef2010-08-18 06:34:1328#include "base/utf_string_conversions.h"
[email protected]1a3aba82010-11-08 23:52:5429#include "chrome/app/chrome_command_ids.h"
[email protected]77a91c72012-08-13 16:19:3430#include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h"
[email protected]ea9edcb02011-09-23 22:05:0431#include "chrome/browser/autofill/personal_data_manager_factory.h"
[email protected]a07676b22011-06-17 16:36:5332#include "chrome/browser/background/background_contents_service.h"
[email protected]4fdf6742012-01-10 20:14:3633#include "chrome/browser/background/background_contents_service_factory.h"
[email protected]a9afddb2009-02-12 17:49:4234#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]b3ac5c82009-10-08 20:56:5435#include "chrome/browser/bookmarks/bookmark_utils.h"
[email protected]5c238752009-06-13 10:29:0736#include "chrome/browser/browser_process.h"
[email protected]c61db1d2009-02-06 03:39:1837#include "chrome/browser/browser_shutdown.h"
[email protected]40d59ce52009-03-06 23:20:1438#include "chrome/browser/character_encoding.h"
[email protected]0f083402011-11-22 02:59:0139#include "chrome/browser/chrome_page_zoom.h"
[email protected]55c87fa2011-10-15 07:28:2840#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]7ae9c322012-07-17 23:46:4441#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]7d189022011-08-25 22:54:2042#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
43#include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h"
[email protected]dce502762011-07-20 08:53:4944#include "chrome/browser/debugger/devtools_toggle_action.h"
45#include "chrome/browser/debugger/devtools_window.h"
[email protected]7fb4bbb2012-05-27 18:06:2246#include "chrome/browser/download/download_crx_util.h"
[email protected]59560e0b2009-06-04 03:30:2247#include "chrome/browser/download/download_item_model.h"
[email protected]9bb54ee2011-10-12 17:43:3548#include "chrome/browser/download/download_service.h"
49#include "chrome/browser/download/download_service_factory.h"
[email protected]a1bc3b82012-04-19 19:32:2050#include "chrome/browser/download/download_shelf.h"
[email protected]59560e0b2009-06-04 03:30:2251#include "chrome/browser/download/download_started_animation.h"
[email protected]a53209b2012-01-20 16:48:1652#include "chrome/browser/download/download_util.h"
[email protected]9c1662b2012-03-06 15:44:3353#include "chrome/browser/extensions/browser_extension_window_controller.h"
[email protected]10abd192010-09-30 02:03:4954#include "chrome/browser/extensions/extension_prefs.h"
[email protected]eaa7dd182010-12-14 11:09:0055#include "chrome/browser/extensions/extension_service.h"
[email protected]a6394ae2012-07-16 20:58:4356#include "chrome/browser/extensions/tab_helper.h"
[email protected]b375c5d2011-05-03 21:15:0457#include "chrome/browser/favicon/favicon_tab_helper.h"
[email protected]3a29a6e2011-08-24 18:26:2158#include "chrome/browser/file_select_helper.h"
[email protected]820735792010-07-29 23:40:0159#include "chrome/browser/first_run/first_run.h"
[email protected]f7578f52010-08-30 22:22:4960#include "chrome/browser/google/google_url_tracker.h"
[email protected]7e204122011-09-01 18:56:2161#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]65c81142012-07-31 19:44:4362#include "chrome/browser/intents/device_attached_intent_source.h"
[email protected]7d189022011-08-25 22:54:2063#include "chrome/browser/intents/register_intent_handler_infobar_delegate.h"
[email protected]59d73ec2012-09-01 02:24:2764#include "chrome/browser/intents/web_intents_reporting.h"
[email protected]8f0bbd62012-02-22 03:37:1865#include "chrome/browser/intents/web_intents_util.h"
[email protected]2e6389f2012-05-18 19:41:2566#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]4afde5c2012-06-25 17:00:5367#include "chrome/browser/media/media_stream_devices_controller.h"
[email protected]a239c3f2009-02-17 22:13:1968#include "chrome/browser/net/url_fixer_upper.h"
[email protected]2c4fb7b2011-04-02 06:33:2969#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]14a000d2010-04-29 21:44:2470#include "chrome/browser/platform_util.h"
[email protected]4e94ab32011-08-05 05:28:2771#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]37858e52010-08-26 00:22:0272#include "chrome/browser/prefs/pref_service.h"
[email protected]02337592010-09-27 18:38:2573#include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h"
[email protected]0996e9b2011-08-26 17:59:0174#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]8ecad5e2010-12-02 21:18:3375#include "chrome/browser/profiles/profile.h"
[email protected]5e919242012-02-13 23:59:3576#include "chrome/browser/profiles/profile_destroyer.h"
[email protected]5a17d492011-10-24 19:37:0377#include "chrome/browser/profiles/profile_manager.h"
[email protected]a7be6982011-12-12 21:53:5778#include "chrome/browser/profiles/profile_metrics.h"
[email protected]67baffc82011-12-19 18:03:0779#include "chrome/browser/repost_form_warning_controller.h"
[email protected]85e921fb82009-02-11 23:19:4480#include "chrome/browser/sessions/session_service.h"
[email protected]92371eb2011-04-28 11:50:1581#include "chrome/browser/sessions/session_service_factory.h"
[email protected]bde40b822012-08-30 17:28:5682#include "chrome/browser/sessions/session_tab_helper.h"
[email protected]c61db1d2009-02-06 03:39:1883#include "chrome/browser/sessions/session_types.h"
[email protected]92926d92010-09-02 18:35:0684#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]92371eb2011-04-28 11:50:1585#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]066629f2009-10-17 00:28:1386#include "chrome/browser/sync/profile_sync_service.h"
[email protected]5e61afb92012-01-27 20:09:1387#include "chrome/browser/sync/profile_sync_service_factory.h"
[email protected]40f047972009-11-25 03:54:4088#include "chrome/browser/sync/sync_ui_util.h"
[email protected]2c4fb7b2011-04-02 06:33:2989#include "chrome/browser/tab_contents/background_contents.h"
[email protected]4fdf6742012-01-10 20:14:3690#include "chrome/browser/tab_contents/retargeting_details.h"
[email protected]1ab4ddf2011-07-21 04:48:0491#include "chrome/browser/tab_contents/tab_util.h"
[email protected]ffa6f592011-06-24 22:03:5792#include "chrome/browser/themes/theme_service.h"
93#include "chrome/browser/themes/theme_service_factory.h"
[email protected]82194b5fb2012-05-22 23:53:0794#include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h"
[email protected]35699d572011-05-11 19:46:1495#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
[email protected]5d98294912012-06-27 22:57:4096#include "chrome/browser/ui/browser_command_controller.h"
[email protected]a37d4b02012-06-25 21:56:1097#include "chrome/browser/ui/browser_commands.h"
[email protected]ef557022012-03-16 10:05:3398#include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
[email protected]55452902011-06-01 21:57:4799#include "chrome/browser/ui/browser_dialogs.h"
[email protected]d8748142012-05-16 21:13:43100#include "chrome/browser/ui/browser_finder.h"
[email protected]7acfaf92012-07-11 15:51:59101#include "chrome/browser/ui/browser_instant_controller.h"
[email protected]6768ac02011-04-06 17:41:04102#include "chrome/browser/ui/browser_list.h"
[email protected]fcca741b2011-06-17 22:46:37103#include "chrome/browser/ui/browser_navigator.h"
[email protected]fb7da4132011-03-15 15:51:00104#include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
[email protected]855370052012-07-10 19:30:32105#include "chrome/browser/ui/browser_tab_strip_model_delegate.h"
[email protected]52877dbc62012-06-29 22:22:03106#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]ef557022012-03-16 10:05:33107#include "chrome/browser/ui/browser_toolbar_model_delegate.h"
[email protected]2cd4fde2012-06-26 03:10:26108#include "chrome/browser/ui/browser_ui_prefs.h"
[email protected]00070c732011-04-09 15:31:33109#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:12110#include "chrome/browser/ui/chrome_pages.h"
[email protected]6e1fcd12012-07-02 17:14:20111#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]a44657202012-01-09 05:48:31112#include "chrome/browser/ui/extensions/shell_window.h"
[email protected]45300ad42010-12-02 15:51:14113#include "chrome/browser/ui/find_bar/find_bar.h"
114#include "chrome/browser/ui/find_bar/find_bar_controller.h"
[email protected]c90c6ca2011-02-16 20:11:38115#include "chrome/browser/ui/find_bar/find_tab_helper.h"
[email protected]9d5c059a82012-06-29 20:13:07116#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
[email protected]1ba55cf2012-06-29 19:11:39117#include "chrome/browser/ui/global_error/global_error.h"
118#include "chrome/browser/ui/global_error/global_error_service.h"
119#include "chrome/browser/ui/global_error/global_error_service_factory.h"
[email protected]943b8612011-08-31 21:07:13120#include "chrome/browser/ui/intents/web_intent_picker_controller.h"
[email protected]f13b4202012-06-12 23:53:23121#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]6a3ec2312010-12-02 19:30:19122#include "chrome/browser/ui/omnibox/location_bar.h"
[email protected]e3a5d5b2012-06-22 17:56:46123#include "chrome/browser/ui/search/search.h"
124#include "chrome/browser/ui/search/search_delegate.h"
125#include "chrome/browser/ui/search/search_model.h"
[email protected]c3166302012-09-25 21:27:08126#include "chrome/browser/ui/search/search_types.h"
[email protected]5d9cace72012-06-21 16:07:12127#include "chrome/browser/ui/singleton_tabs.h"
[email protected]6a3ec2312010-12-02 19:30:19128#include "chrome/browser/ui/status_bubble.h"
[email protected]3da95a102011-11-30 21:47:45129#include "chrome/browser/ui/sync/browser_synced_window_delegate.h"
[email protected]51d83bdf2011-12-09 16:09:29130#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
[email protected]3d61dd02012-06-07 00:05:53131#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]51296c62012-09-26 13:02:44132#include "chrome/browser/ui/tab_modal_confirm_dialog.h"
[email protected]9a800652010-12-02 17:08:44133#include "chrome/browser/ui/tabs/dock_info.h"
[email protected]6a3ec2312010-12-02 19:30:19134#include "chrome/browser/ui/tabs/tab_menu_model.h"
[email protected]b56e2e32012-05-11 21:18:04135#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]736d00322012-10-11 21:32:41136#include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
[email protected]f9b6c092012-07-09 19:32:28137#include "chrome/browser/ui/unload_controller.h"
[email protected]f847e6082011-03-24 00:08:26138#include "chrome/browser/ui/web_applications/web_app_ui.h"
[email protected]65549182012-02-25 00:45:40139#include "chrome/browser/ui/webui/signin/login_ui_service.h"
140#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
[email protected]03639422012-06-28 19:03:37141#include "chrome/browser/ui/window_sizer/window_sizer.h"
[email protected]b1b73942010-05-26 20:11:54142#include "chrome/browser/upgrade_detector.h"
[email protected]86b54012009-11-19 09:18:50143#include "chrome/browser/web_applications/web_app.h"
[email protected]d938aed92009-01-22 19:49:33144#include "chrome/common/chrome_constants.h"
[email protected]432115822011-07-10 15:52:27145#include "chrome/common/chrome_notification_types.h"
[email protected]d938aed92009-01-22 19:49:33146#include "chrome/common/chrome_switches.h"
[email protected]7d189022011-08-25 22:54:20147#include "chrome/common/custom_handlers/protocol_handler.h"
[email protected]5b1a0e22009-05-26 19:00:58148#include "chrome/common/extensions/extension.h"
[email protected]46fd1ea42011-02-16 15:59:33149#include "chrome/common/extensions/extension_constants.h"
[email protected]8a53ee042009-01-21 16:41:33150#include "chrome/common/pref_names.h"
[email protected]7664ab32011-02-01 23:35:25151#include "chrome/common/profiling.h"
[email protected]b5febf72012-07-29 18:10:09152#include "chrome/common/startup_metric_utils.h"
[email protected]b689fce72009-03-17 22:45:34153#include "chrome/common/url_constants.h"
[email protected]bb461532010-11-26 21:50:23154#include "chrome/common/web_apps.h"
[email protected]da8543762012-03-20 08:52:20155#include "content/public/browser/color_chooser.h"
[email protected]0e12d7d2011-12-01 16:21:44156#include "content/public/browser/devtools_manager.h"
[email protected]e582fdd2011-12-20 16:48:17157#include "content/public/browser/download_item.h"
158#include "content/public/browser/download_manager.h"
[email protected]cadaec52012-02-08 21:53:13159#include "content/public/browser/interstitial_page.h"
[email protected]d9083482012-01-06 00:38:46160#include "content/public/browser/invalidate_type.h"
[email protected]cdcb1dee2012-01-04 00:46:20161#include "content/public/browser/navigation_controller.h"
[email protected]022af742011-12-28 18:37:25162#include "content/public/browser/navigation_entry.h"
[email protected]7f6f44c2011-12-14 13:23:38163#include "content/public/browser/notification_details.h"
164#include "content/public/browser/notification_service.h"
[email protected]3a5180ae2011-12-21 02:39:38165#include "content/public/browser/plugin_service.h"
[email protected]9c1662b2012-03-06 15:44:33166#include "content/public/browser/render_process_host.h"
167#include "content/public/browser/render_view_host.h"
[email protected]b6583592012-01-25 19:52:33168#include "content/public/browser/site_instance.h"
[email protected]7f6f44c2011-12-14 13:23:38169#include "content/public/browser/user_metrics.h"
[email protected]d9083482012-01-06 00:38:46170#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10171#include "content/public/browser/web_contents_view.h"
[email protected]0d9989d2011-12-21 20:26:00172#include "content/public/browser/web_intents_dispatcher.h"
[email protected]4573fbd2011-10-31 20:25:18173#include "content/public/common/content_restriction.h"
[email protected]c08950d22011-10-13 22:20:29174#include "content/public/common/content_switches.h"
[email protected]0f083402011-11-22 02:59:01175#include "content/public/common/page_zoom.h"
[email protected]cadaec52012-02-08 21:53:13176#include "content/public/common/renderer_preferences.h"
[email protected]a3e18c42009-03-04 23:36:05177#include "grit/chromium_strings.h"
178#include "grit/generated_resources.h"
179#include "grit/locale_settings.h"
[email protected]2a2813352012-07-11 22:20:23180#include "grit/theme_resources.h"
[email protected]8a53ee042009-01-21 16:41:33181#include "net/base/net_util.h"
[email protected]be28b5f42012-07-20 11:31:25182#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]4d7c4ef2012-03-16 01:47:12183#include "net/cookies/cookie_monster.h"
[email protected]8a53ee042009-01-21 16:41:33184#include "net/url_request/url_request_context.h"
[email protected]f67678062011-01-07 17:33:39185#include "ui/base/animation/animation.h"
[email protected]53f04c82012-07-26 02:31:09186#include "ui/base/dialogs/selected_file_info.h"
[email protected]c051a1b2011-01-21 23:30:17187#include "ui/base/l10n/l10n_util.h"
[email protected]08397d52011-02-05 01:53:38188#include "ui/gfx/point.h"
[email protected]ce9751942011-09-21 01:57:24189#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:36190#include "webkit/glue/web_intent_service_data.h"
[email protected]4a19be92011-09-22 14:25:02191#include "webkit/glue/webkit_glue.h"
[email protected]d938aed92009-01-22 19:49:33192#include "webkit/glue/window_open_disposition.h"
[email protected]3a5180ae2011-12-21 02:39:38193#include "webkit/plugins/webplugininfo.h"
[email protected]8a53ee042009-01-21 16:41:33194
195#if defined(OS_WIN)
[email protected]77cbe50e2012-06-14 02:44:38196#include "base/win/metro.h"
[email protected]36d5e5592010-11-15 20:45:59197#include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h"
[email protected]12f520c2010-01-06 18:11:15198#include "chrome/browser/shell_integration.h"
[email protected]b17d41c2011-02-17 22:09:59199#include "chrome/browser/ssl/ssl_error_info.h"
[email protected]a5d1e1e2010-09-23 19:34:12200#include "chrome/browser/task_manager/task_manager.h"
[email protected]6a3ec2312010-12-02 19:30:19201#include "chrome/browser/ui/view_ids.h"
[email protected]dcd57762011-06-25 12:18:51202#include "ui/base/win/shell.h"
[email protected]8a53ee042009-01-21 16:41:33203#endif // OS_WIN
[email protected]e1acf6f2008-10-27 20:43:33204
[email protected]b7969202010-05-14 21:29:26205#if defined(OS_CHROMEOS)
[email protected]15de8142012-10-11 06:00:54206#include "chrome/browser/chromeos/drive/drive_file_system_util.h"
[email protected]eab8c0f2011-11-18 22:33:50207#endif
208
[email protected]dc04be7c2012-03-15 23:57:49209#if defined(USE_ASH)
[email protected]bafda132012-02-16 19:32:51210#include "ash/ash_switches.h"
[email protected]c2f0a892012-01-24 22:19:21211#endif
212
[email protected]8a53ee042009-01-21 16:41:33213using base::TimeDelta;
[email protected]b87ee522012-05-18 15:16:54214using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50215using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23216using content::NavigationEntry;
[email protected]e5d549d2011-12-28 01:29:20217using content::OpenURLParams;
[email protected]3a5180ae2011-12-21 02:39:38218using content::PluginService;
[email protected]e5d549d2011-12-28 01:29:20219using content::Referrer;
[email protected]b6583592012-01-25 19:52:33220using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38221using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09222using content::WebContents;
[email protected]1c321ee52012-05-21 03:02:34223using extensions::Extension;
[email protected]20c07f8e2012-05-31 08:43:14224using ui::WebDialogDelegate;
initial.commit09911bf2008-07-26 23:55:29225
[email protected]36b6dcb2008-11-12 01:19:57226///////////////////////////////////////////////////////////////////////////////
initial.commit09911bf2008-07-26 23:55:29227
[email protected]505323e22009-01-24 02:47:58228namespace {
229
[email protected]91a79232010-11-10 18:15:08230// The URL to be loaded to display the "Report a broken page" form.
231const char kBrokenPageUrl[] =
[email protected]95fc6f92011-04-13 00:37:20232 "https://www.google.com/support/chrome/bin/request.py?contact_type="
[email protected]91a79232010-11-10 18:15:08233 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2";
234
[email protected]91a79232010-11-10 18:15:08235// How long we wait before updating the browser chrome while loading a page.
236const int kUIUpdateCoalescingTimeMS = 200;
237
[email protected]a4fe67012012-07-25 20:14:29238BrowserWindow* CreateBrowserWindow(Browser* browser) {
[email protected]a4fe67012012-07-25 20:14:29239 return BrowserWindow::CreateBrowserWindow(browser);
240}
241
[email protected]56073dc2012-08-10 16:59:06242#if defined(OS_CHROMEOS)
243chrome::HostDesktopType kDefaultHostDesktopType = chrome::HOST_DESKTOP_TYPE_ASH;
244#else
245chrome::HostDesktopType kDefaultHostDesktopType =
246 chrome::HOST_DESKTOP_TYPE_NATIVE;
247#endif
248
249
[email protected]505323e22009-01-24 02:47:58250} // namespace
251
[email protected]b35b26b32011-05-05 20:35:14252////////////////////////////////////////////////////////////////////////////////
253// Browser, CreateParams:
254
[email protected]da22aa62012-04-04 18:54:35255Browser::CreateParams::CreateParams()
256 : type(TYPE_TABBED),
257 profile(NULL),
[email protected]56073dc2012-08-10 16:59:06258 host_desktop_type(kDefaultHostDesktopType),
[email protected]a4fe67012012-07-25 20:14:29259 app_type(APP_TYPE_HOST),
[email protected]da22aa62012-04-04 18:54:35260 initial_show_state(ui::SHOW_STATE_DEFAULT),
[email protected]a4fe67012012-07-25 20:14:29261 is_session_restore(false),
262 window(NULL) {
263}
264
265Browser::CreateParams::CreateParams(Profile* profile)
[email protected]56073dc2012-08-10 16:59:06266 : type(TYPE_TABBED),
267 profile(profile),
268 host_desktop_type(kDefaultHostDesktopType),
269 app_type(APP_TYPE_HOST),
270 initial_show_state(ui::SHOW_STATE_DEFAULT),
271 is_session_restore(false),
272 window(NULL) {
[email protected]da22aa62012-04-04 18:54:35273}
274
[email protected]b35b26b32011-05-05 20:35:14275Browser::CreateParams::CreateParams(Type type, Profile* profile)
276 : type(type),
[email protected]a636d8e52012-02-28 15:40:41277 profile(profile),
[email protected]56073dc2012-08-10 16:59:06278 host_desktop_type(kDefaultHostDesktopType),
279 app_type(APP_TYPE_HOST),
280 initial_show_state(ui::SHOW_STATE_DEFAULT),
281 is_session_restore(false),
282 window(NULL) {
283}
284
285Browser::CreateParams::CreateParams(Type type,
286 Profile* profile,
287 chrome::HostDesktopType host_desktop_type)
288 : type(type),
289 profile(profile),
290 host_desktop_type(host_desktop_type),
[email protected]0da58292012-03-22 20:37:21291 app_type(APP_TYPE_HOST),
[email protected]a636d8e52012-02-28 15:40:41292 initial_show_state(ui::SHOW_STATE_DEFAULT),
[email protected]a4fe67012012-07-25 20:14:29293 is_session_restore(false),
294 window(NULL) {
[email protected]b35b26b32011-05-05 20:35:14295}
296
[email protected]da22aa62012-04-04 18:54:35297// static
298Browser::CreateParams Browser::CreateParams::CreateForApp(
299 Type type,
300 const std::string& app_name,
301 const gfx::Rect& window_bounds,
302 Profile* profile) {
303 DCHECK(type != TYPE_TABBED);
304 DCHECK(!app_name.empty());
305
[email protected]da22aa62012-04-04 18:54:35306 CreateParams params(type, profile);
307 params.app_name = app_name;
308 params.app_type = APP_TYPE_CHILD;
309 params.initial_bounds = window_bounds;
310
311 return params;
312}
313
314// static
315Browser::CreateParams Browser::CreateParams::CreateForDevTools(
316 Profile* profile) {
317 CreateParams params(TYPE_POPUP, profile);
318 params.app_name = DevToolsWindow::kDevToolsApp;
319 return params;
320}
321
[email protected]36b6dcb2008-11-12 01:19:57322///////////////////////////////////////////////////////////////////////////////
323// Browser, Constructors, Creation, Showing:
initial.commit09911bf2008-07-26 23:55:29324
[email protected]a4fe67012012-07-25 20:14:29325Browser::Browser(const CreateParams& params)
326 : type_(params.type),
327 profile_(params.profile),
[email protected]f3e99e32008-07-30 04:48:39328 window_(NULL),
[email protected]ecc523f62010-09-28 22:45:40329 ALLOW_THIS_IN_INITIALIZER_LIST(
[email protected]855370052012-07-10 19:30:32330 tab_strip_model_delegate_(
331 new chrome::BrowserTabStripModelDelegate(this))),
[email protected]fa9d49ff2012-10-24 22:44:37332 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(),
333 params.profile)),
[email protected]a4fe67012012-07-25 20:14:29334 app_name_(params.app_name),
335 app_type_(params.app_type),
[email protected]15952e462008-11-14 00:29:05336 chrome_updater_factory_(this),
[email protected]69444cc2009-04-09 20:40:06337 cancel_download_confirmation_state_(NOT_PROMPTED),
[email protected]a4fe67012012-07-25 20:14:29338 override_bounds_(params.initial_bounds),
339 initial_show_state_(params.initial_show_state),
340 is_session_restore_(params.is_session_restore),
[email protected]56073dc2012-08-10 16:59:06341 host_desktop_type_(params.host_desktop_type),
[email protected]f9b6c092012-07-09 19:32:28342 ALLOW_THIS_IN_INITIALIZER_LIST(
343 unload_controller_(new chrome::UnloadController(this))),
[email protected]24f1477532011-11-22 22:55:36344 weak_factory_(this),
[email protected]fb7da4132011-03-15 15:51:00345 ALLOW_THIS_IN_INITIALIZER_LIST(
[email protected]ef557022012-03-16 10:05:33346 content_setting_bubble_model_delegate_(
347 new BrowserContentSettingBubbleModelDelegate(this))),
348 ALLOW_THIS_IN_INITIALIZER_LIST(
349 toolbar_model_delegate_(
350 new BrowserToolbarModelDelegate(this))),
351 ALLOW_THIS_IN_INITIALIZER_LIST(
[email protected]fb7da4132011-03-15 15:51:00352 tab_restore_service_delegate_(
[email protected]09b29342011-06-24 19:18:48353 new BrowserTabRestoreServiceDelegate(this))),
[email protected]afefa74e2011-07-26 05:04:23354 ALLOW_THIS_IN_INITIALIZER_LIST(
355 synced_window_delegate_(
356 new BrowserSyncedWindowDelegate(this))),
[email protected]8a5e0ca2011-08-25 06:30:47357 bookmark_bar_state_(BookmarkBar::HIDDEN),
[email protected]5d98294912012-06-27 22:57:40358 ALLOW_THIS_IN_INITIALIZER_LIST(
359 command_controller_(new chrome::BrowserCommandController(this))),
[email protected]2f516c792011-09-19 22:22:09360 window_has_shown_(false) {
[email protected]a4fe67012012-07-25 20:14:29361 if (!app_name_.empty())
362 chrome::RegisterAppPrefs(app_name_, profile_);
[email protected]2fc15ae2012-05-06 00:01:37363 tab_strip_model_->AddObserver(this);
364
[email protected]736d00322012-10-11 21:32:41365 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get()));
[email protected]e3a5d5b2012-06-22 17:56:46366 search_model_.reset(new chrome::search::SearchModel(NULL));
367 search_delegate_.reset(
[email protected]51a53e8f62012-08-28 03:08:56368 new chrome::search::SearchDelegate(search_model_.get(),
369 toolbar_model_.get()));
[email protected]ef557022012-03-16 10:05:33370
[email protected]432115822011-07-10 15:52:27371 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED,
[email protected]ad50def52011-10-19 23:17:07372 content::NotificationService::AllSources());
[email protected]432115822011-07-10 15:52:27373 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
[email protected]a93089b12011-11-22 20:47:38374 content::Source<Profile>(profile_->GetOriginalProfile()));
[email protected]432115822011-07-10 15:52:27375 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]a93089b12011-11-22 20:47:38376 content::Source<Profile>(profile_->GetOriginalProfile()));
[email protected]432115822011-07-10 15:52:27377 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
[email protected]a93089b12011-11-22 20:47:38378 content::Source<Profile>(profile_->GetOriginalProfile()));
[email protected]432115822011-07-10 15:52:27379 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07380 content::NotificationService::AllSources());
[email protected]6b40bb582012-03-15 20:50:38381#if defined(ENABLE_THEMES)
[email protected]ffa6f592011-06-24 22:03:57382 registrar_.Add(
[email protected]432115822011-07-10 15:52:27383 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
[email protected]6c2381d2011-10-19 02:52:53384 content::Source<ThemeService>(
385 ThemeServiceFactory::GetForProfile(profile_)));
[email protected]6b40bb582012-03-15 20:50:38386#endif
[email protected]ea049a02011-12-25 21:37:09387 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
[email protected]ad50def52011-10-19 23:17:07388 content::NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29389
[email protected]97b46382011-05-02 13:23:04390 profile_pref_registrar_.Init(profile_->GetPrefs());
391 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this);
[email protected]3710d0002011-10-11 00:35:00392 profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this);
[email protected]6c6b02d2011-09-02 03:36:47393 profile_pref_registrar_.Add(prefs::kHomePage, this);
[email protected]9e823662010-10-13 23:36:00394
initial.commit09911bf2008-07-26 23:55:29395 BrowserList::AddBrowser(this);
396
[email protected]97b46382011-05-02 13:23:04397 // NOTE: These prefs all need to be explicitly destroyed in the destructor
398 // or you'll get a nasty surprise when you run the incognito tests.
initial.commit09911bf2008-07-26 23:55:29399 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector,
400 profile_->GetPrefs(), NULL);
[email protected]281918912010-05-27 22:05:13401
[email protected]7acfaf92012-07-11 15:51:59402 instant_controller_.reset(new chrome::BrowserInstantController(this));
[email protected]df25eb9f2012-09-13 17:43:23403
404#if 0
405 // Disabled for M22. See http://crbug.com/144326.
[email protected]65c81142012-07-31 19:44:43406 device_attached_intent_source_.reset(
407 new DeviceAttachedIntentSource(this, (this)));
[email protected]df25eb9f2012-09-13 17:43:23408#endif
[email protected]07d490bc2011-03-07 17:05:26409
[email protected]09b29342011-06-24 19:18:48410 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT);
[email protected]a7be6982011-12-12 21:53:57411
[email protected]a4fe67012012-07-25 20:14:29412 FilePath profile_path = profile_->GetPath();
[email protected]a7be6982011-12-12 21:53:57413 ProfileMetrics::LogProfileLaunch(profile_path);
[email protected]a4fe67012012-07-25 20:14:29414
415 window_ = params.window ? params.window : CreateBrowserWindow(this);
416
417 // TODO(beng): move to BrowserFrameWin.
418#if defined(OS_WIN) && !defined(USE_AURA)
419 // Set the app user model id for this application to that of the application
420 // name. See http://crbug.com/7028.
421 ui::win::SetAppIdForWindow(
422 is_app() && !is_type_panel() ?
423 ShellIntegration::GetAppModelIdForProfile(UTF8ToWide(app_name_),
424 profile_->GetPath()) :
425 ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()),
426 window()->GetNativeWindow());
427
428 if (is_type_panel()) {
429 ui::win::SetAppIconForWindow(ShellIntegration::GetChromiumIconPath(),
430 window()->GetNativeWindow());
431 }
432#endif
433
434 // Create the extension window controller before sending notifications.
435 extension_window_controller_.reset(
436 new BrowserExtensionWindowController(this));
437
438 // TODO(beng): Move BrowserList::AddBrowser() to the end of this function and
439 // replace uses of this with BL's notifications.
440 content::NotificationService::current()->Notify(
441 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
442 content::Source<Browser>(this),
443 content::NotificationService::NoDetails());
444
445 // TODO(beng): move to ChromeBrowserMain:
446 PrefService* local_state = g_browser_process->local_state();
447 if (local_state && local_state->FindPreference(
448 prefs::kAutofillPersonalDataManagerFirstRun) &&
449 local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) {
450 // Notify PDM that this is a first run.
451#if defined(OS_WIN)
452 ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_));
453#endif // defined(OS_WIN)
454 // Reset the preference so we don't call it again for subsequent windows.
455 local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun);
456 }
457
[email protected]6fb528e2012-08-01 20:32:33458 fullscreen_controller_.reset(new FullscreenController(this));
[email protected]c3166302012-09-25 21:27:08459 search_model_->AddObserver(this);
initial.commit09911bf2008-07-26 23:55:29460}
461
462Browser::~Browser() {
[email protected]2fc15ae2012-05-06 00:01:37463 // The tab strip should not have any tabs at this point.
464 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers())
465 DCHECK(tab_strip_model_->empty());
[email protected]c3166302012-09-25 21:27:08466
467 search_model_->RemoveObserver(this);
[email protected]2fc15ae2012-05-06 00:01:37468 tab_strip_model_->RemoveObserver(this);
469
initial.commit09911bf2008-07-26 23:55:29470 BrowserList::RemoveBrowser(this);
471
[email protected]bdc6ccd12012-03-20 22:06:13472 SessionService* session_service =
473 SessionServiceFactory::GetForProfile(profile_);
474 if (session_service)
475 session_service->WindowClosed(session_id_);
476
477 TabRestoreService* tab_restore_service =
478 TabRestoreServiceFactory::GetForProfile(profile());
479 if (tab_restore_service)
480 tab_restore_service->BrowserClosed(tab_restore_service_delegate());
481
[email protected]7be64502011-05-03 17:51:47482#if !defined(OS_MACOSX)
[email protected]52ff7d932012-10-28 19:46:46483 if (!chrome::GetBrowserCount(profile_)) {
initial.commit09911bf2008-07-26 23:55:29484 // We're the last browser window with this profile. We need to nuke the
485 // TabRestoreService, which will start the shutdown of the
486 // NavigationControllers and allow for proper shutdown. If we don't do this
487 // chrome won't shutdown cleanly, and may end up crashing when some
488 // thread tries to use the IO thread (or another thread) that is no longer
489 // valid.
[email protected]fbc947b2009-06-19 13:28:24490 // This isn't a valid assumption for Mac OS, as it stays running after
491 // the last browser has closed. The Mac equivalent is in its app
492 // controller.
[email protected]92371eb2011-04-28 11:50:15493 TabRestoreServiceFactory::ResetForProfile(profile_);
initial.commit09911bf2008-07-26 23:55:29494 }
[email protected]fbc947b2009-06-19 13:28:24495#endif
initial.commit09911bf2008-07-26 23:55:29496
[email protected]97b46382011-05-02 13:23:04497 profile_pref_registrar_.RemoveAll();
[email protected]97b46382011-05-02 13:23:04498
[email protected]9a8c4022011-01-25 14:25:33499 encoding_auto_detect_.Destroy();
[email protected]9a8c4022011-01-25 14:25:33500
[email protected]5d98294912012-06-27 22:57:40501 command_controller_.reset();
502
initial.commit09911bf2008-07-26 23:55:29503 if (profile_->IsOffTheRecord() &&
[email protected]474e5db2011-08-12 13:02:23504 !BrowserList::IsOffTheRecordSessionActiveForProfile(profile_)) {
[email protected]5e919242012-02-13 23:59:35505 // An incognito profile is no longer needed, this indirectly frees
506 // its cache and cookies once it gets destroyed at the appropriate time.
[email protected]4dffabe2012-05-19 14:37:06507 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_);
initial.commit09911bf2008-07-26 23:55:29508 }
509
510 // There may be pending file dialogs, we need to tell them that we've gone
511 // away so they don't try and call back to us.
512 if (select_file_dialog_.get())
513 select_file_dialog_->ListenerDestroyed();
514}
515
[email protected]36b6dcb2008-11-12 01:19:57516///////////////////////////////////////////////////////////////////////////////
[email protected]5c238752009-06-13 10:29:07517// Getters & Setters
518
[email protected]b77cb302009-10-29 04:09:17519FindBarController* Browser::GetFindBarController() {
520 if (!find_bar_controller_.get()) {
[email protected]632983f2011-08-08 22:51:24521 FindBar* find_bar = window_->CreateFindBar();
[email protected]b77cb302009-10-29 04:09:17522 find_bar_controller_.reset(new FindBarController(find_bar));
523 find_bar->SetFindBarController(find_bar_controller_.get());
[email protected]52877dbc62012-06-29 22:22:03524 find_bar_controller_->ChangeTabContents(chrome::GetActiveTabContents(this));
[email protected]b77cb302009-10-29 04:09:17525 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
526 }
527 return find_bar_controller_.get();
528}
529
[email protected]24db8a072009-10-29 20:35:37530bool Browser::HasFindBarController() const {
531 return find_bar_controller_.get() != NULL;
532}
533
[email protected]b35b26b32011-05-05 20:35:14534bool Browser::is_app() const {
535 return !app_name_.empty();
536}
537
538bool Browser::is_devtools() const {
539 return app_name_ == DevToolsWindow::kDevToolsApp;
540}
541
[email protected]5c238752009-06-13 10:29:07542///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:57543// Browser, State Storage and Retrieval for UI:
544
[email protected]9b125b732012-08-17 04:43:55545gfx::Image Browser::GetCurrentPageIcon() const {
[email protected]502b5612012-10-02 01:33:10546 WebContents* web_contents = chrome::GetActiveWebContents(this);
547 // |web_contents| can be NULL since GetCurrentPageIcon() is called by the
548 // window during the window's creation (before tabs have been added).
549 FaviconTabHelper* favicon_tab_helper =
550 web_contents ? FaviconTabHelper::FromWebContents(web_contents) : NULL;
551 return favicon_tab_helper ? favicon_tab_helper->GetFavicon() : gfx::Image();
[email protected]36b6dcb2008-11-12 01:19:57552}
553
[email protected]731f8a42009-07-20 22:07:32554string16 Browser::GetWindowTitleForCurrentTab() const {
[email protected]52877dbc62012-06-29 22:22:03555 WebContents* contents = chrome::GetActiveWebContents(this);
[email protected]dda5dfa32009-07-10 00:33:29556 string16 title;
[email protected]c7c42332008-11-15 01:10:54557
[email protected]731f8a42009-07-20 22:07:32558 // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the
559 // window during the window's creation (before tabs have been added).
[email protected]36b6dcb2008-11-12 01:19:57560 if (contents) {
[email protected]dda5dfa32009-07-10 00:33:29561 title = contents->GetTitle();
[email protected]36b6dcb2008-11-12 01:19:57562 FormatTitleForDisplay(&title);
563 }
564 if (title.empty())
[email protected]51d83bdf2011-12-09 16:09:29565 title = CoreTabHelper::GetDefaultTitle();
[email protected]36b6dcb2008-11-12 01:19:57566
[email protected]cae97652012-04-20 03:12:12567#if defined(OS_MACOSX) || defined(USE_ASH)
568 // On Mac or Ash, we don't want to suffix the page title with
[email protected]22a3daa2009-11-09 22:03:33569 // the application name.
[email protected]d904bc82009-07-07 00:41:04570 return title;
[email protected]7be64502011-05-03 17:51:47571#else
[email protected]dff529732010-04-01 23:50:55572 // Don't append the app name to window titles on app frames and app popups
[email protected]9c55de82012-11-01 21:03:52573 return is_app() ?
574 title :
575 l10n_util::GetStringFUTF16(IDS_BROWSER_WINDOW_TITLE_FORMAT, title);
[email protected]57e68dba2009-05-15 21:30:50576#endif
[email protected]36b6dcb2008-11-12 01:19:57577}
578
579// static
[email protected]dda5dfa32009-07-10 00:33:29580void Browser::FormatTitleForDisplay(string16* title) {
[email protected]36b6dcb2008-11-12 01:19:57581 size_t current_index = 0;
582 size_t match_index;
[email protected]57ecc4b2010-08-11 03:02:51583 while ((match_index = title->find(L'\n', current_index)) != string16::npos) {
[email protected]810a52ef2010-01-08 01:22:15584 title->replace(match_index, 1, string16());
[email protected]36b6dcb2008-11-12 01:19:57585 current_index = match_index;
586 }
587}
588
589///////////////////////////////////////////////////////////////////////////////
590// Browser, OnBeforeUnload handling:
591
592bool Browser::ShouldCloseWindow() {
[email protected]69444cc2009-04-09 20:40:06593 if (!CanCloseWithInProgressDownloads())
594 return false;
595
[email protected]f9b6c092012-07-09 19:32:28596 return unload_controller_->ShouldCloseWindow();
597}
[email protected]69444cc2009-04-09 20:40:06598
[email protected]f9b6c092012-07-09 19:32:28599bool Browser::IsAttemptingToCloseBrowser() const {
600 return unload_controller_->is_attempting_to_close_browser();
[email protected]36b6dcb2008-11-12 01:19:57601}
602
603void Browser::OnWindowClosing() {
604 if (!ShouldCloseWindow())
605 return;
606
[email protected]c984d9f2010-07-20 20:52:20607 // Application should shutdown on last window close if the user is explicitly
608 // trying to quit, or if there is nothing keeping the browser alive (such as
609 // AppController on the Mac, or BackgroundContentsService for background
610 // pages).
611 bool should_quit_if_last_browser =
[email protected]2e6389f2012-05-18 19:41:25612 browser_shutdown::IsTryingToQuit() || !browser::WillKeepAlive();
[email protected]7dc8c6b2010-04-09 17:02:50613
[email protected]1e0c7402012-07-27 10:48:15614 if (should_quit_if_last_browser && BrowserList::size() == 1)
[email protected]36b6dcb2008-11-12 01:19:57615 browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE);
616
[email protected]92371eb2011-04-28 11:50:15617 // Don't use GetForProfileIfExisting here, we want to force creation of the
[email protected]36b6dcb2008-11-12 01:19:57618 // session service so that user can restore what was open.
[email protected]92371eb2011-04-28 11:50:15619 SessionService* session_service =
620 SessionServiceFactory::GetForProfile(profile());
[email protected]36b6dcb2008-11-12 01:19:57621 if (session_service)
622 session_service->WindowClosing(session_id());
623
[email protected]92371eb2011-04-28 11:50:15624 TabRestoreService* tab_restore_service =
625 TabRestoreServiceFactory::GetForProfile(profile());
[email protected]a636d8e52012-02-28 15:40:41626
627#if defined(USE_AURA)
628 if (tab_restore_service && is_app())
629 tab_restore_service->BrowserClosing(tab_restore_service_delegate());
630#endif
631
[email protected]b35b26b32011-05-05 20:35:14632 if (tab_restore_service && is_type_tabbed() && tab_count())
[email protected]fb7da4132011-03-15 15:51:00633 tab_restore_service->BrowserClosing(tab_restore_service_delegate());
[email protected]d8375fd2008-11-25 22:45:39634
[email protected]911f8152010-03-18 16:46:40635 // TODO(sky): convert session/tab restore to use notification.
[email protected]ad50def52011-10-19 23:17:07636 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27637 chrome::NOTIFICATION_BROWSER_CLOSING,
[email protected]6c2381d2011-10-19 02:52:53638 content::Source<Browser>(this),
[email protected]1e0c7402012-07-27 10:48:15639 content::NotificationService::NoDetails());
[email protected]911f8152010-03-18 16:46:40640
[email protected]52877dbc62012-06-29 22:22:03641 chrome::CloseAllTabs(this);
[email protected]36b6dcb2008-11-12 01:19:57642}
643
[email protected]28788c7d2011-05-20 23:03:45644void Browser::OnWindowActivated() {
645 // On some platforms we want to automatically reload tabs that are
646 // killed when the user selects them.
[email protected]52877dbc62012-06-29 22:22:03647 WebContents* contents = chrome::GetActiveWebContents(this);
[email protected]be1f56ab2011-12-22 06:55:31648 if (contents && contents->GetCrashedStatus() ==
[email protected]28788c7d2011-05-20 23:03:45649 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) {
650 if (CommandLine::ForCurrentProcess()->HasSwitch(
651 switches::kReloadKilledTabs)) {
[email protected]a37d4b02012-06-25 21:56:10652 chrome::Reload(this, CURRENT_TAB);
[email protected]28788c7d2011-05-20 23:03:45653 }
654 }
655}
656
[email protected]69444cc2009-04-09 20:40:06657////////////////////////////////////////////////////////////////////////////////
658// In-progress download termination handling:
659
660void Browser::InProgressDownloadResponse(bool cancel_downloads) {
661 if (cancel_downloads) {
662 cancel_download_confirmation_state_ = RESPONSE_RECEIVED;
[email protected]a37d4b02012-06-25 21:56:10663 chrome::CloseWindow(this);
[email protected]69444cc2009-04-09 20:40:06664 return;
665 }
666
667 // Sets the confirmation state to NOT_PROMPTED so that if the user tries to
668 // close again we'll show the warning again.
669 cancel_download_confirmation_state_ = NOT_PROMPTED;
670
671 // Show the download page so the user can figure-out what downloads are still
672 // in-progress.
[email protected]5d9cace72012-06-21 16:07:12673 chrome::ShowDownloads(this);
[email protected]69444cc2009-04-09 20:40:06674}
675
[email protected]5a17d492011-10-24 19:37:03676Browser::DownloadClosePreventionType Browser::OkToCloseWithInProgressDownloads(
677 int* num_downloads_blocking) const {
678 DCHECK(num_downloads_blocking);
679 *num_downloads_blocking = 0;
680
[email protected]f9b6c092012-07-09 19:32:28681 if (IsAttemptingToCloseBrowser())
[email protected]5a17d492011-10-24 19:37:03682 return DOWNLOAD_CLOSE_OK;
683
684 // If we're not running a full browser process with a profile manager
685 // (testing), it's ok to close the browser.
686 if (!g_browser_process->profile_manager())
687 return DOWNLOAD_CLOSE_OK;
688
689 int total_download_count = DownloadService::DownloadCountAllProfiles();
690 if (total_download_count == 0)
691 return DOWNLOAD_CLOSE_OK; // No downloads; can definitely close.
692
693 // Figure out how many windows are open total, and associated with this
694 // profile, that are relevant for the ok-to-close decision.
695 int profile_window_count = 0;
696 int total_window_count = 0;
697 for (BrowserList::const_iterator iter = BrowserList::begin();
698 iter != BrowserList::end(); ++iter) {
699 // Don't count this browser window or any other in the process of closing.
700 Browser* const browser = *iter;
[email protected]f9b6c092012-07-09 19:32:28701 // Window closing may be delayed, and windows that are in the process of
702 // closing don't count against our totals.
703 if (browser == this || browser->IsAttemptingToCloseBrowser())
[email protected]5a17d492011-10-24 19:37:03704 continue;
705
706 if ((*iter)->profile() == profile())
707 profile_window_count++;
708 total_window_count++;
709 }
710
711 // If there aren't any other windows, we're at browser shutdown,
712 // which would cancel all current downloads.
713 if (total_window_count == 0) {
714 *num_downloads_blocking = total_download_count;
715 return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN;
716 }
717
718 // If there aren't any other windows on our profile, and we're an incognito
719 // profile, and there are downloads associated with that profile,
720 // those downloads would be cancelled by our window (-> profile) close.
721 DownloadService* download_service =
722 DownloadServiceFactory::GetForProfile(profile());
723 if (profile_window_count == 0 && download_service->DownloadCount() > 0 &&
724 profile()->IsOffTheRecord()) {
725 *num_downloads_blocking = download_service->DownloadCount();
726 return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE;
727 }
728
729 // Those are the only conditions under which we will block shutdown.
730 return DOWNLOAD_CLOSE_OK;
731}
732
[email protected]69444cc2009-04-09 20:40:06733////////////////////////////////////////////////////////////////////////////////
[email protected]c848d3d92010-09-16 21:57:45734// Browser, TabStripModel pass-thrus:
735
736int Browser::tab_count() const {
[email protected]2fc15ae2012-05-06 00:01:37737 return tab_strip_model_->count();
[email protected]c848d3d92010-09-16 21:57:45738}
739
[email protected]1ea49d52011-04-12 17:44:44740int Browser::active_index() const {
[email protected]2fc15ae2012-05-06 00:01:37741 return tab_strip_model_->active_index();
[email protected]c848d3d92010-09-16 21:57:45742}
743
[email protected]c848d3d92010-09-16 21:57:45744////////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:57745// Browser, Tab adding/showing functions:
746
[email protected]227393e2011-06-29 21:28:39747void Browser::WindowFullscreenStateChanged() {
[email protected]01a5a762011-11-21 05:40:55748 fullscreen_controller_->WindowFullscreenStateChanged();
[email protected]5d98294912012-06-27 22:57:40749 command_controller_->FullscreenStateChanged();
[email protected]9adb8b12011-12-09 06:49:13750 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN);
[email protected]ae2622c2009-07-30 23:47:58751}
752
[email protected]36b6dcb2008-11-12 01:19:57753///////////////////////////////////////////////////////////////////////////////
754// Browser, Assorted browser commands:
755
[email protected]41d9faf2012-02-28 23:46:02756void Browser::ToggleFullscreenModeWithExtension(const GURL& extension_url) {
757 fullscreen_controller_->ToggleFullscreenModeWithExtension(extension_url);
[email protected]9282cea2009-02-18 18:49:00758}
759
[email protected]d3766932011-08-04 22:18:23760#if defined(OS_MACOSX)
[email protected]184717d52012-02-22 04:46:16761void Browser::TogglePresentationMode() {
762 fullscreen_controller_->TogglePresentationMode();
[email protected]d3766932011-08-04 22:18:23763}
764#endif
765
[email protected]a3e18c42009-03-04 23:36:05766bool Browser::SupportsWindowFeature(WindowFeature feature) const {
[email protected]018cf362010-05-05 22:43:22767 return SupportsWindowFeatureImpl(feature, true);
768}
[email protected]f5bf8ccf2010-02-05 18:19:25769
[email protected]018cf362010-05-05 22:43:22770bool Browser::CanSupportWindowFeature(WindowFeature feature) const {
771 return SupportsWindowFeatureImpl(feature, false);
[email protected]a3e18c42009-03-04 23:36:05772}
773
[email protected]fbd77592008-11-12 20:50:27774void Browser::ToggleEncodingAutoDetect() {
[email protected]7f6f44c2011-12-14 13:23:38775 content::RecordAction(UserMetricsAction("AutoDetectChange"));
[email protected]fbd77592008-11-12 20:50:27776 encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue());
[email protected]a697f4c2009-09-14 22:30:18777 // If "auto detect" is turned on, then any current override encoding
778 // is cleared. This also implicitly performs a reload.
779 // OTOH, if "auto detect" is turned off, we don't change the currently
780 // active encoding.
781 if (encoding_auto_detect_.GetValue()) {
[email protected]52877dbc62012-06-29 22:22:03782 WebContents* contents = chrome::GetActiveWebContents(this);
[email protected]a697f4c2009-09-14 22:30:18783 if (contents)
[email protected]b2fe07d12010-02-09 14:38:08784 contents->ResetOverrideEncoding();
[email protected]a697f4c2009-09-14 22:30:18785 }
[email protected]fbd77592008-11-12 20:50:27786}
787
788void Browser::OverrideEncoding(int encoding_id) {
[email protected]7f6f44c2011-12-14 13:23:38789 content::RecordAction(UserMetricsAction("OverrideEncoding"));
[email protected]41fc0322009-09-04 22:23:40790 const std::string selected_encoding =
[email protected]fbd77592008-11-12 20:50:27791 CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id);
[email protected]52877dbc62012-06-29 22:22:03792 WebContents* contents = chrome::GetActiveWebContents(this);
[email protected]57c6a652009-05-04 07:58:34793 if (!selected_encoding.empty() && contents)
[email protected]b2fe07d12010-02-09 14:38:08794 contents->SetOverrideEncoding(selected_encoding);
[email protected]fbd77592008-11-12 20:50:27795 // Update the list of recently selected encodings.
[email protected]41fc0322009-09-04 22:23:40796 std::string new_selected_encoding_list;
[email protected]ddd231e2010-06-29 20:35:19797 if (CharacterEncoding::UpdateRecentlySelectedEncoding(
798 profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding),
[email protected]41fc0322009-09-04 22:23:40799 encoding_id,
800 &new_selected_encoding_list)) {
[email protected]fbd77592008-11-12 20:50:27801 profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding,
[email protected]ddd231e2010-06-29 20:35:19802 new_selected_encoding_list);
[email protected]fbd77592008-11-12 20:50:27803 }
[email protected]36b6dcb2008-11-12 01:19:57804}
805
[email protected]84214982008-12-10 18:49:10806void Browser::OpenFile() {
[email protected]7f6f44c2011-12-14 13:23:38807 content::RecordAction(UserMetricsAction("OpenFile"));
[email protected]92f54082012-07-31 01:43:14808 select_file_dialog_ = ui::SelectFileDialog::Create(
[email protected]6e1fcd12012-07-02 17:14:20809 this, new ChromeSelectFilePolicy(
810 chrome::GetActiveWebContents(this)));
[email protected]84214982008-12-10 18:49:10811
[email protected]35896a32010-06-09 08:42:51812 const FilePath directory = profile_->last_selected_directory();
813
[email protected]84214982008-12-10 18:49:10814 // TODO(beng): figure out how to juggle this.
[email protected]90556dd2012-06-07 20:26:18815 gfx::NativeWindow parent_window = window_->GetNativeWindow();
[email protected]479cce782012-09-15 20:15:53816 ui::SelectFileDialog::FileTypeInfo file_types;
817 file_types.support_gdata = true;
[email protected]92f54082012-07-31 01:43:14818 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE,
[email protected]35896a32010-06-09 08:42:51819 string16(), directory,
[email protected]479cce782012-09-15 20:15:53820 &file_types, 0, FILE_PATH_LITERAL(""),
[email protected]d56bcd22009-03-16 19:51:56821 parent_window, NULL);
[email protected]84214982008-12-10 18:49:10822}
823
[email protected]92655362012-04-20 21:33:17824void Browser::UpdateDownloadShelfVisibility(bool visible) {
825 if (GetStatusBubble())
826 GetStatusBubble()->UpdateDownloadShelfVisibility(visible);
827}
828
[email protected]36b6dcb2008-11-12 01:19:57829///////////////////////////////////////////////////////////////////////////////
830
831// static
[email protected]d9083482012-01-06 00:38:46832bool Browser::RunUnloadEventsHelper(WebContents* contents) {
[email protected]075969d2012-04-17 20:05:55833 // If the WebContents is not connected yet, then there's no unload
834 // handler we can fire even if the WebContents has an unload listener.
[email protected]ecc523f62010-09-28 22:45:40835 // One case where we hit this is in a tab that has an infinite loop
836 // before load.
[email protected]5aab5e22010-12-08 22:13:29837 if (contents->NeedToFireBeforeUnload()) {
[email protected]ecc523f62010-09-28 22:45:40838 // If the page has unload listeners, then we tell the renderer to fire
839 // them. Once they have fired, we'll get a message back saying whether
840 // to proceed closing the page or not, which sends us back to this method
[email protected]5aab5e22010-12-08 22:13:29841 // with the NeedToFireBeforeUnload bit cleared.
[email protected]151a63d2011-12-20 22:32:52842 contents->GetRenderViewHost()->FirePageBeforeUnload(false);
[email protected]ecc523f62010-09-28 22:45:40843 return true;
844 }
845 return false;
846}
847
848// static
[email protected]1d3e9172012-06-12 02:59:13849void Browser::JSOutOfMemoryHelper(WebContents* web_contents) {
[email protected]591a59f2012-10-11 01:16:23850 InfoBarTabHelper* infobar_helper =
851 InfoBarTabHelper::FromWebContents(web_contents);
852 if (!infobar_helper)
[email protected]2a6bc3e2011-12-28 23:51:33853 return;
854
[email protected]2a6bc3e2011-12-28 23:51:33855 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate(
856 infobar_helper,
857 NULL,
858 l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
859 true));
[email protected]7d189022011-08-25 22:54:20860}
861
862// static
[email protected]1d3e9172012-06-12 02:59:13863void Browser::RegisterProtocolHandlerHelper(WebContents* web_contents,
[email protected]7d189022011-08-25 22:54:20864 const std::string& protocol,
865 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:36866 const string16& title,
[email protected]7ae9c322012-07-17 23:46:44867 bool user_gesture,
868 BrowserWindow* window) {
[email protected]1d3e9172012-06-12 02:59:13869 TabContents* tab_contents = TabContents::FromWebContents(web_contents);
[email protected]3d61dd02012-06-07 00:05:53870 if (!tab_contents || tab_contents->profile()->IsOffTheRecord())
[email protected]7d189022011-08-25 22:54:20871 return;
872
[email protected]7d189022011-08-25 22:54:20873 ProtocolHandler handler =
874 ProtocolHandler::CreateProtocolHandler(protocol, url, title);
875
876 ProtocolHandlerRegistry* registry =
[email protected]3d61dd02012-06-07 00:05:53877 tab_contents->profile()->GetProtocolHandlerRegistry();
[email protected]c5f51192012-09-28 04:09:50878 TabSpecificContentSettings* tab_content_settings =
879 TabSpecificContentSettings::FromWebContents(web_contents);
[email protected]7d189022011-08-25 22:54:20880
[email protected]96affbc82012-07-23 18:04:42881 if (registry->SilentlyHandleRegisterHandlerRequest(handler))
882 return;
883
[email protected]7ae9c322012-07-17 23:46:44884 if (!user_gesture && window) {
[email protected]c5f51192012-09-28 04:09:50885 tab_content_settings->set_pending_protocol_handler(handler);
886 tab_content_settings->set_previous_protocol_handler(
[email protected]7ae9c322012-07-17 23:46:44887 registry->GetHandlerFor(handler.protocol()));
888 window->GetLocationBar()->UpdateContentSettingsIcons();
[email protected]3fa5e192012-07-15 00:40:34889 return;
[email protected]7ae9c322012-07-17 23:46:44890 }
891
892 // Make sure content-setting icon is turned off in case the page does
893 // ungestured and gestured RPH calls.
894 if (window) {
[email protected]c5f51192012-09-28 04:09:50895 tab_content_settings->ClearPendingProtocolHandler();
[email protected]7ae9c322012-07-17 23:46:44896 window->GetLocationBar()->UpdateContentSettingsIcons();
897 }
[email protected]3fa5e192012-07-15 00:40:34898
[email protected]96affbc82012-07-23 18:04:42899 content::RecordAction(
900 UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown"));
[email protected]591a59f2012-10-11 01:16:23901 InfoBarTabHelper* infobar_helper =
902 InfoBarTabHelper::FromWebContents(web_contents);
[email protected]d3ddb6d2012-01-06 02:51:17903
[email protected]96affbc82012-07-23 18:04:42904 RegisterProtocolHandlerInfoBarDelegate* rph_delegate =
905 new RegisterProtocolHandlerInfoBarDelegate(infobar_helper,
906 registry,
907 handler);
[email protected]d3ddb6d2012-01-06 02:51:17908
[email protected]d715fb802012-08-20 16:34:13909 for (size_t i = 0; i < infobar_helper->GetInfoBarCount(); i++) {
[email protected]96affbc82012-07-23 18:04:42910 InfoBarDelegate* delegate = infobar_helper->GetInfoBarDelegateAt(i);
911 RegisterProtocolHandlerInfoBarDelegate* cast_delegate =
912 delegate->AsRegisterProtocolHandlerInfoBarDelegate();
913 if (cast_delegate != NULL && cast_delegate->IsReplacedBy(rph_delegate)) {
914 infobar_helper->ReplaceInfoBar(cast_delegate, rph_delegate);
915 rph_delegate = NULL;
916 break;
[email protected]d3ddb6d2012-01-06 02:51:17917 }
[email protected]7d189022011-08-25 22:54:20918 }
[email protected]96affbc82012-07-23 18:04:42919
920 if (rph_delegate != NULL)
921 infobar_helper->AddInfoBar(rph_delegate);
[email protected]7d189022011-08-25 22:54:20922}
923
924// static
[email protected]1d3e9172012-06-12 02:59:13925void Browser::FindReplyHelper(WebContents* web_contents,
[email protected]b888919c2011-09-02 00:32:16926 int request_id,
927 int number_of_matches,
928 const gfx::Rect& selection_rect,
929 int active_match_ordinal,
930 bool final_update) {
[email protected]bc852c932012-09-29 21:38:34931 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents);
932 if (!find_tab_helper)
[email protected]b888919c2011-09-02 00:32:16933 return;
934
[email protected]bc852c932012-09-29 21:38:34935 find_tab_helper->HandleFindReply(request_id,
936 number_of_matches,
937 selection_rect,
938 active_match_ordinal,
939 final_update);
[email protected]b888919c2011-09-02 00:32:16940}
941
[email protected]c55d3d122012-07-10 16:53:41942// static
943void Browser::RequestMediaAccessPermissionHelper(
944 content::WebContents* web_contents,
945 const content::MediaStreamRequest* request,
946 const content::MediaResponseCallback& callback) {
947 TabContents* tab = TabContents::FromWebContents(web_contents);
948
949 scoped_ptr<MediaStreamDevicesController>
950 controller(new MediaStreamDevicesController(tab->profile(),
951 request,
952 callback));
953 if (!controller->DismissInfoBarAndTakeActionOnSettings()) {
[email protected]591a59f2012-10-11 01:16:23954 InfoBarTabHelper* infobar_helper =
955 InfoBarTabHelper::FromWebContents(web_contents);
[email protected]c55d3d122012-07-10 16:53:41956 InfoBarDelegate* old_infobar = NULL;
[email protected]d715fb802012-08-20 16:34:13957 for (size_t i = 0; i < infobar_helper->GetInfoBarCount(); ++i) {
[email protected]c55d3d122012-07-10 16:53:41958 old_infobar = infobar_helper->GetInfoBarDelegateAt(i)->
959 AsMediaStreamInfoBarDelegate();
960 if (old_infobar)
961 break;
962 }
963
964 InfoBarDelegate* infobar =
965 new MediaStreamInfoBarDelegate(infobar_helper, controller.release());
966 if (old_infobar)
967 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
968 else
969 infobar_helper->AddInfoBar(infobar);
970 }
971}
972
[email protected]3d61dd02012-06-07 00:05:53973void Browser::UpdateUIForNavigationInTab(TabContents* contents,
[email protected]ef557022012-03-16 10:05:33974 content::PageTransition transition,
975 bool user_initiated) {
[email protected]2fc15ae2012-05-06 00:01:37976 tab_strip_model_->TabNavigating(contents, transition);
[email protected]ef557022012-03-16 10:05:33977
[email protected]52877dbc62012-06-29 22:22:03978 bool contents_is_selected = contents == chrome::GetActiveTabContents(this);
[email protected]ef557022012-03-16 10:05:33979 if (user_initiated && contents_is_selected && window()->GetLocationBar()) {
980 // Forcibly reset the location bar if the url is going to change in the
981 // current tab, since otherwise it won't discard any ongoing user edits,
982 // since it doesn't realize this is a user-initiated action.
983 window()->GetLocationBar()->Revert();
984 }
985
986 if (GetStatusBubble())
987 GetStatusBubble()->Hide();
988
989 // Update the location bar. This is synchronous. We specifically don't
990 // update the load state since the load hasn't started yet and updating it
991 // will put it out of sync with the actual state like whether we're
992 // displaying a favicon, which controls the throbber. If we updated it here,
993 // the throbber will show the default favicon for a split second when
994 // navigating away from the new tab page.
995 ScheduleUIUpdate(contents->web_contents(), content::INVALIDATE_TYPE_URL);
996
[email protected]e1f288d2012-05-23 19:36:10997 if (contents_is_selected)
[email protected]ef557022012-03-16 10:05:33998 contents->web_contents()->Focus();
999}
1000
1001///////////////////////////////////////////////////////////////////////////////
1002// Browser, PageNavigator implementation:
1003
1004WebContents* Browser::OpenURL(const OpenURLParams& params) {
1005 return OpenURLFromTab(NULL, params);
1006}
1007
[email protected]485fba42009-03-24 23:27:291008///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:571009// Browser, TabStripModelObserver implementation:
1010
[email protected]3d61dd02012-06-07 00:05:531011void Browser::TabInsertedAt(TabContents* contents,
[email protected]36b6dcb2008-11-12 01:19:571012 int index,
1013 bool foreground) {
[email protected]6451fe92012-08-30 18:37:261014 SetAsDelegate(contents->web_contents(), this);
[email protected]50a9a76b2012-09-12 14:19:361015 SessionTabHelper* session_tab_helper =
1016 SessionTabHelper::FromWebContents(contents->web_contents());
1017 session_tab_helper->SetWindowID(session_id());
[email protected]e524ff92011-03-30 13:26:581018
[email protected]fb312eb2012-09-24 23:21:101019 content::NotificationService::current()->Notify(
1020 chrome::NOTIFICATION_TAB_PARENTED,
1021 content::Source<content::WebContents>(contents->web_contents()),
1022 content::NotificationService::NoDetails());
1023
[email protected]c37e3b62010-01-22 00:15:171024 SyncHistoryWithTabs(index);
[email protected]36b6dcb2008-11-12 01:19:571025
[email protected]159f7762008-12-19 14:58:271026 // Make sure the loading state is updated correctly, otherwise the throbber
1027 // won't start if the page is loading.
[email protected]2a6bc3e2011-12-28 23:51:331028 LoadingStateChanged(contents->web_contents());
[email protected]159f7762008-12-19 14:58:271029
[email protected]432115822011-07-10 15:52:271030 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED,
[email protected]fbc5e5f92012-01-02 06:08:321031 content::Source<WebContents>(contents->web_contents()));
[email protected]e397a4472011-12-21 21:47:501032
1033 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED,
[email protected]fbc5e5f92012-01-02 06:08:321034 content::Source<WebContents>(contents->web_contents()));
[email protected]40600152012-09-26 10:04:311035 SessionService* session_service =
1036 SessionServiceFactory::GetForProfile(profile_);
1037 if (session_service)
1038 session_service->TabInserted(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]40600152012-09-26 10:04:311045 SessionService* session_service =
1046 SessionServiceFactory::GetForProfile(profile_);
1047 if (session_service)
1048 session_service->TabClosing(contents->web_contents());
[email protected]ad50def52011-10-19 23:17:071049 content::NotificationService::current()->Notify(
[email protected]884033e2012-04-16 19:38:421050 chrome::NOTIFICATION_TAB_CLOSING,
[email protected]c5eed492012-01-04 17:07:501051 content::Source<NavigationController>(
[email protected]cca0f1e2012-01-03 18:27:461052 &contents->web_contents()->GetController()),
[email protected]ad50def52011-10-19 23:17:071053 content::NotificationService::NoDetails());
[email protected]36b6dcb2008-11-12 01:19:571054
[email protected]075969d2012-04-17 20:05:551055 // Sever the WebContents' connection back to us.
[email protected]6451fe92012-08-30 18:37:261056 SetAsDelegate(contents->web_contents(), NULL);
[email protected]36b6dcb2008-11-12 01:19:571057}
1058
[email protected]3d61dd02012-06-07 00:05:531059void Browser::TabDetachedAt(TabContents* contents, int index) {
[email protected]c37e3b62010-01-22 00:15:171060 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH);
[email protected]36b6dcb2008-11-12 01:19:571061}
1062
[email protected]3d61dd02012-06-07 00:05:531063void Browser::TabDeactivated(TabContents* contents) {
[email protected]01a5a762011-11-21 05:40:551064 fullscreen_controller_->OnTabDeactivated(contents);
[email protected]0dc50db2012-09-19 17:57:141065 search_delegate_->OnTabDeactivated(contents->web_contents());
[email protected]e3a5d5b2012-06-22 17:56:461066
[email protected]85ff2c42009-05-29 21:22:031067 // Save what the user's currently typing, so it can be restored when we
1068 // switch back to this tab.
[email protected]83a2610a2012-01-05 01:00:271069 window_->GetLocationBar()->SaveStateToContents(contents->web_contents());
[email protected]85ff2c42009-05-29 21:22:031070}
1071
[email protected]3d61dd02012-06-07 00:05:531072void Browser::ActiveTabChanged(TabContents* old_contents,
1073 TabContents* new_contents,
[email protected]3aca95d42011-05-24 22:06:541074 int index,
1075 bool user_gesture) {
[email protected]a8f024392011-01-13 21:50:161076 // On some platforms we want to automatically reload tabs that are
1077 // killed when the user selects them.
[email protected]9d7518f2012-04-17 02:15:201078 bool did_reload = false;
[email protected]d9083482012-01-06 00:38:461079 if (user_gesture && new_contents->web_contents()->GetCrashedStatus() ==
[email protected]a8f024392011-01-13 21:50:161080 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) {
1081 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
[email protected]f8a35772011-02-02 23:17:561082 if (parsed_command_line.HasSwitch(switches::kReloadKilledTabs)) {
[email protected]734d26692012-03-26 18:00:251083 LOG(WARNING) << "Reloading killed tab at " << index;
[email protected]d6d4dae2012-04-18 17:47:321084 static int reload_count = 0;
[email protected]24c463a2012-04-20 22:33:501085 UMA_HISTOGRAM_CUSTOM_COUNTS(
1086 "Tabs.SadTab.ReloadCount", ++reload_count, 1, 1000, 50);
[email protected]a37d4b02012-06-25 21:56:101087 chrome::Reload(this, CURRENT_TAB);
[email protected]9d7518f2012-04-17 02:15:201088 did_reload = true;
[email protected]f8a35772011-02-02 23:17:561089 }
[email protected]a8f024392011-01-13 21:50:161090 }
1091
[email protected]002efb042011-10-07 17:30:241092 // Discarded tabs always get reloaded.
[email protected]52877dbc62012-06-29 22:22:031093 if (!did_reload && tab_strip_model_->IsTabDiscarded(index)) {
[email protected]d6d4dae2012-04-18 17:47:321094 LOG(WARNING) << "Reloading discarded tab at " << index;
1095 static int reload_count = 0;
[email protected]24c463a2012-04-20 22:33:501096 UMA_HISTOGRAM_CUSTOM_COUNTS(
1097 "Tabs.Discard.ReloadCount", ++reload_count, 1, 1000, 50);
[email protected]a37d4b02012-06-25 21:56:101098 chrome::Reload(this, CURRENT_TAB);
[email protected]002efb042011-10-07 17:30:241099 }
1100
[email protected]36b6dcb2008-11-12 01:19:571101 // If we have any update pending, do it now.
[email protected]24f1477532011-11-22 22:55:361102 if (chrome_updater_factory_.HasWeakPtrs() && old_contents)
[email protected]36b6dcb2008-11-12 01:19:571103 ProcessPendingUIUpdates();
1104
[email protected]36b6dcb2008-11-12 01:19:571105 // Propagate the profile to the location bar.
1106 UpdateToolbar(true);
1107
[email protected]e3a5d5b2012-06-22 17:56:461108 // Propagate tab state to toolbar, tab-strip, etc.
1109 UpdateSearchState(new_contents);
1110
[email protected]943d8122010-06-11 02:13:451111 // Update reload/stop state.
[email protected]5d98294912012-06-27 22:57:401112 command_controller_->LoadingStateChanged(
1113 new_contents->web_contents()->IsLoading(), true);
[email protected]36b6dcb2008-11-12 01:19:571114
[email protected]84214982008-12-10 18:49:101115 // Update commands to reflect current state.
[email protected]5d98294912012-06-27 22:57:401116 command_controller_->TabStateChanged();
[email protected]36b6dcb2008-11-12 01:19:571117
1118 // Reset the status bubble.
[email protected]be3877f2009-01-14 15:51:101119 StatusBubble* status_bubble = GetStatusBubble();
1120 if (status_bubble) {
1121 status_bubble->Hide();
[email protected]36b6dcb2008-11-12 01:19:571122
[email protected]be3877f2009-01-14 15:51:101123 // Show the loading state (if any).
[email protected]51d83bdf2011-12-09 16:09:291124 status_bubble->SetStatus(
[email protected]ece4aca2012-09-19 22:22:581125 CoreTabHelper::FromWebContents(chrome::GetActiveWebContents(this))->
1126 GetStatusText());
[email protected]be3877f2009-01-14 15:51:101127 }
[email protected]36b6dcb2008-11-12 01:19:571128
[email protected]24db8a072009-10-29 20:35:371129 if (HasFindBarController()) {
[email protected]9c318862011-02-01 22:27:241130 find_bar_controller_->ChangeTabContents(new_contents);
[email protected]b77cb302009-10-29 04:09:171131 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
[email protected]4801ecc2009-04-05 04:52:581132 }
1133
[email protected]36b6dcb2008-11-12 01:19:571134 // Update sessions. Don't force creation of sessions. If sessions doesn't
1135 // exist, the change will be picked up by sessions when created.
[email protected]92371eb2011-04-28 11:50:151136 SessionService* session_service =
1137 SessionServiceFactory::GetForProfileIfExisting(profile_);
[email protected]2fc15ae2012-05-06 00:01:371138 if (session_service && !tab_strip_model_->closing_all()) {
[email protected]41f022e2012-01-31 05:56:401139 session_service->SetSelectedTabInWindow(session_id(), active_index());
[email protected]36b6dcb2008-11-12 01:19:571140 }
[email protected]09b29342011-06-24 19:18:481141
1142 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH);
[email protected]36b6dcb2008-11-12 01:19:571143}
1144
[email protected]3d61dd02012-06-07 00:05:531145void Browser::TabMoved(TabContents* contents,
[email protected]36b6dcb2008-11-12 01:19:571146 int from_index,
[email protected]1a242c32010-02-02 21:20:541147 int to_index) {
[email protected]36b6dcb2008-11-12 01:19:571148 DCHECK(from_index >= 0 && to_index >= 0);
1149 // Notify the history service.
1150 SyncHistoryWithTabs(std::min(from_index, to_index));
1151}
1152
[email protected]da25dd52011-01-11 19:06:301153void Browser::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]3d61dd02012-06-07 00:05:531154 TabContents* old_contents,
1155 TabContents* new_contents,
[email protected]8a34e6602010-10-02 17:29:431156 int index) {
[email protected]c37e3b62010-01-22 00:15:171157 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE);
[email protected]40600152012-09-26 10:04:311158 SessionService* session_service =
1159 SessionServiceFactory::GetForProfile(profile_);
1160 if (session_service)
1161 session_service->TabClosing(old_contents->web_contents());
[email protected]41f022e2012-01-31 05:56:401162 TabInsertedAt(new_contents, index, (index == active_index()));
[email protected]c37e3b62010-01-22 00:15:171163
[email protected]a26023822011-12-29 00:23:551164 int entry_count =
[email protected]d9083482012-01-06 00:38:461165 new_contents->web_contents()->GetController().GetEntryCount();
[email protected]c37e3b62010-01-22 00:15:171166 if (entry_count > 0) {
1167 // Send out notification so that observers are updated appropriately.
[email protected]d9083482012-01-06 00:38:461168 new_contents->web_contents()->GetController().NotifyEntryChanged(
1169 new_contents->web_contents()->GetController().GetEntryAtIndex(
[email protected]4a63e242011-12-12 15:23:081170 entry_count - 1),
[email protected]c37e3b62010-01-22 00:15:171171 entry_count - 1);
1172 }
[email protected]47e020a2010-10-15 14:43:371173
[email protected]47e020a2010-10-15 14:43:371174 if (session_service) {
1175 // The new_contents may end up with a different navigation stack. Force
1176 // the session service to update itself.
[email protected]52877dbc62012-06-29 22:22:031177 session_service->TabRestored(new_contents,
1178 tab_strip_model_->IsTabPinned(index));
[email protected]47e020a2010-10-15 14:43:371179 }
[email protected]2914600d2011-01-31 23:25:141180
[email protected]a0262432012-04-13 15:48:091181 content::DevToolsManager::GetInstance()->ContentsReplaced(
[email protected]d9083482012-01-06 00:38:461182 old_contents->web_contents(), new_contents->web_contents());
[email protected]c37e3b62010-01-22 00:15:171183}
1184
[email protected]3d61dd02012-06-07 00:05:531185void Browser::TabPinnedStateChanged(TabContents* contents, int index) {
[email protected]92371eb2011-04-28 11:50:151186 SessionService* session_service =
1187 SessionServiceFactory::GetForProfileIfExisting(profile());
[email protected]5c0e6482009-07-14 20:20:091188 if (session_service) {
[email protected]50a9a76b2012-09-12 14:19:361189 SessionTabHelper* session_tab_helper =
1190 SessionTabHelper::FromWebContents(contents->web_contents());
[email protected]5c0e6482009-07-14 20:20:091191 session_service->SetPinnedState(
1192 session_id(),
[email protected]50a9a76b2012-09-12 14:19:361193 session_tab_helper->session_id(),
[email protected]52877dbc62012-06-29 22:22:031194 tab_strip_model_->IsTabPinned(index));
[email protected]5c0e6482009-07-14 20:20:091195 }
1196}
1197
[email protected]36b6dcb2008-11-12 01:19:571198void Browser::TabStripEmpty() {
1199 // Close the frame after we return to the message loop (not immediately,
1200 // otherwise it will destroy this object before the stack has a chance to
1201 // cleanly unwind.)
1202 // Note: This will be called several times if TabStripEmpty is called several
1203 // times. This is because it does not close the window if tabs are
1204 // still present.
[email protected]0586b0e2010-02-12 21:38:371205 MessageLoop::current()->PostTask(
[email protected]24f1477532011-11-22 22:55:361206 FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr()));
[email protected]36b6dcb2008-11-12 01:19:571207}
1208
[email protected]b3996ba2012-08-08 00:39:131209bool Browser::PreHandleKeyboardEvent(content::WebContents* source,
1210 const NativeWebKeyboardEvent& event,
[email protected]fc761142012-06-08 04:49:201211 bool* is_keyboard_shortcut) {
1212 // Escape exits tabbed fullscreen mode.
1213 // TODO(koz): Write a test for this http://crbug.com/100441.
1214 if (event.windowsKeyCode == 27 &&
1215 fullscreen_controller_->HandleUserPressedEscape()) {
1216 return true;
1217 }
1218 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1219}
1220
[email protected]b3996ba2012-08-08 00:39:131221void Browser::HandleKeyboardEvent(content::WebContents* source,
1222 const NativeWebKeyboardEvent& event) {
[email protected]fc761142012-06-08 04:49:201223 window()->HandleKeyboardEvent(event);
1224}
1225
[email protected]92655362012-04-20 21:33:171226bool Browser::TabsNeedBeforeUnloadFired() {
[email protected]f9b6c092012-07-09 19:32:281227 return unload_controller_->TabsNeedBeforeUnloadFired();
[email protected]92655362012-04-20 21:33:171228}
1229
[email protected]d013f142012-04-27 17:31:141230bool Browser::IsMouseLocked() const {
1231 return fullscreen_controller_->IsMouseLocked();
[email protected]92655362012-04-20 21:33:171232}
1233
1234void Browser::OnWindowDidShow() {
1235 if (window_has_shown_)
1236 return;
1237 window_has_shown_ = true;
1238
[email protected]b5febf72012-07-29 18:10:091239// CurrentProcessInfo::CreationTime() is currently only implemented on Mac and
1240// Windows.
1241#if defined(OS_MACOSX) || defined(OS_WIN)
1242 // Measure the latency from startup till the first browser window becomes
1243 // visible.
1244 static bool is_first_browser_window = true;
1245 if (is_first_browser_window &&
1246 !startup_metric_utils::WasNonBrowserUIDisplayed()) {
1247 is_first_browser_window = false;
1248 const base::Time* process_creation_time =
1249 base::CurrentProcessInfo::CreationTime();
1250
1251 if (process_creation_time) {
1252 UMA_HISTOGRAM_LONG_TIMES(
1253 "Startup.BrowserWindowDisplay",
1254 base::Time::Now() - *process_creation_time);
1255 }
1256 }
[email protected]9c55de82012-11-01 21:03:521257#endif // defined(OS_MACOSX) || defined(OS_WIN)
[email protected]b5febf72012-07-29 18:10:091258
[email protected]92655362012-04-20 21:33:171259 // Nothing to do for non-tabbed windows.
1260 if (!is_type_tabbed())
1261 return;
1262
1263 // Show any pending global error bubble.
1264 GlobalErrorService* service =
1265 GlobalErrorServiceFactory::GetForProfile(profile());
1266 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView();
1267 if (error)
1268 error->ShowBubbleView(this);
1269}
1270
1271void Browser::ShowFirstRunBubble() {
1272 window()->GetLocationBar()->ShowFirstRunBubble();
1273}
1274
1275///////////////////////////////////////////////////////////////////////////////
[email protected]674bc592011-12-20 23:00:421276// Browser, content::WebContentsDelegate implementation:
initial.commit09911bf2008-07-26 23:55:291277
[email protected]e5d549d2011-12-28 01:29:201278WebContents* Browser::OpenURLFromTab(WebContents* source,
[email protected]00c37fc2011-08-02 00:22:501279 const OpenURLParams& params) {
[email protected]78e2edc2012-07-01 23:32:281280 chrome::NavigateParams nav_params(this, params.url, params.transition);
[email protected]52877dbc62012-06-29 22:22:031281 nav_params.source_contents = chrome::GetTabContentsAt(this,
[email protected]e52d0a42012-06-08 22:44:161282 tab_strip_model_->GetIndexOfWebContents(source));
[email protected]cb8fb01a2011-12-05 21:01:141283 nav_params.referrer = params.referrer;
[email protected]72ea827d2012-09-28 01:30:551284 nav_params.extra_headers = params.extra_headers;
[email protected]00c37fc2011-08-02 00:22:501285 nav_params.disposition = params.disposition;
1286 nav_params.tabstrip_add_types = TabStripModel::ADD_NONE;
[email protected]78e2edc2012-07-01 23:32:281287 nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]00c37fc2011-08-02 00:22:501288 nav_params.user_gesture = true;
1289 nav_params.override_encoding = params.override_encoding;
[email protected]e47ae9472011-10-13 19:48:341290 nav_params.is_renderer_initiated = params.is_renderer_initiated;
[email protected]4ad5d77d2011-12-03 02:00:481291 nav_params.transferred_global_request_id =
1292 params.transferred_global_request_id;
[email protected]78e2edc2012-07-01 23:32:281293 chrome::Navigate(&nav_params);
[email protected]00c37fc2011-08-02 00:22:501294
1295 return nav_params.target_contents ?
[email protected]d9083482012-01-06 00:38:461296 nav_params.target_contents->web_contents() : NULL;
initial.commit09911bf2008-07-26 23:55:291297}
1298
[email protected]2a6bc3e2011-12-28 23:51:331299void Browser::NavigationStateChanged(const WebContents* source,
initial.commit09911bf2008-07-26 23:55:291300 unsigned changed_flags) {
initial.commit09911bf2008-07-26 23:55:291301 // Only update the UI when something visible has changed.
[email protected]e83f1682008-09-07 23:57:401302 if (changed_flags)
initial.commit09911bf2008-07-26 23:55:291303 ScheduleUIUpdate(source, changed_flags);
1304
[email protected]83c2e232011-10-07 21:36:461305 // We can synchronously update commands since they will only change once per
1306 // navigation, so we don't have to worry about flickering. We do, however,
1307 // need to update the command state early on load to always present usable
1308 // actions in the face of slow-to-commit pages.
[email protected]d9083482012-01-06 00:38:461309 if (changed_flags & (content::INVALIDATE_TYPE_URL |
1310 content::INVALIDATE_TYPE_LOAD))
[email protected]5d98294912012-06-27 22:57:401311 command_controller_->TabStateChanged();
initial.commit09911bf2008-07-26 23:55:291312}
1313
[email protected]2a6bc3e2011-12-28 23:51:331314void Browser::AddNewContents(WebContents* source,
1315 WebContents* new_contents,
initial.commit09911bf2008-07-26 23:55:291316 WindowOpenDisposition disposition,
1317 const gfx::Rect& initial_pos,
[email protected]eda238a12012-09-07 23:44:001318 bool user_gesture,
1319 bool* was_blocked) {
[email protected]52877dbc62012-06-29 22:22:031320 chrome::AddWebContents(this, source, new_contents, disposition, initial_pos,
[email protected]eda238a12012-09-07 23:44:001321 user_gesture, was_blocked);
initial.commit09911bf2008-07-26 23:55:291322}
1323
[email protected]2a6bc3e2011-12-28 23:51:331324void Browser::ActivateContents(WebContents* contents) {
[email protected]52877dbc62012-06-29 22:22:031325 chrome::ActivateTabAt(this, tab_strip_model_->GetIndexOfWebContents(contents),
1326 false);
[email protected]f3e99e32008-07-30 04:48:391327 window_->Activate();
initial.commit09911bf2008-07-26 23:55:291328}
1329
[email protected]2a6bc3e2011-12-28 23:51:331330void Browser::DeactivateContents(WebContents* contents) {
[email protected]ea42e7782010-08-23 23:58:121331 window_->Deactivate();
1332}
1333
[email protected]2a6bc3e2011-12-28 23:51:331334void Browser::LoadingStateChanged(WebContents* source) {
[email protected]2fc15ae2012-05-06 00:01:371335 window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading());
[email protected]f3e99e32008-07-30 04:48:391336 window_->UpdateTitleBar();
initial.commit09911bf2008-07-26 23:55:291337
[email protected]52877dbc62012-06-29 22:22:031338 WebContents* selected_contents = chrome::GetActiveWebContents(this);
[email protected]3c9e1872010-11-18 16:17:491339 if (source == selected_contents) {
[email protected]f5d978c2011-07-21 14:43:511340 bool is_loading = source->IsLoading();
[email protected]5d98294912012-06-27 22:57:401341 command_controller_->LoadingStateChanged(is_loading, false);
[email protected]43d259d2010-09-03 21:37:461342 if (GetStatusBubble()) {
[email protected]0dd3a0ab2011-02-18 08:17:441343 GetStatusBubble()->SetStatus(
[email protected]ece4aca2012-09-19 22:22:581344 CoreTabHelper::FromWebContents(chrome::GetActiveWebContents(this))->
[email protected]52877dbc62012-06-29 22:22:031345 GetStatusText());
[email protected]43d259d2010-09-03 21:37:461346 }
initial.commit09911bf2008-07-26 23:55:291347 }
1348}
1349
[email protected]a81343d232011-12-27 07:39:201350void Browser::CloseContents(WebContents* source) {
[email protected]f9b6c092012-07-09 19:32:281351 if (unload_controller_->CanCloseContents(source))
1352 chrome::CloseWebContents(this, source);
initial.commit09911bf2008-07-26 23:55:291353}
1354
[email protected]2a6bc3e2011-12-28 23:51:331355void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) {
[email protected]b35b26b32011-05-05 20:35:141356 if (!IsPopupOrPanel(source)) {
initial.commit09911bf2008-07-26 23:55:291357 NOTREACHED() << "moving invalid browser type";
1358 return;
1359 }
[email protected]e561e202010-03-24 17:57:121360 window_->SetBounds(pos);
initial.commit09911bf2008-07-26 23:55:291361}
1362
[email protected]2a6bc3e2011-12-28 23:51:331363bool Browser::IsPopupOrPanel(const WebContents* source) const {
initial.commit09911bf2008-07-26 23:55:291364 // A non-tabbed BROWSER is an unconstrained popup.
[email protected]b35b26b32011-05-05 20:35:141365 return is_type_popup() || is_type_panel();
initial.commit09911bf2008-07-26 23:55:291366}
1367
[email protected]2a6bc3e2011-12-28 23:51:331368void Browser::UpdateTargetURL(WebContents* source, int32 page_id,
[email protected]d952a052011-09-06 18:42:451369 const GURL& url) {
[email protected]be3877f2009-01-14 15:51:101370 if (!GetStatusBubble())
1371 return;
1372
[email protected]52877dbc62012-06-29 22:22:031373 if (source == chrome::GetActiveWebContents(this)) {
[email protected]36b6dcb2008-11-12 01:19:571374 PrefService* prefs = profile_->GetPrefs();
[email protected]65233052011-08-22 19:02:481375 GetStatusBubble()->SetURL(url, prefs->GetString(prefs::kAcceptLanguages));
[email protected]36b6dcb2008-11-12 01:19:571376 }
1377}
1378
[email protected]92655362012-04-20 21:33:171379void Browser::ContentsMouseEvent(
1380 WebContents* source, const gfx::Point& location, bool motion) {
1381 if (!GetStatusBubble())
1382 return;
1383
[email protected]52877dbc62012-06-29 22:22:031384 if (source == chrome::GetActiveWebContents(this)) {
[email protected]92655362012-04-20 21:33:171385 GetStatusBubble()->MouseMoved(location, !motion);
1386 if (!motion)
1387 GetStatusBubble()->SetURL(GURL(), std::string());
1388 }
[email protected]3a6a3b62009-05-27 21:36:201389}
1390
[email protected]36b6dcb2008-11-12 01:19:571391void Browser::ContentsZoomChange(bool zoom_in) {
[email protected]5d98294912012-06-27 22:57:401392 chrome::ExecuteCommand(this, zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS);
[email protected]36b6dcb2008-11-12 01:19:571393}
1394
[email protected]2a6bc3e2011-12-28 23:51:331395void Browser::WebContentsFocused(WebContents* contents) {
1396 window_->WebContentsFocused(contents);
[email protected]7e383692009-06-12 19:14:541397}
1398
[email protected]b3996ba2012-08-08 00:39:131399bool Browser::TakeFocus(content::WebContents* source,
1400 bool reverse) {
[email protected]ad50def52011-10-19 23:17:071401 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271402 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
[email protected]6c2381d2011-10-19 02:52:531403 content::Source<Browser>(this),
[email protected]ad50def52011-10-19 23:17:071404 content::NotificationService::NoDetails());
[email protected]130efb02009-09-18 18:54:351405 return false;
1406}
1407
[email protected]b7a756d42012-01-23 18:08:171408gfx::Rect Browser::GetRootWindowResizerRect() const {
1409 return window_->GetRootWindowResizerRect();
1410}
1411
[email protected]1d3e9172012-06-12 02:59:131412void Browser::BeforeUnloadFired(WebContents* web_contents,
[email protected]36b6dcb2008-11-12 01:19:571413 bool proceed,
1414 bool* proceed_to_fire_unload) {
[email protected]f9b6c092012-07-09 19:32:281415 *proceed_to_fire_unload =
1416 unload_controller_->BeforeUnloadFired(web_contents, proceed);
[email protected]36b6dcb2008-11-12 01:19:571417}
1418
[email protected]a26dc362010-04-23 01:48:581419void Browser::SetFocusToLocationBar(bool select_all) {
[email protected]1a380622009-02-17 17:33:131420 // Two differences between this and FocusLocationBar():
1421 // (1) This doesn't get recorded in user metrics, since it's called
1422 // internally.
1423 // (2) This checks whether the location bar can be focused, and if not, clears
1424 // the focus. FocusLocationBar() is only reached when the location bar is
1425 // focusable, but this may be reached at other times, e.g. while in
1426 // fullscreen mode, where we need to leave focus in a consistent state.
[email protected]a26dc362010-04-23 01:48:581427 window_->SetFocusToLocationBar(select_all);
[email protected]4bcefee2009-01-29 15:57:571428}
1429
[email protected]7d5925a2009-03-03 02:59:121430void Browser::RenderWidgetShowing() {
1431 window_->DisableInactiveFrame();
1432}
[email protected]a239c3f2009-02-17 22:13:191433
[email protected]0a2aeb82009-05-15 21:52:481434int Browser::GetExtraRenderViewHeight() const {
1435 return window_->GetExtraRenderViewHeight();
1436}
1437
[email protected]2a6bc3e2011-12-28 23:51:331438void Browser::OnStartDownload(WebContents* source,
[email protected]e582fdd2011-12-20 16:48:171439 content::DownloadItem* download) {
[email protected]51c2e9a2012-10-10 04:28:101440 if (!download_util::ShouldShowInShelf(download))
1441 return;
1442
[email protected]6790f95f2012-09-21 19:49:451443 WebContents* constrained = GetConstrainingWebContents(source);
1444 if (constrained != source) {
[email protected]686493142011-07-15 21:47:221445 // Download in a constrained popup is shown in the tab that opened it.
[email protected]6790f95f2012-09-21 19:49:451446 constrained->GetDelegate()->OnStartDownload(constrained, download);
[email protected]686493142011-07-15 21:47:221447 return;
1448 }
1449
1450 if (!window())
1451 return;
1452
[email protected]27c14f02012-06-22 17:29:581453 // GetDownloadShelf creates the download shelf if it was not yet created.
1454 DownloadShelf* shelf = window()->GetDownloadShelf();
1455 shelf->AddDownload(new DownloadItemModel(download));
1456 // Don't show the animation for "Save file" downloads.
1457 // For non-theme extensions, we don't show the download animation.
1458 // Show animation in same window as the download shelf. Download shelf
[email protected]1f1cb852012-09-11 02:58:191459 // may not be in the same window that initiated the download.
[email protected]27c14f02012-06-22 17:29:581460 // Don't show the animation if the selected tab is not visible (i.e. the
1461 // window is minimized, we're in a unit test, etc.).
[email protected]52877dbc62012-06-29 22:22:031462 WebContents* shelf_tab = chrome::GetActiveWebContents(shelf->browser());
[email protected]27c14f02012-06-22 17:29:581463 if ((download->GetTotalBytes() > 0) &&
1464 !download_crx_util::IsExtensionDownload(*download) &&
1465 platform_util::IsVisible(shelf_tab->GetNativeView()) &&
1466 ui::Animation::ShouldRenderRichAnimation()) {
1467 DownloadStartedAnimation::Show(shelf_tab);
[email protected]a0e4b072011-08-17 01:47:071468 }
[email protected]686493142011-07-15 21:47:221469
1470 // If the download occurs in a new tab, close it.
[email protected]f5fa20e2011-12-21 22:35:561471 if (source->GetController().IsInitialNavigation() && tab_count() > 1)
[email protected]686493142011-07-15 21:47:221472 CloseContents(source);
1473}
1474
[email protected]2a6bc3e2011-12-28 23:51:331475void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) {
[email protected]1788e772010-12-15 16:40:501476 DCHECK(source);
[email protected]52877dbc62012-06-29 22:22:031477 TabContents* tab_contents = chrome::GetTabContentsAt(this,
[email protected]e52d0a42012-06-08 22:44:161478 tab_strip_model_->GetIndexOfWebContents(source));
[email protected]2cd4fde2012-06-26 03:10:261479 chrome::ViewSource(this, tab_contents);
[email protected]77d8d622010-12-15 10:30:121480}
1481
[email protected]2a6bc3e2011-12-28 23:51:331482void Browser::ViewSourceForFrame(WebContents* source,
[email protected]932b7a12011-03-09 12:50:271483 const GURL& frame_url,
1484 const std::string& frame_content_state) {
1485 DCHECK(source);
[email protected]52877dbc62012-06-29 22:22:031486 TabContents* tab_contents = chrome::GetTabContentsAt(this,
[email protected]e52d0a42012-06-08 22:44:161487 tab_strip_model_->GetIndexOfWebContents(source));
[email protected]2cd4fde2012-06-26 03:10:261488 chrome::ViewSource(this, tab_contents, frame_url, frame_content_state);
[email protected]932b7a12011-03-09 12:50:271489}
1490
[email protected]4fdf6742012-01-10 20:14:361491void Browser::ShowRepostFormWarningDialog(WebContents* source) {
[email protected]51296c62012-09-26 13:02:441492 TabModalConfirmDialog::Create(new RepostFormWarningController(source),
[email protected]70320ab2012-11-02 19:07:161493 source);
[email protected]14f3408a2009-08-31 20:53:531494}
1495
[email protected]4fdf6742012-01-10 20:14:361496bool Browser::ShouldCreateWebContents(
1497 WebContents* web_contents,
1498 int route_id,
1499 WindowContainerType window_container_type,
[email protected]03b6d552012-03-29 04:03:011500 const string16& frame_name,
1501 const GURL& target_url) {
[email protected]4fdf6742012-01-10 20:14:361502 if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1503 // If a BackgroundContents is created, suppress the normal WebContents.
1504 return !MaybeCreateBackgroundContents(
[email protected]03b6d552012-03-29 04:03:011505 route_id, web_contents, frame_name, target_url);
[email protected]4fdf6742012-01-10 20:14:361506 }
1507
1508 return true;
1509}
1510
1511void Browser::WebContentsCreated(WebContents* source_contents,
1512 int64 source_frame_id,
1513 const GURL& target_url,
1514 WebContents* new_contents) {
[email protected]6451fe92012-08-30 18:37:261515 // Adopt the WebContents now, so all observers are in place, as the network
[email protected]3d61dd02012-06-07 00:05:531516 // requests for its initial navigation will start immediately. The WebContents
1517 // will later be inserted into this browser using Browser::Navigate via
[email protected]6451fe92012-08-30 18:37:261518 // AddNewContents.
1519 AdoptAsTabContents(new_contents);
[email protected]4fdf6742012-01-10 20:14:361520
1521 // Notify.
1522 RetargetingDetails details;
1523 details.source_web_contents = source_contents;
1524 details.source_frame_id = source_frame_id;
1525 details.target_url = target_url;
1526 details.target_web_contents = new_contents;
1527 details.not_yet_in_tabstrip = true;
1528 content::NotificationService::current()->Notify(
1529 chrome::NOTIFICATION_RETARGETING,
1530 content::Source<Profile>(profile_),
1531 content::Details<RetargetingDetails>(&details));
[email protected]80c7b802011-10-28 19:59:081532}
1533
[email protected]2a6bc3e2011-12-28 23:51:331534void Browser::ContentRestrictionsChanged(WebContents* source) {
[email protected]5d98294912012-06-27 22:57:401535 command_controller_->ContentRestrictionsChanged();
[email protected]9e823662010-10-13 23:36:001536}
1537
[email protected]2a6bc3e2011-12-28 23:51:331538void Browser::RendererUnresponsive(WebContents* source) {
[email protected]c19d9542011-11-15 22:26:421539 // Ignore hangs if print preview is open.
[email protected]1d3e9172012-06-12 02:59:131540 TabContents* tab_contents = TabContents::FromWebContents(source);
[email protected]3d61dd02012-06-07 00:05:531541 if (tab_contents) {
[email protected]c19d9542011-11-15 22:26:421542 printing::PrintPreviewTabController* controller =
1543 printing::PrintPreviewTabController::GetInstance();
1544 if (controller) {
[email protected]3d61dd02012-06-07 00:05:531545 TabContents* preview_tab =
1546 controller->GetPrintPreviewForTab(tab_contents);
1547 if (preview_tab && preview_tab != tab_contents) {
[email protected]c19d9542011-11-15 22:26:421548 return;
1549 }
1550 }
1551 }
1552
[email protected]87586fb72012-07-02 13:15:021553 chrome::ShowHungRendererDialog(source);
[email protected]55452902011-06-01 21:57:471554}
1555
[email protected]2a6bc3e2011-12-28 23:51:331556void Browser::RendererResponsive(WebContents* source) {
[email protected]87586fb72012-07-02 13:15:021557 chrome::HideHungRendererDialog(source);
[email protected]55452902011-06-01 21:57:471558}
1559
[email protected]2a6bc3e2011-12-28 23:51:331560void Browser::WorkerCrashed(WebContents* source) {
[email protected]591a59f2012-10-11 01:16:231561 InfoBarTabHelper* infobar_helper =
1562 InfoBarTabHelper::FromWebContents(source);
[email protected]95a33ed62011-09-30 15:07:081563 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate(
1564 infobar_helper,
1565 NULL,
1566 l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]55452902011-06-01 21:57:471567 true));
[email protected]0dd3a0ab2011-02-18 08:17:441568}
1569
[email protected]1d3e9172012-06-12 02:59:131570void Browser::DidNavigateMainFramePostCommit(WebContents* web_contents) {
[email protected]52877dbc62012-06-29 22:22:031571 if (web_contents == chrome::GetActiveWebContents(this))
[email protected]09b29342011-06-24 19:18:481572 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
[email protected]93f230e02011-06-01 14:40:001573}
1574
[email protected]1d3e9172012-06-12 02:59:131575void Browser::DidNavigateToPendingEntry(WebContents* web_contents) {
[email protected]52877dbc62012-06-29 22:22:031576 if (web_contents == chrome::GetActiveWebContents(this))
[email protected]09b29342011-06-24 19:18:481577 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
[email protected]93f230e02011-06-01 14:40:001578}
1579
[email protected]3ab9cb82011-06-03 18:02:071580content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() {
1581 return GetJavaScriptDialogCreatorInstance();
1582}
1583
[email protected]1d3e9172012-06-12 02:59:131584content::ColorChooser* Browser::OpenColorChooser(WebContents* web_contents,
[email protected]da8543762012-03-20 08:52:201585 int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321586 SkColor color) {
[email protected]da8543762012-03-20 08:52:201587#if defined(OS_WIN)
1588 // On Windows, only create a color chooser if one doesn't exist, because we
1589 // can't close the old color chooser dialog.
1590 if (!color_chooser_.get())
[email protected]1d3e9172012-06-12 02:59:131591 color_chooser_.reset(content::ColorChooser::Create(color_chooser_id,
1592 web_contents,
[email protected]da8543762012-03-20 08:52:201593 color));
1594#else
1595 if (color_chooser_.get())
1596 color_chooser_->End();
[email protected]1d3e9172012-06-12 02:59:131597 color_chooser_.reset(content::ColorChooser::Create(color_chooser_id,
1598 web_contents,
[email protected]da8543762012-03-20 08:52:201599 color));
1600#endif
1601 return color_chooser_.get();
1602}
1603
1604void Browser::DidEndColorChooser() {
1605 color_chooser_.reset();
1606}
1607
[email protected]1d3e9172012-06-12 02:59:131608void Browser::RunFileChooser(WebContents* web_contents,
[email protected]8caadeb2011-11-22 02:45:231609 const content::FileChooserParams& params) {
[email protected]1d3e9172012-06-12 02:59:131610 FileSelectHelper::RunFileChooser(web_contents, params);
[email protected]3a29a6e2011-08-24 18:26:211611}
1612
[email protected]1d3e9172012-06-12 02:59:131613void Browser::EnumerateDirectory(WebContents* web_contents,
[email protected]33f8ad52012-05-22 18:10:131614 int request_id,
[email protected]3a29a6e2011-08-24 18:26:211615 const FilePath& path) {
[email protected]1d3e9172012-06-12 02:59:131616 FileSelectHelper::EnumerateDirectory(web_contents, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211617}
1618
[email protected]1d3e9172012-06-12 02:59:131619void Browser::ToggleFullscreenModeForTab(WebContents* web_contents,
[email protected]01a5a762011-11-21 05:40:551620 bool enter_fullscreen) {
[email protected]1d3e9172012-06-12 02:59:131621 fullscreen_controller_->ToggleFullscreenModeForTab(web_contents,
1622 enter_fullscreen);
[email protected]8a5e0ca2011-08-25 06:30:471623}
1624
[email protected]1d3e9172012-06-12 02:59:131625bool Browser::IsFullscreenForTabOrPending(
1626 const WebContents* web_contents) const {
1627 return fullscreen_controller_->IsFullscreenForTabOrPending(web_contents);
[email protected]5d5f7af2011-10-01 01:38:121628}
1629
[email protected]1d3e9172012-06-12 02:59:131630void Browser::JSOutOfMemory(WebContents* web_contents) {
1631 JSOutOfMemoryHelper(web_contents);
[email protected]7d189022011-08-25 22:54:201632}
1633
[email protected]1d3e9172012-06-12 02:59:131634void Browser::RegisterProtocolHandler(WebContents* web_contents,
[email protected]7d189022011-08-25 22:54:201635 const std::string& protocol,
1636 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:361637 const string16& title,
1638 bool user_gesture) {
[email protected]1d3e9172012-06-12 02:59:131639 RegisterProtocolHandlerHelper(
[email protected]7ae9c322012-07-17 23:46:441640 web_contents, protocol, url, title, user_gesture, window());
[email protected]7d189022011-08-25 22:54:201641}
1642
[email protected]3a3b75a2012-06-01 08:38:361643void Browser::RegisterIntentHandler(
[email protected]1d3e9172012-06-12 02:59:131644 WebContents* web_contents,
[email protected]3a3b75a2012-06-01 08:38:361645 const webkit_glue::WebIntentServiceData& data,
1646 bool user_gesture) {
[email protected]1d3e9172012-06-12 02:59:131647 RegisterIntentHandlerHelper(web_contents, data, user_gesture);
[email protected]7d189022011-08-25 22:54:201648}
1649
[email protected]0d9989d2011-12-21 20:26:001650void Browser::WebIntentDispatch(
[email protected]1d3e9172012-06-12 02:59:131651 WebContents* web_contents,
1652 content::WebIntentsDispatcher* intents_dispatcher) {
[email protected]59d73ec2012-09-01 02:24:271653 if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) {
1654 web_intents::RecordIntentsDispatchDisabled();
[email protected]2c273bd2012-10-25 18:55:031655 delete intents_dispatcher;
[email protected]828e61af2011-09-14 19:45:061656 return;
[email protected]59d73ec2012-09-01 02:24:271657 }
[email protected]828e61af2011-09-14 19:45:061658
[email protected]2c273bd2012-10-25 18:55:031659 // Make sure the requester is coming from an extension/app page.
1660 // Internal dispatches set |web_contents| to NULL.
1661#if !defined(OS_CHROMEOS)
1662 if (web_contents &&
1663 !CommandLine::ForCurrentProcess()->HasSwitch(
1664 switches::kWebIntentsInvocationEnabled)) {
1665 ExtensionService* extensions_service = profile_->GetExtensionService();
1666 if (!extensions_service ||
1667 extensions_service->extensions()->GetExtensionOrAppByURL(
1668 ExtensionURLInfo(web_contents->GetURL())) == NULL) {
1669 web_intents::RecordIntentsDispatchDisabled();
1670 intents_dispatcher->SendReplyMessage(
1671 webkit_glue::WEB_INTENT_REPLY_FAILURE,
1672 ASCIIToUTF16("Intents may only be invoked from extensions/apps."));
1673 return;
1674 }
1675 }
[email protected]6942641d2012-10-26 06:42:391676#else
1677 // ChromeOS currently uses a couple specific intent actions.
1678 // TODO(gbillock): delete this when we find good alternatives for those uses.
1679 if (intents_dispatcher->GetIntent().action !=
1680 ASCIIToUTF16(web_intents::kActionCrosEcho) &&
1681 intents_dispatcher->GetIntent().action !=
1682 ASCIIToUTF16(web_intents::kActionView)) {
1683 web_intents::RecordIntentsDispatchDisabled();
1684 intents_dispatcher->SendReplyMessage(
1685 webkit_glue::WEB_INTENT_REPLY_FAILURE,
1686 ASCIIToUTF16("Intents may only be invoked from extensions/apps."));
1687 return;
1688 }
[email protected]2c273bd2012-10-25 18:55:031689#endif
1690
[email protected]59d73ec2012-09-01 02:24:271691 web_intents::RecordIntentDispatchRequested();
[email protected]86238d22012-05-22 20:00:111692
[email protected]bd52a982012-06-26 23:34:291693 if (!web_contents) {
1694 // Intent is system-caused and the picker will show over the currently
1695 // active web contents.
[email protected]52877dbc62012-06-29 22:22:031696 web_contents = chrome::GetActiveWebContents(this);
[email protected]bd52a982012-06-26 23:34:291697 }
[email protected]231cf3e2012-09-25 20:54:471698 WebIntentPickerController* web_intent_picker_controller =
1699 WebIntentPickerController::FromWebContents(web_contents);
1700 web_intent_picker_controller->SetIntentsDispatcher(intents_dispatcher);
1701 web_intent_picker_controller->ShowDialog(
[email protected]0d9989d2011-12-21 20:26:001702 intents_dispatcher->GetIntent().action,
1703 intents_dispatcher->GetIntent().type);
[email protected]b888919c2011-09-02 00:32:161704}
1705
[email protected]2a6bc3e2011-12-28 23:51:331706void Browser::UpdatePreferredSize(WebContents* source,
[email protected]0548c5352011-09-07 00:33:331707 const gfx::Size& pref_size) {
1708 window_->UpdatePreferredSize(source, pref_size);
1709}
1710
[email protected]61e2b3cc2012-03-02 16:13:341711void Browser::ResizeDueToAutoResize(WebContents* source,
1712 const gfx::Size& new_size) {
1713 window_->ResizeDueToAutoResize(source, new_size);
1714}
1715
[email protected]1d3e9172012-06-12 02:59:131716void Browser::FindReply(WebContents* web_contents,
[email protected]92655362012-04-20 21:33:171717 int request_id,
1718 int number_of_matches,
1719 const gfx::Rect& selection_rect,
1720 int active_match_ordinal,
1721 bool final_update) {
[email protected]1d3e9172012-06-12 02:59:131722 FindReplyHelper(web_contents, request_id, number_of_matches, selection_rect,
[email protected]92655362012-04-20 21:33:171723 active_match_ordinal, final_update);
1724}
1725
[email protected]1d3e9172012-06-12 02:59:131726void Browser::RequestToLockMouse(WebContents* web_contents,
[email protected]a9c81f02012-06-01 00:15:441727 bool user_gesture,
1728 bool last_unlocked_by_target) {
[email protected]1d3e9172012-06-12 02:59:131729 fullscreen_controller_->RequestToLockMouse(web_contents,
[email protected]a9c81f02012-06-01 00:15:441730 user_gesture,
1731 last_unlocked_by_target);
[email protected]55c87fa2011-10-15 07:28:281732}
1733
[email protected]5ef8e372011-10-18 04:25:551734void Browser::LostMouseLock() {
[email protected]01a5a762011-11-21 05:40:551735 fullscreen_controller_->LostMouseLock();
[email protected]5ef8e372011-10-18 04:25:551736}
1737
[email protected]f13b4202012-06-12 23:53:231738void Browser::RequestMediaAccessPermission(
1739 content::WebContents* web_contents,
1740 const content::MediaStreamRequest* request,
1741 const content::MediaResponseCallback& callback) {
[email protected]c55d3d122012-07-10 16:53:411742 RequestMediaAccessPermissionHelper(web_contents, request, callback);
[email protected]f13b4202012-06-12 23:53:231743}
1744
[email protected]36b6dcb2008-11-12 01:19:571745///////////////////////////////////////////////////////////////////////////////
[email protected]51d83bdf2011-12-09 16:09:291746// Browser, CoreTabHelperDelegate implementation:
[email protected]a0366a52011-02-04 20:04:211747
[email protected]ece4aca2012-09-19 22:22:581748void Browser::SwapTabContents(content::WebContents* old_contents,
1749 content::WebContents* new_contents) {
1750 int index = tab_strip_model_->GetIndexOfWebContents(old_contents);
[email protected]92655362012-04-20 21:33:171751 DCHECK_NE(TabStripModel::kNoTab, index);
[email protected]ece4aca2012-09-19 22:22:581752 TabContents* new_tab_contents = TabContents::FromWebContents(new_contents);
[email protected]2fc15ae2012-05-06 00:01:371753 tab_strip_model_->ReplaceTabContentsAt(index, new_tab_contents);
[email protected]92655362012-04-20 21:33:171754}
1755
[email protected]ece4aca2012-09-19 22:22:581756bool Browser::CanReloadContents(content::WebContents* web_contents) const {
[email protected]5d98294912012-06-27 22:57:401757 return chrome::CanReload(this);
[email protected]e1461952012-06-14 21:05:351758}
1759
[email protected]ece4aca2012-09-19 22:22:581760bool Browser::CanSaveContents(content::WebContents* web_contents) const {
[email protected]5d98294912012-06-27 22:57:401761 return chrome::CanSavePage(this);
[email protected]e1461952012-06-14 21:05:351762}
1763
[email protected]92655362012-04-20 21:33:171764///////////////////////////////////////////////////////////////////////////////
1765// Browser, SearchEngineTabHelperDelegate implementation:
1766
[email protected]3613347d2012-04-27 20:27:371767void Browser::ConfirmAddSearchProvider(TemplateURL* template_url,
[email protected]92655362012-04-20 21:33:171768 Profile* profile) {
1769 window()->ConfirmAddSearchProvider(template_url, profile);
1770}
1771
1772///////////////////////////////////////////////////////////////////////////////
1773// Browser, ConstrainedWindowTabHelperDelegate implementation:
1774
[email protected]c6464ad2012-10-03 00:27:281775void Browser::SetTabContentBlocked(content::WebContents* web_contents,
1776 bool blocked) {
1777 int index = tab_strip_model_->GetIndexOfWebContents(web_contents);
[email protected]92655362012-04-20 21:33:171778 if (index == TabStripModel::kNoTab) {
1779 NOTREACHED();
1780 return;
1781 }
[email protected]2fc15ae2012-05-06 00:01:371782 tab_strip_model_->SetTabBlocked(index, blocked);
[email protected]5d98294912012-06-27 22:57:401783 command_controller_->PrintingStateChanged();
[email protected]c6464ad2012-10-03 00:27:281784 if (!blocked && chrome::GetActiveWebContents(this) == web_contents)
1785 web_contents->Focus();
[email protected]92655362012-04-20 21:33:171786}
1787
[email protected]0d7f382f2012-10-26 00:57:511788bool Browser::GetConstrainedWindowTopCenter(gfx::Point* point) {
1789 int y = 0;
1790 if (window_->GetConstrainedWindowTopY(&y)) {
1791 *point = gfx::Point(window_->GetBounds().width() / 2, y);
1792 return true;
1793 }
1794
1795 return false;
[email protected]6a151762012-10-03 22:33:191796}
1797
[email protected]92655362012-04-20 21:33:171798///////////////////////////////////////////////////////////////////////////////
1799// Browser, BlockedContentTabHelperDelegate implementation:
1800
[email protected]6790f95f2012-09-21 19:49:451801content::WebContents* Browser::GetConstrainingWebContents(
1802 content::WebContents* source) {
[email protected]92655362012-04-20 21:33:171803 return source;
1804}
1805
1806///////////////////////////////////////////////////////////////////////////////
1807// Browser, BookmarkTabHelperDelegate implementation:
1808
[email protected]1c5119c2012-09-19 00:08:571809void Browser::URLStarredChanged(content::WebContents* web_contents,
1810 bool starred) {
1811 if (web_contents == chrome::GetActiveWebContents(this))
[email protected]92655362012-04-20 21:33:171812 window_->SetStarredState(starred);
1813}
1814
1815///////////////////////////////////////////////////////////////////////////////
[email protected]6f80e932012-06-04 19:00:071816// Browser, ZoomObserver implementation:
1817
[email protected]dea9cee82012-09-25 03:10:521818void Browser::OnZoomChanged(content::WebContents* source,
1819 bool can_show_bubble) {
1820 if (source == chrome::GetActiveWebContents(this)) {
[email protected]6f80e932012-06-04 19:00:071821 // Only show the zoom bubble for zoom changes in the active window.
[email protected]5423c372012-08-22 05:50:161822 window_->ZoomChangedForActiveTab(can_show_bubble && window_->IsActive());
[email protected]6f80e932012-06-04 19:00:071823 }
1824}
1825
1826///////////////////////////////////////////////////////////////////////////////
[email protected]92f54082012-07-31 01:43:141827// Browser, ui::SelectFileDialog::Listener implementation:
[email protected]36b6dcb2008-11-12 01:19:571828
[email protected]561abe62009-04-06 18:08:341829void Browser::FileSelected(const FilePath& path, int index, void* params) {
[email protected]53f04c82012-07-26 02:31:091830 FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params);
1831}
1832
1833void Browser::FileSelectedWithExtraInfo(
1834 const ui::SelectedFileInfo& file_info,
1835 int index,
1836 void* params) {
1837 profile_->set_last_selected_directory(file_info.file_path.DirName());
1838
1839 const FilePath& path = file_info.local_path;
[email protected]72cbd322009-04-07 10:17:121840 GURL file_url = net::FilePathToFileURL(path);
[email protected]b7813a22012-04-04 18:41:021841
1842#if defined(OS_CHROMEOS)
[email protected]d9d04df2012-10-12 07:06:351843 drive::util::ModifyDriveFileResourceUrl(profile_, path, &file_url);
[email protected]b7813a22012-04-04 18:41:021844#endif
1845
[email protected]e5d549d2011-12-28 01:29:201846 if (file_url.is_empty())
1847 return;
1848
1849 OpenURL(OpenURLParams(
1850 file_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED,
1851 false));
[email protected]36b6dcb2008-11-12 01:19:571852}
1853
1854///////////////////////////////////////////////////////////////////////////////
[email protected]6c2381d2011-10-19 02:52:531855// Browser, content::NotificationObserver implementation:
[email protected]36b6dcb2008-11-12 01:19:571856
[email protected]432115822011-07-10 15:52:271857void Browser::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:531858 const content::NotificationSource& source,
1859 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:271860 switch (type) {
[email protected]432115822011-07-10 15:52:271861 case content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED:
[email protected]e83f1682008-09-07 23:57:401862 // When the current tab's SSL state changes, we need to update the URL
[email protected]90e8d062008-09-08 02:26:321863 // bar to reflect the new state. Note that it's possible for the selected
1864 // tab contents to be NULL. This is because we listen for all sources
1865 // (NavigationControllers) for convenience, so the notification could
1866 // actually be for a different window while we're doing asynchronous
1867 // closing of this one.
[email protected]52877dbc62012-06-29 22:22:031868 if (chrome::GetActiveWebContents(this) &&
1869 &chrome::GetActiveWebContents(this)->GetController() ==
[email protected]c5eed492012-01-04 17:07:501870 content::Source<NavigationController>(source).ptr())
[email protected]36b6dcb2008-11-12 01:19:571871 UpdateToolbar(false);
[email protected]e83f1682008-09-07 23:57:401872 break;
1873
[email protected]432115822011-07-10 15:52:271874 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
[email protected]ce696a452011-05-31 17:47:361875 if (window()->GetLocationBar())
1876 window()->GetLocationBar()->UpdatePageActions();
[email protected]57f71b92009-09-11 19:31:381877
[email protected]b3f7fe22011-11-11 19:27:561878 // Close any tabs from the unloaded extension, unless it's terminated,
1879 // in which case let the sad tabs remain.
[email protected]1c321ee52012-05-21 03:02:341880 if (content::Details<extensions::UnloadedExtensionInfo>(
1881 details)->reason != extension_misc::UNLOAD_REASON_TERMINATE) {
[email protected]b3f7fe22011-11-11 19:27:561882 const Extension* extension =
[email protected]1c321ee52012-05-21 03:02:341883 content::Details<extensions::UnloadedExtensionInfo>(
1884 details)->extension;
[email protected]2fc15ae2012-05-06 00:01:371885 for (int i = tab_strip_model_->count() - 1; i >= 0; --i) {
[email protected]52877dbc62012-06-29 22:22:031886 WebContents* tc = chrome::GetTabContentsAt(this, i)->web_contents();
[email protected]1f1cb852012-09-11 02:58:191887 if (tc->GetURL().SchemeIs(chrome::kExtensionScheme) &&
1888 tc->GetURL().host() == extension->id())
[email protected]52877dbc62012-06-29 22:22:031889 chrome::CloseWebContents(this, tc);
[email protected]894bb502009-05-21 22:39:571890 }
1891 }
1892 break;
1893 }
1894
[email protected]432115822011-07-10 15:52:271895 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:531896 Profile* profile = content::Source<Profile>(source).ptr();
[email protected]fe8944f2011-08-30 17:47:321897 if (profile_->IsSameProfile(profile) && window()->GetLocationBar())
[email protected]ce696a452011-05-31 17:47:361898 window()->GetLocationBar()->InvalidatePageActions();
[email protected]371ed7a2009-08-25 15:22:461899 break;
1900 }
1901
[email protected]432115822011-07-10 15:52:271902 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED:
1903 case chrome::NOTIFICATION_EXTENSION_LOADED:
[email protected]1797f4a2011-08-30 18:00:281904 // During window creation on Windows we may end up calling into
1905 // SHAppBarMessage, which internally spawns a nested message loop. This
1906 // makes it possible for us to end up here before window creation has
1907 // completed,at which point window_ is NULL. See 94752 for details.
1908 if (window() && window()->GetLocationBar())
[email protected]ce696a452011-05-31 17:47:361909 window()->GetLocationBar()->UpdatePageActions();
[email protected]0dfe05c2011-02-23 23:03:361910 break;
[email protected]ad0c2e1b2010-01-30 00:00:101911
[email protected]6b40bb582012-03-15 20:50:381912#if defined(ENABLE_THEMES)
[email protected]432115822011-07-10 15:52:271913 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
[email protected]e001d412009-06-26 20:53:251914 window()->UserChangedTheme();
1915 break;
[email protected]6b40bb582012-03-15 20:50:381916#endif
[email protected]e001d412009-06-26 20:53:251917
[email protected]ea049a02011-12-25 21:37:091918 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: {
1919 WebContents* web_contents = content::Source<WebContents>(source).ptr();
[email protected]52877dbc62012-06-29 22:22:031920 if (web_contents == chrome::GetActiveWebContents(this)) {
[email protected]9a9a9e22011-05-13 22:20:351921 LocationBar* location_bar = window()->GetLocationBar();
1922 if (location_bar)
1923 location_bar->UpdateContentSettingsIcons();
1924 }
1925 break;
1926 }
1927
[email protected]432115822011-07-10 15:52:271928 case content::NOTIFICATION_INTERSTITIAL_ATTACHED:
[email protected]09b29342011-06-24 19:18:481929 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
[email protected]e397a4472011-12-21 21:47:501930 break;
1931
1932 case content::NOTIFICATION_INTERSTITIAL_DETACHED:
1933 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
[email protected]09b29342011-06-24 19:18:481934 break;
1935
[email protected]e83f1682008-09-07 23:57:401936 default:
1937 NOTREACHED() << "Got a notification we didn't register for.";
initial.commit09911bf2008-07-26 23:55:291938 }
1939}
1940
[email protected]a6a7ced2012-11-01 17:24:181941void Browser::OnPreferenceChanged(PrefServiceBase* service,
1942 const std::string& pref_name) {
1943 if (pref_name == prefs::kDevToolsDisabled) {
1944 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
1945 content::DevToolsManager::GetInstance()->CloseAllClientHosts();
1946 } else if (pref_name == prefs::kShowBookmarkBar) {
1947 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE);
1948 } else if (pref_name == prefs::kHomePage) {
1949 MarkHomePageAsChanged(static_cast<PrefService*>(service));
1950 } else {
1951 NOTREACHED();
1952 }
1953}
1954
[email protected]c3166302012-09-25 21:27:081955void Browser::ModeChanged(const chrome::search::Mode& old_mode,
1956 const chrome::search::Mode& new_mode) {
1957 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
1958}
1959
[email protected]d3b98c82010-07-14 07:45:591960///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:571961// Browser, Command and state updating (private):
1962
[email protected]6c6b02d2011-09-02 03:36:471963void Browser::MarkHomePageAsChanged(PrefService* pref_service) {
1964 pref_service->SetBoolean(prefs::kHomePageChanged, true);
[email protected]6c6b02d2011-09-02 03:36:471965}
1966
[email protected]36b6dcb2008-11-12 01:19:571967///////////////////////////////////////////////////////////////////////////////
1968// Browser, UI update coalescing and handling (private):
1969
1970void Browser::UpdateToolbar(bool should_restore_state) {
[email protected]52877dbc62012-06-29 22:22:031971 window_->UpdateToolbar(chrome::GetActiveTabContents(this),
1972 should_restore_state);
initial.commit09911bf2008-07-26 23:55:291973}
1974
[email protected]e3a5d5b2012-06-22 17:56:461975void Browser::UpdateSearchState(TabContents* contents) {
1976 if (chrome::search::IsInstantExtendedAPIEnabled(profile_))
[email protected]0dc50db2012-09-19 17:57:141977 search_delegate_->OnTabActivated(contents->web_contents());
[email protected]e3a5d5b2012-06-22 17:56:461978}
1979
[email protected]2a6bc3e2011-12-28 23:51:331980void Browser::ScheduleUIUpdate(const WebContents* source,
[email protected]36b6dcb2008-11-12 01:19:571981 unsigned changed_flags) {
[email protected]a5231662009-09-26 00:56:001982 if (!source)
1983 return;
1984
[email protected]2b4355c2009-04-04 17:55:461985 // Do some synchronous updates.
[email protected]d9083482012-01-06 00:38:461986 if (changed_flags & content::INVALIDATE_TYPE_URL &&
[email protected]52877dbc62012-06-29 22:22:031987 source == chrome::GetActiveWebContents(this)) {
[email protected]36b6dcb2008-11-12 01:19:571988 // Only update the URL for the current tab. Note that we do not update
1989 // the navigation commands since those would have already been updated
1990 // synchronously by NavigationStateChanged.
1991 UpdateToolbar(false);
[email protected]d9083482012-01-06 00:38:461992 changed_flags &= ~content::INVALIDATE_TYPE_URL;
[email protected]36b6dcb2008-11-12 01:19:571993 }
[email protected]d9083482012-01-06 00:38:461994 if (changed_flags & content::INVALIDATE_TYPE_LOAD) {
[email protected]6ebdc9b2010-09-27 16:55:571995 // Update the loading state synchronously. This is so the throbber will
1996 // immediately start/stop, which gives a more snappy feel. We want to do
[email protected]a5231662009-09-26 00:56:001997 // this for any tab so they start & stop quickly.
[email protected]2fc15ae2012-05-06 00:01:371998 tab_strip_model_->UpdateTabContentsStateAt(
[email protected]52877dbc62012-06-29 22:22:031999 chrome::GetIndexOfTab(this, source),
[email protected]6ebdc9b2010-09-27 16:55:572000 TabStripModelObserver::LOADING_ONLY);
[email protected]d9083482012-01-06 00:38:462001 // The status bubble needs to be updated during INVALIDATE_TYPE_LOAD too,
2002 // but we do that asynchronously by not stripping INVALIDATE_TYPE_LOAD from
[email protected]6ebdc9b2010-09-27 16:55:572003 // changed_flags.
[email protected]8030f012009-09-25 18:09:372004 }
2005
[email protected]d9083482012-01-06 00:38:462006 if (changed_flags & content::INVALIDATE_TYPE_TITLE && !source->IsLoading()) {
[email protected]f1cd5e82009-10-23 17:19:032007 // To correctly calculate whether the title changed while not loading
2008 // we need to process the update synchronously. This state only matters for
2009 // the TabStripModel, so we notify the TabStripModel now and notify others
2010 // asynchronously.
[email protected]2fc15ae2012-05-06 00:01:372011 tab_strip_model_->UpdateTabContentsStateAt(
[email protected]52877dbc62012-06-29 22:22:032012 chrome::GetIndexOfTab(this, source),
[email protected]f1cd5e82009-10-23 17:19:032013 TabStripModelObserver::TITLE_NOT_LOADING);
2014 }
2015
[email protected]2b4355c2009-04-04 17:55:462016 // If the only updates were synchronously handled above, we're done.
[email protected]8030f012009-09-25 18:09:372017 if (changed_flags == 0)
[email protected]2b4355c2009-04-04 17:55:462018 return;
[email protected]36b6dcb2008-11-12 01:19:572019
2020 // Save the dirty bits.
[email protected]85354982009-09-25 19:58:402021 scheduled_updates_[source] |= changed_flags;
[email protected]36b6dcb2008-11-12 01:19:572022
[email protected]24f1477532011-11-22 22:55:362023 if (!chrome_updater_factory_.HasWeakPtrs()) {
[email protected]36b6dcb2008-11-12 01:19:572024 // No task currently scheduled, start another.
[email protected]0586b0e2010-02-12 21:38:372025 MessageLoop::current()->PostDelayedTask(
2026 FROM_HERE,
[email protected]24f1477532011-11-22 22:55:362027 base::Bind(&Browser::ProcessPendingUIUpdates,
2028 chrome_updater_factory_.GetWeakPtr()),
[email protected]11d6ab1a2012-01-12 21:37:262029 base::TimeDelta::FromMilliseconds(kUIUpdateCoalescingTimeMS));
[email protected]36b6dcb2008-11-12 01:19:572030 }
2031}
2032
2033void Browser::ProcessPendingUIUpdates() {
2034#ifndef NDEBUG
2035 // Validate that all tabs we have pending updates for exist. This is scary
2036 // because the pending list must be kept in sync with any detached or
[email protected]a5231662009-09-26 00:56:002037 // deleted tabs.
[email protected]85354982009-09-25 19:58:402038 for (UpdateMap::const_iterator i = scheduled_updates_.begin();
2039 i != scheduled_updates_.end(); ++i) {
[email protected]36b6dcb2008-11-12 01:19:572040 bool found = false;
2041 for (int tab = 0; tab < tab_count(); tab++) {
[email protected]52877dbc62012-06-29 22:22:032042 if (chrome::GetWebContentsAt(this, tab) == i->first) {
[email protected]36b6dcb2008-11-12 01:19:572043 found = true;
2044 break;
2045 }
2046 }
2047 DCHECK(found);
2048 }
2049#endif
2050
[email protected]24f1477532011-11-22 22:55:362051 chrome_updater_factory_.InvalidateWeakPtrs();
[email protected]36b6dcb2008-11-12 01:19:572052
[email protected]85354982009-09-25 19:58:402053 for (UpdateMap::const_iterator i = scheduled_updates_.begin();
2054 i != scheduled_updates_.end(); ++i) {
[email protected]36b6dcb2008-11-12 01:19:572055 // Do not dereference |contents|, it may be out-of-date!
[email protected]2a6bc3e2011-12-28 23:51:332056 const WebContents* contents = i->first;
[email protected]85354982009-09-25 19:58:402057 unsigned flags = i->second;
[email protected]36b6dcb2008-11-12 01:19:572058
[email protected]52877dbc62012-06-29 22:22:032059 if (contents == chrome::GetActiveWebContents(this)) {
[email protected]a5231662009-09-26 00:56:002060 // Updates that only matter when the tab is selected go here.
[email protected]f7f3a5f2009-05-01 22:02:342061
[email protected]d9083482012-01-06 00:38:462062 if (flags & content::INVALIDATE_TYPE_PAGE_ACTIONS) {
[email protected]9800de5e2011-03-11 18:19:492063 LocationBar* location_bar = window()->GetLocationBar();
2064 if (location_bar)
2065 location_bar->UpdatePageActions();
2066 }
[email protected]6ebdc9b2010-09-27 16:55:572067 // Updating the URL happens synchronously in ScheduleUIUpdate.
[email protected]d9083482012-01-06 00:38:462068 if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) {
[email protected]ece4aca2012-09-19 22:22:582069 GetStatusBubble()->SetStatus(
2070 CoreTabHelper::FromWebContents(chrome::GetActiveWebContents(this))->
2071 GetStatusText());
[email protected]0dd3a0ab2011-02-18 08:17:442072 }
[email protected]a5231662009-09-26 00:56:002073
[email protected]d9083482012-01-06 00:38:462074 if (flags & (content::INVALIDATE_TYPE_TAB |
2075 content::INVALIDATE_TYPE_TITLE)) {
[email protected]a5231662009-09-26 00:56:002076 window_->UpdateTitleBar();
2077 }
[email protected]4d34e2e2009-05-26 22:55:282078 }
[email protected]36b6dcb2008-11-12 01:19:572079
[email protected]a5231662009-09-26 00:56:002080 // Updates that don't depend upon the selected state go here.
[email protected]d9083482012-01-06 00:38:462081 if (flags &
2082 (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) {
[email protected]2fc15ae2012-05-06 00:01:372083 tab_strip_model_->UpdateTabContentsStateAt(
[email protected]e52d0a42012-06-08 22:44:162084 tab_strip_model_->GetIndexOfWebContents(contents),
[email protected]f1cd5e82009-10-23 17:19:032085 TabStripModelObserver::ALL);
[email protected]36b6dcb2008-11-12 01:19:572086 }
2087
2088 // We don't need to process INVALIDATE_STATE, since that's not visible.
2089 }
2090
2091 scheduled_updates_.clear();
2092}
2093
[email protected]d9083482012-01-06 00:38:462094void Browser::RemoveScheduledUpdatesFor(WebContents* contents) {
[email protected]36b6dcb2008-11-12 01:19:572095 if (!contents)
2096 return;
2097
[email protected]85354982009-09-25 19:58:402098 UpdateMap::iterator i = scheduled_updates_.find(contents);
2099 if (i != scheduled_updates_.end())
2100 scheduled_updates_.erase(i);
initial.commit09911bf2008-07-26 23:55:292101}
2102
[email protected]d938aed92009-01-22 19:49:332103
[email protected]36b6dcb2008-11-12 01:19:572104///////////////////////////////////////////////////////////////////////////////
2105// Browser, Getters for UI (private):
initial.commit09911bf2008-07-26 23:55:292106
[email protected]36b6dcb2008-11-12 01:19:572107StatusBubble* Browser::GetStatusBubble() {
[email protected]34930432009-11-09 00:12:092108 // In kiosk mode, we want to always hide the status bubble.
2109 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
2110 return NULL;
[email protected]9b032bf2009-07-21 17:34:232111 return window_ ? window_->GetStatusBubble() : NULL;
initial.commit09911bf2008-07-26 23:55:292112}
2113
[email protected]36b6dcb2008-11-12 01:19:572114///////////////////////////////////////////////////////////////////////////////
2115// Browser, Session restore functions (private):
initial.commit09911bf2008-07-26 23:55:292116
2117void Browser::SyncHistoryWithTabs(int index) {
[email protected]92371eb2011-04-28 11:50:152118 SessionService* session_service =
2119 SessionServiceFactory::GetForProfileIfExisting(profile());
initial.commit09911bf2008-07-26 23:55:292120 if (session_service) {
2121 for (int i = index; i < tab_count(); ++i) {
[email protected]50a9a76b2012-09-12 14:19:362122 WebContents* web_contents = chrome::GetWebContentsAt(this, i);
2123 if (web_contents) {
2124 SessionTabHelper* session_tab_helper =
2125 SessionTabHelper::FromWebContents(web_contents);
initial.commit09911bf2008-07-26 23:55:292126 session_service->SetTabIndexInWindow(
[email protected]50a9a76b2012-09-12 14:19:362127 session_id(), session_tab_helper->session_id(), i);
[email protected]ecc523f62010-09-28 22:45:402128 session_service->SetPinnedState(
2129 session_id(),
[email protected]50a9a76b2012-09-12 14:19:362130 session_tab_helper->session_id(),
[email protected]52877dbc62012-06-29 22:22:032131 tab_strip_model_->IsTabPinned(i));
initial.commit09911bf2008-07-26 23:55:292132 }
2133 }
2134 }
2135}
2136
[email protected]36b6dcb2008-11-12 01:19:572137///////////////////////////////////////////////////////////////////////////////
[email protected]69444cc2009-04-09 20:40:062138// Browser, In-progress download termination handling (private):
2139
[email protected]b6a4ac2b2011-10-17 20:05:482140bool Browser::CanCloseWithInProgressDownloads() {
[email protected]5a17d492011-10-24 19:37:032141 // If we've prompted, we need to hear from the user before we
2142 // can close.
2143 if (cancel_download_confirmation_state_ != NOT_PROMPTED)
2144 return cancel_download_confirmation_state_ != WAITING_FOR_RESPONSE;
2145
2146 int num_downloads_blocking;
2147 if (DOWNLOAD_CLOSE_OK ==
2148 OkToCloseWithInProgressDownloads(&num_downloads_blocking))
[email protected]446295a2010-04-19 23:43:002149 return true;
2150
[email protected]5a17d492011-10-24 19:37:032151 // Closing this window will kill some downloads; prompt to make sure
2152 // that's ok.
[email protected]69444cc2009-04-09 20:40:062153 cancel_download_confirmation_state_ = WAITING_FOR_RESPONSE;
2154 window_->ConfirmBrowserCloseWithPendingDownloads();
2155
2156 // Return false so the browser does not close. We'll close if the user
2157 // confirms in the dialog.
2158 return false;
2159}
2160
2161///////////////////////////////////////////////////////////////////////////////
[email protected]36b6dcb2008-11-12 01:19:572162// Browser, Assorted utility functions (private):
initial.commit09911bf2008-07-26 23:55:292163
[email protected]36b6dcb2008-11-12 01:19:572164void Browser::CloseFrame() {
2165 window_->Close();
initial.commit09911bf2008-07-26 23:55:292166}
2167
[email protected]3d61dd02012-06-07 00:05:532168void Browser::TabDetachedAtImpl(TabContents* contents, int index,
[email protected]c37e3b62010-01-22 00:15:172169 DetachType type) {
2170 if (type == DETACH_TYPE_DETACH) {
[email protected]56580852010-11-17 16:09:152171 // Save the current location bar state, but only if the tab being detached
2172 // is the selected tab. Because saving state can conditionally revert the
2173 // location bar, saving the current tab's location bar state to a
2174 // non-selected tab can corrupt both tabs.
[email protected]52877dbc62012-06-29 22:22:032175 if (contents == chrome::GetActiveTabContents(this)) {
[email protected]9800de5e2011-03-11 18:19:492176 LocationBar* location_bar = window()->GetLocationBar();
2177 if (location_bar)
[email protected]83a2610a2012-01-05 01:00:272178 location_bar->SaveStateToContents(contents->web_contents());
[email protected]9800de5e2011-03-11 18:19:492179 }
[email protected]c37e3b62010-01-22 00:15:172180
[email protected]2fc15ae2012-05-06 00:01:372181 if (!tab_strip_model_->closing_all())
[email protected]c37e3b62010-01-22 00:15:172182 SyncHistoryWithTabs(0);
2183 }
2184
[email protected]6451fe92012-08-30 18:37:262185 SetAsDelegate(contents->web_contents(), NULL);
[email protected]d9083482012-01-06 00:38:462186 RemoveScheduledUpdatesFor(contents->web_contents());
[email protected]c37e3b62010-01-22 00:15:172187
[email protected]41f022e2012-01-31 05:56:402188 if (find_bar_controller_.get() && index == active_index()) {
[email protected]c37e3b62010-01-22 00:15:172189 find_bar_controller_->ChangeTabContents(NULL);
[email protected]ecc523f62010-09-28 22:45:402190 }
[email protected]c37e3b62010-01-22 00:15:172191
[email protected]e3a5d5b2012-06-22 17:56:462192 // Stop observing search model changes for this tab.
[email protected]0dc50db2012-09-19 17:57:142193 search_delegate_->OnTabDetached(contents->web_contents());
[email protected]e3a5d5b2012-06-22 17:56:462194
[email protected]432115822011-07-10 15:52:272195 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED,
[email protected]fbc5e5f92012-01-02 06:08:322196 content::Source<WebContents>(contents->web_contents()));
[email protected]e397a4472011-12-21 21:47:502197 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED,
[email protected]4b19ea52012-01-02 20:15:252198 content::Source<WebContents>(contents->web_contents()));
[email protected]c37e3b62010-01-22 00:15:172199}
2200
[email protected]92655362012-04-20 21:33:172201bool Browser::SupportsWindowFeatureImpl(WindowFeature feature,
2202 bool check_fullscreen) const {
2203 // On Mac, fullscreen mode has most normal things (in a slide-down panel). On
2204 // other platforms, we hide some controls when in fullscreen mode.
2205 bool hide_ui_for_fullscreen = false;
2206#if !defined(OS_MACOSX)
2207 hide_ui_for_fullscreen = check_fullscreen && window_ &&
2208 window_->IsFullscreen();
2209#endif
2210
2211 unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF;
2212
2213 if (is_type_tabbed())
2214 features |= FEATURE_BOOKMARKBAR;
2215
2216 if (!hide_ui_for_fullscreen) {
2217 if (!is_type_tabbed())
2218 features |= FEATURE_TITLEBAR;
2219
2220 if (is_type_tabbed())
2221 features |= FEATURE_TABSTRIP;
2222
2223 if (is_type_tabbed())
2224 features |= FEATURE_TOOLBAR;
2225
2226 if (!is_app())
2227 features |= FEATURE_LOCATIONBAR;
2228 }
2229 return !!(features & feature);
2230}
2231
[email protected]09b29342011-06-24 19:18:482232void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) {
2233 BookmarkBar::State state;
[email protected]227393e2011-06-29 21:28:392234 // The bookmark bar is hidden in fullscreen mode, unless on the new tab page.
[email protected]3710d0002011-10-11 00:35:002235 if (browser_defaults::bookmarks_enabled &&
2236 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) &&
[email protected]227393e2011-06-29 21:28:392237 (!window_ || !window_->IsFullscreen())) {
[email protected]70a412e2012-10-25 19:55:032238 // Always show detached mode if search mode is |NTP|.
2239 state = search_model_->mode().is_ntp() ?
2240 BookmarkBar::DETACHED : BookmarkBar::SHOW;
[email protected]09b29342011-06-24 19:18:482241 } else {
[email protected]1c5119c2012-09-19 00:08:572242 WebContents* web_contents = chrome::GetActiveWebContents(this);
2243 BookmarkTabHelper* bookmark_tab_helper =
2244 web_contents ? BookmarkTabHelper::FromWebContents(web_contents) : NULL;
2245 if (bookmark_tab_helper && bookmark_tab_helper->ShouldShowBookmarkBar())
[email protected]09b29342011-06-24 19:18:482246 state = BookmarkBar::DETACHED;
2247 else
2248 state = BookmarkBar::HIDDEN;
2249 }
[email protected]2d4e43a02012-06-26 00:11:552250
[email protected]70a412e2012-10-25 19:55:032251 // Don't allow the bookmark bar to be shown in suggestions mode.
2252 if (search_model_->mode().is_search_suggestions())
[email protected]2d4e43a02012-06-26 00:11:552253 state = BookmarkBar::HIDDEN;
2254
[email protected]09b29342011-06-24 19:18:482255 if (state == bookmark_bar_state_)
2256 return;
2257
2258 bookmark_bar_state_ = state;
2259
2260 if (!window_)
2261 return; // This is called from the constructor when window_ is NULL.
2262
2263 if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) {
2264 // Don't notify BrowserWindow on a tab switch as at the time this is invoked
2265 // BrowserWindow hasn't yet switched tabs. The BrowserWindow implementations
2266 // end up querying state once they process the tab switch.
2267 return;
2268 }
2269
2270 BookmarkBar::AnimateChangeType animate_type =
2271 (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE) ?
2272 BookmarkBar::ANIMATE_STATE_CHANGE :
2273 BookmarkBar::DONT_ANIMATE_STATE_CHANGE;
2274 window_->BookmarkBarStateChanged(animate_type);
2275}
[email protected]2e2cacc2011-07-12 21:54:262276
[email protected]92655362012-04-20 21:33:172277bool Browser::MaybeCreateBackgroundContents(int route_id,
2278 WebContents* opener_web_contents,
2279 const string16& frame_name,
2280 const GURL& target_url) {
2281 GURL opener_url = opener_web_contents->GetURL();
2282 ExtensionService* extensions_service = profile_->GetExtensionService();
2283
2284 if (!opener_url.is_valid() ||
2285 frame_name.empty() ||
2286 !extensions_service ||
2287 !extensions_service->is_ready())
2288 return false;
2289
2290 // Only hosted apps have web extents, so this ensures that only hosted apps
2291 // can create BackgroundContents. We don't have to check for background
2292 // permission as that is checked in RenderMessageFilter when the CreateWindow
2293 // message is processed.
2294 const Extension* extension =
2295 extensions_service->extensions()->GetHostedAppByURL(
2296 ExtensionURLInfo(opener_url));
2297 if (!extension)
2298 return false;
2299
2300 // No BackgroundContents allowed if BackgroundContentsService doesn't exist.
2301 BackgroundContentsService* service =
2302 BackgroundContentsServiceFactory::GetForProfile(profile_);
2303 if (!service)
2304 return false;
2305
2306 // Ensure that we're trying to open this from the extension's process.
2307 SiteInstance* opener_site_instance = opener_web_contents->GetSiteInstance();
2308 extensions::ProcessMap* process_map = extensions_service->process_map();
2309 if (!opener_site_instance->GetProcess() ||
2310 !process_map->Contains(
2311 extension->id(), opener_site_instance->GetProcess()->GetID())) {
2312 return false;
2313 }
2314
2315 // Only allow a single background contents per app.
2316 bool allow_js_access = extension->allow_background_js_access();
2317 BackgroundContents* existing =
2318 service->GetAppBackgroundContents(ASCIIToUTF16(extension->id()));
2319 if (existing) {
2320 // For non-scriptable background contents, ignore the request altogether,
2321 // (returning true, so that a regular WebContents isn't created either).
2322 if (!allow_js_access)
2323 return true;
2324 // For scriptable background pages, if one already exists, close it (even
2325 // if it was specified in the manifest).
2326 DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url;
2327 delete existing;
2328 }
2329
2330 // If script access is not allowed, create the the background contents in a
2331 // new SiteInstance, so that a separate process is used.
2332 scoped_refptr<content::SiteInstance> site_instance =
2333 allow_js_access ?
2334 opener_site_instance :
2335 content::SiteInstance::Create(opener_web_contents->GetBrowserContext());
2336
2337 // Passed all the checks, so this should be created as a BackgroundContents.
2338 BackgroundContents* contents = service->CreateBackgroundContents(
2339 site_instance,
2340 route_id,
2341 profile_,
2342 frame_name,
2343 ASCIIToUTF16(extension->id()));
2344
2345 // When a separate process is used, the original renderer cannot access the
2346 // new window later, thus we need to navigate the window now.
2347 if (contents && !allow_js_access) {
2348 contents->web_contents()->GetController().LoadURL(
2349 target_url,
2350 content::Referrer(),
2351 content::PAGE_TRANSITION_LINK,
2352 std::string()); // No extra headers.
2353 }
2354
2355 return contents != NULL;
[email protected]afcb43562011-09-02 23:33:382356}