12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <windows.h>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <shellapi.h>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // defined(OS_WIN)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <algorithm>
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/base_paths.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/metrics/histogram.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/path_service.h"
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
22bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#include "base/process/process_info.h"
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/strings/string_number_conversions.h"
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_util.h"
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/stringprintf.h"
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/thread.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/thread_restrictions.h"
29eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/app/chrome_command_ids.h"
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/app_mode/app_mode_utils.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autofill/personal_data_manager_factory.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/background/background_contents_service.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/background/background_contents_service_factory.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browser_process.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browser_shutdown.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/character_encoding.h"
387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h"
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chrome_page_zoom.h"
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/host_content_settings_map.h"
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/tab_specific_content_settings.h"
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h"
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/custom_handlers/register_protocol_handler_permission_request.h"
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/defaults.h"
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/devtools/devtools_toggle_action.h"
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/devtools/devtools_window.h"
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/download/download_item_model.h"
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/download/download_service.h"
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/download/download_service_factory.h"
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/download/download_shelf.h"
53116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/browser/extensions/api/tabs/tabs_event_router.h"
54116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/browser_extension_window_controller.h"
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/extension_service.h"
571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/browser/extensions/extension_util.h"
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/tab_helper.h"
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/favicon/favicon_tab_helper.h"
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/file_select_helper.h"
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/first_run/first_run.h"
62c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/history/top_sites.h"
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/infobars/infobar_service.h"
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/infobars/simple_alert_infobar_delegate.h"
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/lifetime/application_lifetime.h"
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/notifications/notification_ui_manager.h"
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/pepper_broker_infobar_delegate.h"
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/prefs/incognito_mode_prefs.h"
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile.h"
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_destroyer.h"
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_metrics.h"
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/repost_form_warning_controller.h"
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/search/search.h"
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/session_service.h"
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/session_service_factory.h"
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/session_tab_helper.h"
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/session_types.h"
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/tab_restore_service.h"
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sessions/tab_restore_service_factory.h"
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sync/profile_sync_service.h"
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sync/profile_sync_service_factory.h"
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sync/sync_ui_util.h"
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/tab_contents/background_contents.h"
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/tab_contents/retargeting_details.h"
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/tab_contents/tab_util.h"
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/themes/theme_service.h"
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/themes/theme_service_factory.h"
8846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "chrome/browser/translate/chrome_translate_client.h"
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h"
90f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
91ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/ui/bookmarks/bookmark_utils.h"
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_command_controller.h"
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_commands.h"
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/browser_content_translate_driver_observer.h"
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_dialogs.h"
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_finder.h"
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_instant_controller.h"
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_iterator.h"
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_list.h"
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_navigator.h"
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_tab_strip_model_delegate.h"
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_tabstrip.h"
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_toolbar_model_delegate.h"
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_ui_prefs.h"
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_window.h"
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/chrome_pages.h"
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/chrome_select_file_policy.h"
112eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/ui/fast_unload_controller.h"
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/find_bar/find_bar.h"
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/find_bar/find_bar_controller.h"
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/find_bar/find_tab_helper.h"
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/global_error/global_error.h"
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/global_error/global_error_service.h"
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/global_error/global_error_service_factory.h"
120116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/browser/ui/location_bar/location_bar.h"
121d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/browser/ui/media_utils.h"
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/search/search_delegate.h"
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/search/search_model.h"
1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/search/search_tab_helper.h"
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
1265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/ui/settings_window_manager.h"
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/singleton_tabs.h"
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/status_bubble.h"
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/sync/browser_synced_window_delegate.h"
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/tab_helpers.h"
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/tab_modal_confirm_dialog.h"
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/tabs/tab_menu_model.h"
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h"
135c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/ui/tabs/tab_strip_model_utils.h"
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/unload_controller.h"
1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/validation_message_bubble.h"
1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/webui/signin/login_ui_service.h"
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/window_sizer/window_sizer.h"
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/zoom/zoom_controller.h"
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/upgrade_detector.h"
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/web_applications/web_app.h"
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_constants.h"
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h"
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/custom_handlers/protocol_handler.h"
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h"
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/profiling.h"
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/search_types.h"
152c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/common/url_constants.h"
1531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/grit/chromium_strings.h"
1541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/grit/generated_resources.h"
1551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/grit/locale_settings.h"
156cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/bookmarks/browser/bookmark_model.h"
157cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/bookmarks/browser/bookmark_utils.h"
158f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "components/google/core/browser/google_url_tracker.h"
1595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/search/search.h"
16058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "components/startup_metric_utils/startup_metric_utils.h"
161116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/web_modal/popup_manager.h"
16290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "components/web_modal/web_contents_modal_dialog_manager.h"
16303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "content/public/browser/devtools_agent_host.h"
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/download_item.h"
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/download_manager.h"
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/interstitial_page.h"
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/invalidate_type.h"
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_controller.h"
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_entry.h"
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_details.h"
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h"
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/plugin_service.h"
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/render_process_host.h"
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/render_view_host.h"
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/render_widget_host_view.h"
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/site_instance.h"
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/user_metrics.h"
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h"
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/content_switches.h"
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/page_zoom.h"
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/renderer_preferences.h"
182ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "content/public/common/webplugininfo.h"
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/extension_prefs.h"
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/extension_system.h"
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "extensions/common/constants.h"
186f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/extension.h"
187f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/manifest_handlers/background_info.h"
188c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "net/base/filename_util.h"
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/cookie_monster.h"
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request_context.h"
192a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "third_party/WebKit/public/web/WebWindowFeatures.h"
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/window_open_disposition.h"
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/point.h"
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/shell_dialogs/selected_file_info.h"
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/metro.h"
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ssl/ssl_error_info.h"
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/task_manager/task_manager.h"
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/view_ids.h"
203eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_ie_toolbar_import_win.h"
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/win/shell.h"
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // OS_WIN
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_CHROMEOS)
2081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/browser/chromeos/fileapi/external_file_url_util.h"
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(USE_ASH)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/ash_switches.h"
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::TimeDelta;
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using base::UserMetricsAction;
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::NativeWebKeyboardEvent;
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::NavigationController;
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::NavigationEntry;
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::OpenURLParams;
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::PluginService;
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::Referrer;
2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using content::RenderWidgetHostView;
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::SiteInstance;
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::WebContents;
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using extensions::Extension;
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using ui::WebDialogDelegate;
22890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using web_modal::WebContentsModalDialogManager;
229f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)using blink::WebWindowFeatures;
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// How long we wait before updating the browser chrome while loading a page.
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kUIUpdateCoalescingTimeMS = 200;
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BrowserWindow* CreateBrowserWindow(Browser* browser) {
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return BrowserWindow::CreateBrowserWindow(browser);
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
242eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Is the fast tab unload experiment enabled?
243eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool IsFastTabUnloadEnabled() {
244eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return CommandLine::ForCurrentProcess()->HasSwitch(
245eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        switches::kEnableFastUnload);
246eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
247eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Browser, CreateParams:
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)Browser::CreateParams::CreateParams(Profile* profile,
2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                    chrome::HostDesktopType host_desktop_type)
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : type(TYPE_TABBED),
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      profile(profile),
2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      host_desktop_type(host_desktop_type),
258a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      trusted_source(false),
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      initial_show_state(ui::SHOW_STATE_DEFAULT),
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      is_session_restore(false),
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      window(NULL) {
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Browser::CreateParams::CreateParams(Type type,
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    Profile* profile,
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    chrome::HostDesktopType host_desktop_type)
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : type(type),
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      profile(profile),
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      host_desktop_type(host_desktop_type),
270a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      trusted_source(false),
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      initial_show_state(ui::SHOW_STATE_DEFAULT),
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      is_session_restore(false),
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      window(NULL) {
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Browser::CreateParams Browser::CreateParams::CreateForApp(
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& app_name,
279a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    bool trusted_source,
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const gfx::Rect& window_bounds,
2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Profile* profile,
2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    chrome::HostDesktopType host_desktop_type) {
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(!app_name.empty());
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  CreateParams params(TYPE_POPUP, profile, host_desktop_type);
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params.app_name = app_name;
287a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  params.trusted_source = trusted_source;
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params.initial_bounds = window_bounds;
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return params;
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Browser::CreateParams Browser::CreateParams::CreateForDevTools(
2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Profile* profile,
2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    chrome::HostDesktopType host_desktop_type) {
2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CreateParams params(TYPE_POPUP, profile, host_desktop_type);
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params.app_name = DevToolsWindow::kDevToolsApp;
299a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  params.trusted_source = true;
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return params;
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Browser, InterstitialObserver:
3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Browser::InterstitialObserver : public content::WebContentsObserver {
3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  InterstitialObserver(Browser* browser, content::WebContents* web_contents)
3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      : WebContentsObserver(web_contents),
3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        browser_(browser) {
3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidAttachInterstitialPage() OVERRIDE {
3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    browser_->UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidDetachInterstitialPage() OVERRIDE {
3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    browser_->UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
3222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Browser* browser_;
3232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Browser, Constructors, Creation, Showing:
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Browser::Browser(const CreateParams& params)
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : type_(params.type),
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      profile_(params.profile),
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      window_(NULL),
334c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      tab_strip_model_delegate_(new chrome::BrowserTabStripModelDelegate(this)),
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(),
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                         params.profile)),
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      app_name_(params.app_name),
338a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      is_trusted_source_(params.trusted_source),
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cancel_download_confirmation_state_(NOT_PROMPTED),
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      override_bounds_(params.initial_bounds),
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      initial_show_state_(params.initial_show_state),
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      is_session_restore_(params.is_session_restore),
343f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      host_desktop_type_(BrowserWindow::AdjustHostDesktopType(
344f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          params.host_desktop_type)),
345c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      content_setting_bubble_model_delegate_(
346c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          new BrowserContentSettingBubbleModelDelegate(this)),
347c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)),
348c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      tab_restore_service_delegate_(new BrowserTabRestoreServiceDelegate(this)),
349c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      synced_window_delegate_(new BrowserSyncedWindowDelegate(this)),
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      bookmark_bar_state_(BookmarkBar::HIDDEN),
351cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      command_controller_(new chrome::BrowserCommandController(this)),
3524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      window_has_shown_(false),
3534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      chrome_updater_factory_(this),
3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      translate_driver_observer_(
3551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci          new BrowserContentTranslateDriverObserver(this)),
3561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      weak_factory_(this) {
357868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // If this causes a crash then a window is being opened using a profile type
358868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // that is disallowed by policy. The crash prevents the disabled window type
359868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // from opening at all, but the path that triggered it should be fixed.
360868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  CHECK(IncognitoModePrefs::CanOpenBrowser(profile_));
3615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CHECK(!profile_->IsGuestSession() || profile_->IsOffTheRecord())
3625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      << "Only off the record browser may be opened in guest mode";
363868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
364eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // TODO(jeremy): Move to initializer list once flag is removed.
365eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (IsFastTabUnloadEnabled())
366eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    fast_unload_controller_.reset(new chrome::FastUnloadController(this));
367eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  else
368eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    unload_controller_.reset(new chrome::UnloadController(this));
369eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_strip_model_->AddObserver(this);
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get()));
373c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  search_model_.reset(new SearchModel());
3743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  search_delegate_.reset(new SearchDelegate(search_model_.get()));
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  registrar_.Add(this,
3775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 content::Source<Profile>(profile_->GetOriginalProfile()));
3795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  registrar_.Add(this,
3805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 content::Source<Profile>(profile_->GetOriginalProfile()));
382cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  registrar_.Add(this,
3835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 content::Source<Profile>(profile_->GetOriginalProfile()));
3855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  registrar_.Add(this,
3865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 content::NotificationService::AllSources());
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(ENABLE_THEMES)
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  registrar_.Add(
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::Source<ThemeService>(
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          ThemeServiceFactory::GetForProfile(profile_)));
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 content::NotificationService::AllSources());
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  profile_pref_registrar_.Init(profile_->GetPrefs());
3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  profile_pref_registrar_.Add(
3992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      prefs::kDevToolsDisabled,
4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::Bind(&Browser::OnDevToolsDisabledChanged, base::Unretained(this)));
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  profile_pref_registrar_.Add(
4021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      bookmarks::prefs::kShowBookmarkBar,
4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::Bind(&Browser::UpdateBookmarkBarState, base::Unretained(this),
4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE));
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BrowserList::AddBrowser(this);
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NOTE: These prefs all need to be explicitly destroyed in the destructor
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // or you'll get a nasty surprise when you run the incognito tests.
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector,
4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             profile_->GetPrefs());
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
413a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (chrome::IsInstantExtendedAPIEnabled() && is_type_tabbed())
414c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    instant_controller_.reset(new BrowserInstantController(this));
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT);
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
418c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ProfileMetrics::LogProfileLaunch(profile_);
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  window_ = params.window ? params.window : CreateBrowserWindow(this);
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create the extension window controller before sending notifications.
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  extension_window_controller_.reset(
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      new BrowserExtensionWindowController(this));
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
426f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SessionService* session_service =
427f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      SessionServiceFactory::GetForProfileForSessionRestore(profile_);
428f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (session_service)
429f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    session_service->WindowOpened(this);
430f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(beng): Move BrowserList::AddBrowser() to the end of this function and
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //             replace uses of this with BL's notifications.
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationService::current()->Notify(
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::NOTIFICATION_BROWSER_WINDOW_READY,
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::Source<Browser>(this),
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::NotificationService::NoDetails());
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(beng): move to ChromeBrowserMain:
4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (first_run::ShouldDoPersonalDataManagerFirstRun()) {
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Notify PDM that this is a first run.
442c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    ImportAutofillDataWin(
443c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        autofill::PersonalDataManagerFactory::GetForProfile(profile_));
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // defined(OS_WIN)
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  fullscreen_controller_.reset(new FullscreenController(this));
448116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
449116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Must be initialized after window_.
450116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Also: surprise! a modal dialog host is not necessary to host modal dialogs
451116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // without a modal dialog host, so that value may be null.
452116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  popup_manager_.reset(new web_modal::PopupManager(
453116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      GetWebContentsModalDialogHost()));
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Browser::~Browser() {
457cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Stop observing notifications before continuing with destruction. Profile
458cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // destruction will unload extensions and reentrant calls to Browser:: should
459cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // be avoided while it is being torn down.
460cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  registrar_.RemoveAll();
461cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The tab strip should not have any tabs at this point.
463effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  DCHECK(tab_strip_model_->empty());
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_strip_model_->RemoveObserver(this);
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Destroy the BrowserCommandController before removing the browser, so that
4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // it doesn't act on any notifications that are sent as a result of removing
4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the browser.
4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  command_controller_.reset();
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BrowserList::RemoveBrowser(this);
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionService* session_service =
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      SessionServiceFactory::GetForProfile(profile_);
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (session_service)
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    session_service->WindowClosed(session_id_);
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TabRestoreService* tab_restore_service =
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      TabRestoreServiceFactory::GetForProfile(profile());
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (tab_restore_service)
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    tab_restore_service->BrowserClosed(tab_restore_service_delegate());
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_MACOSX)
4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!chrome::GetTotalBrowserCountForProfile(profile_)) {
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // We're the last browser window with this profile. We need to nuke the
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // TabRestoreService, which will start the shutdown of the
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // NavigationControllers and allow for proper shutdown. If we don't do this
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // chrome won't shutdown cleanly, and may end up crashing when some
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // thread tries to use the IO thread (or another thread) that is no longer
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // valid.
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // This isn't a valid assumption for Mac OS, as it stays running after
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // the last browser has closed. The Mac equivalent is in its app
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // controller.
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TabRestoreServiceFactory::ResetForProfile(profile_);
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  profile_pref_registrar_.RemoveAll();
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  encoding_auto_detect_.Destroy();
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
50190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Destroy BrowserExtensionWindowController before the incognito profile
50290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // is destroyed to make sure the chrome.windows.onRemoved event is sent.
50390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  extension_window_controller_.reset();
50490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
505eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Destroy BrowserInstantController before the incongnito profile is destroyed
506eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // because the InstantController destructor depends on this profile.
507eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  instant_controller_.reset();
508eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (profile_->IsOffTheRecord() &&
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      !BrowserList::IsOffTheRecordSessionActiveForProfile(profile_)) {
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // An incognito profile is no longer needed, this indirectly frees
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // its cache and cookies once it gets destroyed at the appropriate time.
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ProfileDestroyer::DestroyProfileWhenAppropriate(profile_);
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // There may be pending file dialogs, we need to tell them that we've gone
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // away so they don't try and call back to us.
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (select_file_dialog_.get())
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    select_file_dialog_->ListenerDestroyed();
520f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
521f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int num_downloads;
522f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (OkToCloseWithInProgressDownloads(&num_downloads) ==
523f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          DOWNLOAD_CLOSE_BROWSER_SHUTDOWN &&
524f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      !browser_defaults::kBrowserAliveWithNoWindows) {
525f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    DownloadService::CancelAllDownloads();
526f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Getters & Setters
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FindBarController* Browser::GetFindBarController() {
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!find_bar_controller_.get()) {
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    FindBar* find_bar = window_->CreateFindBar();
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    find_bar_controller_.reset(new FindBarController(find_bar));
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    find_bar->SetFindBarController(find_bar_controller_.get());
5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    find_bar_controller_->ChangeWebContents(
5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        tab_strip_model_->GetActiveWebContents());
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return find_bar_controller_.get();
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Browser::HasFindBarController() const {
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return find_bar_controller_.get() != NULL;
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Browser::is_app() const {
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return !app_name_.empty();
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Browser::is_devtools() const {
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return app_name_ == DevToolsWindow::kDevToolsApp;
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Browser, State Storage and Retrieval for UI:
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Image Browser::GetCurrentPageIcon() const {
5602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebContents* web_contents = tab_strip_model_->GetActiveWebContents();
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |web_contents| can be NULL since GetCurrentPageIcon() is called by the
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // window during the window's creation (before tabs have been added).
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FaviconTabHelper* favicon_tab_helper =
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      web_contents ? FaviconTabHelper::FromWebContents(web_contents) : NULL;
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return favicon_tab_helper ? favicon_tab_helper->GetFavicon() : gfx::Image();
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
568a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)base::string16 Browser::GetWindowTitleForCurrentTab() const {
5692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebContents* contents = tab_strip_model_->GetActiveWebContents();
570a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 title;
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // window during the window's creation (before tabs have been added).
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (contents) {
57503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // Streamlined hosted apps use the host instead of the title.
5761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    if (is_app() && extensions::util::IsStreamlinedHostedAppsEnabled())
57703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      return base::UTF8ToUTF16(contents->GetURL().host());
57803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    title = contents->GetTitle();
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    FormatTitleForDisplay(&title);
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (title.empty())
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    title = CoreTabHelper::GetDefaultTitle();
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX)
5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // On Mac, we don't want to suffix the page title with
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the application name.
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return title;
5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#elif defined(USE_ASH)
5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // On Ash, we don't want to suffix the page title with the application name,
5912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // but on Windows, where USE_ASH can also be true, we still want the prefix
5922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // on desktop.
5932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH)
5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return title;
5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Don't append the app name to window titles on app frames and app popups
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return is_app() ?
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      title :
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      l10n_util::GetStringFUTF16(IDS_BROWSER_WINDOW_TITLE_FORMAT, title);
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
603a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void Browser::FormatTitleForDisplay(base::string16* title) {
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size_t current_index = 0;
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size_t match_index;
606a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  while ((match_index = title->find(L'\n', current_index)) !=
607a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)         base::string16::npos) {
608a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    title->replace(match_index, 1, base::string16());
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    current_index = match_index;
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Browser, OnBeforeUnload handling:
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Browser::ShouldCloseWindow() {
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!CanCloseWithInProgressDownloads())
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
620eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (IsFastTabUnloadEnabled())
621eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return fast_unload_controller_->ShouldCloseWindow();
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return unload_controller_->ShouldCloseWindow();
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)bool Browser::CallBeforeUnloadHandlers(
6263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    const base::Callback<void(bool)>& on_close_confirmed) {
6273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  cancel_download_confirmation_state_ = RESPONSE_RECEIVED;
6283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (IsFastTabUnloadEnabled()) {
6293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    return fast_unload_controller_->CallBeforeUnloadHandlers(
6303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)        on_close_confirmed);
6313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
6323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  return unload_controller_->CallBeforeUnloadHandlers(on_close_confirmed);
6333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
6343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
6353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void Browser::ResetBeforeUnloadHandlers() {
6363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  cancel_download_confirmation_state_ = NOT_PROMPTED;
6373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (IsFastTabUnloadEnabled())
6383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    fast_unload_controller_->ResetBeforeUnloadHandlers();
6393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  else
6403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    unload_controller_->ResetBeforeUnloadHandlers();
6413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
6423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
643868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)bool Browser::HasCompletedUnloadProcessing() const {
644eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  DCHECK(IsFastTabUnloadEnabled());
645eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return fast_unload_controller_->HasCompletedUnloadProcessing();
646868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
647868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Browser::IsAttemptingToCloseBrowser() const {
649eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (IsFastTabUnloadEnabled())
650eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return fast_unload_controller_->is_attempting_to_close_browser();
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return unload_controller_->is_attempting_to_close_browser();
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Browser::OnWindowClosing() {
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!ShouldCloseWindow())
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Application should shutdown on last window close if the user is explicitly
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // trying to quit, or if there is nothing keeping the browser alive (such as
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // AppController on the Mac, or BackgroundContentsService for background
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // pages).
6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool should_quit_if_last_browser =
6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      browser_shutdown::IsTryingToQuit() || !chrome::WillKeepAlive();
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (should_quit_if_last_browser && chrome::ShouldStartShutdown(this))
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE);
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Don't use GetForProfileIfExisting here, we want to force creation of the
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // session service so that user can restore what was open.
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionService* session_service =
6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      SessionServiceFactory::GetForProfile(profile());
6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (session_service)
6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    session_service->WindowClosing(session_id());
6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TabRestoreService* tab_restore_service =
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      TabRestoreServiceFactory::GetForProfile(profile());
6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(USE_AURA)
6790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  if (tab_restore_service && is_app() && !is_devtools())
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    tab_restore_service->BrowserClosing(tab_restore_service_delegate());
6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (tab_restore_service && is_type_tabbed() && tab_strip_model_->count())
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    tab_restore_service->BrowserClosing(tab_restore_service_delegate());
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(sky): convert session/tab restore to use notification.
6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationService::current()->Notify(
6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::NOTIFICATION_BROWSER_CLOSING,
6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::Source<Browser>(this),
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::NotificationService::NoDetails());
691eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
692eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!IsFastTabUnloadEnabled())
693eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    tab_strip_model_->CloseAllTabs();
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// In-progress download termination handling:
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Browser::InProgressDownloadResponse(bool cancel_downloads) {
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (cancel_downloads) {
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cancel_download_confirmation_state_ = RESPONSE_RECEIVED;
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    chrome::CloseWindow(this);
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the confirmation state to NOT_PROMPTED so that if the user tries to
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // close again we'll show the warning again.
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  cancel_download_confirmation_state_ = NOT_PROMPTED;
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Show the download page so the user can figure-out what downloads are still
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in-progress.
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chrome::ShowDownloads(this);
713a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
714a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Reset UnloadController::is_attempting_to_close_browser_ so that we don't
715a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // prompt every time any tab is closed. http://crbug.com/305516
716a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (IsFastTabUnloadEnabled())
717a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    fast_unload_controller_->CancelWindowClose();
718a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  else
719a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    unload_controller_->CancelWindowClose();
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Browser::DownloadClosePreventionType Browser::OkToCloseWithInProgressDownloads(
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int* num_downloads_blocking) const {
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(num_downloads_blocking);
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  *num_downloads_blocking = 0;
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If we're not running a full browser process with a profile manager
7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (testing), it's ok to close the browser.
7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!g_browser_process->profile_manager())
7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return DOWNLOAD_CLOSE_OK;
7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int total_download_count =
7338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      DownloadService::NonMaliciousDownloadCountAllProfiles();
7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (total_download_count == 0)
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return DOWNLOAD_CLOSE_OK;   // No downloads; can definitely close.
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Figure out how many windows are open total, and associated with this
7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // profile, that are relevant for the ok-to-close decision.
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int profile_window_count = 0;
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int total_window_count = 0;
7412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (chrome::BrowserIterator it; !it.done(); it.Next()) {
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Don't count this browser window or any other in the process of closing.
7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Browser* const browser = *it;
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Window closing may be delayed, and windows that are in the process of
7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // closing don't count against our totals.
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (browser == this || browser->IsAttemptingToCloseBrowser())
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      continue;
7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (it->profile() == profile())
7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      profile_window_count++;
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    total_window_count++;
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If there aren't any other windows, we're at browser shutdown,
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // which would cancel all current downloads.
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (total_window_count == 0) {
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    *num_downloads_blocking = total_download_count;
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN;
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If there aren't any other windows on our profile, and we're an incognito
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // profile, and there are downloads associated with that profile,
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // those downloads would be cancelled by our window (-> profile) close.
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DownloadService* download_service =
765a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      DownloadServiceFactory::GetForBrowserContext(profile());
766ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  if ((profile_window_count == 0) &&
7678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      (download_service->NonMaliciousDownloadCount() > 0) &&
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      profile()->IsOffTheRecord()) {
7698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    *num_downloads_blocking = download_service->NonMaliciousDownloadCount();
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE;
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Those are the only conditions under which we will block shutdown.
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return DOWNLOAD_CLOSE_OK;
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Browser, Tab adding/showing functions:
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Browser::WindowFullscreenStateChanged() {
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  fullscreen_controller_->WindowFullscreenStateChanged();
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  command_controller_->FullscreenStateChanged();
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN);
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Browser, Assorted browser commands:
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Browser::ToggleFullscreenModeWithExtension(const GURL& extension_url) {
790a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  fullscreen_controller_->
791a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      ToggleBrowserFullscreenModeWithExtension(extension_url);
7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Browser::SupportsWindowFeature(WindowFeature feature) const {
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return SupportsWindowFeatureImpl(feature, true);
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Browser::CanSupportWindowFeature(WindowFeature feature) const {
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return SupportsWindowFeatureImpl(feature, false);
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Browser::ToggleEncodingAutoDetect() {
8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::RecordAction(UserMetricsAction("AutoDetectChange"));
8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue());
8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If "auto detect" is turned on, then any current override encoding
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is cleared. This also implicitly performs a reload.
8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // OTOH, if "auto detect" is turned off, we don't change the currently
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // active encoding.
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (encoding_auto_detect_.GetValue()) {
8102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    WebContents* contents = tab_strip_model_->GetActiveWebContents();
8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (contents)
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      contents->ResetOverrideEncoding();
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Browser::OverrideEncoding(int encoding_id) {
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::RecordAction(UserMetricsAction("OverrideEncoding"));
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::string selected_encoding =
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id);
8202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebContents* contents = tab_strip_model_->GetActiveWebContents();
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!selected_encoding.empty() && contents)
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     contents->SetOverrideEncoding(selected_encoding);
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Update the list of recently selected encodings.
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string new_selected_encoding_list;
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (CharacterEncoding::UpdateRecentlySelectedEncoding(
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding),
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        encoding_id,
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        &new_selected_encoding_list)) {
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding,
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    new_selected_encoding_list);
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Browser::OpenFile() {
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::RecordAction(UserMetricsAction("OpenFile"));
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  select_file_dialog_ = ui::SelectFileDialog::Create(
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      this, new ChromeSelectFilePolicy(
8382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          tab_strip_model_->GetActiveWebContents()));
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const base::FilePath directory = profile_->last_selected_directory();
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(beng): figure out how to juggle this.
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::NativeWindow parent_window = window_->GetNativeWindow();
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ui::SelectFileDialog::FileTypeInfo file_types;
8452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  file_types.support_drive = true;
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE,
847a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                  base::string16(),
848c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                  directory,
849c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                  &file_types,
850c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                  0,
851c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                  base::FilePath::StringType(),
852c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                  parent_window,
853c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                  NULL);
8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Browser::UpdateDownloadShelfVisibility(bool visible) {
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (GetStatusBubble())
8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GetStatusBubble()->UpdateDownloadShelfVisibility(visible);
8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void Browser::UpdateUIForNavigationInTab(WebContents* contents,
8641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                         ui::PageTransition transition,
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                         bool user_initiated) {
8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_strip_model_->TabNavigating(contents, transition);
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool contents_is_selected =
8692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      contents == tab_strip_model_->GetActiveWebContents();
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (user_initiated && contents_is_selected && window()->GetLocationBar()) {
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Forcibly reset the location bar if the url is going to change in the
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // current tab, since otherwise it won't discard any ongoing user edits,
8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // since it doesn't realize this is a user-initiated action.
8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    window()->GetLocationBar()->Revert();
8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (GetStatusBubble())
8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GetStatusBubble()->Hide();
8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Update the location bar. This is synchronous. We specifically don't
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // update the load state since the load hasn't started yet and updating it
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will put it out of sync with the actual state like whether we're
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // displaying a favicon, which controls the throbber. If we updated it here,
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the throbber will show the default favicon for a split second when
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // navigating away from the new tab page.
8862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScheduleUIUpdate(contents, content::INVALIDATE_TYPE_URL);
8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (contents_is_selected)
889010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    contents->SetInitialFocus();
8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Browser, PageNavigator implementation:
8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContents* Browser::OpenURL(const OpenURLParams& params) {
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return OpenURLFromTab(NULL, params);
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Browser, TabStripModelObserver implementation:
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Browser::TabInsertedAt(WebContents* contents,
9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            int index,
9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            bool foreground) {
905116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  SetAsDelegate(contents, true);
906116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
907116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (popup_manager_)
908116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    popup_manager_->RegisterWith(contents);
909116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionTabHelper* session_tab_helper =
9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      SessionTabHelper::FromWebContents(contents);
9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  session_tab_helper->SetWindowID(session_id());
9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationService::current()->Notify(
9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::NOTIFICATION_TAB_PARENTED,
9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::Source<content::WebContents>(contents),
9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::NotificationService::NoDetails());
9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SyncHistoryWithTabs(index);
9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Make sure the loading state is updated correctly, otherwise the throbber
9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // won't start if the page is loading.
923effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  LoadingStateChanged(contents, true);
9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interstitial_observers_.push_back(new InterstitialObserver(this, contents));
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionService* session_service =
9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      SessionServiceFactory::GetForProfile(profile_);
929c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (session_service) {
9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    session_service->TabInserted(contents);
931c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    int new_active_index = tab_strip_model_->active_index();
932c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (index < new_active_index)
933c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      session_service->SetSelectedTabInWindow(session_id(),
934c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                              new_active_index);
935c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Browser::TabClosingAt(TabStripModel* tab_strip_model,
9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           WebContents* contents,
9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           int index) {
9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  fullscreen_controller_->OnTabClosing(contents);
9425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionService* session_service =
9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      SessionServiceFactory::GetForProfile(profile_);
9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (session_service)
9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    session_service->TabClosing(contents);
9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationService::current()->Notify(
9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      chrome::NOTIFICATION_TAB_CLOSING,
9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::Source<NavigationController>(&contents->GetController()),
9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      content::NotificationService::NoDetails());
9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
951116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (popup_manager_)
952116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    popup_manager_->UnregisterWith(contents);
953116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sever the WebContents' connection back to us.
955116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  SetAsDelegate(contents, false);
9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Browser::TabDetachedAt(WebContents* contents, int index) {
959c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TabDetachedAt is called before TabStripModel has updated the
960c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // active index.
961c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  int old_active_index = tab_strip_model_->active_index();
962c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (index < old_active_index && !tab_strip_model_->closing_all()) {
963c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)