[email protected] | daa9e38 | 2012-01-06 00:30:34 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 7b5dc00 | 2010-11-16 23:08:10 | [diff] [blame] | 5 | #include "chrome/browser/ui/browser.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 6 | |
[email protected] | aca02cf | 2010-05-03 18:56:01 | [diff] [blame] | 7 | #if defined(OS_WIN) |
[email protected] | 541434c | 2011-06-25 01:38:59 | [diff] [blame] | 8 | #include <windows.h> |
[email protected] | dcd5776 | 2011-06-25 12:18:51 | [diff] [blame] | 9 | #include <shellapi.h> |
[email protected] | aca02cf | 2010-05-03 18:56:01 | [diff] [blame] | 10 | #endif // OS_WIN |
| 11 | |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 12 | #include <algorithm> |
| 13 | #include <string> |
| 14 | |
[email protected] | b02d038 | 2009-11-30 21:19:50 | [diff] [blame] | 15 | #include "base/base_paths.h" |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 16 | #include "base/bind.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 17 | #include "base/command_line.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 18 | #include "base/logging.h" |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 19 | #include "base/metrics/field_trial.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 20 | #include "base/metrics/histogram.h" |
[email protected] | b02d038 | 2009-11-30 21:19:50 | [diff] [blame] | 21 | #include "base/path_service.h" |
[email protected] | b5febf7 | 2012-07-29 18:10:09 | [diff] [blame] | 22 | #include "base/process_info.h" |
[email protected] | 0af8f13 | 2011-07-16 01:37:02 | [diff] [blame] | 23 | #include "base/string_number_conversions.h" |
[email protected] | b6a4ac2b | 2011-10-17 20:05:48 | [diff] [blame] | 24 | #include "base/string_util.h" |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 25 | #include "base/stringprintf.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 26 | #include "base/threading/thread.h" |
| 27 | #include "base/threading/thread_restrictions.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 28 | #include "base/time.h" |
[email protected] | 6524385ef | 2010-08-18 06:34:13 | [diff] [blame] | 29 | #include "base/utf_string_conversions.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 30 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 77a91c7 | 2012-08-13 16:19:34 | [diff] [blame] | 31 | #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 32 | #include "chrome/browser/autofill/personal_data_manager_factory.h" |
[email protected] | a07676b2 | 2011-06-17 16:36:53 | [diff] [blame] | 33 | #include "chrome/browser/background/background_contents_service.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 34 | #include "chrome/browser/background/background_contents_service_factory.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 35 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 36 | #include "chrome/browser/bookmarks/bookmark_utils.h" |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 37 | #include "chrome/browser/browser_process.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 38 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | 40d59ce5 | 2009-03-06 23:20:14 | [diff] [blame] | 39 | #include "chrome/browser/character_encoding.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 40 | #include "chrome/browser/chrome_page_zoom.h" |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 41 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 42 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 43 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 44 | #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h" |
[email protected] | dce50276 | 2011-07-20 08:53:49 | [diff] [blame] | 45 | #include "chrome/browser/debugger/devtools_toggle_action.h" |
| 46 | #include "chrome/browser/debugger/devtools_window.h" |
[email protected] | 7fb4bbb | 2012-05-27 18:06:22 | [diff] [blame] | 47 | #include "chrome/browser/download/download_crx_util.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 48 | #include "chrome/browser/download/download_item_model.h" |
[email protected] | 9bb54ee | 2011-10-12 17:43:35 | [diff] [blame] | 49 | #include "chrome/browser/download/download_service.h" |
| 50 | #include "chrome/browser/download/download_service_factory.h" |
[email protected] | a1bc3b8 | 2012-04-19 19:32:20 | [diff] [blame] | 51 | #include "chrome/browser/download/download_shelf.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 52 | #include "chrome/browser/download/download_started_animation.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 53 | #include "chrome/browser/download/download_util.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 54 | #include "chrome/browser/extensions/browser_extension_window_controller.h" |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 55 | #include "chrome/browser/extensions/default_apps_trial.h" |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 56 | #include "chrome/browser/extensions/extension_prefs.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 57 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | a6394ae | 2012-07-16 20:58:43 | [diff] [blame] | 58 | #include "chrome/browser/extensions/tab_helper.h" |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 59 | #include "chrome/browser/favicon/favicon_tab_helper.h" |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 60 | #include "chrome/browser/file_select_helper.h" |
[email protected] | 82073579 | 2010-07-29 23:40:01 | [diff] [blame] | 61 | #include "chrome/browser/first_run/first_run.h" |
[email protected] | f7578f5 | 2010-08-30 22:22:49 | [diff] [blame] | 62 | #include "chrome/browser/google/google_url_tracker.h" |
[email protected] | 7e20412 | 2011-09-01 18:56:21 | [diff] [blame] | 63 | #include "chrome/browser/infobars/infobar_tab_helper.h" |
[email protected] | 65c8114 | 2012-07-31 19:44:43 | [diff] [blame] | 64 | #include "chrome/browser/intents/device_attached_intent_source.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 65 | #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" |
[email protected] | 59d73ec | 2012-09-01 02:24:27 | [diff] [blame] | 66 | #include "chrome/browser/intents/web_intents_reporting.h" |
[email protected] | 8f0bbd6 | 2012-02-22 03:37:18 | [diff] [blame] | 67 | #include "chrome/browser/intents/web_intents_util.h" |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 68 | #include "chrome/browser/lifetime/application_lifetime.h" |
[email protected] | 4afde5c | 2012-06-25 17:00:53 | [diff] [blame] | 69 | #include "chrome/browser/media/media_stream_devices_controller.h" |
[email protected] | a239c3f | 2009-02-17 22:13:19 | [diff] [blame] | 70 | #include "chrome/browser/net/url_fixer_upper.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 71 | #include "chrome/browser/notifications/notification_ui_manager.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 72 | #include "chrome/browser/platform_util.h" |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 73 | #include "chrome/browser/prefs/incognito_mode_prefs.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 74 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 0233759 | 2010-09-27 18:38:25 | [diff] [blame] | 75 | #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 76 | #include "chrome/browser/printing/print_preview_tab_controller.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 77 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 5e91924 | 2012-02-13 23:59:35 | [diff] [blame] | 78 | #include "chrome/browser/profiles/profile_destroyer.h" |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 79 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 80 | #include "chrome/browser/profiles/profile_metrics.h" |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 81 | #include "chrome/browser/repost_form_warning_controller.h" |
[email protected] | 85e921fb8 | 2009-02-11 23:19:44 | [diff] [blame] | 82 | #include "chrome/browser/sessions/session_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 83 | #include "chrome/browser/sessions/session_service_factory.h" |
[email protected] | bde40b82 | 2012-08-30 17:28:56 | [diff] [blame] | 84 | #include "chrome/browser/sessions/session_tab_helper.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 85 | #include "chrome/browser/sessions/session_types.h" |
[email protected] | 92926d9 | 2010-09-02 18:35:06 | [diff] [blame] | 86 | #include "chrome/browser/sessions/tab_restore_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 87 | #include "chrome/browser/sessions/tab_restore_service_factory.h" |
[email protected] | 066629f | 2009-10-17 00:28:13 | [diff] [blame] | 88 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | 5e61afb9 | 2012-01-27 20:09:13 | [diff] [blame] | 89 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
[email protected] | 40f04797 | 2009-11-25 03:54:40 | [diff] [blame] | 90 | #include "chrome/browser/sync/sync_ui_util.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 91 | #include "chrome/browser/tab_contents/background_contents.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 92 | #include "chrome/browser/tab_contents/retargeting_details.h" |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 93 | #include "chrome/browser/tab_contents/tab_util.h" |
[email protected] | ffa6f59 | 2011-06-24 22:03:57 | [diff] [blame] | 94 | #include "chrome/browser/themes/theme_service.h" |
| 95 | #include "chrome/browser/themes/theme_service_factory.h" |
[email protected] | 82194b5fb | 2012-05-22 23:53:07 | [diff] [blame] | 96 | #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 97 | #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 98 | #include "chrome/browser/ui/browser_command_controller.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 99 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 100 | #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 101 | #include "chrome/browser/ui/browser_dialogs.h" |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 102 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | 7acfaf9 | 2012-07-11 15:51:59 | [diff] [blame] | 103 | #include "chrome/browser/ui/browser_instant_controller.h" |
[email protected] | 6768ac0 | 2011-04-06 17:41:04 | [diff] [blame] | 104 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 105 | #include "chrome/browser/ui/browser_navigator.h" |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 106 | #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
[email protected] | 85537005 | 2012-07-10 19:30:32 | [diff] [blame] | 107 | #include "chrome/browser/ui/browser_tab_strip_model_delegate.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 108 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 109 | #include "chrome/browser/ui/browser_toolbar_model_delegate.h" |
[email protected] | 2cd4fde | 2012-06-26 03:10:26 | [diff] [blame] | 110 | #include "chrome/browser/ui/browser_ui_prefs.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 111 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 112 | #include "chrome/browser/ui/chrome_pages.h" |
[email protected] | 6e1fcd1 | 2012-07-02 17:14:20 | [diff] [blame] | 113 | #include "chrome/browser/ui/chrome_select_file_policy.h" |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 114 | #include "chrome/browser/ui/extensions/shell_window.h" |
[email protected] | 45300ad4 | 2010-12-02 15:51:14 | [diff] [blame] | 115 | #include "chrome/browser/ui/find_bar/find_bar.h" |
| 116 | #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 117 | #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
[email protected] | 9d5c059a8 | 2012-06-29 20:13:07 | [diff] [blame] | 118 | #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
[email protected] | 1ba55cf | 2012-06-29 19:11:39 | [diff] [blame] | 119 | #include "chrome/browser/ui/global_error/global_error.h" |
| 120 | #include "chrome/browser/ui/global_error/global_error_service.h" |
| 121 | #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
[email protected] | 943b861 | 2011-08-31 21:07:13 | [diff] [blame] | 122 | #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 123 | #include "chrome/browser/ui/media_stream_infobar_delegate.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 124 | #include "chrome/browser/ui/omnibox/location_bar.h" |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 125 | #include "chrome/browser/ui/search/search.h" |
| 126 | #include "chrome/browser/ui/search/search_delegate.h" |
| 127 | #include "chrome/browser/ui/search/search_model.h" |
[email protected] | c316630 | 2012-09-25 21:27:08 | [diff] [blame] | 128 | #include "chrome/browser/ui/search/search_types.h" |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 129 | #include "chrome/browser/ui/singleton_tabs.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 130 | #include "chrome/browser/ui/status_bubble.h" |
[email protected] | 3da95a10 | 2011-11-30 21:47:45 | [diff] [blame] | 131 | #include "chrome/browser/ui/sync/browser_synced_window_delegate.h" |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 132 | #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 133 | #include "chrome/browser/ui/tab_contents/tab_contents.h" |
[email protected] | 51296c6 | 2012-09-26 13:02:44 | [diff] [blame^] | 134 | #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
[email protected] | 9a80065 | 2010-12-02 17:08:44 | [diff] [blame] | 135 | #include "chrome/browser/ui/tabs/dock_info.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 136 | #include "chrome/browser/ui/tabs/tab_menu_model.h" |
[email protected] | b56e2e3 | 2012-05-11 21:18:04 | [diff] [blame] | 137 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 138 | #include "chrome/browser/ui/unload_controller.h" |
[email protected] | f847e608 | 2011-03-24 00:08:26 | [diff] [blame] | 139 | #include "chrome/browser/ui/web_applications/web_app_ui.h" |
[email protected] | 6554918 | 2012-02-25 00:45:40 | [diff] [blame] | 140 | #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 141 | #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
[email protected] | 0363942 | 2012-06-28 19:03:37 | [diff] [blame] | 142 | #include "chrome/browser/ui/window_sizer/window_sizer.h" |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 143 | #include "chrome/browser/upgrade_detector.h" |
[email protected] | 86b5401 | 2009-11-19 09:18:50 | [diff] [blame] | 144 | #include "chrome/browser/web_applications/web_app.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 145 | #include "chrome/common/chrome_constants.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 146 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 147 | #include "chrome/common/chrome_switches.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 148 | #include "chrome/common/custom_handlers/protocol_handler.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 149 | #include "chrome/common/extensions/extension.h" |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 150 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 151 | #include "chrome/common/pref_names.h" |
[email protected] | 7664ab3 | 2011-02-01 23:35:25 | [diff] [blame] | 152 | #include "chrome/common/profiling.h" |
[email protected] | b5febf7 | 2012-07-29 18:10:09 | [diff] [blame] | 153 | #include "chrome/common/startup_metric_utils.h" |
[email protected] | b689fce7 | 2009-03-17 22:45:34 | [diff] [blame] | 154 | #include "chrome/common/url_constants.h" |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 155 | #include "chrome/common/web_apps.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 156 | #include "content/public/browser/color_chooser.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 157 | #include "content/public/browser/devtools_manager.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 158 | #include "content/public/browser/download_item.h" |
| 159 | #include "content/public/browser/download_manager.h" |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 160 | #include "content/public/browser/interstitial_page.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 161 | #include "content/public/browser/invalidate_type.h" |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 162 | #include "content/public/browser/navigation_controller.h" |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 163 | #include "content/public/browser/navigation_entry.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 164 | #include "content/public/browser/notification_details.h" |
| 165 | #include "content/public/browser/notification_service.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 166 | #include "content/public/browser/plugin_service.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 167 | #include "content/public/browser/render_process_host.h" |
| 168 | #include "content/public/browser/render_view_host.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 169 | #include "content/public/browser/site_instance.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 170 | #include "content/public/browser/user_metrics.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 171 | #include "content/public/browser/web_contents.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 172 | #include "content/public/browser/web_contents_view.h" |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 173 | #include "content/public/browser/web_intents_dispatcher.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 174 | #include "content/public/common/content_restriction.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 175 | #include "content/public/common/content_switches.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 176 | #include "content/public/common/page_zoom.h" |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 177 | #include "content/public/common/renderer_preferences.h" |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 178 | #include "grit/chromium_strings.h" |
| 179 | #include "grit/generated_resources.h" |
| 180 | #include "grit/locale_settings.h" |
[email protected] | 2a281335 | 2012-07-11 22:20:23 | [diff] [blame] | 181 | #include "grit/theme_resources.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 182 | #include "net/base/net_util.h" |
[email protected] | be28b5f4 | 2012-07-20 11:31:25 | [diff] [blame] | 183 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 4d7c4ef | 2012-03-16 01:47:12 | [diff] [blame] | 184 | #include "net/cookies/cookie_monster.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 185 | #include "net/url_request/url_request_context.h" |
[email protected] | f6767806 | 2011-01-07 17:33:39 | [diff] [blame] | 186 | #include "ui/base/animation/animation.h" |
[email protected] | 53f04c8 | 2012-07-26 02:31:09 | [diff] [blame] | 187 | #include "ui/base/dialogs/selected_file_info.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 188 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 189 | #include "ui/gfx/point.h" |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 190 | #include "webkit/glue/web_intent_data.h" |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 191 | #include "webkit/glue/web_intent_service_data.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 192 | #include "webkit/glue/webkit_glue.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 193 | #include "webkit/glue/window_open_disposition.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 194 | #include "webkit/plugins/webplugininfo.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 195 | |
| 196 | #if defined(OS_WIN) |
[email protected] | 77cbe50e | 2012-06-14 02:44:38 | [diff] [blame] | 197 | #include "base/win/metro.h" |
[email protected] | 36d5e559 | 2010-11-15 20:45:59 | [diff] [blame] | 198 | #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 199 | #include "chrome/browser/shell_integration.h" |
[email protected] | b17d41c | 2011-02-17 22:09:59 | [diff] [blame] | 200 | #include "chrome/browser/ssl/ssl_error_info.h" |
[email protected] | a5d1e1e | 2010-09-23 19:34:12 | [diff] [blame] | 201 | #include "chrome/browser/task_manager/task_manager.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 202 | #include "chrome/browser/ui/view_ids.h" |
[email protected] | dcd5776 | 2011-06-25 12:18:51 | [diff] [blame] | 203 | #include "ui/base/win/shell.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 204 | #endif // OS_WIN |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 205 | |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 206 | #if defined(OS_CHROMEOS) |
[email protected] | 361c201 | 2012-09-05 16:31:13 | [diff] [blame] | 207 | #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 208 | #endif |
| 209 | |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 210 | #if defined(USE_ASH) |
[email protected] | bafda13 | 2012-02-16 19:32:51 | [diff] [blame] | 211 | #include "ash/ash_switches.h" |
[email protected] | c2f0a89 | 2012-01-24 22:19:21 | [diff] [blame] | 212 | #endif |
| 213 | |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 214 | using base::TimeDelta; |
[email protected] | b87ee52 | 2012-05-18 15:16:54 | [diff] [blame] | 215 | using content::NativeWebKeyboardEvent; |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 216 | using content::NavigationController; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 217 | using content::NavigationEntry; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 218 | using content::OpenURLParams; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 219 | using content::PluginService; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 220 | using content::Referrer; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 221 | using content::SiteInstance; |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 222 | using content::UserMetricsAction; |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 223 | using content::WebContents; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 224 | using extensions::Extension; |
[email protected] | 20c07f8e | 2012-05-31 08:43:14 | [diff] [blame] | 225 | using ui::WebDialogDelegate; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 226 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 227 | /////////////////////////////////////////////////////////////////////////////// |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 228 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 229 | namespace { |
| 230 | |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 231 | // The URL to be loaded to display the "Report a broken page" form. |
| 232 | const char kBrokenPageUrl[] = |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 233 | "https://www.google.com/support/chrome/bin/request.py?contact_type=" |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 234 | "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; |
| 235 | |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 236 | // How long we wait before updating the browser chrome while loading a page. |
| 237 | const int kUIUpdateCoalescingTimeMS = 200; |
| 238 | |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 239 | BrowserWindow* CreateBrowserWindow(Browser* browser) { |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 240 | return BrowserWindow::CreateBrowserWindow(browser); |
| 241 | } |
| 242 | |
[email protected] | 56073dc | 2012-08-10 16:59:06 | [diff] [blame] | 243 | #if defined(OS_CHROMEOS) |
| 244 | chrome::HostDesktopType kDefaultHostDesktopType = chrome::HOST_DESKTOP_TYPE_ASH; |
| 245 | #else |
| 246 | chrome::HostDesktopType kDefaultHostDesktopType = |
| 247 | chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 248 | #endif |
| 249 | |
| 250 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 251 | } // namespace |
| 252 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 253 | //////////////////////////////////////////////////////////////////////////////// |
| 254 | // Browser, CreateParams: |
| 255 | |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 256 | Browser::CreateParams::CreateParams() |
| 257 | : type(TYPE_TABBED), |
| 258 | profile(NULL), |
[email protected] | 56073dc | 2012-08-10 16:59:06 | [diff] [blame] | 259 | host_desktop_type(kDefaultHostDesktopType), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 260 | app_type(APP_TYPE_HOST), |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 261 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 262 | is_session_restore(false), |
| 263 | window(NULL) { |
| 264 | } |
| 265 | |
| 266 | Browser::CreateParams::CreateParams(Profile* profile) |
[email protected] | 56073dc | 2012-08-10 16:59:06 | [diff] [blame] | 267 | : type(TYPE_TABBED), |
| 268 | profile(profile), |
| 269 | host_desktop_type(kDefaultHostDesktopType), |
| 270 | app_type(APP_TYPE_HOST), |
| 271 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
| 272 | is_session_restore(false), |
| 273 | window(NULL) { |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 274 | } |
| 275 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 276 | Browser::CreateParams::CreateParams(Type type, Profile* profile) |
| 277 | : type(type), |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 278 | profile(profile), |
[email protected] | 56073dc | 2012-08-10 16:59:06 | [diff] [blame] | 279 | host_desktop_type(kDefaultHostDesktopType), |
| 280 | app_type(APP_TYPE_HOST), |
| 281 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
| 282 | is_session_restore(false), |
| 283 | window(NULL) { |
| 284 | } |
| 285 | |
| 286 | Browser::CreateParams::CreateParams(Type type, |
| 287 | Profile* profile, |
| 288 | chrome::HostDesktopType host_desktop_type) |
| 289 | : type(type), |
| 290 | profile(profile), |
| 291 | host_desktop_type(host_desktop_type), |
[email protected] | 0da5829 | 2012-03-22 20:37:21 | [diff] [blame] | 292 | app_type(APP_TYPE_HOST), |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 293 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 294 | is_session_restore(false), |
| 295 | window(NULL) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 296 | } |
| 297 | |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 298 | // static |
| 299 | Browser::CreateParams Browser::CreateParams::CreateForApp( |
| 300 | Type type, |
| 301 | const std::string& app_name, |
| 302 | const gfx::Rect& window_bounds, |
| 303 | Profile* profile) { |
| 304 | DCHECK(type != TYPE_TABBED); |
| 305 | DCHECK(!app_name.empty()); |
| 306 | |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 307 | CreateParams params(type, profile); |
| 308 | params.app_name = app_name; |
| 309 | params.app_type = APP_TYPE_CHILD; |
| 310 | params.initial_bounds = window_bounds; |
| 311 | |
| 312 | return params; |
| 313 | } |
| 314 | |
| 315 | // static |
| 316 | Browser::CreateParams Browser::CreateParams::CreateForDevTools( |
| 317 | Profile* profile) { |
| 318 | CreateParams params(TYPE_POPUP, profile); |
| 319 | params.app_name = DevToolsWindow::kDevToolsApp; |
| 320 | return params; |
| 321 | } |
| 322 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 323 | /////////////////////////////////////////////////////////////////////////////// |
| 324 | // Browser, Constructors, Creation, Showing: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 325 | |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 326 | Browser::Browser(const CreateParams& params) |
| 327 | : type_(params.type), |
| 328 | profile_(params.profile), |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 329 | window_(NULL), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 330 | ALLOW_THIS_IN_INITIALIZER_LIST( |
[email protected] | 85537005 | 2012-07-10 19:30:32 | [diff] [blame] | 331 | tab_strip_model_delegate_( |
| 332 | new chrome::BrowserTabStripModelDelegate(this))), |
| 333 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 334 | tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 335 | params.profile))), |
| 336 | app_name_(params.app_name), |
| 337 | app_type_(params.app_type), |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 338 | chrome_updater_factory_(this), |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 339 | cancel_download_confirmation_state_(NOT_PROMPTED), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 340 | override_bounds_(params.initial_bounds), |
| 341 | initial_show_state_(params.initial_show_state), |
| 342 | is_session_restore_(params.is_session_restore), |
[email protected] | 56073dc | 2012-08-10 16:59:06 | [diff] [blame] | 343 | host_desktop_type_(params.host_desktop_type), |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 344 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 345 | unload_controller_(new chrome::UnloadController(this))), |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 346 | weak_factory_(this), |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 347 | ALLOW_THIS_IN_INITIALIZER_LIST( |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 348 | content_setting_bubble_model_delegate_( |
| 349 | new BrowserContentSettingBubbleModelDelegate(this))), |
| 350 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 351 | toolbar_model_delegate_( |
| 352 | new BrowserToolbarModelDelegate(this))), |
| 353 | ALLOW_THIS_IN_INITIALIZER_LIST( |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 354 | tab_restore_service_delegate_( |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 355 | new BrowserTabRestoreServiceDelegate(this))), |
[email protected] | afefa74e | 2011-07-26 05:04:23 | [diff] [blame] | 356 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 357 | synced_window_delegate_( |
| 358 | new BrowserSyncedWindowDelegate(this))), |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 359 | bookmark_bar_state_(BookmarkBar::HIDDEN), |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 360 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 361 | command_controller_(new chrome::BrowserCommandController(this))), |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 362 | window_has_shown_(false) { |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 363 | if (!app_name_.empty()) |
| 364 | chrome::RegisterAppPrefs(app_name_, profile_); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 365 | tab_strip_model_->AddObserver(this); |
| 366 | |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 367 | toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get())); |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 368 | search_model_.reset(new chrome::search::SearchModel(NULL)); |
| 369 | search_delegate_.reset( |
[email protected] | 51a53e8f6 | 2012-08-28 03:08:56 | [diff] [blame] | 370 | new chrome::search::SearchDelegate(search_model_.get(), |
| 371 | toolbar_model_.get())); |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 372 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 373 | registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 374 | content::NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 375 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 376 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 377 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 378 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 379 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 380 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 381 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 382 | content::NotificationService::AllSources()); |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 383 | #if defined(ENABLE_THEMES) |
[email protected] | ffa6f59 | 2011-06-24 22:03:57 | [diff] [blame] | 384 | registrar_.Add( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 385 | this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 386 | content::Source<ThemeService>( |
| 387 | ThemeServiceFactory::GetForProfile(profile_))); |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 388 | #endif |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 389 | registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 390 | content::NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 391 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 392 | profile_pref_registrar_.Init(profile_->GetPrefs()); |
| 393 | profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 394 | profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 395 | profile_pref_registrar_.Add(prefs::kHomePage, this); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 396 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 397 | BrowserList::AddBrowser(this); |
| 398 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 399 | // NOTE: These prefs all need to be explicitly destroyed in the destructor |
| 400 | // or you'll get a nasty surprise when you run the incognito tests. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 401 | encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, |
| 402 | profile_->GetPrefs(), NULL); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 403 | |
[email protected] | 7acfaf9 | 2012-07-11 15:51:59 | [diff] [blame] | 404 | instant_controller_.reset(new chrome::BrowserInstantController(this)); |
[email protected] | df25eb9f | 2012-09-13 17:43:23 | [diff] [blame] | 405 | |
| 406 | #if 0 |
| 407 | // Disabled for M22. See http://crbug.com/144326. |
[email protected] | 65c8114 | 2012-07-31 19:44:43 | [diff] [blame] | 408 | device_attached_intent_source_.reset( |
| 409 | new DeviceAttachedIntentSource(this, (this))); |
[email protected] | df25eb9f | 2012-09-13 17:43:23 | [diff] [blame] | 410 | #endif |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 411 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 412 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 413 | |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 414 | FilePath profile_path = profile_->GetPath(); |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 415 | ProfileMetrics::LogProfileLaunch(profile_path); |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 416 | |
| 417 | window_ = params.window ? params.window : CreateBrowserWindow(this); |
| 418 | |
| 419 | // TODO(beng): move to BrowserFrameWin. |
| 420 | #if defined(OS_WIN) && !defined(USE_AURA) |
| 421 | // Set the app user model id for this application to that of the application |
| 422 | // name. See http://crbug.com/7028. |
| 423 | ui::win::SetAppIdForWindow( |
| 424 | is_app() && !is_type_panel() ? |
| 425 | ShellIntegration::GetAppModelIdForProfile(UTF8ToWide(app_name_), |
| 426 | profile_->GetPath()) : |
| 427 | ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()), |
| 428 | window()->GetNativeWindow()); |
| 429 | |
| 430 | if (is_type_panel()) { |
| 431 | ui::win::SetAppIconForWindow(ShellIntegration::GetChromiumIconPath(), |
| 432 | window()->GetNativeWindow()); |
| 433 | } |
| 434 | #endif |
| 435 | |
| 436 | // Create the extension window controller before sending notifications. |
| 437 | extension_window_controller_.reset( |
| 438 | new BrowserExtensionWindowController(this)); |
| 439 | |
| 440 | // TODO(beng): Move BrowserList::AddBrowser() to the end of this function and |
| 441 | // replace uses of this with BL's notifications. |
| 442 | content::NotificationService::current()->Notify( |
| 443 | chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 444 | content::Source<Browser>(this), |
| 445 | content::NotificationService::NoDetails()); |
| 446 | |
| 447 | // TODO(beng): move to ChromeBrowserMain: |
| 448 | PrefService* local_state = g_browser_process->local_state(); |
| 449 | if (local_state && local_state->FindPreference( |
| 450 | prefs::kAutofillPersonalDataManagerFirstRun) && |
| 451 | local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) { |
| 452 | // Notify PDM that this is a first run. |
| 453 | #if defined(OS_WIN) |
| 454 | ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_)); |
| 455 | #endif // defined(OS_WIN) |
| 456 | // Reset the preference so we don't call it again for subsequent windows. |
| 457 | local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun); |
| 458 | } |
| 459 | |
[email protected] | 6fb528e | 2012-08-01 20:32:33 | [diff] [blame] | 460 | fullscreen_controller_.reset(new FullscreenController(this)); |
[email protected] | c316630 | 2012-09-25 21:27:08 | [diff] [blame] | 461 | search_model_->AddObserver(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | Browser::~Browser() { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 465 | // The tab strip should not have any tabs at this point. |
| 466 | if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) |
| 467 | DCHECK(tab_strip_model_->empty()); |
[email protected] | c316630 | 2012-09-25 21:27:08 | [diff] [blame] | 468 | |
| 469 | search_model_->RemoveObserver(this); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 470 | tab_strip_model_->RemoveObserver(this); |
| 471 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 472 | BrowserList::RemoveBrowser(this); |
| 473 | |
[email protected] | bdc6ccd1 | 2012-03-20 22:06:13 | [diff] [blame] | 474 | SessionService* session_service = |
| 475 | SessionServiceFactory::GetForProfile(profile_); |
| 476 | if (session_service) |
| 477 | session_service->WindowClosed(session_id_); |
| 478 | |
| 479 | TabRestoreService* tab_restore_service = |
| 480 | TabRestoreServiceFactory::GetForProfile(profile()); |
| 481 | if (tab_restore_service) |
| 482 | tab_restore_service->BrowserClosed(tab_restore_service_delegate()); |
| 483 | |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 484 | #if !defined(OS_MACOSX) |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 485 | if (!browser::GetBrowserCount(profile_)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 486 | // We're the last browser window with this profile. We need to nuke the |
| 487 | // TabRestoreService, which will start the shutdown of the |
| 488 | // NavigationControllers and allow for proper shutdown. If we don't do this |
| 489 | // chrome won't shutdown cleanly, and may end up crashing when some |
| 490 | // thread tries to use the IO thread (or another thread) that is no longer |
| 491 | // valid. |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 492 | // This isn't a valid assumption for Mac OS, as it stays running after |
| 493 | // the last browser has closed. The Mac equivalent is in its app |
| 494 | // controller. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 495 | TabRestoreServiceFactory::ResetForProfile(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 496 | } |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 497 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 498 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 499 | profile_pref_registrar_.RemoveAll(); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 500 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 501 | encoding_auto_detect_.Destroy(); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 502 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 503 | command_controller_.reset(); |
| 504 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 505 | if (profile_->IsOffTheRecord() && |
[email protected] | 474e5db | 2011-08-12 13:02:23 | [diff] [blame] | 506 | !BrowserList::IsOffTheRecordSessionActiveForProfile(profile_)) { |
[email protected] | 5e91924 | 2012-02-13 23:59:35 | [diff] [blame] | 507 | // An incognito profile is no longer needed, this indirectly frees |
| 508 | // its cache and cookies once it gets destroyed at the appropriate time. |
[email protected] | 4dffabe | 2012-05-19 14:37:06 | [diff] [blame] | 509 | ProfileDestroyer::DestroyProfileWhenAppropriate(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | // There may be pending file dialogs, we need to tell them that we've gone |
| 513 | // away so they don't try and call back to us. |
| 514 | if (select_file_dialog_.get()) |
| 515 | select_file_dialog_->ListenerDestroyed(); |
| 516 | } |
| 517 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 518 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 519 | // Getters & Setters |
| 520 | |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 521 | FindBarController* Browser::GetFindBarController() { |
| 522 | if (!find_bar_controller_.get()) { |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 523 | FindBar* find_bar = window_->CreateFindBar(); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 524 | find_bar_controller_.reset(new FindBarController(find_bar)); |
| 525 | find_bar->SetFindBarController(find_bar_controller_.get()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 526 | find_bar_controller_->ChangeTabContents(chrome::GetActiveTabContents(this)); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 527 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
| 528 | } |
| 529 | return find_bar_controller_.get(); |
| 530 | } |
| 531 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 532 | bool Browser::HasFindBarController() const { |
| 533 | return find_bar_controller_.get() != NULL; |
| 534 | } |
| 535 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 536 | bool Browser::is_app() const { |
| 537 | return !app_name_.empty(); |
| 538 | } |
| 539 | |
| 540 | bool Browser::is_devtools() const { |
| 541 | return app_name_ == DevToolsWindow::kDevToolsApp; |
| 542 | } |
| 543 | |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 544 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 545 | // Browser, State Storage and Retrieval for UI: |
| 546 | |
[email protected] | 9b125b73 | 2012-08-17 04:43:55 | [diff] [blame] | 547 | gfx::Image Browser::GetCurrentPageIcon() const { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 548 | TabContents* contents = chrome::GetActiveTabContents(this); |
[email protected] | ce5348a8 | 2008-12-18 18:36:23 | [diff] [blame] | 549 | // |contents| can be NULL since GetCurrentPageIcon() is called by the window |
| 550 | // during the window's creation (before tabs have been added). |
[email protected] | 6172089 | 2012-08-03 19:35:33 | [diff] [blame] | 551 | return contents ? |
[email protected] | 9b125b73 | 2012-08-17 04:43:55 | [diff] [blame] | 552 | contents->favicon_tab_helper()->GetFavicon() : gfx::Image(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 553 | } |
| 554 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 555 | string16 Browser::GetWindowTitleForCurrentTab() const { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 556 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 557 | string16 title; |
[email protected] | c7c4233 | 2008-11-15 01:10:54 | [diff] [blame] | 558 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 559 | // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the |
| 560 | // window during the window's creation (before tabs have been added). |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 561 | if (contents) { |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 562 | title = contents->GetTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 563 | FormatTitleForDisplay(&title); |
| 564 | } |
| 565 | if (title.empty()) |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 566 | title = CoreTabHelper::GetDefaultTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 567 | |
[email protected] | cae9765 | 2012-04-20 03:12:12 | [diff] [blame] | 568 | #if defined(OS_MACOSX) || defined(USE_ASH) |
| 569 | // On Mac or Ash, we don't want to suffix the page title with |
[email protected] | 22a3daa | 2009-11-09 22:03:33 | [diff] [blame] | 570 | // the application name. |
[email protected] | d904bc8 | 2009-07-07 00:41:04 | [diff] [blame] | 571 | return title; |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 572 | #else |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 573 | int string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT; |
[email protected] | dff52973 | 2010-04-01 23:50:55 | [diff] [blame] | 574 | // Don't append the app name to window titles on app frames and app popups |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 575 | if (is_app()) |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 576 | string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT_NO_LOGO; |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 577 | return l10n_util::GetStringFUTF16(string_id, title); |
[email protected] | 57e68dba | 2009-05-15 21:30:50 | [diff] [blame] | 578 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | // static |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 582 | void Browser::FormatTitleForDisplay(string16* title) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 583 | size_t current_index = 0; |
| 584 | size_t match_index; |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 585 | while ((match_index = title->find(L'\n', current_index)) != string16::npos) { |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 586 | title->replace(match_index, 1, string16()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 587 | current_index = match_index; |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | /////////////////////////////////////////////////////////////////////////////// |
| 592 | // Browser, OnBeforeUnload handling: |
| 593 | |
| 594 | bool Browser::ShouldCloseWindow() { |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 595 | if (!CanCloseWithInProgressDownloads()) |
| 596 | return false; |
| 597 | |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 598 | return unload_controller_->ShouldCloseWindow(); |
| 599 | } |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 600 | |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 601 | bool Browser::IsAttemptingToCloseBrowser() const { |
| 602 | return unload_controller_->is_attempting_to_close_browser(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | void Browser::OnWindowClosing() { |
| 606 | if (!ShouldCloseWindow()) |
| 607 | return; |
| 608 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 609 | // Application should shutdown on last window close if the user is explicitly |
| 610 | // trying to quit, or if there is nothing keeping the browser alive (such as |
| 611 | // AppController on the Mac, or BackgroundContentsService for background |
| 612 | // pages). |
| 613 | bool should_quit_if_last_browser = |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 614 | browser_shutdown::IsTryingToQuit() || !browser::WillKeepAlive(); |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 615 | |
[email protected] | 1e0c740 | 2012-07-27 10:48:15 | [diff] [blame] | 616 | if (should_quit_if_last_browser && BrowserList::size() == 1) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 617 | browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); |
| 618 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 619 | // Don't use GetForProfileIfExisting here, we want to force creation of the |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 620 | // session service so that user can restore what was open. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 621 | SessionService* session_service = |
| 622 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 623 | if (session_service) |
| 624 | session_service->WindowClosing(session_id()); |
| 625 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 626 | TabRestoreService* tab_restore_service = |
| 627 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 628 | |
| 629 | #if defined(USE_AURA) |
| 630 | if (tab_restore_service && is_app()) |
| 631 | tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
| 632 | #endif |
| 633 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 634 | if (tab_restore_service && is_type_tabbed() && tab_count()) |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 635 | tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 636 | |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 637 | // TODO(sky): convert session/tab restore to use notification. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 638 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 639 | chrome::NOTIFICATION_BROWSER_CLOSING, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 640 | content::Source<Browser>(this), |
[email protected] | 1e0c740 | 2012-07-27 10:48:15 | [diff] [blame] | 641 | content::NotificationService::NoDetails()); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 642 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 643 | chrome::CloseAllTabs(this); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 644 | } |
| 645 | |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 646 | void Browser::OnWindowActivated() { |
| 647 | // On some platforms we want to automatically reload tabs that are |
| 648 | // killed when the user selects them. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 649 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 650 | if (contents && contents->GetCrashedStatus() == |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 651 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 652 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 653 | switches::kReloadKilledTabs)) { |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 654 | chrome::Reload(this, CURRENT_TAB); |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | } |
| 658 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 659 | //////////////////////////////////////////////////////////////////////////////// |
| 660 | // In-progress download termination handling: |
| 661 | |
| 662 | void Browser::InProgressDownloadResponse(bool cancel_downloads) { |
| 663 | if (cancel_downloads) { |
| 664 | cancel_download_confirmation_state_ = RESPONSE_RECEIVED; |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 665 | chrome::CloseWindow(this); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 666 | return; |
| 667 | } |
| 668 | |
| 669 | // Sets the confirmation state to NOT_PROMPTED so that if the user tries to |
| 670 | // close again we'll show the warning again. |
| 671 | cancel_download_confirmation_state_ = NOT_PROMPTED; |
| 672 | |
| 673 | // Show the download page so the user can figure-out what downloads are still |
| 674 | // in-progress. |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 675 | chrome::ShowDownloads(this); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 676 | } |
| 677 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 678 | Browser::DownloadClosePreventionType Browser::OkToCloseWithInProgressDownloads( |
| 679 | int* num_downloads_blocking) const { |
| 680 | DCHECK(num_downloads_blocking); |
| 681 | *num_downloads_blocking = 0; |
| 682 | |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 683 | if (IsAttemptingToCloseBrowser()) |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 684 | return DOWNLOAD_CLOSE_OK; |
| 685 | |
| 686 | // If we're not running a full browser process with a profile manager |
| 687 | // (testing), it's ok to close the browser. |
| 688 | if (!g_browser_process->profile_manager()) |
| 689 | return DOWNLOAD_CLOSE_OK; |
| 690 | |
| 691 | int total_download_count = DownloadService::DownloadCountAllProfiles(); |
| 692 | if (total_download_count == 0) |
| 693 | return DOWNLOAD_CLOSE_OK; // No downloads; can definitely close. |
| 694 | |
| 695 | // Figure out how many windows are open total, and associated with this |
| 696 | // profile, that are relevant for the ok-to-close decision. |
| 697 | int profile_window_count = 0; |
| 698 | int total_window_count = 0; |
| 699 | for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 700 | iter != BrowserList::end(); ++iter) { |
| 701 | // Don't count this browser window or any other in the process of closing. |
| 702 | Browser* const browser = *iter; |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 703 | // Window closing may be delayed, and windows that are in the process of |
| 704 | // closing don't count against our totals. |
| 705 | if (browser == this || browser->IsAttemptingToCloseBrowser()) |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 706 | continue; |
| 707 | |
| 708 | if ((*iter)->profile() == profile()) |
| 709 | profile_window_count++; |
| 710 | total_window_count++; |
| 711 | } |
| 712 | |
| 713 | // If there aren't any other windows, we're at browser shutdown, |
| 714 | // which would cancel all current downloads. |
| 715 | if (total_window_count == 0) { |
| 716 | *num_downloads_blocking = total_download_count; |
| 717 | return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN; |
| 718 | } |
| 719 | |
| 720 | // If there aren't any other windows on our profile, and we're an incognito |
| 721 | // profile, and there are downloads associated with that profile, |
| 722 | // those downloads would be cancelled by our window (-> profile) close. |
| 723 | DownloadService* download_service = |
| 724 | DownloadServiceFactory::GetForProfile(profile()); |
| 725 | if (profile_window_count == 0 && download_service->DownloadCount() > 0 && |
| 726 | profile()->IsOffTheRecord()) { |
| 727 | *num_downloads_blocking = download_service->DownloadCount(); |
| 728 | return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE; |
| 729 | } |
| 730 | |
| 731 | // Those are the only conditions under which we will block shutdown. |
| 732 | return DOWNLOAD_CLOSE_OK; |
| 733 | } |
| 734 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 735 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 736 | // Browser, TabStripModel pass-thrus: |
| 737 | |
| 738 | int Browser::tab_count() const { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 739 | return tab_strip_model_->count(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 740 | } |
| 741 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 742 | int Browser::active_index() const { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 743 | return tab_strip_model_->active_index(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 744 | } |
| 745 | |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 746 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 747 | // Browser, Tab adding/showing functions: |
| 748 | |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 749 | void Browser::WindowFullscreenStateChanged() { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 750 | fullscreen_controller_->WindowFullscreenStateChanged(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 751 | command_controller_->FullscreenStateChanged(); |
[email protected] | 9adb8b1 | 2011-12-09 06:49:13 | [diff] [blame] | 752 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 753 | } |
| 754 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 755 | /////////////////////////////////////////////////////////////////////////////// |
| 756 | // Browser, Assorted browser commands: |
| 757 | |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 758 | void Browser::ToggleFullscreenModeWithExtension(const GURL& extension_url) { |
| 759 | fullscreen_controller_->ToggleFullscreenModeWithExtension(extension_url); |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 760 | } |
| 761 | |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 762 | #if defined(OS_MACOSX) |
[email protected] | 184717d5 | 2012-02-22 04:46:16 | [diff] [blame] | 763 | void Browser::TogglePresentationMode() { |
| 764 | fullscreen_controller_->TogglePresentationMode(); |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 765 | } |
| 766 | #endif |
| 767 | |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 768 | bool Browser::SupportsWindowFeature(WindowFeature feature) const { |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 769 | return SupportsWindowFeatureImpl(feature, true); |
| 770 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 771 | |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 772 | bool Browser::CanSupportWindowFeature(WindowFeature feature) const { |
| 773 | return SupportsWindowFeatureImpl(feature, false); |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 774 | } |
| 775 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 776 | void Browser::ToggleEncodingAutoDetect() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 777 | content::RecordAction(UserMetricsAction("AutoDetectChange")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 778 | encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 779 | // If "auto detect" is turned on, then any current override encoding |
| 780 | // is cleared. This also implicitly performs a reload. |
| 781 | // OTOH, if "auto detect" is turned off, we don't change the currently |
| 782 | // active encoding. |
| 783 | if (encoding_auto_detect_.GetValue()) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 784 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 785 | if (contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 786 | contents->ResetOverrideEncoding(); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 787 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | void Browser::OverrideEncoding(int encoding_id) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 791 | content::RecordAction(UserMetricsAction("OverrideEncoding")); |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 792 | const std::string selected_encoding = |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 793 | CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 794 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 795 | if (!selected_encoding.empty() && contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 796 | contents->SetOverrideEncoding(selected_encoding); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 797 | // Update the list of recently selected encodings. |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 798 | std::string new_selected_encoding_list; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 799 | if (CharacterEncoding::UpdateRecentlySelectedEncoding( |
| 800 | profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding), |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 801 | encoding_id, |
| 802 | &new_selected_encoding_list)) { |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 803 | profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 804 | new_selected_encoding_list); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 805 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 806 | } |
| 807 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 808 | void Browser::OpenFile() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 809 | content::RecordAction(UserMetricsAction("OpenFile")); |
[email protected] | 92f5408 | 2012-07-31 01:43:14 | [diff] [blame] | 810 | select_file_dialog_ = ui::SelectFileDialog::Create( |
[email protected] | 6e1fcd1 | 2012-07-02 17:14:20 | [diff] [blame] | 811 | this, new ChromeSelectFilePolicy( |
| 812 | chrome::GetActiveWebContents(this))); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 813 | |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 814 | const FilePath directory = profile_->last_selected_directory(); |
| 815 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 816 | // TODO(beng): figure out how to juggle this. |
[email protected] | 90556dd | 2012-06-07 20:26:18 | [diff] [blame] | 817 | gfx::NativeWindow parent_window = window_->GetNativeWindow(); |
[email protected] | 479cce78 | 2012-09-15 20:15:53 | [diff] [blame] | 818 | ui::SelectFileDialog::FileTypeInfo file_types; |
| 819 | file_types.support_gdata = true; |
[email protected] | 92f5408 | 2012-07-31 01:43:14 | [diff] [blame] | 820 | select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE, |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 821 | string16(), directory, |
[email protected] | 479cce78 | 2012-09-15 20:15:53 | [diff] [blame] | 822 | &file_types, 0, FILE_PATH_LITERAL(""), |
[email protected] | d56bcd2 | 2009-03-16 19:51:56 | [diff] [blame] | 823 | parent_window, NULL); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 824 | } |
| 825 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 826 | void Browser::UpdateDownloadShelfVisibility(bool visible) { |
| 827 | if (GetStatusBubble()) |
| 828 | GetStatusBubble()->UpdateDownloadShelfVisibility(visible); |
| 829 | } |
| 830 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 831 | /////////////////////////////////////////////////////////////////////////////// |
| 832 | |
| 833 | // static |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 834 | bool Browser::RunUnloadEventsHelper(WebContents* contents) { |
[email protected] | 075969d | 2012-04-17 20:05:55 | [diff] [blame] | 835 | // If the WebContents is not connected yet, then there's no unload |
| 836 | // handler we can fire even if the WebContents has an unload listener. |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 837 | // One case where we hit this is in a tab that has an infinite loop |
| 838 | // before load. |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 839 | if (contents->NeedToFireBeforeUnload()) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 840 | // If the page has unload listeners, then we tell the renderer to fire |
| 841 | // them. Once they have fired, we'll get a message back saying whether |
| 842 | // to proceed closing the page or not, which sends us back to this method |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 843 | // with the NeedToFireBeforeUnload bit cleared. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 844 | contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 845 | return true; |
| 846 | } |
| 847 | return false; |
| 848 | } |
| 849 | |
| 850 | // static |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 851 | void Browser::JSOutOfMemoryHelper(WebContents* web_contents) { |
| 852 | TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 853 | if (!tab_contents) |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 854 | return; |
| 855 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 856 | InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 857 | infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 858 | infobar_helper, |
| 859 | NULL, |
| 860 | l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), |
| 861 | true)); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | // static |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 865 | void Browser::RegisterProtocolHandlerHelper(WebContents* web_contents, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 866 | const std::string& protocol, |
| 867 | const GURL& url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 868 | const string16& title, |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 869 | bool user_gesture, |
| 870 | BrowserWindow* window) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 871 | TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 872 | if (!tab_contents || tab_contents->profile()->IsOffTheRecord()) |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 873 | return; |
| 874 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 875 | ProtocolHandler handler = |
| 876 | ProtocolHandler::CreateProtocolHandler(protocol, url, title); |
| 877 | |
| 878 | ProtocolHandlerRegistry* registry = |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 879 | tab_contents->profile()->GetProtocolHandlerRegistry(); |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 880 | TabSpecificContentSettings* content_settings = |
| 881 | tab_contents->content_settings(); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 882 | |
[email protected] | 96affbc8 | 2012-07-23 18:04:42 | [diff] [blame] | 883 | if (registry->SilentlyHandleRegisterHandlerRequest(handler)) |
| 884 | return; |
| 885 | |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 886 | if (!user_gesture && window) { |
| 887 | content_settings->set_pending_protocol_handler(handler); |
| 888 | content_settings->set_previous_protocol_handler( |
| 889 | registry->GetHandlerFor(handler.protocol())); |
| 890 | window->GetLocationBar()->UpdateContentSettingsIcons(); |
[email protected] | 3fa5e19 | 2012-07-15 00:40:34 | [diff] [blame] | 891 | return; |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | // Make sure content-setting icon is turned off in case the page does |
| 895 | // ungestured and gestured RPH calls. |
| 896 | if (window) { |
| 897 | content_settings->ClearPendingProtocolHandler(); |
| 898 | window->GetLocationBar()->UpdateContentSettingsIcons(); |
| 899 | } |
[email protected] | 3fa5e19 | 2012-07-15 00:40:34 | [diff] [blame] | 900 | |
[email protected] | 96affbc8 | 2012-07-23 18:04:42 | [diff] [blame] | 901 | content::RecordAction( |
| 902 | UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); |
| 903 | InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 904 | |
[email protected] | 96affbc8 | 2012-07-23 18:04:42 | [diff] [blame] | 905 | RegisterProtocolHandlerInfoBarDelegate* rph_delegate = |
| 906 | new RegisterProtocolHandlerInfoBarDelegate(infobar_helper, |
| 907 | registry, |
| 908 | handler); |
[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 909 | |
[email protected] | d715fb80 | 2012-08-20 16:34:13 | [diff] [blame] | 910 | for (size_t i = 0; i < infobar_helper->GetInfoBarCount(); i++) { |
[email protected] | 96affbc8 | 2012-07-23 18:04:42 | [diff] [blame] | 911 | InfoBarDelegate* delegate = infobar_helper->GetInfoBarDelegateAt(i); |
| 912 | RegisterProtocolHandlerInfoBarDelegate* cast_delegate = |
| 913 | delegate->AsRegisterProtocolHandlerInfoBarDelegate(); |
| 914 | if (cast_delegate != NULL && cast_delegate->IsReplacedBy(rph_delegate)) { |
| 915 | infobar_helper->ReplaceInfoBar(cast_delegate, rph_delegate); |
| 916 | rph_delegate = NULL; |
| 917 | break; |
[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 918 | } |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 919 | } |
[email protected] | 96affbc8 | 2012-07-23 18:04:42 | [diff] [blame] | 920 | |
| 921 | if (rph_delegate != NULL) |
| 922 | infobar_helper->AddInfoBar(rph_delegate); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | // static |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 926 | void Browser::FindReplyHelper(WebContents* web_contents, |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 927 | int request_id, |
| 928 | int number_of_matches, |
| 929 | const gfx::Rect& selection_rect, |
| 930 | int active_match_ordinal, |
| 931 | bool final_update) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 932 | TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 933 | if (!tab_contents || !tab_contents->find_tab_helper()) |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 934 | return; |
| 935 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 936 | tab_contents->find_tab_helper()->HandleFindReply(request_id, |
| 937 | number_of_matches, |
| 938 | selection_rect, |
| 939 | active_match_ordinal, |
| 940 | final_update); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 941 | } |
| 942 | |
[email protected] | c55d3d12 | 2012-07-10 16:53:41 | [diff] [blame] | 943 | // static |
| 944 | void Browser::RequestMediaAccessPermissionHelper( |
| 945 | content::WebContents* web_contents, |
| 946 | const content::MediaStreamRequest* request, |
| 947 | const content::MediaResponseCallback& callback) { |
| 948 | TabContents* tab = TabContents::FromWebContents(web_contents); |
| 949 | |
| 950 | scoped_ptr<MediaStreamDevicesController> |
| 951 | controller(new MediaStreamDevicesController(tab->profile(), |
| 952 | request, |
| 953 | callback)); |
| 954 | if (!controller->DismissInfoBarAndTakeActionOnSettings()) { |
| 955 | InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); |
| 956 | InfoBarDelegate* old_infobar = NULL; |
[email protected] | d715fb80 | 2012-08-20 16:34:13 | [diff] [blame] | 957 | for (size_t i = 0; i < infobar_helper->GetInfoBarCount(); ++i) { |
[email protected] | c55d3d12 | 2012-07-10 16:53:41 | [diff] [blame] | 958 | old_infobar = infobar_helper->GetInfoBarDelegateAt(i)-> |
| 959 | AsMediaStreamInfoBarDelegate(); |
| 960 | if (old_infobar) |
| 961 | break; |
| 962 | } |
| 963 | |
| 964 | InfoBarDelegate* infobar = |
| 965 | new MediaStreamInfoBarDelegate(infobar_helper, controller.release()); |
| 966 | if (old_infobar) |
| 967 | infobar_helper->ReplaceInfoBar(old_infobar, infobar); |
| 968 | else |
| 969 | infobar_helper->AddInfoBar(infobar); |
| 970 | } |
| 971 | } |
| 972 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 973 | void Browser::UpdateUIForNavigationInTab(TabContents* contents, |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 974 | content::PageTransition transition, |
| 975 | bool user_initiated) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 976 | tab_strip_model_->TabNavigating(contents, transition); |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 977 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 978 | bool contents_is_selected = contents == chrome::GetActiveTabContents(this); |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 979 | if (user_initiated && contents_is_selected && window()->GetLocationBar()) { |
| 980 | // Forcibly reset the location bar if the url is going to change in the |
| 981 | // current tab, since otherwise it won't discard any ongoing user edits, |
| 982 | // since it doesn't realize this is a user-initiated action. |
| 983 | window()->GetLocationBar()->Revert(); |
| 984 | } |
| 985 | |
| 986 | if (GetStatusBubble()) |
| 987 | GetStatusBubble()->Hide(); |
| 988 | |
| 989 | // Update the location bar. This is synchronous. We specifically don't |
| 990 | // update the load state since the load hasn't started yet and updating it |
| 991 | // will put it out of sync with the actual state like whether we're |
| 992 | // displaying a favicon, which controls the throbber. If we updated it here, |
| 993 | // the throbber will show the default favicon for a split second when |
| 994 | // navigating away from the new tab page. |
| 995 | ScheduleUIUpdate(contents->web_contents(), content::INVALIDATE_TYPE_URL); |
| 996 | |
[email protected] | e1f288d | 2012-05-23 19:36:10 | [diff] [blame] | 997 | if (contents_is_selected) |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 998 | contents->web_contents()->Focus(); |
| 999 | } |
| 1000 | |
| 1001 | /////////////////////////////////////////////////////////////////////////////// |
| 1002 | // Browser, PageNavigator implementation: |
| 1003 | |
| 1004 | WebContents* Browser::OpenURL(const OpenURLParams& params) { |
| 1005 | return OpenURLFromTab(NULL, params); |
| 1006 | } |
| 1007 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1008 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1009 | // Browser, TabStripModelObserver implementation: |
| 1010 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1011 | void Browser::TabInsertedAt(TabContents* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1012 | int index, |
| 1013 | bool foreground) { |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 1014 | SetAsDelegate(contents->web_contents(), this); |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 1015 | SessionTabHelper* session_tab_helper = |
| 1016 | SessionTabHelper::FromWebContents(contents->web_contents()); |
| 1017 | session_tab_helper->SetWindowID(session_id()); |
[email protected] | e524ff9 | 2011-03-30 13:26:58 | [diff] [blame] | 1018 | |
[email protected] | fb312eb | 2012-09-24 23:21:10 | [diff] [blame] | 1019 | content::NotificationService::current()->Notify( |
| 1020 | chrome::NOTIFICATION_TAB_PARENTED, |
| 1021 | content::Source<content::WebContents>(contents->web_contents()), |
| 1022 | content::NotificationService::NoDetails()); |
| 1023 | |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1024 | SyncHistoryWithTabs(index); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1025 | |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 1026 | // Make sure the loading state is updated correctly, otherwise the throbber |
| 1027 | // won't start if the page is loading. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1028 | LoadingStateChanged(contents->web_contents()); |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 1029 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1030 | registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 1031 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 1032 | |
| 1033 | registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 1034 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | 4060015 | 2012-09-26 10:04:31 | [diff] [blame] | 1035 | SessionService* session_service = |
| 1036 | SessionServiceFactory::GetForProfile(profile_); |
| 1037 | if (session_service) |
| 1038 | session_service->TabInserted(contents->web_contents()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1039 | } |
| 1040 | |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 1041 | void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1042 | TabContents* contents, |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 1043 | int index) { |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1044 | fullscreen_controller_->OnTabClosing(contents->web_contents()); |
[email protected] | 4060015 | 2012-09-26 10:04:31 | [diff] [blame] | 1045 | SessionService* session_service = |
| 1046 | SessionServiceFactory::GetForProfile(profile_); |
| 1047 | if (session_service) |
| 1048 | session_service->TabClosing(contents->web_contents()); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1049 | content::NotificationService::current()->Notify( |
[email protected] | 884033e | 2012-04-16 19:38:42 | [diff] [blame] | 1050 | chrome::NOTIFICATION_TAB_CLOSING, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1051 | content::Source<NavigationController>( |
[email protected] | cca0f1e | 2012-01-03 18:27:46 | [diff] [blame] | 1052 | &contents->web_contents()->GetController()), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1053 | content::NotificationService::NoDetails()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1054 | |
[email protected] | 075969d | 2012-04-17 20:05:55 | [diff] [blame] | 1055 | // Sever the WebContents' connection back to us. |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 1056 | SetAsDelegate(contents->web_contents(), NULL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1057 | } |
| 1058 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1059 | void Browser::TabDetachedAt(TabContents* contents, int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1060 | TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1061 | } |
| 1062 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1063 | void Browser::TabDeactivated(TabContents* contents) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1064 | fullscreen_controller_->OnTabDeactivated(contents); |
[email protected] | 0dc50db | 2012-09-19 17:57:14 | [diff] [blame] | 1065 | search_delegate_->OnTabDeactivated(contents->web_contents()); |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 1066 | |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 1067 | // Save what the user's currently typing, so it can be restored when we |
| 1068 | // switch back to this tab. |
[email protected] | 83a2610a | 2012-01-05 01:00:27 | [diff] [blame] | 1069 | window_->GetLocationBar()->SaveStateToContents(contents->web_contents()); |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 1070 | } |
| 1071 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1072 | void Browser::ActiveTabChanged(TabContents* old_contents, |
| 1073 | TabContents* new_contents, |
[email protected] | 3aca95d4 | 2011-05-24 22:06:54 | [diff] [blame] | 1074 | int index, |
| 1075 | bool user_gesture) { |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 1076 | // On some platforms we want to automatically reload tabs that are |
| 1077 | // killed when the user selects them. |
[email protected] | 9d7518f | 2012-04-17 02:15:20 | [diff] [blame] | 1078 | bool did_reload = false; |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1079 | if (user_gesture && new_contents->web_contents()->GetCrashedStatus() == |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 1080 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 1081 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 1082 | if (parsed_command_line.HasSwitch(switches::kReloadKilledTabs)) { |
[email protected] | 734d2669 | 2012-03-26 18:00:25 | [diff] [blame] | 1083 | LOG(WARNING) << "Reloading killed tab at " << index; |
[email protected] | d6d4dae | 2012-04-18 17:47:32 | [diff] [blame] | 1084 | static int reload_count = 0; |
[email protected] | 24c463a | 2012-04-20 22:33:50 | [diff] [blame] | 1085 | UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 1086 | "Tabs.SadTab.ReloadCount", ++reload_count, 1, 1000, 50); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 1087 | chrome::Reload(this, CURRENT_TAB); |
[email protected] | 9d7518f | 2012-04-17 02:15:20 | [diff] [blame] | 1088 | did_reload = true; |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 1089 | } |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 1090 | } |
| 1091 | |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 1092 | // Discarded tabs always get reloaded. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1093 | if (!did_reload && tab_strip_model_->IsTabDiscarded(index)) { |
[email protected] | d6d4dae | 2012-04-18 17:47:32 | [diff] [blame] | 1094 | LOG(WARNING) << "Reloading discarded tab at " << index; |
| 1095 | static int reload_count = 0; |
[email protected] | 24c463a | 2012-04-20 22:33:50 | [diff] [blame] | 1096 | UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 1097 | "Tabs.Discard.ReloadCount", ++reload_count, 1, 1000, 50); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 1098 | chrome::Reload(this, CURRENT_TAB); |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 1099 | } |
| 1100 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1101 | // If we have any update pending, do it now. |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1102 | if (chrome_updater_factory_.HasWeakPtrs() && old_contents) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1103 | ProcessPendingUIUpdates(); |
| 1104 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1105 | // Propagate the profile to the location bar. |
| 1106 | UpdateToolbar(true); |
| 1107 | |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 1108 | // Propagate tab state to toolbar, tab-strip, etc. |
| 1109 | UpdateSearchState(new_contents); |
| 1110 | |
[email protected] | 943d812 | 2010-06-11 02:13:45 | [diff] [blame] | 1111 | // Update reload/stop state. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1112 | command_controller_->LoadingStateChanged( |
| 1113 | new_contents->web_contents()->IsLoading(), true); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1114 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1115 | // Update commands to reflect current state. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1116 | command_controller_->TabStateChanged(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1117 | |
| 1118 | // Reset the status bubble. |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1119 | StatusBubble* status_bubble = GetStatusBubble(); |
| 1120 | if (status_bubble) { |
| 1121 | status_bubble->Hide(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1122 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1123 | // Show the loading state (if any). |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 1124 | status_bubble->SetStatus( |
[email protected] | ece4aca | 2012-09-19 22:22:58 | [diff] [blame] | 1125 | CoreTabHelper::FromWebContents(chrome::GetActiveWebContents(this))-> |
| 1126 | GetStatusText()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1127 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1128 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 1129 | if (HasFindBarController()) { |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 1130 | find_bar_controller_->ChangeTabContents(new_contents); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 1131 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1132 | } |
| 1133 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1134 | // Update sessions. Don't force creation of sessions. If sessions doesn't |
| 1135 | // exist, the change will be picked up by sessions when created. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1136 | SessionService* session_service = |
| 1137 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1138 | if (session_service && !tab_strip_model_->closing_all()) { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1139 | session_service->SetSelectedTabInWindow(session_id(), active_index()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1140 | } |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1141 | |
| 1142 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1143 | } |
| 1144 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1145 | void Browser::TabMoved(TabContents* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1146 | int from_index, |
[email protected] | 1a242c3 | 2010-02-02 21:20:54 | [diff] [blame] | 1147 | int to_index) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1148 | DCHECK(from_index >= 0 && to_index >= 0); |
| 1149 | // Notify the history service. |
| 1150 | SyncHistoryWithTabs(std::min(from_index, to_index)); |
| 1151 | } |
| 1152 | |
[email protected] | da25dd5 | 2011-01-11 19:06:30 | [diff] [blame] | 1153 | void Browser::TabReplacedAt(TabStripModel* tab_strip_model, |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1154 | TabContents* old_contents, |
| 1155 | TabContents* new_contents, |
[email protected] | 8a34e660 | 2010-10-02 17:29:43 | [diff] [blame] | 1156 | int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1157 | TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); |
[email protected] | 4060015 | 2012-09-26 10:04:31 | [diff] [blame] | 1158 | SessionService* session_service = |
| 1159 | SessionServiceFactory::GetForProfile(profile_); |
| 1160 | if (session_service) |
| 1161 | session_service->TabClosing(old_contents->web_contents()); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1162 | TabInsertedAt(new_contents, index, (index == active_index())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1163 | |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 1164 | int entry_count = |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1165 | new_contents->web_contents()->GetController().GetEntryCount(); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1166 | if (entry_count > 0) { |
| 1167 | // Send out notification so that observers are updated appropriately. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1168 | new_contents->web_contents()->GetController().NotifyEntryChanged( |
| 1169 | new_contents->web_contents()->GetController().GetEntryAtIndex( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 1170 | entry_count - 1), |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1171 | entry_count - 1); |
| 1172 | } |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1173 | |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1174 | if (session_service) { |
| 1175 | // The new_contents may end up with a different navigation stack. Force |
| 1176 | // the session service to update itself. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1177 | session_service->TabRestored(new_contents, |
| 1178 | tab_strip_model_->IsTabPinned(index)); |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1179 | } |
[email protected] | 2914600d | 2011-01-31 23:25:14 | [diff] [blame] | 1180 | |
[email protected] | a026243 | 2012-04-13 15:48:09 | [diff] [blame] | 1181 | content::DevToolsManager::GetInstance()->ContentsReplaced( |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1182 | old_contents->web_contents(), new_contents->web_contents()); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1183 | } |
| 1184 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1185 | void Browser::TabPinnedStateChanged(TabContents* contents, int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1186 | SessionService* session_service = |
| 1187 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1188 | if (session_service) { |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 1189 | SessionTabHelper* session_tab_helper = |
| 1190 | SessionTabHelper::FromWebContents(contents->web_contents()); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1191 | session_service->SetPinnedState( |
| 1192 | session_id(), |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 1193 | session_tab_helper->session_id(), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1194 | tab_strip_model_->IsTabPinned(index)); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1198 | void Browser::TabStripEmpty() { |
| 1199 | // Close the frame after we return to the message loop (not immediately, |
| 1200 | // otherwise it will destroy this object before the stack has a chance to |
| 1201 | // cleanly unwind.) |
| 1202 | // Note: This will be called several times if TabStripEmpty is called several |
| 1203 | // times. This is because it does not close the window if tabs are |
| 1204 | // still present. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 1205 | MessageLoop::current()->PostTask( |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1206 | FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1207 | } |
| 1208 | |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1209 | bool Browser::PreHandleKeyboardEvent(content::WebContents* source, |
| 1210 | const NativeWebKeyboardEvent& event, |
[email protected] | fc76114 | 2012-06-08 04:49:20 | [diff] [blame] | 1211 | bool* is_keyboard_shortcut) { |
| 1212 | // Escape exits tabbed fullscreen mode. |
| 1213 | // TODO(koz): Write a test for this http://crbug.com/100441. |
| 1214 | if (event.windowsKeyCode == 27 && |
| 1215 | fullscreen_controller_->HandleUserPressedEscape()) { |
| 1216 | return true; |
| 1217 | } |
| 1218 | return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 1219 | } |
| 1220 | |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1221 | void Browser::HandleKeyboardEvent(content::WebContents* source, |
| 1222 | const NativeWebKeyboardEvent& event) { |
[email protected] | fc76114 | 2012-06-08 04:49:20 | [diff] [blame] | 1223 | window()->HandleKeyboardEvent(event); |
| 1224 | } |
| 1225 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1226 | bool Browser::TabsNeedBeforeUnloadFired() { |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 1227 | return unload_controller_->TabsNeedBeforeUnloadFired(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1228 | } |
| 1229 | |
[email protected] | d013f14 | 2012-04-27 17:31:14 | [diff] [blame] | 1230 | bool Browser::IsMouseLocked() const { |
| 1231 | return fullscreen_controller_->IsMouseLocked(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | void Browser::OnWindowDidShow() { |
| 1235 | if (window_has_shown_) |
| 1236 | return; |
| 1237 | window_has_shown_ = true; |
| 1238 | |
[email protected] | b5febf7 | 2012-07-29 18:10:09 | [diff] [blame] | 1239 | // CurrentProcessInfo::CreationTime() is currently only implemented on Mac and |
| 1240 | // Windows. |
| 1241 | #if defined(OS_MACOSX) || defined(OS_WIN) |
| 1242 | // Measure the latency from startup till the first browser window becomes |
| 1243 | // visible. |
| 1244 | static bool is_first_browser_window = true; |
| 1245 | if (is_first_browser_window && |
| 1246 | !startup_metric_utils::WasNonBrowserUIDisplayed()) { |
| 1247 | is_first_browser_window = false; |
| 1248 | const base::Time* process_creation_time = |
| 1249 | base::CurrentProcessInfo::CreationTime(); |
| 1250 | |
| 1251 | if (process_creation_time) { |
| 1252 | UMA_HISTOGRAM_LONG_TIMES( |
| 1253 | "Startup.BrowserWindowDisplay", |
| 1254 | base::Time::Now() - *process_creation_time); |
| 1255 | } |
| 1256 | } |
| 1257 | #endif // OS_MACOSX || OS_WIN |
| 1258 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1259 | // Nothing to do for non-tabbed windows. |
| 1260 | if (!is_type_tabbed()) |
| 1261 | return; |
| 1262 | |
| 1263 | // Show any pending global error bubble. |
| 1264 | GlobalErrorService* service = |
| 1265 | GlobalErrorServiceFactory::GetForProfile(profile()); |
| 1266 | GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
| 1267 | if (error) |
| 1268 | error->ShowBubbleView(this); |
| 1269 | } |
| 1270 | |
| 1271 | void Browser::ShowFirstRunBubble() { |
| 1272 | window()->GetLocationBar()->ShowFirstRunBubble(); |
| 1273 | } |
| 1274 | |
| 1275 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 1276 | // Browser, content::WebContentsDelegate implementation: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1277 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1278 | WebContents* Browser::OpenURLFromTab(WebContents* source, |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1279 | const OpenURLParams& params) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 1280 | chrome::NavigateParams nav_params(this, params.url, params.transition); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1281 | nav_params.source_contents = chrome::GetTabContentsAt(this, |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 1282 | tab_strip_model_->GetIndexOfWebContents(source)); |
[email protected] | cb8fb01a | 2011-12-05 21:01:14 | [diff] [blame] | 1283 | nav_params.referrer = params.referrer; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1284 | nav_params.disposition = params.disposition; |
| 1285 | nav_params.tabstrip_add_types = TabStripModel::ADD_NONE; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 1286 | nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1287 | nav_params.user_gesture = true; |
| 1288 | nav_params.override_encoding = params.override_encoding; |
[email protected] | e47ae947 | 2011-10-13 19:48:34 | [diff] [blame] | 1289 | nav_params.is_renderer_initiated = params.is_renderer_initiated; |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 1290 | nav_params.transferred_global_request_id = |
| 1291 | params.transferred_global_request_id; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 1292 | chrome::Navigate(&nav_params); |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1293 | |
| 1294 | return nav_params.target_contents ? |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1295 | nav_params.target_contents->web_contents() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1296 | } |
| 1297 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1298 | void Browser::NavigationStateChanged(const WebContents* source, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1299 | unsigned changed_flags) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1300 | // Only update the UI when something visible has changed. |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 1301 | if (changed_flags) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1302 | ScheduleUIUpdate(source, changed_flags); |
| 1303 | |
[email protected] | 83c2e23 | 2011-10-07 21:36:46 | [diff] [blame] | 1304 | // We can synchronously update commands since they will only change once per |
| 1305 | // navigation, so we don't have to worry about flickering. We do, however, |
| 1306 | // need to update the command state early on load to always present usable |
| 1307 | // actions in the face of slow-to-commit pages. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1308 | if (changed_flags & (content::INVALIDATE_TYPE_URL | |
| 1309 | content::INVALIDATE_TYPE_LOAD)) |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1310 | command_controller_->TabStateChanged(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1311 | } |
| 1312 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1313 | void Browser::AddNewContents(WebContents* source, |
| 1314 | WebContents* new_contents, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1315 | WindowOpenDisposition disposition, |
| 1316 | const gfx::Rect& initial_pos, |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 1317 | bool user_gesture, |
| 1318 | bool* was_blocked) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1319 | chrome::AddWebContents(this, source, new_contents, disposition, initial_pos, |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 1320 | user_gesture, was_blocked); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1321 | } |
| 1322 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1323 | void Browser::ActivateContents(WebContents* contents) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1324 | chrome::ActivateTabAt(this, tab_strip_model_->GetIndexOfWebContents(contents), |
| 1325 | false); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 1326 | window_->Activate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1327 | } |
| 1328 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1329 | void Browser::DeactivateContents(WebContents* contents) { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1330 | window_->Deactivate(); |
| 1331 | } |
| 1332 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1333 | void Browser::LoadingStateChanged(WebContents* source) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1334 | window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading()); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 1335 | window_->UpdateTitleBar(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1336 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1337 | WebContents* selected_contents = chrome::GetActiveWebContents(this); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1338 | if (source == selected_contents) { |
[email protected] | f5d978c | 2011-07-21 14:43:51 | [diff] [blame] | 1339 | bool is_loading = source->IsLoading(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1340 | command_controller_->LoadingStateChanged(is_loading, false); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 1341 | if (GetStatusBubble()) { |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1342 | GetStatusBubble()->SetStatus( |
[email protected] | ece4aca | 2012-09-19 22:22:58 | [diff] [blame] | 1343 | CoreTabHelper::FromWebContents(chrome::GetActiveWebContents(this))-> |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1344 | GetStatusText()); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 1345 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1346 | } |
| 1347 | } |
| 1348 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 1349 | void Browser::CloseContents(WebContents* source) { |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 1350 | if (unload_controller_->CanCloseContents(source)) |
| 1351 | chrome::CloseWebContents(this, source); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1352 | } |
| 1353 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1354 | void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1355 | if (!IsPopupOrPanel(source)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1356 | NOTREACHED() << "moving invalid browser type"; |
| 1357 | return; |
| 1358 | } |
[email protected] | e561e20 | 2010-03-24 17:57:12 | [diff] [blame] | 1359 | window_->SetBounds(pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1360 | } |
| 1361 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1362 | bool Browser::IsPopupOrPanel(const WebContents* source) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1363 | // A non-tabbed BROWSER is an unconstrained popup. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1364 | return is_type_popup() || is_type_panel(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1365 | } |
| 1366 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1367 | void Browser::UpdateTargetURL(WebContents* source, int32 page_id, |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 1368 | const GURL& url) { |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1369 | if (!GetStatusBubble()) |
| 1370 | return; |
| 1371 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1372 | if (source == chrome::GetActiveWebContents(this)) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1373 | PrefService* prefs = profile_->GetPrefs(); |
[email protected] | 6523305 | 2011-08-22 19:02:48 | [diff] [blame] | 1374 | GetStatusBubble()->SetURL(url, prefs->GetString(prefs::kAcceptLanguages)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1375 | } |
| 1376 | } |
| 1377 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1378 | void Browser::ContentsMouseEvent( |
| 1379 | WebContents* source, const gfx::Point& location, bool motion) { |
| 1380 | if (!GetStatusBubble()) |
| 1381 | return; |
| 1382 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1383 | if (source == chrome::GetActiveWebContents(this)) { |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1384 | GetStatusBubble()->MouseMoved(location, !motion); |
| 1385 | if (!motion) |
| 1386 | GetStatusBubble()->SetURL(GURL(), std::string()); |
| 1387 | } |
[email protected] | 3a6a3b6 | 2009-05-27 21:36:20 | [diff] [blame] | 1388 | } |
| 1389 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1390 | void Browser::ContentsZoomChange(bool zoom_in) { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1391 | chrome::ExecuteCommand(this, zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1392 | } |
| 1393 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1394 | void Browser::WebContentsFocused(WebContents* contents) { |
| 1395 | window_->WebContentsFocused(contents); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 1396 | } |
| 1397 | |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1398 | bool Browser::TakeFocus(content::WebContents* source, |
| 1399 | bool reverse) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1400 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1401 | chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1402 | content::Source<Browser>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1403 | content::NotificationService::NoDetails()); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 1404 | return false; |
| 1405 | } |
| 1406 | |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 1407 | gfx::Rect Browser::GetRootWindowResizerRect() const { |
| 1408 | return window_->GetRootWindowResizerRect(); |
| 1409 | } |
| 1410 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1411 | void Browser::BeforeUnloadFired(WebContents* web_contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1412 | bool proceed, |
| 1413 | bool* proceed_to_fire_unload) { |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 1414 | *proceed_to_fire_unload = |
| 1415 | unload_controller_->BeforeUnloadFired(web_contents, proceed); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1416 | } |
| 1417 | |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 1418 | void Browser::SetFocusToLocationBar(bool select_all) { |
[email protected] | 1a38062 | 2009-02-17 17:33:13 | [diff] [blame] | 1419 | // Two differences between this and FocusLocationBar(): |
| 1420 | // (1) This doesn't get recorded in user metrics, since it's called |
| 1421 | // internally. |
| 1422 | // (2) This checks whether the location bar can be focused, and if not, clears |
| 1423 | // the focus. FocusLocationBar() is only reached when the location bar is |
| 1424 | // focusable, but this may be reached at other times, e.g. while in |
| 1425 | // fullscreen mode, where we need to leave focus in a consistent state. |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 1426 | window_->SetFocusToLocationBar(select_all); |
[email protected] | 4bcefee | 2009-01-29 15:57:57 | [diff] [blame] | 1427 | } |
| 1428 | |
[email protected] | 7d5925a | 2009-03-03 02:59:12 | [diff] [blame] | 1429 | void Browser::RenderWidgetShowing() { |
| 1430 | window_->DisableInactiveFrame(); |
| 1431 | } |
[email protected] | a239c3f | 2009-02-17 22:13:19 | [diff] [blame] | 1432 | |
[email protected] | 0a2aeb8 | 2009-05-15 21:52:48 | [diff] [blame] | 1433 | int Browser::GetExtraRenderViewHeight() const { |
| 1434 | return window_->GetExtraRenderViewHeight(); |
| 1435 | } |
| 1436 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1437 | void Browser::OnStartDownload(WebContents* source, |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 1438 | content::DownloadItem* download) { |
[email protected] | 6790f95f | 2012-09-21 19:49:45 | [diff] [blame] | 1439 | WebContents* constrained = GetConstrainingWebContents(source); |
| 1440 | if (constrained != source) { |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1441 | // Download in a constrained popup is shown in the tab that opened it. |
[email protected] | 6790f95f | 2012-09-21 19:49:45 | [diff] [blame] | 1442 | constrained->GetDelegate()->OnStartDownload(constrained, download); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1443 | return; |
| 1444 | } |
| 1445 | |
| 1446 | if (!window()) |
| 1447 | return; |
| 1448 | |
[email protected] | 27c14f0 | 2012-06-22 17:29:58 | [diff] [blame] | 1449 | // GetDownloadShelf creates the download shelf if it was not yet created. |
| 1450 | DownloadShelf* shelf = window()->GetDownloadShelf(); |
| 1451 | shelf->AddDownload(new DownloadItemModel(download)); |
| 1452 | // Don't show the animation for "Save file" downloads. |
| 1453 | // For non-theme extensions, we don't show the download animation. |
| 1454 | // Show animation in same window as the download shelf. Download shelf |
[email protected] | 1f1cb85 | 2012-09-11 02:58:19 | [diff] [blame] | 1455 | // may not be in the same window that initiated the download. |
[email protected] | 27c14f0 | 2012-06-22 17:29:58 | [diff] [blame] | 1456 | // Don't show the animation if the selected tab is not visible (i.e. the |
| 1457 | // window is minimized, we're in a unit test, etc.). |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1458 | WebContents* shelf_tab = chrome::GetActiveWebContents(shelf->browser()); |
[email protected] | 27c14f0 | 2012-06-22 17:29:58 | [diff] [blame] | 1459 | if ((download->GetTotalBytes() > 0) && |
| 1460 | !download_crx_util::IsExtensionDownload(*download) && |
| 1461 | platform_util::IsVisible(shelf_tab->GetNativeView()) && |
| 1462 | ui::Animation::ShouldRenderRichAnimation()) { |
| 1463 | DownloadStartedAnimation::Show(shelf_tab); |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 1464 | } |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1465 | |
| 1466 | // If the download occurs in a new tab, close it. |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1467 | if (source->GetController().IsInitialNavigation() && tab_count() > 1) |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1468 | CloseContents(source); |
| 1469 | } |
| 1470 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1471 | void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 1472 | DCHECK(source); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1473 | TabContents* tab_contents = chrome::GetTabContentsAt(this, |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 1474 | tab_strip_model_->GetIndexOfWebContents(source)); |
[email protected] | 2cd4fde | 2012-06-26 03:10:26 | [diff] [blame] | 1475 | chrome::ViewSource(this, tab_contents); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 1476 | } |
| 1477 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1478 | void Browser::ViewSourceForFrame(WebContents* source, |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1479 | const GURL& frame_url, |
| 1480 | const std::string& frame_content_state) { |
| 1481 | DCHECK(source); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1482 | TabContents* tab_contents = chrome::GetTabContentsAt(this, |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 1483 | tab_strip_model_->GetIndexOfWebContents(source)); |
[email protected] | 2cd4fde | 2012-06-26 03:10:26 | [diff] [blame] | 1484 | chrome::ViewSource(this, tab_contents, frame_url, frame_content_state); |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1485 | } |
| 1486 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1487 | void Browser::ShowRepostFormWarningDialog(WebContents* source) { |
[email protected] | 51296c6 | 2012-09-26 13:02:44 | [diff] [blame^] | 1488 | TabModalConfirmDialog::Create(new RepostFormWarningController(source), |
| 1489 | TabContents::FromWebContents(source)); |
[email protected] | 14f3408a | 2009-08-31 20:53:53 | [diff] [blame] | 1490 | } |
| 1491 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1492 | bool Browser::ShouldCreateWebContents( |
| 1493 | WebContents* web_contents, |
| 1494 | int route_id, |
| 1495 | WindowContainerType window_container_type, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 1496 | const string16& frame_name, |
| 1497 | const GURL& target_url) { |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1498 | if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
| 1499 | // If a BackgroundContents is created, suppress the normal WebContents. |
| 1500 | return !MaybeCreateBackgroundContents( |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 1501 | route_id, web_contents, frame_name, target_url); |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | return true; |
| 1505 | } |
| 1506 | |
| 1507 | void Browser::WebContentsCreated(WebContents* source_contents, |
| 1508 | int64 source_frame_id, |
| 1509 | const GURL& target_url, |
| 1510 | WebContents* new_contents) { |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 1511 | // Adopt the WebContents now, so all observers are in place, as the network |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1512 | // requests for its initial navigation will start immediately. The WebContents |
| 1513 | // will later be inserted into this browser using Browser::Navigate via |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 1514 | // AddNewContents. |
| 1515 | AdoptAsTabContents(new_contents); |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1516 | |
| 1517 | // Notify. |
| 1518 | RetargetingDetails details; |
| 1519 | details.source_web_contents = source_contents; |
| 1520 | details.source_frame_id = source_frame_id; |
| 1521 | details.target_url = target_url; |
| 1522 | details.target_web_contents = new_contents; |
| 1523 | details.not_yet_in_tabstrip = true; |
| 1524 | content::NotificationService::current()->Notify( |
| 1525 | chrome::NOTIFICATION_RETARGETING, |
| 1526 | content::Source<Profile>(profile_), |
| 1527 | content::Details<RetargetingDetails>(&details)); |
[email protected] | 80c7b80 | 2011-10-28 19:59:08 | [diff] [blame] | 1528 | } |
| 1529 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1530 | void Browser::ContentRestrictionsChanged(WebContents* source) { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1531 | command_controller_->ContentRestrictionsChanged(); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 1532 | } |
| 1533 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1534 | void Browser::RendererUnresponsive(WebContents* source) { |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 1535 | // Ignore hangs if print preview is open. |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1536 | TabContents* tab_contents = TabContents::FromWebContents(source); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1537 | if (tab_contents) { |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 1538 | printing::PrintPreviewTabController* controller = |
| 1539 | printing::PrintPreviewTabController::GetInstance(); |
| 1540 | if (controller) { |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1541 | TabContents* preview_tab = |
| 1542 | controller->GetPrintPreviewForTab(tab_contents); |
| 1543 | if (preview_tab && preview_tab != tab_contents) { |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 1544 | return; |
| 1545 | } |
| 1546 | } |
| 1547 | } |
| 1548 | |
[email protected] | 87586fb7 | 2012-07-02 13:15:02 | [diff] [blame] | 1549 | chrome::ShowHungRendererDialog(source); |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 1550 | } |
| 1551 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1552 | void Browser::RendererResponsive(WebContents* source) { |
[email protected] | 87586fb7 | 2012-07-02 13:15:02 | [diff] [blame] | 1553 | chrome::HideHungRendererDialog(source); |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 1554 | } |
| 1555 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1556 | void Browser::WorkerCrashed(WebContents* source) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1557 | TabContents* tab_contents = TabContents::FromWebContents(source); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1558 | InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 1559 | infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 1560 | infobar_helper, |
| 1561 | NULL, |
| 1562 | l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 1563 | true)); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1564 | } |
| 1565 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1566 | void Browser::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1567 | if (web_contents == chrome::GetActiveWebContents(this)) |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1568 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1569 | } |
| 1570 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1571 | void Browser::DidNavigateToPendingEntry(WebContents* web_contents) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1572 | if (web_contents == chrome::GetActiveWebContents(this)) |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1573 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1574 | } |
| 1575 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 1576 | content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { |
| 1577 | return GetJavaScriptDialogCreatorInstance(); |
| 1578 | } |
| 1579 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1580 | content::ColorChooser* Browser::OpenColorChooser(WebContents* web_contents, |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1581 | int color_chooser_id, |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 1582 | SkColor color) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1583 | #if defined(OS_WIN) |
| 1584 | // On Windows, only create a color chooser if one doesn't exist, because we |
| 1585 | // can't close the old color chooser dialog. |
| 1586 | if (!color_chooser_.get()) |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1587 | color_chooser_.reset(content::ColorChooser::Create(color_chooser_id, |
| 1588 | web_contents, |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1589 | color)); |
| 1590 | #else |
| 1591 | if (color_chooser_.get()) |
| 1592 | color_chooser_->End(); |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1593 | color_chooser_.reset(content::ColorChooser::Create(color_chooser_id, |
| 1594 | web_contents, |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1595 | color)); |
| 1596 | #endif |
| 1597 | return color_chooser_.get(); |
| 1598 | } |
| 1599 | |
| 1600 | void Browser::DidEndColorChooser() { |
| 1601 | color_chooser_.reset(); |
| 1602 | } |
| 1603 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1604 | void Browser::RunFileChooser(WebContents* web_contents, |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 1605 | const content::FileChooserParams& params) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1606 | FileSelectHelper::RunFileChooser(web_contents, params); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1607 | } |
| 1608 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1609 | void Browser::EnumerateDirectory(WebContents* web_contents, |
[email protected] | 33f8ad5 | 2012-05-22 18:10:13 | [diff] [blame] | 1610 | int request_id, |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1611 | const FilePath& path) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1612 | FileSelectHelper::EnumerateDirectory(web_contents, request_id, path); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1613 | } |
| 1614 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1615 | void Browser::ToggleFullscreenModeForTab(WebContents* web_contents, |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1616 | bool enter_fullscreen) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1617 | fullscreen_controller_->ToggleFullscreenModeForTab(web_contents, |
| 1618 | enter_fullscreen); |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1619 | } |
| 1620 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1621 | bool Browser::IsFullscreenForTabOrPending( |
| 1622 | const WebContents* web_contents) const { |
| 1623 | return fullscreen_controller_->IsFullscreenForTabOrPending(web_contents); |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 1624 | } |
| 1625 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1626 | void Browser::JSOutOfMemory(WebContents* web_contents) { |
| 1627 | JSOutOfMemoryHelper(web_contents); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1628 | } |
| 1629 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1630 | void Browser::RegisterProtocolHandler(WebContents* web_contents, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1631 | const std::string& protocol, |
| 1632 | const GURL& url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 1633 | const string16& title, |
| 1634 | bool user_gesture) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1635 | RegisterProtocolHandlerHelper( |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 1636 | web_contents, protocol, url, title, user_gesture, window()); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1637 | } |
| 1638 | |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 1639 | void Browser::RegisterIntentHandler( |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1640 | WebContents* web_contents, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 1641 | const webkit_glue::WebIntentServiceData& data, |
| 1642 | bool user_gesture) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1643 | RegisterIntentHandlerHelper(web_contents, data, user_gesture); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1644 | } |
| 1645 | |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 1646 | void Browser::WebIntentDispatch( |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1647 | WebContents* web_contents, |
| 1648 | content::WebIntentsDispatcher* intents_dispatcher) { |
[email protected] | 59d73ec | 2012-09-01 02:24:27 | [diff] [blame] | 1649 | if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) { |
| 1650 | web_intents::RecordIntentsDispatchDisabled(); |
[email protected] | 828e61af | 2011-09-14 19:45:06 | [diff] [blame] | 1651 | return; |
[email protected] | 59d73ec | 2012-09-01 02:24:27 | [diff] [blame] | 1652 | } |
[email protected] | 828e61af | 2011-09-14 19:45:06 | [diff] [blame] | 1653 | |
[email protected] | 59d73ec | 2012-09-01 02:24:27 | [diff] [blame] | 1654 | web_intents::RecordIntentDispatchRequested(); |
[email protected] | 86238d2 | 2012-05-22 20:00:11 | [diff] [blame] | 1655 | |
[email protected] | bd52a98 | 2012-06-26 23:34:29 | [diff] [blame] | 1656 | if (!web_contents) { |
| 1657 | // Intent is system-caused and the picker will show over the currently |
| 1658 | // active web contents. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1659 | web_contents = chrome::GetActiveWebContents(this); |
[email protected] | bd52a98 | 2012-06-26 23:34:29 | [diff] [blame] | 1660 | } |
[email protected] | 231cf3e | 2012-09-25 20:54:47 | [diff] [blame] | 1661 | WebIntentPickerController* web_intent_picker_controller = |
| 1662 | WebIntentPickerController::FromWebContents(web_contents); |
| 1663 | web_intent_picker_controller->SetIntentsDispatcher(intents_dispatcher); |
| 1664 | web_intent_picker_controller->ShowDialog( |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 1665 | intents_dispatcher->GetIntent().action, |
| 1666 | intents_dispatcher->GetIntent().type); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 1667 | } |
| 1668 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1669 | void Browser::UpdatePreferredSize(WebContents* source, |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 1670 | const gfx::Size& pref_size) { |
| 1671 | window_->UpdatePreferredSize(source, pref_size); |
| 1672 | } |
| 1673 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1674 | void Browser::ResizeDueToAutoResize(WebContents* source, |
| 1675 | const gfx::Size& new_size) { |
| 1676 | window_->ResizeDueToAutoResize(source, new_size); |
| 1677 | } |
| 1678 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1679 | void Browser::FindReply(WebContents* web_contents, |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1680 | int request_id, |
| 1681 | int number_of_matches, |
| 1682 | const gfx::Rect& selection_rect, |
| 1683 | int active_match_ordinal, |
| 1684 | bool final_update) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1685 | FindReplyHelper(web_contents, request_id, number_of_matches, selection_rect, |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1686 | active_match_ordinal, final_update); |
| 1687 | } |
| 1688 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1689 | void Browser::RequestToLockMouse(WebContents* web_contents, |
[email protected] | a9c81f0 | 2012-06-01 00:15:44 | [diff] [blame] | 1690 | bool user_gesture, |
| 1691 | bool last_unlocked_by_target) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1692 | fullscreen_controller_->RequestToLockMouse(web_contents, |
[email protected] | a9c81f0 | 2012-06-01 00:15:44 | [diff] [blame] | 1693 | user_gesture, |
| 1694 | last_unlocked_by_target); |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 1695 | } |
| 1696 | |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 1697 | void Browser::LostMouseLock() { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1698 | fullscreen_controller_->LostMouseLock(); |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 1699 | } |
| 1700 | |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 1701 | void Browser::RequestMediaAccessPermission( |
| 1702 | content::WebContents* web_contents, |
| 1703 | const content::MediaStreamRequest* request, |
| 1704 | const content::MediaResponseCallback& callback) { |
[email protected] | c55d3d12 | 2012-07-10 16:53:41 | [diff] [blame] | 1705 | RequestMediaAccessPermissionHelper(web_contents, request, callback); |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 1706 | } |
| 1707 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1708 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 1709 | // Browser, CoreTabHelperDelegate implementation: |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 1710 | |
[email protected] | ece4aca | 2012-09-19 22:22:58 | [diff] [blame] | 1711 | void Browser::SwapTabContents(content::WebContents* old_contents, |
| 1712 | content::WebContents* new_contents) { |
| 1713 | int index = tab_strip_model_->GetIndexOfWebContents(old_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1714 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | ece4aca | 2012-09-19 22:22:58 | [diff] [blame] | 1715 | TabContents* new_tab_contents = TabContents::FromWebContents(new_contents); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1716 | tab_strip_model_->ReplaceTabContentsAt(index, new_tab_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1717 | } |
| 1718 | |
[email protected] | ece4aca | 2012-09-19 22:22:58 | [diff] [blame] | 1719 | bool Browser::CanReloadContents(content::WebContents* web_contents) const { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1720 | return chrome::CanReload(this); |
[email protected] | e146195 | 2012-06-14 21:05:35 | [diff] [blame] | 1721 | } |
| 1722 | |
[email protected] | ece4aca | 2012-09-19 22:22:58 | [diff] [blame] | 1723 | bool Browser::CanSaveContents(content::WebContents* web_contents) const { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1724 | return chrome::CanSavePage(this); |
[email protected] | e146195 | 2012-06-14 21:05:35 | [diff] [blame] | 1725 | } |
| 1726 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1727 | /////////////////////////////////////////////////////////////////////////////// |
| 1728 | // Browser, SearchEngineTabHelperDelegate implementation: |
| 1729 | |
[email protected] | 3613347d | 2012-04-27 20:27:37 | [diff] [blame] | 1730 | void Browser::ConfirmAddSearchProvider(TemplateURL* template_url, |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1731 | Profile* profile) { |
| 1732 | window()->ConfirmAddSearchProvider(template_url, profile); |
| 1733 | } |
| 1734 | |
| 1735 | /////////////////////////////////////////////////////////////////////////////// |
| 1736 | // Browser, ConstrainedWindowTabHelperDelegate implementation: |
| 1737 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1738 | void Browser::SetTabContentBlocked(TabContents* tab_contents, bool blocked) { |
| 1739 | int index = tab_strip_model_->GetIndexOfTabContents(tab_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1740 | if (index == TabStripModel::kNoTab) { |
| 1741 | NOTREACHED(); |
| 1742 | return; |
| 1743 | } |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1744 | tab_strip_model_->SetTabBlocked(index, blocked); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1745 | command_controller_->PrintingStateChanged(); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1746 | if (!blocked && chrome::GetActiveTabContents(this) == tab_contents) |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1747 | tab_contents->web_contents()->Focus(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | /////////////////////////////////////////////////////////////////////////////// |
| 1751 | // Browser, BlockedContentTabHelperDelegate implementation: |
| 1752 | |
[email protected] | 6790f95f | 2012-09-21 19:49:45 | [diff] [blame] | 1753 | content::WebContents* Browser::GetConstrainingWebContents( |
| 1754 | content::WebContents* source) { |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1755 | return source; |
| 1756 | } |
| 1757 | |
| 1758 | /////////////////////////////////////////////////////////////////////////////// |
| 1759 | // Browser, BookmarkTabHelperDelegate implementation: |
| 1760 | |
[email protected] | 1c5119c | 2012-09-19 00:08:57 | [diff] [blame] | 1761 | void Browser::URLStarredChanged(content::WebContents* web_contents, |
| 1762 | bool starred) { |
| 1763 | if (web_contents == chrome::GetActiveWebContents(this)) |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1764 | window_->SetStarredState(starred); |
| 1765 | } |
| 1766 | |
| 1767 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 1768 | // Browser, ZoomObserver implementation: |
| 1769 | |
[email protected] | dea9cee8 | 2012-09-25 03:10:52 | [diff] [blame] | 1770 | void Browser::OnZoomChanged(content::WebContents* source, |
| 1771 | bool can_show_bubble) { |
| 1772 | if (source == chrome::GetActiveWebContents(this)) { |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 1773 | // Only show the zoom bubble for zoom changes in the active window. |
[email protected] | 5423c37 | 2012-08-22 05:50:16 | [diff] [blame] | 1774 | window_->ZoomChangedForActiveTab(can_show_bubble && window_->IsActive()); |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 92f5408 | 2012-07-31 01:43:14 | [diff] [blame] | 1779 | // Browser, ui::SelectFileDialog::Listener implementation: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1780 | |
[email protected] | 561abe6 | 2009-04-06 18:08:34 | [diff] [blame] | 1781 | void Browser::FileSelected(const FilePath& path, int index, void* params) { |
[email protected] | 53f04c8 | 2012-07-26 02:31:09 | [diff] [blame] | 1782 | FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params); |
| 1783 | } |
| 1784 | |
| 1785 | void Browser::FileSelectedWithExtraInfo( |
| 1786 | const ui::SelectedFileInfo& file_info, |
| 1787 | int index, |
| 1788 | void* params) { |
| 1789 | profile_->set_last_selected_directory(file_info.file_path.DirName()); |
| 1790 | |
| 1791 | const FilePath& path = file_info.local_path; |
[email protected] | 72cbd32 | 2009-04-07 10:17:12 | [diff] [blame] | 1792 | GURL file_url = net::FilePathToFileURL(path); |
[email protected] | b7813a2 | 2012-04-04 18:41:02 | [diff] [blame] | 1793 | |
| 1794 | #if defined(OS_CHROMEOS) |
[email protected] | 06809de | 2012-09-07 05:51:05 | [diff] [blame] | 1795 | gdata::util::ModifyDriveFileResourceUrl(profile_, path, &file_url); |
[email protected] | b7813a2 | 2012-04-04 18:41:02 | [diff] [blame] | 1796 | #endif |
| 1797 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1798 | if (file_url.is_empty()) |
| 1799 | return; |
| 1800 | |
| 1801 | OpenURL(OpenURLParams( |
| 1802 | file_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, |
| 1803 | false)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1807 | // Browser, content::NotificationObserver implementation: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1808 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1809 | void Browser::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1810 | const content::NotificationSource& source, |
| 1811 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1812 | switch (type) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1813 | case content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED: |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 1814 | // When the current tab's SSL state changes, we need to update the URL |
[email protected] | 90e8d06 | 2008-09-08 02:26:32 | [diff] [blame] | 1815 | // bar to reflect the new state. Note that it's possible for the selected |
| 1816 | // tab contents to be NULL. This is because we listen for all sources |
| 1817 | // (NavigationControllers) for convenience, so the notification could |
| 1818 | // actually be for a different window while we're doing asynchronous |
| 1819 | // closing of this one. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1820 | if (chrome::GetActiveWebContents(this) && |
| 1821 | &chrome::GetActiveWebContents(this)->GetController() == |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1822 | content::Source<NavigationController>(source).ptr()) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1823 | UpdateToolbar(false); |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 1824 | break; |
| 1825 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1826 | case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 1827 | if (window()->GetLocationBar()) |
| 1828 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 57f71b9 | 2009-09-11 19:31:38 | [diff] [blame] | 1829 | |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 1830 | // Close any tabs from the unloaded extension, unless it's terminated, |
| 1831 | // in which case let the sad tabs remain. |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 1832 | if (content::Details<extensions::UnloadedExtensionInfo>( |
| 1833 | details)->reason != extension_misc::UNLOAD_REASON_TERMINATE) { |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 1834 | const Extension* extension = |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 1835 | content::Details<extensions::UnloadedExtensionInfo>( |
| 1836 | details)->extension; |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1837 | for (int i = tab_strip_model_->count() - 1; i >= 0; --i) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1838 | WebContents* tc = chrome::GetTabContentsAt(this, i)->web_contents(); |
[email protected] | 1f1cb85 | 2012-09-11 02:58:19 | [diff] [blame] | 1839 | if (tc->GetURL().SchemeIs(chrome::kExtensionScheme) && |
| 1840 | tc->GetURL().host() == extension->id()) |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1841 | chrome::CloseWebContents(this, tc); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1842 | } |
| 1843 | } |
| 1844 | break; |
| 1845 | } |
| 1846 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1847 | case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1848 | Profile* profile = content::Source<Profile>(source).ptr(); |
[email protected] | fe8944f | 2011-08-30 17:47:32 | [diff] [blame] | 1849 | if (profile_->IsSameProfile(profile) && window()->GetLocationBar()) |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 1850 | window()->GetLocationBar()->InvalidatePageActions(); |
[email protected] | 371ed7a | 2009-08-25 15:22:46 | [diff] [blame] | 1851 | break; |
| 1852 | } |
| 1853 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1854 | case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: |
| 1855 | case chrome::NOTIFICATION_EXTENSION_LOADED: |
[email protected] | 1797f4a | 2011-08-30 18:00:28 | [diff] [blame] | 1856 | // During window creation on Windows we may end up calling into |
| 1857 | // SHAppBarMessage, which internally spawns a nested message loop. This |
| 1858 | // makes it possible for us to end up here before window creation has |
| 1859 | // completed,at which point window_ is NULL. See 94752 for details. |
| 1860 | if (window() && window()->GetLocationBar()) |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 1861 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 1862 | break; |
[email protected] | ad0c2e1b | 2010-01-30 00:00:10 | [diff] [blame] | 1863 | |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 1864 | #if defined(ENABLE_THEMES) |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1865 | case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 1866 | window()->UserChangedTheme(); |
| 1867 | break; |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 1868 | #endif |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 1869 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1870 | case chrome::NOTIFICATION_PREF_CHANGED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1871 | const std::string& pref_name = |
| 1872 | *content::Details<std::string>(details).ptr(); |
[email protected] | 7acfaf9 | 2012-07-11 15:51:59 | [diff] [blame] | 1873 | if (pref_name == prefs::kDevToolsDisabled) { |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 1874 | if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 1875 | content::DevToolsManager::GetInstance()->CloseAllClientHosts(); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 1876 | } else if (pref_name == prefs::kShowBookmarkBar) { |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 1877 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 1878 | } else if (pref_name == prefs::kHomePage) { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1879 | PrefService* pref_service = content::Source<PrefService>(source).ptr(); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 1880 | MarkHomePageAsChanged(pref_service); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 1881 | } else { |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 1882 | NOTREACHED(); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 1883 | } |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 1884 | break; |
| 1885 | } |
| 1886 | |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 1887 | case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { |
| 1888 | WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1889 | if (web_contents == chrome::GetActiveWebContents(this)) { |
[email protected] | 9a9a9e2 | 2011-05-13 22:20:35 | [diff] [blame] | 1890 | LocationBar* location_bar = window()->GetLocationBar(); |
| 1891 | if (location_bar) |
| 1892 | location_bar->UpdateContentSettingsIcons(); |
| 1893 | } |
| 1894 | break; |
| 1895 | } |
| 1896 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1897 | case content::NOTIFICATION_INTERSTITIAL_ATTACHED: |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1898 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 1899 | break; |
| 1900 | |
| 1901 | case content::NOTIFICATION_INTERSTITIAL_DETACHED: |
| 1902 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1903 | break; |
| 1904 | |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 1905 | default: |
| 1906 | NOTREACHED() << "Got a notification we didn't register for."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | |
[email protected] | c316630 | 2012-09-25 21:27:08 | [diff] [blame] | 1910 | void Browser::ModeChanged(const chrome::search::Mode& old_mode, |
| 1911 | const chrome::search::Mode& new_mode) { |
| 1912 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
| 1913 | } |
| 1914 | |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 1915 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1916 | // Browser, Command and state updating (private): |
| 1917 | |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 1918 | void Browser::MarkHomePageAsChanged(PrefService* pref_service) { |
| 1919 | pref_service->SetBoolean(prefs::kHomePageChanged, true); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 1920 | } |
| 1921 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1922 | /////////////////////////////////////////////////////////////////////////////// |
| 1923 | // Browser, UI update coalescing and handling (private): |
| 1924 | |
| 1925 | void Browser::UpdateToolbar(bool should_restore_state) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1926 | window_->UpdateToolbar(chrome::GetActiveTabContents(this), |
| 1927 | should_restore_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1928 | } |
| 1929 | |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 1930 | void Browser::UpdateSearchState(TabContents* contents) { |
| 1931 | if (chrome::search::IsInstantExtendedAPIEnabled(profile_)) |
[email protected] | 0dc50db | 2012-09-19 17:57:14 | [diff] [blame] | 1932 | search_delegate_->OnTabActivated(contents->web_contents()); |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 1933 | } |
| 1934 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1935 | void Browser::ScheduleUIUpdate(const WebContents* source, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1936 | unsigned changed_flags) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 1937 | if (!source) |
| 1938 | return; |
| 1939 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 1940 | // Do some synchronous updates. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1941 | if (changed_flags & content::INVALIDATE_TYPE_URL && |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1942 | source == chrome::GetActiveWebContents(this)) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1943 | // Only update the URL for the current tab. Note that we do not update |
| 1944 | // the navigation commands since those would have already been updated |
| 1945 | // synchronously by NavigationStateChanged. |
| 1946 | UpdateToolbar(false); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1947 | changed_flags &= ~content::INVALIDATE_TYPE_URL; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1948 | } |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1949 | if (changed_flags & content::INVALIDATE_TYPE_LOAD) { |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 1950 | // Update the loading state synchronously. This is so the throbber will |
| 1951 | // immediately start/stop, which gives a more snappy feel. We want to do |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 1952 | // this for any tab so they start & stop quickly. |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1953 | tab_strip_model_->UpdateTabContentsStateAt( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1954 | chrome::GetIndexOfTab(this, source), |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 1955 | TabStripModelObserver::LOADING_ONLY); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1956 | // The status bubble needs to be updated during INVALIDATE_TYPE_LOAD too, |
| 1957 | // but we do that asynchronously by not stripping INVALIDATE_TYPE_LOAD from |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 1958 | // changed_flags. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 1959 | } |
| 1960 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1961 | if (changed_flags & content::INVALIDATE_TYPE_TITLE && !source->IsLoading()) { |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 1962 | // To correctly calculate whether the title changed while not loading |
| 1963 | // we need to process the update synchronously. This state only matters for |
| 1964 | // the TabStripModel, so we notify the TabStripModel now and notify others |
| 1965 | // asynchronously. |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1966 | tab_strip_model_->UpdateTabContentsStateAt( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1967 | chrome::GetIndexOfTab(this, source), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 1968 | TabStripModelObserver::TITLE_NOT_LOADING); |
| 1969 | } |
| 1970 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 1971 | // If the only updates were synchronously handled above, we're done. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 1972 | if (changed_flags == 0) |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 1973 | return; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1974 | |
| 1975 | // Save the dirty bits. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 1976 | scheduled_updates_[source] |= changed_flags; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1977 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1978 | if (!chrome_updater_factory_.HasWeakPtrs()) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1979 | // No task currently scheduled, start another. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 1980 | MessageLoop::current()->PostDelayedTask( |
| 1981 | FROM_HERE, |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1982 | base::Bind(&Browser::ProcessPendingUIUpdates, |
| 1983 | chrome_updater_factory_.GetWeakPtr()), |
[email protected] | 11d6ab1a | 2012-01-12 21:37:26 | [diff] [blame] | 1984 | base::TimeDelta::FromMilliseconds(kUIUpdateCoalescingTimeMS)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1985 | } |
| 1986 | } |
| 1987 | |
| 1988 | void Browser::ProcessPendingUIUpdates() { |
| 1989 | #ifndef NDEBUG |
| 1990 | // Validate that all tabs we have pending updates for exist. This is scary |
| 1991 | // because the pending list must be kept in sync with any detached or |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 1992 | // deleted tabs. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 1993 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 1994 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1995 | bool found = false; |
| 1996 | for (int tab = 0; tab < tab_count(); tab++) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1997 | if (chrome::GetWebContentsAt(this, tab) == i->first) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1998 | found = true; |
| 1999 | break; |
| 2000 | } |
| 2001 | } |
| 2002 | DCHECK(found); |
| 2003 | } |
| 2004 | #endif |
| 2005 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 2006 | chrome_updater_factory_.InvalidateWeakPtrs(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2007 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2008 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 2009 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2010 | // Do not dereference |contents|, it may be out-of-date! |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2011 | const WebContents* contents = i->first; |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2012 | unsigned flags = i->second; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2013 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2014 | if (contents == chrome::GetActiveWebContents(this)) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2015 | // Updates that only matter when the tab is selected go here. |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 2016 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2017 | if (flags & content::INVALIDATE_TYPE_PAGE_ACTIONS) { |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2018 | LocationBar* location_bar = window()->GetLocationBar(); |
| 2019 | if (location_bar) |
| 2020 | location_bar->UpdatePageActions(); |
| 2021 | } |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 2022 | // Updating the URL happens synchronously in ScheduleUIUpdate. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2023 | if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) { |
[email protected] | ece4aca | 2012-09-19 22:22:58 | [diff] [blame] | 2024 | GetStatusBubble()->SetStatus( |
| 2025 | CoreTabHelper::FromWebContents(chrome::GetActiveWebContents(this))-> |
| 2026 | GetStatusText()); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 2027 | } |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2028 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2029 | if (flags & (content::INVALIDATE_TYPE_TAB | |
| 2030 | content::INVALIDATE_TYPE_TITLE)) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2031 | window_->UpdateTitleBar(); |
| 2032 | } |
[email protected] | 4d34e2e | 2009-05-26 22:55:28 | [diff] [blame] | 2033 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2034 | |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2035 | // Updates that don't depend upon the selected state go here. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2036 | if (flags & |
| 2037 | (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2038 | tab_strip_model_->UpdateTabContentsStateAt( |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 2039 | tab_strip_model_->GetIndexOfWebContents(contents), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 2040 | TabStripModelObserver::ALL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | // We don't need to process INVALIDATE_STATE, since that's not visible. |
| 2044 | } |
| 2045 | |
| 2046 | scheduled_updates_.clear(); |
| 2047 | } |
| 2048 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2049 | void Browser::RemoveScheduledUpdatesFor(WebContents* contents) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2050 | if (!contents) |
| 2051 | return; |
| 2052 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2053 | UpdateMap::iterator i = scheduled_updates_.find(contents); |
| 2054 | if (i != scheduled_updates_.end()) |
| 2055 | scheduled_updates_.erase(i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2056 | } |
| 2057 | |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 2058 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2059 | /////////////////////////////////////////////////////////////////////////////// |
| 2060 | // Browser, Getters for UI (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2061 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2062 | StatusBubble* Browser::GetStatusBubble() { |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 2063 | // In kiosk mode, we want to always hide the status bubble. |
| 2064 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 2065 | return NULL; |
[email protected] | 9b032bf | 2009-07-21 17:34:23 | [diff] [blame] | 2066 | return window_ ? window_->GetStatusBubble() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2067 | } |
| 2068 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2069 | /////////////////////////////////////////////////////////////////////////////// |
| 2070 | // Browser, Session restore functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2071 | |
| 2072 | void Browser::SyncHistoryWithTabs(int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2073 | SessionService* session_service = |
| 2074 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2075 | if (session_service) { |
| 2076 | for (int i = index; i < tab_count(); ++i) { |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 2077 | WebContents* web_contents = chrome::GetWebContentsAt(this, i); |
| 2078 | if (web_contents) { |
| 2079 | SessionTabHelper* session_tab_helper = |
| 2080 | SessionTabHelper::FromWebContents(web_contents); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2081 | session_service->SetTabIndexInWindow( |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 2082 | session_id(), session_tab_helper->session_id(), i); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2083 | session_service->SetPinnedState( |
| 2084 | session_id(), |
[email protected] | 50a9a76b | 2012-09-12 14:19:36 | [diff] [blame] | 2085 | session_tab_helper->session_id(), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2086 | tab_strip_model_->IsTabPinned(i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2087 | } |
| 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2092 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 2093 | // Browser, In-progress download termination handling (private): |
| 2094 | |
[email protected] | b6a4ac2b | 2011-10-17 20:05:48 | [diff] [blame] | 2095 | bool Browser::CanCloseWithInProgressDownloads() { |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 2096 | // If we've prompted, we need to hear from the user before we |
| 2097 | // can close. |
| 2098 | if (cancel_download_confirmation_state_ != NOT_PROMPTED) |
| 2099 | return cancel_download_confirmation_state_ != WAITING_FOR_RESPONSE; |
| 2100 | |
| 2101 | int num_downloads_blocking; |
| 2102 | if (DOWNLOAD_CLOSE_OK == |
| 2103 | OkToCloseWithInProgressDownloads(&num_downloads_blocking)) |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 2104 | return true; |
| 2105 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 2106 | // Closing this window will kill some downloads; prompt to make sure |
| 2107 | // that's ok. |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 2108 | cancel_download_confirmation_state_ = WAITING_FOR_RESPONSE; |
| 2109 | window_->ConfirmBrowserCloseWithPendingDownloads(); |
| 2110 | |
| 2111 | // Return false so the browser does not close. We'll close if the user |
| 2112 | // confirms in the dialog. |
| 2113 | return false; |
| 2114 | } |
| 2115 | |
| 2116 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2117 | // Browser, Assorted utility functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2118 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2119 | void Browser::CloseFrame() { |
| 2120 | window_->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2121 | } |
| 2122 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2123 | void Browser::TabDetachedAtImpl(TabContents* contents, int index, |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2124 | DetachType type) { |
| 2125 | if (type == DETACH_TYPE_DETACH) { |
[email protected] | 5658085 | 2010-11-17 16:09:15 | [diff] [blame] | 2126 | // Save the current location bar state, but only if the tab being detached |
| 2127 | // is the selected tab. Because saving state can conditionally revert the |
| 2128 | // location bar, saving the current tab's location bar state to a |
| 2129 | // non-selected tab can corrupt both tabs. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2130 | if (contents == chrome::GetActiveTabContents(this)) { |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2131 | LocationBar* location_bar = window()->GetLocationBar(); |
| 2132 | if (location_bar) |
[email protected] | 83a2610a | 2012-01-05 01:00:27 | [diff] [blame] | 2133 | location_bar->SaveStateToContents(contents->web_contents()); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2134 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2135 | |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2136 | if (!tab_strip_model_->closing_all()) |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2137 | SyncHistoryWithTabs(0); |
| 2138 | } |
| 2139 | |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 2140 | SetAsDelegate(contents->web_contents(), NULL); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2141 | RemoveScheduledUpdatesFor(contents->web_contents()); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2142 | |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 2143 | if (find_bar_controller_.get() && index == active_index()) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2144 | find_bar_controller_->ChangeTabContents(NULL); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2145 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2146 | |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 2147 | // Stop observing search model changes for this tab. |
[email protected] | 0dc50db | 2012-09-19 17:57:14 | [diff] [blame] | 2148 | search_delegate_->OnTabDetached(contents->web_contents()); |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 2149 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2150 | registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2151 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 2152 | registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
[email protected] | 4b19ea5 | 2012-01-02 20:15:25 | [diff] [blame] | 2153 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2154 | } |
| 2155 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2156 | bool Browser::SupportsWindowFeatureImpl(WindowFeature feature, |
| 2157 | bool check_fullscreen) const { |
| 2158 | // On Mac, fullscreen mode has most normal things (in a slide-down panel). On |
| 2159 | // other platforms, we hide some controls when in fullscreen mode. |
| 2160 | bool hide_ui_for_fullscreen = false; |
| 2161 | #if !defined(OS_MACOSX) |
| 2162 | hide_ui_for_fullscreen = check_fullscreen && window_ && |
| 2163 | window_->IsFullscreen(); |
| 2164 | #endif |
| 2165 | |
| 2166 | unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF; |
| 2167 | |
| 2168 | if (is_type_tabbed()) |
| 2169 | features |= FEATURE_BOOKMARKBAR; |
| 2170 | |
| 2171 | if (!hide_ui_for_fullscreen) { |
| 2172 | if (!is_type_tabbed()) |
| 2173 | features |= FEATURE_TITLEBAR; |
| 2174 | |
| 2175 | if (is_type_tabbed()) |
| 2176 | features |= FEATURE_TABSTRIP; |
| 2177 | |
| 2178 | if (is_type_tabbed()) |
| 2179 | features |= FEATURE_TOOLBAR; |
| 2180 | |
| 2181 | if (!is_app()) |
| 2182 | features |= FEATURE_LOCATIONBAR; |
| 2183 | } |
| 2184 | return !!(features & feature); |
| 2185 | } |
| 2186 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2187 | void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { |
| 2188 | BookmarkBar::State state; |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 2189 | // The bookmark bar is hidden in fullscreen mode, unless on the new tab page. |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 2190 | if (browser_defaults::bookmarks_enabled && |
| 2191 | profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) && |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 2192 | (!window_ || !window_->IsFullscreen())) { |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2193 | state = BookmarkBar::SHOW; |
| 2194 | } else { |
[email protected] | 1c5119c | 2012-09-19 00:08:57 | [diff] [blame] | 2195 | WebContents* web_contents = chrome::GetActiveWebContents(this); |
| 2196 | BookmarkTabHelper* bookmark_tab_helper = |
| 2197 | web_contents ? BookmarkTabHelper::FromWebContents(web_contents) : NULL; |
| 2198 | if (bookmark_tab_helper && bookmark_tab_helper->ShouldShowBookmarkBar()) |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2199 | state = BookmarkBar::DETACHED; |
| 2200 | else |
| 2201 | state = BookmarkBar::HIDDEN; |
| 2202 | } |
[email protected] | 2d4e43a0 | 2012-06-26 00:11:55 | [diff] [blame] | 2203 | |
| 2204 | // Only allow the bookmark bar to be shown in default mode. |
| 2205 | if (!search_model_->mode().is_default()) |
| 2206 | state = BookmarkBar::HIDDEN; |
| 2207 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2208 | if (state == bookmark_bar_state_) |
| 2209 | return; |
| 2210 | |
| 2211 | bookmark_bar_state_ = state; |
| 2212 | |
| 2213 | if (!window_) |
| 2214 | return; // This is called from the constructor when window_ is NULL. |
| 2215 | |
| 2216 | if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) { |
| 2217 | // Don't notify BrowserWindow on a tab switch as at the time this is invoked |
| 2218 | // BrowserWindow hasn't yet switched tabs. The BrowserWindow implementations |
| 2219 | // end up querying state once they process the tab switch. |
| 2220 | return; |
| 2221 | } |
| 2222 | |
| 2223 | BookmarkBar::AnimateChangeType animate_type = |
| 2224 | (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE) ? |
| 2225 | BookmarkBar::ANIMATE_STATE_CHANGE : |
| 2226 | BookmarkBar::DONT_ANIMATE_STATE_CHANGE; |
| 2227 | window_->BookmarkBarStateChanged(animate_type); |
| 2228 | } |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 2229 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2230 | bool Browser::MaybeCreateBackgroundContents(int route_id, |
| 2231 | WebContents* opener_web_contents, |
| 2232 | const string16& frame_name, |
| 2233 | const GURL& target_url) { |
| 2234 | GURL opener_url = opener_web_contents->GetURL(); |
| 2235 | ExtensionService* extensions_service = profile_->GetExtensionService(); |
| 2236 | |
| 2237 | if (!opener_url.is_valid() || |
| 2238 | frame_name.empty() || |
| 2239 | !extensions_service || |
| 2240 | !extensions_service->is_ready()) |
| 2241 | return false; |
| 2242 | |
| 2243 | // Only hosted apps have web extents, so this ensures that only hosted apps |
| 2244 | // can create BackgroundContents. We don't have to check for background |
| 2245 | // permission as that is checked in RenderMessageFilter when the CreateWindow |
| 2246 | // message is processed. |
| 2247 | const Extension* extension = |
| 2248 | extensions_service->extensions()->GetHostedAppByURL( |
| 2249 | ExtensionURLInfo(opener_url)); |
| 2250 | if (!extension) |
| 2251 | return false; |
| 2252 | |
| 2253 | // No BackgroundContents allowed if BackgroundContentsService doesn't exist. |
| 2254 | BackgroundContentsService* service = |
| 2255 | BackgroundContentsServiceFactory::GetForProfile(profile_); |
| 2256 | if (!service) |
| 2257 | return false; |
| 2258 | |
| 2259 | // Ensure that we're trying to open this from the extension's process. |
| 2260 | SiteInstance* opener_site_instance = opener_web_contents->GetSiteInstance(); |
| 2261 | extensions::ProcessMap* process_map = extensions_service->process_map(); |
| 2262 | if (!opener_site_instance->GetProcess() || |
| 2263 | !process_map->Contains( |
| 2264 | extension->id(), opener_site_instance->GetProcess()->GetID())) { |
| 2265 | return false; |
| 2266 | } |
| 2267 | |
| 2268 | // Only allow a single background contents per app. |
| 2269 | bool allow_js_access = extension->allow_background_js_access(); |
| 2270 | BackgroundContents* existing = |
| 2271 | service->GetAppBackgroundContents(ASCIIToUTF16(extension->id())); |
| 2272 | if (existing) { |
| 2273 | // For non-scriptable background contents, ignore the request altogether, |
| 2274 | // (returning true, so that a regular WebContents isn't created either). |
| 2275 | if (!allow_js_access) |
| 2276 | return true; |
| 2277 | // For scriptable background pages, if one already exists, close it (even |
| 2278 | // if it was specified in the manifest). |
| 2279 | DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url; |
| 2280 | delete existing; |
| 2281 | } |
| 2282 | |
| 2283 | // If script access is not allowed, create the the background contents in a |
| 2284 | // new SiteInstance, so that a separate process is used. |
| 2285 | scoped_refptr<content::SiteInstance> site_instance = |
| 2286 | allow_js_access ? |
| 2287 | opener_site_instance : |
| 2288 | content::SiteInstance::Create(opener_web_contents->GetBrowserContext()); |
| 2289 | |
| 2290 | // Passed all the checks, so this should be created as a BackgroundContents. |
| 2291 | BackgroundContents* contents = service->CreateBackgroundContents( |
| 2292 | site_instance, |
| 2293 | route_id, |
| 2294 | profile_, |
| 2295 | frame_name, |
| 2296 | ASCIIToUTF16(extension->id())); |
| 2297 | |
| 2298 | // When a separate process is used, the original renderer cannot access the |
| 2299 | // new window later, thus we need to navigate the window now. |
| 2300 | if (contents && !allow_js_access) { |
| 2301 | contents->web_contents()->GetController().LoadURL( |
| 2302 | target_url, |
| 2303 | content::Referrer(), |
| 2304 | content::PAGE_TRANSITION_LINK, |
| 2305 | std::string()); // No extra headers. |
| 2306 | } |
| 2307 | |
| 2308 | return contents != NULL; |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 2309 | } |