[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] | 0af8f13 | 2011-07-16 01:37:02 | [diff] [blame] | 22 | #include "base/string_number_conversions.h" |
[email protected] | b6a4ac2b | 2011-10-17 20:05:48 | [diff] [blame] | 23 | #include "base/string_util.h" |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 24 | #include "base/stringprintf.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 25 | #include "base/threading/thread.h" |
| 26 | #include "base/threading/thread_restrictions.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 27 | #include "base/time.h" |
[email protected] | 6524385ef | 2010-08-18 06:34:13 | [diff] [blame] | 28 | #include "base/utf_string_conversions.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 29 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 30 | #include "chrome/browser/autofill/personal_data_manager_factory.h" |
[email protected] | a07676b2 | 2011-06-17 16:36:53 | [diff] [blame] | 31 | #include "chrome/browser/background/background_contents_service.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 32 | #include "chrome/browser/background/background_contents_service_factory.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 33 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 34 | #include "chrome/browser/bookmarks/bookmark_utils.h" |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 35 | #include "chrome/browser/browser_process.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 36 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | 40d59ce5 | 2009-03-06 23:20:14 | [diff] [blame] | 37 | #include "chrome/browser/character_encoding.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 38 | #include "chrome/browser/chrome_page_zoom.h" |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 39 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 40 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 41 | #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h" |
[email protected] | dce50276 | 2011-07-20 08:53:49 | [diff] [blame] | 42 | #include "chrome/browser/debugger/devtools_toggle_action.h" |
| 43 | #include "chrome/browser/debugger/devtools_window.h" |
[email protected] | 8a28271 | 2011-08-23 19:28:00 | [diff] [blame] | 44 | #include "chrome/browser/download/chrome_download_manager_delegate.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 45 | #include "chrome/browser/download/download_item_model.h" |
[email protected] | 9bb54ee | 2011-10-12 17:43:35 | [diff] [blame] | 46 | #include "chrome/browser/download/download_service.h" |
| 47 | #include "chrome/browser/download/download_service_factory.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 48 | #include "chrome/browser/download/download_started_animation.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 49 | #include "chrome/browser/download/download_util.h" |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 50 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 51 | #include "chrome/browser/extensions/default_apps_trial.h" |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame^] | 52 | #include "chrome/browser/extensions/browser_extension_window_controller.h" |
[email protected] | 9fd542df | 2009-09-30 07:32:01 | [diff] [blame] | 53 | #include "chrome/browser/extensions/extension_browser_event_router.h" |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 54 | #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 55 | #include "chrome/browser/extensions/extension_prefs.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 56 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 57 | #include "chrome/browser/extensions/extension_tab_helper.h" |
[email protected] | b17d41c | 2011-02-17 22:09:59 | [diff] [blame] | 58 | #include "chrome/browser/extensions/extension_tabs_module.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] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 64 | #include "chrome/browser/instant/instant_controller.h" |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 65 | #include "chrome/browser/instant/instant_unload_handler.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 66 | #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 67 | #include "chrome/browser/intents/web_intents_registry_factory.h" |
[email protected] | 8f0bbd6 | 2012-02-22 03:37:18 | [diff] [blame] | 68 | #include "chrome/browser/intents/web_intents_util.h" |
[email protected] | 90f3990 | 2009-10-03 04:25:37 | [diff] [blame] | 69 | #include "chrome/browser/net/browser_url_util.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] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 75 | #include "chrome/browser/prerender/prerender_manager.h" |
| 76 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 77 | #include "chrome/browser/prerender/prerender_tab_helper.h" |
[email protected] | 0233759 | 2010-09-27 18:38:25 | [diff] [blame] | 78 | #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 79 | #include "chrome/browser/printing/print_preview_tab_controller.h" |
[email protected] | 6876147 | 2011-08-31 18:55:14 | [diff] [blame] | 80 | #include "chrome/browser/printing/print_view_manager.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 81 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 5e91924 | 2012-02-13 23:59:35 | [diff] [blame] | 82 | #include "chrome/browser/profiles/profile_destroyer.h" |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 83 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 84 | #include "chrome/browser/profiles/profile_metrics.h" |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 85 | #include "chrome/browser/repost_form_warning_controller.h" |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 86 | #include "chrome/browser/sessions/restore_tab_helper.h" |
[email protected] | 85e921fb8 | 2009-02-11 23:19:44 | [diff] [blame] | 87 | #include "chrome/browser/sessions/session_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 88 | #include "chrome/browser/sessions/session_service_factory.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 89 | #include "chrome/browser/sessions/session_types.h" |
[email protected] | 92926d9 | 2010-09-02 18:35:06 | [diff] [blame] | 90 | #include "chrome/browser/sessions/tab_restore_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 91 | #include "chrome/browser/sessions/tab_restore_service_factory.h" |
[email protected] | 066629f | 2009-10-17 00:28:13 | [diff] [blame] | 92 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | 5e61afb9 | 2012-01-27 20:09:13 | [diff] [blame] | 93 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
[email protected] | 40f04797 | 2009-11-25 03:54:40 | [diff] [blame] | 94 | #include "chrome/browser/sync/sync_ui_util.h" |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 95 | #include "chrome/browser/tab_closeable_state_watcher.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 96 | #include "chrome/browser/tab_contents/background_contents.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 97 | #include "chrome/browser/tab_contents/retargeting_details.h" |
[email protected] | 7cceebac | 2011-03-03 00:32:21 | [diff] [blame] | 98 | #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 99 | #include "chrome/browser/tab_contents/tab_util.h" |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 100 | #include "chrome/browser/tabs/tab_finder.h" |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 101 | #include "chrome/browser/tabs/tab_strip_model.h" |
[email protected] | ffa6f59 | 2011-06-24 22:03:57 | [diff] [blame] | 102 | #include "chrome/browser/themes/theme_service.h" |
| 103 | #include "chrome/browser/themes/theme_service_factory.h" |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 104 | #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 105 | #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 106 | #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 107 | #include "chrome/browser/ui/browser_dialogs.h" |
[email protected] | 6768ac0 | 2011-04-06 17:41:04 | [diff] [blame] | 108 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 109 | #include "chrome/browser/ui/browser_navigator.h" |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 110 | #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 111 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 112 | #include "chrome/browser/ui/constrained_window_tab_helper.h" |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 113 | #include "chrome/browser/ui/extensions/shell_window.h" |
[email protected] | 45300ad4 | 2010-12-02 15:51:14 | [diff] [blame] | 114 | #include "chrome/browser/ui/find_bar/find_bar.h" |
| 115 | #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 116 | #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
[email protected] | bf870869 | 2011-12-20 21:24:28 | [diff] [blame] | 117 | #include "chrome/browser/ui/fullscreen_controller.h" |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 118 | #include "chrome/browser/ui/global_error.h" |
| 119 | #include "chrome/browser/ui/global_error_service.h" |
| 120 | #include "chrome/browser/ui/global_error_service_factory.h" |
[email protected] | 943b861 | 2011-08-31 21:07:13 | [diff] [blame] | 121 | #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 122 | #include "chrome/browser/ui/omnibox/location_bar.h" |
[email protected] | fe90ca8e | 2011-04-08 20:40:43 | [diff] [blame] | 123 | #include "chrome/browser/ui/panels/panel.h" |
| 124 | #include "chrome/browser/ui/panels/panel_manager.h" |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 125 | #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 126 | #include "chrome/browser/ui/status_bubble.h" |
[email protected] | 3da95a10 | 2011-11-30 21:47:45 | [diff] [blame] | 127 | #include "chrome/browser/ui/sync/browser_synced_window_delegate.h" |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 128 | #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 129 | #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
[email protected] | 9a80065 | 2010-12-02 17:08:44 | [diff] [blame] | 130 | #include "chrome/browser/ui/tabs/dock_info.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 131 | #include "chrome/browser/ui/tabs/tab_menu_model.h" |
[email protected] | f847e608 | 2011-03-24 00:08:26 | [diff] [blame] | 132 | #include "chrome/browser/ui/web_applications/web_app_ui.h" |
[email protected] | daa9e38 | 2012-01-06 00:30:34 | [diff] [blame] | 133 | #include "chrome/browser/ui/webui/feedback_ui.h" |
[email protected] | 6a1622a | 2011-09-20 22:37:45 | [diff] [blame] | 134 | #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" |
[email protected] | 5c557f37 | 2011-02-26 15:09:20 | [diff] [blame] | 135 | #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
[email protected] | 6554918 | 2012-02-25 00:45:40 | [diff] [blame] | 136 | #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 137 | #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
[email protected] | aff3de2 | 2012-02-13 22:58:06 | [diff] [blame] | 138 | #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
[email protected] | 9a80065 | 2010-12-02 17:08:44 | [diff] [blame] | 139 | #include "chrome/browser/ui/window_sizer.h" |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 140 | #include "chrome/browser/upgrade_detector.h" |
[email protected] | 86b5401 | 2009-11-19 09:18:50 | [diff] [blame] | 141 | #include "chrome/browser/web_applications/web_app.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 142 | #include "chrome/common/chrome_constants.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 143 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 144 | #include "chrome/common/chrome_switches.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 145 | #include "chrome/common/custom_handlers/protocol_handler.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 146 | #include "chrome/common/extensions/extension.h" |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 147 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 148 | #include "chrome/common/pref_names.h" |
[email protected] | 7664ab3 | 2011-02-01 23:35:25 | [diff] [blame] | 149 | #include "chrome/common/profiling.h" |
[email protected] | b689fce7 | 2009-03-17 22:45:34 | [diff] [blame] | 150 | #include "chrome/common/url_constants.h" |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 151 | #include "chrome/common/web_apps.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 152 | #include "content/browser/browser_url_handler.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 153 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 154 | #include "content/public/browser/devtools_manager.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 155 | #include "content/public/browser/download_item.h" |
| 156 | #include "content/public/browser/download_manager.h" |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 157 | #include "content/public/browser/interstitial_page.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 158 | #include "content/public/browser/invalidate_type.h" |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 159 | #include "content/public/browser/navigation_controller.h" |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 160 | #include "content/public/browser/navigation_entry.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 161 | #include "content/public/browser/notification_details.h" |
| 162 | #include "content/public/browser/notification_service.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 163 | #include "content/public/browser/plugin_service.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 164 | #include "content/public/browser/site_instance.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 165 | #include "content/public/browser/user_metrics.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 166 | #include "content/public/browser/web_contents.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 167 | #include "content/public/browser/web_contents_view.h" |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 168 | #include "content/public/browser/web_intents_dispatcher.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 169 | #include "content/public/common/content_restriction.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 170 | #include "content/public/common/content_switches.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 171 | #include "content/public/common/page_zoom.h" |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 172 | #include "content/public/common/renderer_preferences.h" |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 173 | #include "grit/chromium_strings.h" |
| 174 | #include "grit/generated_resources.h" |
| 175 | #include "grit/locale_settings.h" |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 176 | #include "grit/theme_resources_standard.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 177 | #include "net/base/cookie_monster.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 178 | #include "net/base/net_util.h" |
| 179 | #include "net/base/registry_controlled_domain.h" |
| 180 | #include "net/url_request/url_request_context.h" |
[email protected] | f6767806 | 2011-01-07 17:33:39 | [diff] [blame] | 181 | #include "ui/base/animation/animation.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 182 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 183 | #include "ui/gfx/point.h" |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 184 | #include "webkit/glue/web_intent_data.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 185 | #include "webkit/glue/webkit_glue.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 186 | #include "webkit/glue/window_open_disposition.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 187 | #include "webkit/plugins/webplugininfo.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 188 | |
| 189 | #if defined(OS_WIN) |
[email protected] | 36d5e559 | 2010-11-15 20:45:59 | [diff] [blame] | 190 | #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 191 | #include "chrome/browser/shell_integration.h" |
[email protected] | b17d41c | 2011-02-17 22:09:59 | [diff] [blame] | 192 | #include "chrome/browser/ssl/ssl_error_info.h" |
[email protected] | a5d1e1e | 2010-09-23 19:34:12 | [diff] [blame] | 193 | #include "chrome/browser/task_manager/task_manager.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 194 | #include "chrome/browser/ui/view_ids.h" |
| 195 | #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
[email protected] | dcd5776 | 2011-06-25 12:18:51 | [diff] [blame] | 196 | #include "ui/base/win/shell.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 197 | #endif // OS_WIN |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 198 | |
[email protected] | 6a4f5af2 | 2009-09-23 22:43:00 | [diff] [blame] | 199 | #if defined(OS_MACOSX) |
[email protected] | 8aee8ed3 | 2011-06-14 20:16:41 | [diff] [blame] | 200 | #include "content/browser/find_pasteboard.h" |
[email protected] | 6a4f5af2 | 2009-09-23 22:43:00 | [diff] [blame] | 201 | #endif |
| 202 | |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 203 | #if defined(OS_CHROMEOS) |
[email protected] | 6a2a61d | 2010-11-22 03:25:35 | [diff] [blame] | 204 | #include "chrome/browser/chromeos/boot_times_loader.h" |
[email protected] | 2166c43 | 2011-12-07 20:18:28 | [diff] [blame] | 205 | #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 206 | #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
[email protected] | 598e6c21 | 2012-02-01 04:57:56 | [diff] [blame] | 207 | #if defined(USE_AURA) |
| 208 | #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h" |
| 209 | #endif |
[email protected] | efda32f9 | 2011-07-06 22:47:04 | [diff] [blame] | 210 | #include "chrome/browser/ui/webui/active_downloads_ui.h" |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 211 | #endif |
| 212 | |
[email protected] | c2f0a89 | 2012-01-24 22:19:21 | [diff] [blame] | 213 | #if defined(USE_AURA) |
[email protected] | bafda13 | 2012-02-16 19:32:51 | [diff] [blame] | 214 | #include "ash/ash_switches.h" |
[email protected] | c2f0a89 | 2012-01-24 22:19:21 | [diff] [blame] | 215 | #include "ash/shell.h" |
[email protected] | bafda13 | 2012-02-16 19:32:51 | [diff] [blame] | 216 | #include "chrome/browser/ui/views/aura/panel_view_aura.h" |
[email protected] | c2f0a89 | 2012-01-24 22:19:21 | [diff] [blame] | 217 | #endif |
| 218 | |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 219 | #if !defined(OS_CHROMEOS) || defined(USE_AURA) |
[email protected] | efda32f9 | 2011-07-06 22:47:04 | [diff] [blame] | 220 | #include "chrome/browser/download/download_shelf.h" |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 221 | #endif |
| 222 | |
[email protected] | cb6dbc5 | 2011-08-10 17:34:39 | [diff] [blame] | 223 | #if defined(FILE_MANAGER_EXTENSION) |
[email protected] | 7df1dad | 2012-02-27 11:19:51 | [diff] [blame] | 224 | #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
[email protected] | cb6dbc5 | 2011-08-10 17:34:39 | [diff] [blame] | 225 | #endif |
| 226 | |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 227 | using base::TimeDelta; |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 228 | using content::NavigationController; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 229 | using content::NavigationEntry; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 230 | using content::OpenURLParams; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 231 | using content::PluginService; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 232 | using content::Referrer; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 233 | using content::SiteInstance; |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 234 | using content::SSLStatus; |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 235 | using content::UserMetricsAction; |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 236 | using content::WebContents; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 237 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 238 | /////////////////////////////////////////////////////////////////////////////// |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 239 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 240 | namespace { |
| 241 | |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 242 | // The URL to be loaded to display the "Report a broken page" form. |
| 243 | const char kBrokenPageUrl[] = |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 244 | "https://www.google.com/support/chrome/bin/request.py?contact_type=" |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 245 | "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; |
| 246 | |
| 247 | // The URL for the privacy dashboard. |
| 248 | const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; |
| 249 | |
| 250 | // How long we wait before updating the browser chrome while loading a page. |
| 251 | const int kUIUpdateCoalescingTimeMS = 200; |
| 252 | |
| 253 | const char kHashMark[] = "#"; |
| 254 | |
[email protected] | 50dc3deb | 2011-07-07 01:07:19 | [diff] [blame] | 255 | // Returns |true| if entry has an internal chrome:// URL, |false| otherwise. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 256 | bool HasInternalURL(const NavigationEntry* entry) { |
[email protected] | 50dc3deb | 2011-07-07 01:07:19 | [diff] [blame] | 257 | if (!entry) |
| 258 | return false; |
| 259 | |
| 260 | // Check the |virtual_url()| first. This catches regular chrome:// URLs |
| 261 | // including URLs that were rewritten (such as chrome://bookmarks). |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 262 | if (entry->GetVirtualURL().SchemeIs(chrome::kChromeUIScheme)) |
[email protected] | 50dc3deb | 2011-07-07 01:07:19 | [diff] [blame] | 263 | return true; |
| 264 | |
| 265 | // If the |virtual_url()| isn't a chrome:// URL, check if it's actually |
| 266 | // view-source: of a chrome:// URL. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 267 | if (entry->GetVirtualURL().SchemeIs(chrome::kViewSourceScheme)) |
| 268 | return entry->GetURL().SchemeIs(chrome::kChromeUIScheme); |
[email protected] | 50dc3deb | 2011-07-07 01:07:19 | [diff] [blame] | 269 | |
| 270 | return false; |
| 271 | } |
| 272 | |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 273 | // Get the launch URL for a given extension, with optional override/fallback. |
| 274 | // |override_url|, if non-empty, will be preferred over the extension's |
| 275 | // launch url. |
| 276 | GURL UrlForExtension(const Extension* extension, const GURL& override_url) { |
| 277 | if (!extension) |
| 278 | return override_url; |
| 279 | |
| 280 | GURL url; |
| 281 | if (!override_url.is_empty()) { |
| 282 | DCHECK(extension->web_extent().MatchesURL(override_url)); |
| 283 | url = override_url; |
| 284 | } else { |
| 285 | url = extension->GetFullLaunchURL(); |
| 286 | } |
| 287 | |
| 288 | // For extensions lacking launch urls, determine a reasonable fallback. |
| 289 | if (!url.is_valid()) { |
| 290 | url = extension->options_url(); |
| 291 | if (!url.is_valid()) { |
| 292 | url = GURL(std::string(chrome::kChromeUISettingsURL) + |
| 293 | chrome::kExtensionsSubPage); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | return url; |
| 298 | } |
| 299 | |
[email protected] | 113baf9 | 2012-02-14 02:21:06 | [diff] [blame] | 300 | // Parse two comma-separated integers from str. Return true on success. |
| 301 | bool ParseCommaSeparatedIntegers(const std::string& str, |
| 302 | int* ret_num1, |
| 303 | int* ret_num2) { |
| 304 | size_t num1_size = str.find_first_of(','); |
| 305 | if (num1_size == std::string::npos) |
| 306 | return false; |
| 307 | |
| 308 | size_t num2_pos = num1_size + 1; |
| 309 | size_t num2_size = str.size() - num2_pos; |
| 310 | int num1, num2; |
| 311 | if (!base::StringToInt(str.substr(0, num1_size), &num1) || |
| 312 | !base::StringToInt(str.substr(num2_pos, num2_size), &num2)) |
| 313 | return false; |
| 314 | |
| 315 | *ret_num1 = num1; |
| 316 | *ret_num2 = num2; |
| 317 | return true; |
| 318 | } |
| 319 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 320 | } // namespace |
| 321 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 322 | //////////////////////////////////////////////////////////////////////////////// |
| 323 | // Browser, CreateParams: |
| 324 | |
| 325 | Browser::CreateParams::CreateParams(Type type, Profile* profile) |
| 326 | : type(type), |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 327 | profile(profile), |
| 328 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
| 329 | is_session_restore(false) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 332 | /////////////////////////////////////////////////////////////////////////////// |
| 333 | // Browser, Constructors, Creation, Showing: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 334 | |
[email protected] | 299dabd | 2008-11-19 02:27:16 | [diff] [blame] | 335 | Browser::Browser(Type type, Profile* profile) |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 336 | : type_(type), |
| 337 | profile_(profile), |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 338 | window_(NULL), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 339 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 340 | tab_handler_(TabHandler::CreateTabHandler(this))), |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 341 | command_updater_(this), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 342 | toolbar_model_(this), |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 343 | chrome_updater_factory_(this), |
| 344 | is_attempting_to_close_browser_(false), |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 345 | cancel_download_confirmation_state_(NOT_PROMPTED), |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 346 | show_state_(ui::SHOW_STATE_DEFAULT), |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 347 | is_session_restore_(false), |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 348 | weak_factory_(this), |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 349 | block_command_execution_(false), |
| 350 | last_blocked_command_id_(-1), |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 351 | last_blocked_command_disposition_(CURRENT_TAB), |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 352 | pending_web_app_action_(NONE), |
| 353 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 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] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 360 | window_has_shown_(false) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 361 | registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 362 | content::NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 363 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 364 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 365 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 366 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 367 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 368 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 369 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 370 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 371 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 372 | content::NotificationService::AllSources()); |
[email protected] | ffa6f59 | 2011-06-24 22:03:57 | [diff] [blame] | 373 | registrar_.Add( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 374 | this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 375 | content::Source<ThemeService>( |
| 376 | ThemeServiceFactory::GetForProfile(profile_))); |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 377 | registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 378 | content::NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 379 | |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 380 | PrefService* local_state = g_browser_process->local_state(); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 381 | if (local_state) { |
| 382 | local_pref_registrar_.Init(local_state); |
| 383 | local_pref_registrar_.Add(prefs::kPrintingEnabled, this); |
| 384 | local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); |
[email protected] | 3819f2ee | 2011-08-21 09:44:38 | [diff] [blame] | 385 | local_pref_registrar_.Add(prefs::kMetricsReportingEnabled, this); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | profile_pref_registrar_.Init(profile_->GetPrefs()); |
| 389 | profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); |
| 390 | profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 391 | profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 392 | profile_pref_registrar_.Add(prefs::kHomePage, this); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 393 | profile_pref_registrar_.Add(prefs::kInstantEnabled, this); |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 394 | profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this); |
[email protected] | 3819f2ee | 2011-08-21 09:44:38 | [diff] [blame] | 395 | profile_pref_registrar_.Add(prefs::kSearchSuggestEnabled, 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 | InitCommandState(); |
| 398 | BrowserList::AddBrowser(this); |
| 399 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 400 | // NOTE: These prefs all need to be explicitly destroyed in the destructor |
| 401 | // or you'll get a nasty surprise when you run the incognito tests. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 402 | encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, |
| 403 | profile_->GetPrefs(), NULL); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 404 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 405 | tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 406 | if (tab_restore_service_) { |
| 407 | tab_restore_service_->AddObserver(this); |
| 408 | TabRestoreServiceChanged(tab_restore_service_); |
| 409 | } |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 410 | |
[email protected] | 5e61afb9 | 2012-01-27 20:09:13 | [diff] [blame] | 411 | ProfileSyncService* service = |
| 412 | ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| 413 | if (service) |
| 414 | service->AddObserver(this); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 415 | |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 416 | CreateInstantIfNecessary(); |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 417 | |
| 418 | // Make sure TabFinder has been created. This does nothing if TabFinder is |
| 419 | // not enabled. |
| 420 | TabFinder::GetInstance(); |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 421 | |
| 422 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 423 | |
| 424 | FilePath profile_path = profile->GetPath(); |
| 425 | ProfileMetrics::LogProfileLaunch(profile_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | Browser::~Browser() { |
[email protected] | 5e61afb9 | 2012-01-27 20:09:13 | [diff] [blame] | 429 | ProfileSyncService* service = |
| 430 | ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| 431 | if (service) |
| 432 | service->RemoveObserver(this); |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 433 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 434 | BrowserList::RemoveBrowser(this); |
| 435 | |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 436 | #if !defined(OS_MACOSX) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 437 | if (!BrowserList::HasBrowserWithProfile(profile_)) { |
| 438 | // We're the last browser window with this profile. We need to nuke the |
| 439 | // TabRestoreService, which will start the shutdown of the |
| 440 | // NavigationControllers and allow for proper shutdown. If we don't do this |
| 441 | // chrome won't shutdown cleanly, and may end up crashing when some |
| 442 | // thread tries to use the IO thread (or another thread) that is no longer |
| 443 | // valid. |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 444 | // This isn't a valid assumption for Mac OS, as it stays running after |
| 445 | // the last browser has closed. The Mac equivalent is in its app |
| 446 | // controller. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 447 | TabRestoreServiceFactory::ResetForProfile(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 448 | } |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 449 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 450 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 451 | SessionService* session_service = |
| 452 | SessionServiceFactory::GetForProfile(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 453 | if (session_service) |
| 454 | session_service->WindowClosed(session_id_); |
| 455 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 456 | TabRestoreService* tab_restore_service = |
| 457 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 458 | if (tab_restore_service) |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 459 | tab_restore_service->BrowserClosed(tab_restore_service_delegate()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 460 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 461 | profile_pref_registrar_.RemoveAll(); |
| 462 | local_pref_registrar_.RemoveAll(); |
| 463 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 464 | encoding_auto_detect_.Destroy(); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 465 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 466 | if (profile_->IsOffTheRecord() && |
[email protected] | 474e5db | 2011-08-12 13:02:23 | [diff] [blame] | 467 | !BrowserList::IsOffTheRecordSessionActiveForProfile(profile_)) { |
[email protected] | 5e91924 | 2012-02-13 23:59:35 | [diff] [blame] | 468 | // An incognito profile is no longer needed, this indirectly frees |
| 469 | // its cache and cookies once it gets destroyed at the appropriate time. |
[email protected] | f722750 | 2012-02-22 21:54:32 | [diff] [blame] | 470 | ProfileDestroyer::DestroyOffTheRecordProfile(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | // There may be pending file dialogs, we need to tell them that we've gone |
| 474 | // away so they don't try and call back to us. |
| 475 | if (select_file_dialog_.get()) |
| 476 | select_file_dialog_->ListenerDestroyed(); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 477 | |
| 478 | TabRestoreServiceDestroyed(tab_restore_service_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 479 | } |
| 480 | |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 481 | bool Browser::IsFullscreenForTab() const { |
| 482 | return fullscreen_controller_->IsFullscreenForTab(); |
| 483 | } |
| 484 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 485 | // static |
| 486 | Browser* Browser::Create(Profile* profile) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 487 | Browser* browser = new Browser(TYPE_TABBED, profile); |
| 488 | browser->InitBrowserWindow(); |
| 489 | return browser; |
| 490 | } |
| 491 | |
| 492 | // static |
| 493 | Browser* Browser::CreateWithParams(const CreateParams& params) { |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 494 | if (!params.app_name.empty()) |
| 495 | RegisterAppPrefs(params.app_name, params.profile); |
| 496 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 497 | Browser* browser = new Browser(params.type, params.profile); |
| 498 | browser->app_name_ = params.app_name; |
[email protected] | 81b2b0ac | 2011-11-23 01:54:48 | [diff] [blame] | 499 | browser->set_override_bounds(params.initial_bounds); |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 500 | browser->set_show_state(params.initial_show_state); |
| 501 | browser->set_is_session_restore(params.is_session_restore); |
| 502 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 503 | browser->InitBrowserWindow(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 504 | return browser; |
| 505 | } |
[email protected] | 6104acf | 2008-11-11 22:27:34 | [diff] [blame] | 506 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 507 | // static |
[email protected] | 9ee17e8c | 2010-08-10 19:17:31 | [diff] [blame] | 508 | Browser* Browser::CreateForType(Type type, Profile* profile) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 509 | CreateParams params(type, profile); |
| 510 | return CreateWithParams(params); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | // static |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 514 | Browser* Browser::CreateForApp(Type type, |
| 515 | const std::string& app_name, |
[email protected] | 5c20924 | 2011-06-06 20:36:17 | [diff] [blame] | 516 | const gfx::Rect& window_bounds, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 517 | Profile* profile) { |
| 518 | DCHECK(type != TYPE_TABBED); |
| 519 | DCHECK(!app_name.empty()); |
[email protected] | f075fe0a2 | 2010-04-26 04:06:43 | [diff] [blame] | 520 | |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 521 | #if !defined(OS_CHROMEOS) || defined(USE_AURA) |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 522 | if (type == TYPE_PANEL && |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 523 | !PanelManager::ShouldUsePanels( |
| 524 | web_app::GetExtensionIdFromApplicationName(app_name))) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 525 | type = TYPE_POPUP; |
[email protected] | 5530ac65 | 2010-09-25 05:35:49 | [diff] [blame] | 526 | } |
[email protected] | 384cb19 | 2011-10-14 20:46:51 | [diff] [blame] | 527 | #if defined(TOOLKIT_GTK) |
[email protected] | 4517b27 | 2011-11-09 01:58:05 | [diff] [blame] | 528 | // Panels are only supported on a white list of window managers for Linux. |
| 529 | if (type == TYPE_PANEL) { |
[email protected] | ca595c8f | 2011-11-10 19:30:58 | [diff] [blame] | 530 | ui::WindowManagerName wm_type = ui::GuessWindowManager(); |
| 531 | if (wm_type != ui::WM_COMPIZ && |
| 532 | wm_type != ui::WM_ICE_WM && |
| 533 | wm_type != ui::WM_KWIN && |
| 534 | wm_type != ui::WM_METACITY && |
| 535 | wm_type != ui::WM_MUTTER) { |
[email protected] | 4517b27 | 2011-11-09 01:58:05 | [diff] [blame] | 536 | type = TYPE_POPUP; |
| 537 | } |
| 538 | } |
[email protected] | 384cb19 | 2011-10-14 20:46:51 | [diff] [blame] | 539 | #endif // TOOLKIT_GTK |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 540 | #endif // !OS_CHROMEOS || USE_AURA |
[email protected] | f075fe0a2 | 2010-04-26 04:06:43 | [diff] [blame] | 541 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 542 | CreateParams params(type, profile); |
| 543 | params.app_name = app_name; |
[email protected] | 81b2b0ac | 2011-11-23 01:54:48 | [diff] [blame] | 544 | params.initial_bounds = window_bounds; |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 545 | return CreateWithParams(params); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 546 | } |
| 547 | |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 548 | // static |
| 549 | Browser* Browser::CreateForDevTools(Profile* profile) { |
[email protected] | 4befe2ec | 2011-08-31 16:13:39 | [diff] [blame] | 550 | #if defined(OS_CHROMEOS) |
| 551 | CreateParams params(TYPE_TABBED, profile); |
| 552 | #else |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 553 | CreateParams params(TYPE_POPUP, profile); |
[email protected] | 4befe2ec | 2011-08-31 16:13:39 | [diff] [blame] | 554 | #endif |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 555 | params.app_name = DevToolsWindow::kDevToolsApp; |
| 556 | return CreateWithParams(params); |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 557 | } |
| 558 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 559 | void Browser::InitBrowserWindow() { |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 560 | DCHECK(!window_); |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 561 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 562 | window_ = CreateBrowserWindow(); |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 563 | fullscreen_controller_ = new FullscreenController(window_, profile_, this); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 564 | |
[email protected] | 5e37c45 | 2011-09-06 19:31:39 | [diff] [blame] | 565 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | 6a34951a | 2012-01-17 18:10:40 | [diff] [blame] | 566 | // Set the app user model id for this application to that of the application |
| 567 | // name. See http://crbug.com/7028. |
| 568 | ui::win::SetAppIdForWindow( |
| 569 | is_app() && !is_type_panel() ? |
| 570 | ShellIntegration::GetAppId(UTF8ToWide(app_name_), profile_->GetPath()) : |
| 571 | ShellIntegration::GetChromiumAppId(profile_->GetPath()), |
| 572 | window()->GetNativeHandle()); |
[email protected] | 45446a5 | 2010-11-04 17:41:00 | [diff] [blame] | 573 | |
[email protected] | 6a34951a | 2012-01-17 18:10:40 | [diff] [blame] | 574 | if (is_type_panel()) { |
| 575 | ui::win::SetAppIconForWindow(ShellIntegration::GetChromiumIconPath(), |
| 576 | window()->GetNativeHandle()); |
[email protected] | 45446a5 | 2010-11-04 17:41:00 | [diff] [blame] | 577 | } |
[email protected] | 80cf356 | 2009-11-17 08:17:24 | [diff] [blame] | 578 | #endif |
| 579 | |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame^] | 580 | // Create the extension window controller before sending notifications. |
| 581 | extension_window_controller_.reset( |
| 582 | new BrowserExtensionWindowController(this)); |
| 583 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 584 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 585 | chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 586 | content::Source<Browser>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 587 | content::NotificationService::NoDetails()); |
[email protected] | 14d8c66e | 2009-09-22 00:32:52 | [diff] [blame] | 588 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 589 | PrefService* local_state = g_browser_process->local_state(); |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 590 | if (local_state && local_state->FindPreference( |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 591 | prefs::kAutofillPersonalDataManagerFirstRun) && |
| 592 | local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) { |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 593 | // Notify PDM that this is a first run. |
| 594 | #if defined(OS_WIN) |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 595 | ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_)); |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 596 | #endif // defined(OS_WIN) |
| 597 | // Reset the preference so we don't call it again for subsequent windows. |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 598 | local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun); |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 599 | } |
[email protected] | 6a1622a | 2011-09-20 22:37:45 | [diff] [blame] | 600 | |
| 601 | // Permanently dismiss ntp4 bubble for new users. |
[email protected] | dfa08b04 | 2011-12-28 23:07:21 | [diff] [blame] | 602 | if (first_run::IsChromeFirstRun()) |
[email protected] | 27e96a97 | 2011-10-20 20:06:55 | [diff] [blame] | 603 | NewTabPageHandler::DismissIntroMessage(local_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 604 | } |
| 605 | |
[email protected] | bf870869 | 2011-12-20 21:24:28 | [diff] [blame] | 606 | void Browser::SetWindowForTesting(BrowserWindow* window) { |
| 607 | DCHECK(!window_); |
| 608 | window_ = window; |
| 609 | fullscreen_controller_ = new FullscreenController(window_, profile_, this); |
| 610 | } |
| 611 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 612 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 613 | // Getters & Setters |
| 614 | |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 615 | FindBarController* Browser::GetFindBarController() { |
| 616 | if (!find_bar_controller_.get()) { |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 617 | FindBar* find_bar = window_->CreateFindBar(); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 618 | find_bar_controller_.reset(new FindBarController(find_bar)); |
| 619 | find_bar->SetFindBarController(find_bar_controller_.get()); |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 620 | find_bar_controller_->ChangeTabContents(GetSelectedTabContentsWrapper()); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 621 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
| 622 | } |
| 623 | return find_bar_controller_.get(); |
| 624 | } |
| 625 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 626 | bool Browser::HasFindBarController() const { |
| 627 | return find_bar_controller_.get() != NULL; |
| 628 | } |
| 629 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 630 | bool Browser::is_app() const { |
| 631 | return !app_name_.empty(); |
| 632 | } |
| 633 | |
| 634 | bool Browser::is_devtools() const { |
| 635 | return app_name_ == DevToolsWindow::kDevToolsApp; |
| 636 | } |
| 637 | |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 638 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 639 | // Browser, Creation Helpers: |
| 640 | |
| 641 | // static |
[email protected] | eddcf750 | 2012-02-09 22:43:48 | [diff] [blame] | 642 | void Browser::NewEmptyWindow(Profile* profile) { |
| 643 | bool incognito = profile->IsOffTheRecord(); |
| 644 | PrefService* prefs = profile->GetPrefs(); |
| 645 | if (incognito) { |
| 646 | if (IncognitoModePrefs::GetAvailability(prefs) == |
| 647 | IncognitoModePrefs::DISABLED) { |
| 648 | incognito = false; |
| 649 | } |
| 650 | } else { |
| 651 | if (browser_defaults::kAlwaysOpenIncognitoWindow && |
| 652 | IncognitoModePrefs::ShouldLaunchIncognito( |
| 653 | *CommandLine::ForCurrentProcess(), prefs)) { |
| 654 | incognito = true; |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | if (incognito) { |
| 659 | content::RecordAction(UserMetricsAction("NewIncognitoWindow")); |
| 660 | OpenEmptyWindow(profile->GetOffTheRecordProfile()); |
| 661 | } else { |
| 662 | content::RecordAction(UserMetricsAction("NewWindow")); |
| 663 | SessionService* session_service = |
| 664 | SessionServiceFactory::GetForProfile(profile->GetOriginalProfile()); |
| 665 | if (!session_service || |
| 666 | !session_service->RestoreIfNecessary(std::vector<GURL>())) { |
| 667 | OpenEmptyWindow(profile->GetOriginalProfile()); |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | // static |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 673 | void Browser::OpenEmptyWindow(Profile* profile) { |
| 674 | Browser* browser = Browser::Create(profile); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 675 | browser->AddBlankTab(true); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 676 | browser->window()->Show(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 677 | } |
| 678 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 679 | // static |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 680 | void Browser::OpenWindowWithRestoredTabs(Profile* profile) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 681 | TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile); |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 682 | if (service) |
| 683 | service->RestoreMostRecentEntry(NULL); |
| 684 | } |
| 685 | |
| 686 | // static |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 687 | void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 688 | Browser* browser = GetOrCreateTabbedBrowser( |
| 689 | profile->GetOffTheRecordProfile()); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 690 | browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 691 | browser->window()->Show(); |
[email protected] | 2baf83d | 2008-07-30 05:58:17 | [diff] [blame] | 692 | } |
| 693 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 694 | // static |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 695 | WebContents* Browser::OpenApplication( |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 696 | Profile* profile, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 697 | const Extension* extension, |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 698 | extension_misc::LaunchContainer container, |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 699 | const GURL& override_url, |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 700 | WindowOpenDisposition disposition) { |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 701 | WebContents* tab = NULL; |
[email protected] | 4033bd9 | 2011-03-08 19:27:04 | [diff] [blame] | 702 | ExtensionPrefs* prefs = profile->GetExtensionService()->extension_prefs(); |
| 703 | prefs->SetActiveBit(extension->id(), true); |
[email protected] | e3acb7c | 2010-05-11 19:23:37 | [diff] [blame] | 704 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 705 | UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchContainer", container, 100); |
| 706 | |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 707 | switch (container) { |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 708 | case extension_misc::LAUNCH_SHELL: { |
| 709 | ShellWindow* shell_window = ShellWindow::Create( |
| 710 | profile, |
| 711 | extension, |
| 712 | UrlForExtension(extension, override_url)); |
| 713 | if (shell_window) |
| 714 | tab = shell_window->web_contents(); |
| 715 | break; |
| 716 | } |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 717 | case extension_misc::LAUNCH_PANEL: |
[email protected] | bafda13 | 2012-02-16 19:32:51 | [diff] [blame] | 718 | #if defined(USE_AURA) |
| 719 | if (extension && |
| 720 | CommandLine::ForCurrentProcess()->HasSwitch( |
| 721 | ash::switches::kAuraPanelManager)) { |
| 722 | tab = OpenApplicationPanel(profile, extension, override_url); |
| 723 | break; |
| 724 | } |
| 725 | // else fall through to LAUNCH_WINDOW |
| 726 | #endif |
| 727 | case extension_misc::LAUNCH_WINDOW: |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 728 | tab = Browser::OpenApplicationWindow(profile, extension, container, |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 729 | override_url, NULL); |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 730 | break; |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 731 | case extension_misc::LAUNCH_TAB: { |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 732 | tab = Browser::OpenApplicationTab(profile, extension, override_url, |
| 733 | disposition); |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 734 | break; |
| 735 | } |
| 736 | default: |
| 737 | NOTREACHED(); |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 738 | break; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 739 | } |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 740 | return tab; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 741 | } |
| 742 | |
[email protected] | bafda13 | 2012-02-16 19:32:51 | [diff] [blame] | 743 | #if defined(USE_AURA) |
| 744 | // static |
| 745 | WebContents* Browser::OpenApplicationPanel( |
| 746 | Profile* profile, |
| 747 | const Extension* extension, |
| 748 | const GURL& url_input) { |
| 749 | GURL url = UrlForExtension(extension, url_input); |
| 750 | std::string app_name = |
| 751 | web_app::GenerateApplicationNameFromExtensionId(extension->id()); |
| 752 | gfx::Rect panel_bounds; |
| 753 | panel_bounds.set_width(extension->launch_width()); |
| 754 | panel_bounds.set_height(extension->launch_height()); |
| 755 | PanelViewAura* panel_view = new PanelViewAura(app_name); |
| 756 | panel_view->Init(profile, url, panel_bounds); |
| 757 | return panel_view->WebContents(); |
| 758 | } |
| 759 | #endif |
| 760 | |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 761 | // static |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 762 | WebContents* Browser::OpenApplicationWindow( |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 763 | Profile* profile, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 764 | const Extension* extension, |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 765 | extension_misc::LaunchContainer container, |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 766 | const GURL& url_input, |
| 767 | Browser** app_browser) { |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 768 | DCHECK(!url_input.is_empty() || extension); |
| 769 | GURL url = UrlForExtension(extension, url_input); |
[email protected] | f381dfa | 2010-04-29 04:41:37 | [diff] [blame] | 770 | |
[email protected] | 2f1c09d | 2011-01-14 14:58:14 | [diff] [blame] | 771 | std::string app_name; |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 772 | app_name = extension ? |
| 773 | web_app::GenerateApplicationNameFromExtensionId(extension->id()) : |
| 774 | web_app::GenerateApplicationNameFromURL(url); |
[email protected] | 2f1c09d | 2011-01-14 14:58:14 | [diff] [blame] | 775 | |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 776 | Type type = extension && (container == extension_misc::LAUNCH_PANEL) ? |
| 777 | TYPE_PANEL : TYPE_POPUP; |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 778 | |
[email protected] | 5c20924 | 2011-06-06 20:36:17 | [diff] [blame] | 779 | gfx::Rect window_bounds; |
| 780 | if (extension) { |
| 781 | window_bounds.set_width(extension->launch_width()); |
| 782 | window_bounds.set_height(extension->launch_height()); |
| 783 | } |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 784 | |
[email protected] | 5c20924 | 2011-06-06 20:36:17 | [diff] [blame] | 785 | Browser* browser = Browser::CreateForApp(type, app_name, window_bounds, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 786 | profile); |
[email protected] | 011396a | 2011-04-13 23:35:28 | [diff] [blame] | 787 | |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 788 | if (app_browser) |
| 789 | *app_browser = browser; |
| 790 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 791 | TabContentsWrapper* wrapper = |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 792 | browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_START_PAGE); |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 793 | WebContents* contents = wrapper->web_contents(); |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 794 | contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 795 | contents->GetRenderViewHost()->SyncRendererPrefs(); |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 796 | browser->window()->Show(); |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 797 | |
[email protected] | 68f009f | 2009-02-26 19:43:35 | [diff] [blame] | 798 | // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
| 799 | // focus explicitly. |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 800 | contents->GetView()->SetInitialFocus(); |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 801 | return contents; |
| 802 | } |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 803 | |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 804 | WebContents* Browser::OpenAppShortcutWindow(Profile* profile, |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 805 | const GURL& url, |
| 806 | bool update_shortcut) { |
| 807 | Browser* app_browser; |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 808 | WebContents* tab = OpenApplicationWindow( |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 809 | profile, |
| 810 | NULL, // this is a URL app. No extension. |
| 811 | extension_misc::LAUNCH_WINDOW, |
| 812 | url, |
| 813 | &app_browser); |
| 814 | |
| 815 | if (!tab) |
| 816 | return NULL; |
| 817 | |
| 818 | if (update_shortcut) { |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 819 | // Set UPDATE_SHORTCUT as the pending web app action. This action is picked |
| 820 | // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
| 821 | // the web app info is available, TabContents notifies Browser via |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 822 | // OnDidGetApplicationInfo, which calls |
| 823 | // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
| 824 | // pending web app action. |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 825 | app_browser->pending_web_app_action_ = UPDATE_SHORTCUT; |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 826 | } |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 827 | return tab; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | // static |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 831 | WebContents* Browser::OpenApplicationTab(Profile* profile, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 832 | const Extension* extension, |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 833 | const GURL& override_url, |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 834 | WindowOpenDisposition disposition) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 835 | Browser* browser = BrowserList::FindTabbedBrowser(profile, false); |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 836 | WebContents* contents = NULL; |
[email protected] | 78d78a6 | 2011-09-29 18:24:33 | [diff] [blame] | 837 | if (!browser) { |
| 838 | // No browser for this profile, need to open a new one. |
| 839 | browser = Browser::Create(profile); |
| 840 | browser->window()->Show(); |
| 841 | // There's no current tab in this browser window, so add a new one. |
| 842 | disposition = NEW_FOREGROUND_TAB; |
| 843 | } |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 844 | |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 845 | // Check the prefs for overridden mode. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 846 | ExtensionService* extension_service = profile->GetExtensionService(); |
| 847 | DCHECK(extension_service); |
[email protected] | b283a753 | 2010-08-12 21:24:59 | [diff] [blame] | 848 | |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 849 | ExtensionPrefs::LaunchType launch_type = |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 850 | extension_service->extension_prefs()->GetLaunchType( |
[email protected] | 4e59568 | 2011-02-09 17:07:02 | [diff] [blame] | 851 | extension->id(), ExtensionPrefs::LAUNCH_DEFAULT); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 852 | UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 853 | |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 854 | static bool default_apps_trial_exists = |
[email protected] | 568c331 | 2011-12-06 15:36:04 | [diff] [blame] | 855 | base::FieldTrialList::TrialExists(kDefaultAppsTrialName); |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 856 | if (default_apps_trial_exists) { |
| 857 | UMA_HISTOGRAM_ENUMERATION( |
| 858 | base::FieldTrial::MakeName("Extensions.AppTabLaunchType", |
[email protected] | 568c331 | 2011-12-06 15:36:04 | [diff] [blame] | 859 | kDefaultAppsTrialName), |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 860 | launch_type, 100); |
| 861 | } |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 862 | |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 863 | int add_type = TabStripModel::ADD_ACTIVE; |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 864 | if (launch_type == ExtensionPrefs::LAUNCH_PINNED) |
| 865 | add_type |= TabStripModel::ADD_PINNED; |
| 866 | |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 867 | GURL extension_url = UrlForExtension(extension, override_url); |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 868 | // TODO(erikkay): START_PAGE doesn't seem like the right transition in all |
| 869 | // cases. |
[email protected] | 37fcf26 | 2011-01-26 19:39:15 | [diff] [blame] | 870 | browser::NavigateParams params(browser, extension_url, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 871 | content::PAGE_TRANSITION_START_PAGE); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 872 | params.tabstrip_add_types = add_type; |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 873 | params.disposition = disposition; |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 874 | |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 875 | if (disposition == CURRENT_TAB) { |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 876 | WebContents* existing_tab = browser->GetSelectedWebContents(); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 877 | TabStripModel* model = browser->tabstrip_model(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 878 | int tab_index = model->GetWrapperIndex(existing_tab); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 879 | |
[email protected] | bce1f1c | 2011-12-05 15:11:58 | [diff] [blame] | 880 | existing_tab->OpenURL(OpenURLParams( |
| 881 | extension_url, |
| 882 | content::Referrer(existing_tab->GetURL(), |
| 883 | WebKit::WebReferrerPolicyDefault), |
| 884 | disposition, content::PAGE_TRANSITION_LINK, false)); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 885 | if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) { |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 886 | model->SetTabPinned(tab_index, true); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 887 | tab_index = model->GetWrapperIndex(existing_tab); |
[email protected] | 7dfec421 | 2010-11-01 22:12:26 | [diff] [blame] | 888 | } |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 889 | if (params.tabstrip_add_types & TabStripModel::ADD_ACTIVE) |
| 890 | model->ActivateTabAt(tab_index, true); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 891 | |
| 892 | contents = existing_tab; |
| 893 | } else { |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 894 | browser::Navigate(¶ms); |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 895 | contents = params.target_contents->web_contents(); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 896 | } |
| 897 | |
[email protected] | 7bd42fc | 2011-02-09 17:32:42 | [diff] [blame] | 898 | // TODO(skerner): If we are already in full screen mode, and the user |
| 899 | // set the app to open as a regular or pinned tab, what should happen? |
| 900 | // Today we open the tab, but stay in full screen mode. Should we leave |
| 901 | // full screen mode in this case? |
| 902 | if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 903 | !browser->window()->IsFullscreen()) { |
[email protected] | 184717d5 | 2012-02-22 04:46:16 | [diff] [blame] | 904 | browser->ToggleFullscreenMode(); |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 905 | } |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 906 | |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 907 | return contents; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | // static |
[email protected] | 90a8bf25 | 2010-03-12 00:09:47 | [diff] [blame] | 911 | void Browser::OpenBookmarkManagerWindow(Profile* profile) { |
| 912 | Browser* browser = Browser::Create(profile); |
[email protected] | 0af8f13 | 2011-07-16 01:37:02 | [diff] [blame] | 913 | browser->OpenBookmarkManager(); |
[email protected] | 90a8bf25 | 2010-03-12 00:09:47 | [diff] [blame] | 914 | browser->window()->Show(); |
| 915 | } |
| 916 | |
[email protected] | 057d959a | 2010-03-12 02:56:20 | [diff] [blame] | 917 | #if defined(OS_MACOSX) |
[email protected] | 90a8bf25 | 2010-03-12 00:09:47 | [diff] [blame] | 918 | // static |
[email protected] | 91a5b3e | 2009-10-30 19:32:22 | [diff] [blame] | 919 | void Browser::OpenHistoryWindow(Profile* profile) { |
| 920 | Browser* browser = Browser::Create(profile); |
| 921 | browser->ShowHistoryTab(); |
| 922 | browser->window()->Show(); |
| 923 | } |
| 924 | |
| 925 | // static |
| 926 | void Browser::OpenDownloadsWindow(Profile* profile) { |
| 927 | Browser* browser = Browser::Create(profile); |
| 928 | browser->ShowDownloadsTab(); |
| 929 | browser->window()->Show(); |
| 930 | } |
| 931 | |
| 932 | // static |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 933 | void Browser::OpenHelpWindow(Profile* profile) { |
| 934 | Browser* browser = Browser::Create(profile); |
[email protected] | 202802e4 | 2011-07-06 11:40:46 | [diff] [blame] | 935 | browser->ShowHelpTab(); |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 936 | browser->window()->Show(); |
| 937 | } |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 938 | |
[email protected] | eca25813 | 2010-11-15 23:33:08 | [diff] [blame] | 939 | // static |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 940 | void Browser::OpenOptionsWindow(Profile* profile) { |
| 941 | Browser* browser = Browser::Create(profile); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 942 | browser->OpenOptionsDialog(); |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 943 | browser->window()->Show(); |
| 944 | } |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 945 | |
| 946 | // static |
[email protected] | 6554918 | 2012-02-25 00:45:40 | [diff] [blame] | 947 | void Browser::OpenSyncSetupWindow(Profile* profile) { |
| 948 | Browser* browser = Browser::Create(profile); |
| 949 | browser->ShowSyncSetup(); |
| 950 | browser->window()->Show(); |
| 951 | } |
| 952 | |
| 953 | // static |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 954 | void Browser::OpenClearBrowsingDataDialogWindow(Profile* profile) { |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 955 | Browser* browser = Browser::Create(profile); |
| 956 | browser->OpenClearBrowsingDataDialog(); |
| 957 | browser->window()->Show(); |
| 958 | } |
| 959 | |
| 960 | // static |
| 961 | void Browser::OpenImportSettingsDialogWindow(Profile* profile) { |
| 962 | Browser* browser = Browser::Create(profile); |
| 963 | browser->OpenImportSettingsDialog(); |
| 964 | browser->window()->Show(); |
| 965 | } |
[email protected] | b99081b | 2011-03-10 17:43:47 | [diff] [blame] | 966 | |
| 967 | // static |
| 968 | void Browser::OpenInstantConfirmDialogWindow(Profile* profile) { |
| 969 | Browser* browser = Browser::Create(profile); |
| 970 | browser->OpenInstantConfirmDialog(); |
| 971 | browser->window()->Show(); |
| 972 | } |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 973 | #endif |
| 974 | |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 975 | // static |
| 976 | void Browser::OpenExtensionsWindow(Profile* profile) { |
| 977 | Browser* browser = Browser::Create(profile); |
| 978 | browser->ShowExtensionsTab(); |
| 979 | browser->window()->Show(); |
| 980 | } |
| 981 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 982 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 983 | // Browser, State Storage and Retrieval for UI: |
| 984 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 985 | std::string Browser::GetWindowPlacementKey() const { |
| 986 | std::string name(prefs::kBrowserWindowPlacement); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 987 | if (!app_name_.empty()) { |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 988 | name.append("_"); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 989 | name.append(app_name_); |
| 990 | } |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 991 | return name; |
| 992 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 993 | |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 994 | bool Browser::ShouldSaveWindowPlacement() const { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 995 | switch (type_) { |
| 996 | case TYPE_TABBED: |
| 997 | return true; |
| 998 | case TYPE_POPUP: |
[email protected] | bd6cdf2 | 2011-06-21 08:11:51 | [diff] [blame] | 999 | // Only save the window placement of popups if they are restored, |
| 1000 | // or the window belongs to DevTools. |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 1001 | #if defined USE_AURA |
| 1002 | if (is_app()) |
| 1003 | return true; |
| 1004 | #endif |
[email protected] | bd6cdf2 | 2011-06-21 08:11:51 | [diff] [blame] | 1005 | return browser_defaults::kRestorePopups || is_devtools(); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1006 | case TYPE_PANEL: |
| 1007 | // Do not save the window placement of panels. |
| 1008 | return false; |
| 1009 | default: |
| 1010 | return false; |
| 1011 | } |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 1012 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1013 | |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 1014 | void Browser::SaveWindowPlacement(const gfx::Rect& bounds, |
| 1015 | ui::WindowShowState show_state) { |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 1016 | // Save to the session storage service, used when reloading a past session. |
| 1017 | // Note that we don't want to be the ones who cause lazy initialization of |
| 1018 | // the session service. This function gets called during initial window |
| 1019 | // showing, and we don't want to bring in the session service this early. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1020 | SessionService* session_service = |
| 1021 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
| 1022 | if (session_service) |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 1023 | session_service->SetWindowBounds(session_id_, bounds, show_state); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1024 | } |
| 1025 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1026 | gfx::Rect Browser::GetSavedWindowBounds() const { |
[email protected] | 113baf9 | 2012-02-14 02:21:06 | [diff] [blame] | 1027 | gfx::Rect restored_bounds = override_bounds_; |
| 1028 | WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, |
| 1029 | &restored_bounds); |
| 1030 | |
[email protected] | bb97536 | 2009-01-21 01:00:22 | [diff] [blame] | 1031 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1032 | bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode); |
| 1033 | bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode); |
| 1034 | if (record_mode || playback_mode) { |
| 1035 | // In playback/record mode we always fix the size of the browser and |
| 1036 | // move it to (0,0). The reason for this is two reasons: First we want |
| 1037 | // resize/moves in the playback to still work, and Second we want |
| 1038 | // playbacks to work (as much as possible) on machines w/ different |
| 1039 | // screen sizes. |
[email protected] | 113baf9 | 2012-02-14 02:21:06 | [diff] [blame] | 1040 | restored_bounds = gfx::Rect(0, 0, 800, 600); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1041 | } |
| 1042 | |
[email protected] | 113baf9 | 2012-02-14 02:21:06 | [diff] [blame] | 1043 | // The following options override playback/record. |
| 1044 | if (parsed_command_line.HasSwitch(switches::kWindowSize)) { |
| 1045 | std::string str = |
| 1046 | parsed_command_line.GetSwitchValueASCII(switches::kWindowSize); |
| 1047 | int width, height; |
| 1048 | if (ParseCommaSeparatedIntegers(str, &width, &height)) |
| 1049 | restored_bounds.set_size(gfx::Size(width, height)); |
| 1050 | } |
| 1051 | if (parsed_command_line.HasSwitch(switches::kWindowPosition)) { |
| 1052 | std::string str = |
| 1053 | parsed_command_line.GetSwitchValueASCII(switches::kWindowPosition); |
| 1054 | int x, y; |
| 1055 | if (ParseCommaSeparatedIntegers(str, &x, &y)) |
| 1056 | restored_bounds.set_origin(gfx::Point(x, y)); |
| 1057 | } |
| 1058 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1059 | return restored_bounds; |
| 1060 | } |
| 1061 | |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 1062 | ui::WindowShowState Browser::GetSavedWindowShowState() const { |
[email protected] | 76d8a4f | 2012-02-27 19:25:10 | [diff] [blame] | 1063 | // Only tabbed browsers use the command line or preference state, with the |
| 1064 | // exception of devtools. |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 1065 | bool show_state = !is_type_tabbed(); |
| 1066 | |
| 1067 | #if defined(USE_AURA) |
| 1068 | // Apps save state on aura. |
| 1069 | show_state &= !is_app(); |
| 1070 | #endif |
| 1071 | |
| 1072 | if (show_state) |
[email protected] | 3c627ff | 2012-01-27 17:04:07 | [diff] [blame] | 1073 | return show_state_; |
[email protected] | dfca0c3 | 2012-01-18 22:32:25 | [diff] [blame] | 1074 | |
[email protected] | bb97536 | 2009-01-21 01:00:22 | [diff] [blame] | 1075 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 1076 | return ui::SHOW_STATE_MAXIMIZED; |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1077 | |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 1078 | if (show_state_ != ui::SHOW_STATE_DEFAULT) |
| 1079 | return show_state_; |
[email protected] | 2e71662 | 2009-03-09 21:11:01 | [diff] [blame] | 1080 | |
[email protected] | 96f2010 | 2011-11-16 17:20:32 | [diff] [blame] | 1081 | const DictionaryValue* window_pref = |
| 1082 | profile()->GetPrefs()->GetDictionary(GetWindowPlacementKey().c_str()); |
[email protected] | 2e71662 | 2009-03-09 21:11:01 | [diff] [blame] | 1083 | bool maximized = false; |
[email protected] | 96f2010 | 2011-11-16 17:20:32 | [diff] [blame] | 1084 | window_pref->GetBoolean("maximized", &maximized); |
| 1085 | |
[email protected] | 3c627ff | 2012-01-27 17:04:07 | [diff] [blame] | 1086 | return maximized ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_DEFAULT; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | SkBitmap Browser::GetCurrentPageIcon() const { |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1090 | TabContentsWrapper* contents = GetSelectedTabContentsWrapper(); |
[email protected] | ce5348a8 | 2008-12-18 18:36:23 | [diff] [blame] | 1091 | // |contents| can be NULL since GetCurrentPageIcon() is called by the window |
| 1092 | // during the window's creation (before tabs have been added). |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1093 | return contents ? contents->favicon_tab_helper()->GetFavicon() : SkBitmap(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1094 | } |
| 1095 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 1096 | string16 Browser::GetWindowTitleForCurrentTab() const { |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1097 | WebContents* contents = GetSelectedWebContents(); |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 1098 | string16 title; |
[email protected] | c7c4233 | 2008-11-15 01:10:54 | [diff] [blame] | 1099 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 1100 | // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the |
| 1101 | // window during the window's creation (before tabs have been added). |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1102 | if (contents) { |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 1103 | title = contents->GetTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1104 | FormatTitleForDisplay(&title); |
| 1105 | } |
| 1106 | if (title.empty()) |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 1107 | title = CoreTabHelper::GetDefaultTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1108 | |
[email protected] | 1677984 | 2009-07-08 23:45:29 | [diff] [blame] | 1109 | #if defined(OS_MACOSX) || defined(OS_CHROMEOS) |
[email protected] | 22a3daa | 2009-11-09 22:03:33 | [diff] [blame] | 1110 | // On Mac or ChromeOS, we don't want to suffix the page title with |
| 1111 | // the application name. |
[email protected] | d904bc8 | 2009-07-07 00:41:04 | [diff] [blame] | 1112 | return title; |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 1113 | #else |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 1114 | int string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT; |
[email protected] | dff52973 | 2010-04-01 23:50:55 | [diff] [blame] | 1115 | // 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] | 1116 | if (is_app()) |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 1117 | string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT_NO_LOGO; |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 1118 | return l10n_util::GetStringFUTF16(string_id, title); |
[email protected] | 57e68dba | 2009-05-15 21:30:50 | [diff] [blame] | 1119 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | // static |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 1123 | void Browser::FormatTitleForDisplay(string16* title) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1124 | size_t current_index = 0; |
| 1125 | size_t match_index; |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 1126 | while ((match_index = title->find(L'\n', current_index)) != string16::npos) { |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 1127 | title->replace(match_index, 1, string16()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1128 | current_index = match_index; |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | /////////////////////////////////////////////////////////////////////////////// |
| 1133 | // Browser, OnBeforeUnload handling: |
| 1134 | |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 1135 | bool Browser::TabsNeedBeforeUnloadFired() { |
| 1136 | if (tabs_needing_before_unload_fired_.empty()) { |
| 1137 | for (int i = 0; i < tab_count(); ++i) { |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 1138 | WebContents* contents = GetTabContentsWrapperAt(i)->web_contents(); |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 1139 | if (contents->NeedToFireBeforeUnload()) |
| 1140 | tabs_needing_before_unload_fired_.insert(contents); |
| 1141 | } |
| 1142 | } |
| 1143 | return !tabs_needing_before_unload_fired_.empty(); |
| 1144 | } |
| 1145 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1146 | bool Browser::ShouldCloseWindow() { |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 1147 | if (!CanCloseWithInProgressDownloads()) |
| 1148 | return false; |
| 1149 | |
| 1150 | if (HasCompletedUnloadProcessing()) |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 1151 | return IsClosingPermitted(); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 1152 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1153 | is_attempting_to_close_browser_ = true; |
| 1154 | |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 1155 | if (!TabsNeedBeforeUnloadFired()) |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 1156 | return IsClosingPermitted(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1157 | |
| 1158 | ProcessPendingTabs(); |
| 1159 | return false; |
| 1160 | } |
| 1161 | |
| 1162 | void Browser::OnWindowClosing() { |
| 1163 | if (!ShouldCloseWindow()) |
| 1164 | return; |
| 1165 | |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 1166 | bool exiting = false; |
| 1167 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 1168 | // Application should shutdown on last window close if the user is explicitly |
| 1169 | // trying to quit, or if there is nothing keeping the browser alive (such as |
| 1170 | // AppController on the Mac, or BackgroundContentsService for background |
| 1171 | // pages). |
| 1172 | bool should_quit_if_last_browser = |
| 1173 | browser_shutdown::IsTryingToQuit() || !BrowserList::WillKeepAlive(); |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 1174 | |
| 1175 | if (should_quit_if_last_browser && BrowserList::size() == 1) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1176 | browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 1177 | exiting = true; |
| 1178 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1179 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1180 | // Don't use GetForProfileIfExisting here, we want to force creation of the |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1181 | // session service so that user can restore what was open. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1182 | SessionService* session_service = |
| 1183 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1184 | if (session_service) |
| 1185 | session_service->WindowClosing(session_id()); |
| 1186 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1187 | TabRestoreService* tab_restore_service = |
| 1188 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 1189 | |
| 1190 | #if defined(USE_AURA) |
| 1191 | if (tab_restore_service && is_app()) |
| 1192 | tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
| 1193 | #endif |
| 1194 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1195 | if (tab_restore_service && is_type_tabbed() && tab_count()) |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 1196 | tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 1197 | |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 1198 | // TODO(sky): convert session/tab restore to use notification. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1199 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1200 | chrome::NOTIFICATION_BROWSER_CLOSING, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1201 | content::Source<Browser>(this), |
| 1202 | content::Details<bool>(&exiting)); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 1203 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1204 | CloseAllTabs(); |
| 1205 | } |
| 1206 | |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 1207 | void Browser::OnWindowActivated() { |
| 1208 | // On some platforms we want to automatically reload tabs that are |
| 1209 | // killed when the user selects them. |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1210 | WebContents* contents = GetSelectedWebContents(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1211 | if (contents && contents->GetCrashedStatus() == |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 1212 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 1213 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1214 | switches::kReloadKilledTabs)) { |
| 1215 | Reload(CURRENT_TAB); |
| 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 1220 | //////////////////////////////////////////////////////////////////////////////// |
| 1221 | // In-progress download termination handling: |
| 1222 | |
| 1223 | void Browser::InProgressDownloadResponse(bool cancel_downloads) { |
| 1224 | if (cancel_downloads) { |
| 1225 | cancel_download_confirmation_state_ = RESPONSE_RECEIVED; |
| 1226 | CloseWindow(); |
| 1227 | return; |
| 1228 | } |
| 1229 | |
| 1230 | // Sets the confirmation state to NOT_PROMPTED so that if the user tries to |
| 1231 | // close again we'll show the warning again. |
| 1232 | cancel_download_confirmation_state_ = NOT_PROMPTED; |
| 1233 | |
| 1234 | // Show the download page so the user can figure-out what downloads are still |
| 1235 | // in-progress. |
| 1236 | ShowDownloadsTab(); |
| 1237 | } |
| 1238 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 1239 | Browser::DownloadClosePreventionType Browser::OkToCloseWithInProgressDownloads( |
| 1240 | int* num_downloads_blocking) const { |
| 1241 | DCHECK(num_downloads_blocking); |
| 1242 | *num_downloads_blocking = 0; |
| 1243 | |
| 1244 | if (is_attempting_to_close_browser_) |
| 1245 | return DOWNLOAD_CLOSE_OK; |
| 1246 | |
| 1247 | // If we're not running a full browser process with a profile manager |
| 1248 | // (testing), it's ok to close the browser. |
| 1249 | if (!g_browser_process->profile_manager()) |
| 1250 | return DOWNLOAD_CLOSE_OK; |
| 1251 | |
| 1252 | int total_download_count = DownloadService::DownloadCountAllProfiles(); |
| 1253 | if (total_download_count == 0) |
| 1254 | return DOWNLOAD_CLOSE_OK; // No downloads; can definitely close. |
| 1255 | |
| 1256 | // Figure out how many windows are open total, and associated with this |
| 1257 | // profile, that are relevant for the ok-to-close decision. |
| 1258 | int profile_window_count = 0; |
| 1259 | int total_window_count = 0; |
| 1260 | for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 1261 | iter != BrowserList::end(); ++iter) { |
| 1262 | // Don't count this browser window or any other in the process of closing. |
| 1263 | Browser* const browser = *iter; |
| 1264 | // Check is_attempting_to_close_browser_ as window closing may be |
| 1265 | // delayed, and windows that are in the process of closing don't |
| 1266 | // count against our totals. |
| 1267 | if (browser == this || browser->is_attempting_to_close_browser_) |
| 1268 | continue; |
| 1269 | |
| 1270 | if ((*iter)->profile() == profile()) |
| 1271 | profile_window_count++; |
| 1272 | total_window_count++; |
| 1273 | } |
| 1274 | |
| 1275 | // If there aren't any other windows, we're at browser shutdown, |
| 1276 | // which would cancel all current downloads. |
| 1277 | if (total_window_count == 0) { |
| 1278 | *num_downloads_blocking = total_download_count; |
| 1279 | return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN; |
| 1280 | } |
| 1281 | |
| 1282 | // If there aren't any other windows on our profile, and we're an incognito |
| 1283 | // profile, and there are downloads associated with that profile, |
| 1284 | // those downloads would be cancelled by our window (-> profile) close. |
| 1285 | DownloadService* download_service = |
| 1286 | DownloadServiceFactory::GetForProfile(profile()); |
| 1287 | if (profile_window_count == 0 && download_service->DownloadCount() > 0 && |
| 1288 | profile()->IsOffTheRecord()) { |
| 1289 | *num_downloads_blocking = download_service->DownloadCount(); |
| 1290 | return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE; |
| 1291 | } |
| 1292 | |
| 1293 | // Those are the only conditions under which we will block shutdown. |
| 1294 | return DOWNLOAD_CLOSE_OK; |
| 1295 | } |
| 1296 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 1297 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1298 | // Browser, TabStripModel pass-thrus: |
| 1299 | |
| 1300 | int Browser::tab_count() const { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1301 | return tab_handler_->GetTabStripModel()->count(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1302 | } |
| 1303 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 1304 | int Browser::active_index() const { |
| 1305 | return tab_handler_->GetTabStripModel()->active_index(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | int Browser::GetIndexOfController( |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1309 | const NavigationController* controller) const { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1310 | return tab_handler_->GetTabStripModel()->GetIndexOfController(controller); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1311 | } |
| 1312 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1313 | TabContentsWrapper* Browser::GetSelectedTabContentsWrapper() const { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1314 | return tab_handler_->GetTabStripModel()->GetActiveTabContents(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1315 | } |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1316 | |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1317 | WebContents* Browser::GetSelectedWebContents() const { |
| 1318 | TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); |
| 1319 | return wrapper ? wrapper->web_contents() : NULL; |
| 1320 | } |
| 1321 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1322 | TabContentsWrapper* Browser::GetTabContentsWrapperAt(int index) const { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1323 | return tab_handler_->GetTabStripModel()->GetTabContentsAt(index); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1324 | } |
| 1325 | |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 1326 | WebContents* Browser::GetWebContentsAt(int index) const { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1327 | TabContentsWrapper* wrapper = GetTabContentsWrapperAt(index); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1328 | if (wrapper) |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 1329 | return wrapper->web_contents(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1330 | return NULL; |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1331 | } |
| 1332 | |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1333 | void Browser::ActivateTabAt(int index, bool user_gesture) { |
| 1334 | tab_handler_->GetTabStripModel()->ActivateTabAt(index, user_gesture); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1335 | } |
| 1336 | |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 1337 | bool Browser::IsTabPinned(int index) const { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1338 | return tab_handler_->GetTabStripModel()->IsTabPinned(index); |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 1339 | } |
| 1340 | |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 1341 | bool Browser::IsTabDiscarded(int index) const { |
| 1342 | return tab_handler_->GetTabStripModel()->IsTabDiscarded(index); |
| 1343 | } |
| 1344 | |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1345 | void Browser::CloseAllTabs() { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1346 | tab_handler_->GetTabStripModel()->CloseAllTabs(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1350 | // Browser, Tab adding/showing functions: |
| 1351 | |
[email protected] | 95bf8a5b | 2010-12-22 16:04:07 | [diff] [blame] | 1352 | bool Browser::IsTabStripEditable() const { |
| 1353 | return window()->IsTabStripEditable(); |
| 1354 | } |
| 1355 | |
[email protected] | b334487 | 2010-05-03 15:52:29 | [diff] [blame] | 1356 | int Browser::GetIndexForInsertionDuringRestore(int relative_index) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1357 | return (tab_handler_->GetTabStripModel()->insertion_policy() == |
| 1358 | TabStripModel::INSERT_AFTER) ? tab_count() : relative_index; |
[email protected] | b334487 | 2010-05-03 15:52:29 | [diff] [blame] | 1359 | } |
| 1360 | |
[email protected] | dad09ce4 | 2011-08-25 23:11:30 | [diff] [blame] | 1361 | TabContentsWrapper* Browser::AddSelectedTabWithURL( |
| 1362 | const GURL& url, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1363 | content::PageTransition transition) { |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1364 | browser::NavigateParams params(this, url, transition); |
| 1365 | params.disposition = NEW_FOREGROUND_TAB; |
| 1366 | browser::Navigate(¶ms); |
| 1367 | return params.target_contents; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1368 | } |
| 1369 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1370 | WebContents* Browser::AddTab(TabContentsWrapper* tab_contents, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1371 | content::PageTransition type) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1372 | tab_handler_->GetTabStripModel()->AddTabContents( |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1373 | tab_contents, -1, type, TabStripModel::ADD_ACTIVE); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1374 | return tab_contents->web_contents(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1375 | } |
| 1376 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1377 | void Browser::AddWebContents(WebContents* new_contents, |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 1378 | WindowOpenDisposition disposition, |
| 1379 | const gfx::Rect& initial_pos, |
| 1380 | bool user_gesture) { |
| 1381 | AddNewContents(NULL, new_contents, disposition, initial_pos, user_gesture); |
| 1382 | } |
| 1383 | |
[email protected] | 0ec4898e | 2011-12-30 21:09:24 | [diff] [blame] | 1384 | void Browser::CloseTabContents(WebContents* contents) { |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 1385 | CloseContents(contents); |
| 1386 | } |
| 1387 | |
[email protected] | b86451c | 2011-08-16 02:13:44 | [diff] [blame] | 1388 | gfx::NativeWindow Browser::BrowserShowHtmlDialog( |
[email protected] | 62c1f7a | 2011-10-01 01:12:04 | [diff] [blame] | 1389 | HtmlDialogUIDelegate* delegate, |
[email protected] | 22c830d | 2011-11-29 20:00:37 | [diff] [blame] | 1390 | gfx::NativeWindow parent_window, |
| 1391 | DialogStyle style) { |
[email protected] | 62c1f7a | 2011-10-01 01:12:04 | [diff] [blame] | 1392 | #if defined(OS_CHROMEOS) |
| 1393 | // For Chrome OS, first try to parent the dialog over the current browser -- |
| 1394 | // it's likely to be maximized onscreen. If it isn't tabbed (e.g. it's a |
| 1395 | // panel), find a browser that is. |
| 1396 | parent_window = window_->GetNativeHandle(); |
| 1397 | if (!is_type_tabbed()) { |
| 1398 | Browser* tabbed_browser = BrowserList::FindTabbedBrowser(profile_, true); |
| 1399 | if (tabbed_browser && tabbed_browser->window()) |
| 1400 | parent_window = tabbed_browser->window()->GetNativeHandle(); |
| 1401 | } |
| 1402 | #endif // defined(OS_CHROMEOS) |
| 1403 | if (!parent_window) |
| 1404 | parent_window = window_->GetNativeHandle(); |
| 1405 | |
[email protected] | c5e22aee5 | 2012-01-19 16:10:51 | [diff] [blame] | 1406 | return browser::ShowHtmlDialog(parent_window, |
| 1407 | profile_, |
| 1408 | this, |
| 1409 | delegate, |
| 1410 | style); |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | void Browser::BrowserRenderWidgetShowing() { |
| 1414 | RenderWidgetShowing(); |
| 1415 | } |
| 1416 | |
[email protected] | c9bd2e8 | 2011-04-15 23:28:19 | [diff] [blame] | 1417 | void Browser::BookmarkBarSizeChanged(bool is_animating) { |
| 1418 | window_->ToolbarSizeChanged(is_animating); |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 1419 | } |
| 1420 | |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 1421 | WebContents* Browser::AddRestoredTab( |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1422 | const std::vector<TabNavigation>& navigations, |
| 1423 | int tab_index, |
| 1424 | int selected_navigation, |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 1425 | const std::string& extension_app_id, |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1426 | bool select, |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1427 | bool pin, |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 1428 | bool from_last_session, |
[email protected] | adbfb8df | 2012-02-24 01:19:43 | [diff] [blame] | 1429 | content::SessionStorageNamespace* session_storage_namespace) { |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 1430 | GURL restore_url = navigations.at(selected_navigation).virtual_url(); |
| 1431 | TabContentsWrapper* wrapper = TabContentsFactory( |
| 1432 | profile(), |
| 1433 | tab_util::GetSiteInstanceForNewTab(NULL, profile_, restore_url), |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1434 | MSG_ROUTING_NONE, |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 1435 | GetSelectedWebContents(), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1436 | session_storage_namespace); |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 1437 | WebContents* new_tab = wrapper->web_contents(); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1438 | wrapper->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1439 | std::vector<NavigationEntry*> entries; |
[email protected] | 03838e2 | 2011-06-06 15:27:14 | [diff] [blame] | 1440 | TabNavigation::CreateNavigationEntriesFromTabNavigations( |
| 1441 | profile_, navigations, &entries); |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1442 | new_tab->GetController().Restore( |
[email protected] | 03838e2 | 2011-06-06 15:27:14 | [diff] [blame] | 1443 | selected_navigation, from_last_session, &entries); |
| 1444 | DCHECK_EQ(0u, entries.size()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1445 | |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1446 | int add_types = select ? TabStripModel::ADD_ACTIVE : |
[email protected] | 981b992e | 2011-03-28 21:05:21 | [diff] [blame] | 1447 | TabStripModel::ADD_NONE; |
| 1448 | if (pin) { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1449 | int first_mini_tab_idx = |
| 1450 | tab_handler_->GetTabStripModel()->IndexOfFirstNonMiniTab(); |
| 1451 | tab_index = std::min(tab_index, first_mini_tab_idx); |
[email protected] | 981b992e | 2011-03-28 21:05:21 | [diff] [blame] | 1452 | add_types |= TabStripModel::ADD_PINNED; |
| 1453 | } |
| 1454 | tab_handler_->GetTabStripModel()->InsertTabContentsAt(tab_index, wrapper, |
| 1455 | add_types); |
[email protected] | c93a9dd | 2010-04-22 20:25:18 | [diff] [blame] | 1456 | if (select) { |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 1457 | window_->Activate(); |
[email protected] | c93a9dd | 2010-04-22 20:25:18 | [diff] [blame] | 1458 | } else { |
| 1459 | // We set the size of the view here, before WebKit does its initial |
| 1460 | // layout. If we don't, the initial layout of background tabs will be |
| 1461 | // performed with a view width of 0, which may cause script outputs and |
| 1462 | // anchor link location calculations to be incorrect even after a new |
| 1463 | // layout with proper view dimensions. TabStripModel::AddTabContents() |
| 1464 | // contains similar logic. |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 1465 | new_tab->GetView()->SizeContents(window_->GetRestoredBounds().size()); |
[email protected] | c93a9dd | 2010-04-22 20:25:18 | [diff] [blame] | 1466 | new_tab->HideContents(); |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1467 | new_tab->GetController().LoadIfNecessary(); |
[email protected] | c93a9dd | 2010-04-22 20:25:18 | [diff] [blame] | 1468 | } |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1469 | SessionService* session_service = |
| 1470 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 1471 | if (session_service) |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 1472 | session_service->TabRestored(wrapper, pin); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1473 | return new_tab; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | void Browser::ReplaceRestoredTab( |
| 1477 | const std::vector<TabNavigation>& navigations, |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1478 | int selected_navigation, |
[email protected] | fca656c | 2010-02-10 20:30:10 | [diff] [blame] | 1479 | bool from_last_session, |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 1480 | const std::string& extension_app_id, |
[email protected] | adbfb8df | 2012-02-24 01:19:43 | [diff] [blame] | 1481 | content::SessionStorageNamespace* session_storage_namespace) { |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 1482 | GURL restore_url = navigations.at(selected_navigation).virtual_url(); |
| 1483 | TabContentsWrapper* wrapper = TabContentsFactory( |
| 1484 | profile(), |
| 1485 | tab_util::GetSiteInstanceForNewTab(NULL, profile_, restore_url), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1486 | MSG_ROUTING_NONE, |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 1487 | GetSelectedWebContents(), |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 1488 | session_storage_namespace); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1489 | wrapper->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1490 | WebContents* replacement = wrapper->web_contents(); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1491 | std::vector<NavigationEntry*> entries; |
[email protected] | 03838e2 | 2011-06-06 15:27:14 | [diff] [blame] | 1492 | TabNavigation::CreateNavigationEntriesFromTabNavigations( |
| 1493 | profile_, navigations, &entries); |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1494 | replacement->GetController().Restore( |
[email protected] | 03838e2 | 2011-06-06 15:27:14 | [diff] [blame] | 1495 | selected_navigation, from_last_session, &entries); |
| 1496 | DCHECK_EQ(0u, entries.size()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1497 | |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1498 | tab_handler_->GetTabStripModel()->ReplaceNavigationControllerAt( |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1499 | active_index(), wrapper); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1500 | } |
| 1501 | |
[email protected] | a8eff10 | 2009-04-14 15:23:43 | [diff] [blame] | 1502 | bool Browser::CanRestoreTab() { |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 1503 | return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB); |
[email protected] | a8eff10 | 2009-04-14 15:23:43 | [diff] [blame] | 1504 | } |
| 1505 | |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1506 | bool Browser::NavigateToIndexWithDisposition(int index, |
| 1507 | WindowOpenDisposition disp) { |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1508 | NavigationController& controller = |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1509 | GetOrCloneTabForDisposition(disp)->GetController(); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 1510 | if (index < 0 || index >= controller.GetEntryCount()) |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1511 | return false; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1512 | controller.GoToIndex(index); |
| 1513 | return true; |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1514 | } |
| 1515 | |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1516 | browser::NavigateParams Browser::GetSingletonTabNavigateParams( |
| 1517 | const GURL& url) { |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1518 | browser::NavigateParams params( |
| 1519 | this, url, content::PAGE_TRANSITION_AUTO_BOOKMARK); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1520 | params.disposition = SINGLETON_TAB; |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 1521 | params.window_action = browser::NavigateParams::SHOW_WINDOW; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 1522 | params.user_gesture = true; |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1523 | return params; |
| 1524 | } |
| 1525 | |
| 1526 | void Browser::ShowSingletonTab(const GURL& url) { |
| 1527 | browser::NavigateParams params(GetSingletonTabNavigateParams(url)); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1528 | browser::Navigate(¶ms); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1529 | } |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 1530 | |
[email protected] | 578c696 | 2011-08-24 22:06:40 | [diff] [blame] | 1531 | void Browser::ShowSingletonTabRespectRef(const GURL& url) { |
| 1532 | browser::NavigateParams params(GetSingletonTabNavigateParams(url)); |
| 1533 | params.ref_behavior = browser::NavigateParams::RESPECT_REF; |
| 1534 | browser::Navigate(¶ms); |
| 1535 | } |
| 1536 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1537 | void Browser::ShowSingletonTabOverwritingNTP( |
| 1538 | const browser::NavigateParams& params) { |
| 1539 | browser::NavigateParams local_params(params); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1540 | WebContents* contents = GetSelectedWebContents(); |
[email protected] | 842a648c | 2011-07-20 23:23:16 | [diff] [blame] | 1541 | if (contents) { |
| 1542 | const GURL& contents_url = contents->GetURL(); |
| 1543 | if ((contents_url == GURL(chrome::kChromeUINewTabURL) || |
| 1544 | contents_url == GURL(chrome::kAboutBlankURL)) && |
| 1545 | browser::GetIndexOfSingletonTab(&local_params) < 0) { |
| 1546 | local_params.disposition = CURRENT_TAB; |
| 1547 | } |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | browser::Navigate(&local_params); |
| 1551 | } |
| 1552 | |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 1553 | void Browser::WindowFullscreenStateChanged() { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1554 | fullscreen_controller_->WindowFullscreenStateChanged(); |
[email protected] | 9adb8b1 | 2011-12-09 06:49:13 | [diff] [blame] | 1555 | UpdateCommandsForFullscreenMode(window_->IsFullscreen()); |
| 1556 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1557 | } |
| 1558 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1559 | /////////////////////////////////////////////////////////////////////////////// |
| 1560 | // Browser, Assorted browser commands: |
| 1561 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1562 | WebContents* Browser::GetOrCloneTabForDisposition( |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1563 | WindowOpenDisposition disposition) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1564 | TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
[email protected] | bbafdc7 | 2011-07-06 22:27:17 | [diff] [blame] | 1565 | switch (disposition) { |
| 1566 | case NEW_FOREGROUND_TAB: |
| 1567 | case NEW_BACKGROUND_TAB: { |
| 1568 | current_tab = current_tab->Clone(); |
| 1569 | tab_handler_->GetTabStripModel()->AddTabContents( |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1570 | current_tab, -1, content::PAGE_TRANSITION_LINK, |
[email protected] | bbafdc7 | 2011-07-06 22:27:17 | [diff] [blame] | 1571 | disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE : |
| 1572 | TabStripModel::ADD_NONE); |
| 1573 | break; |
| 1574 | } |
| 1575 | case NEW_WINDOW: { |
| 1576 | current_tab = current_tab->Clone(); |
| 1577 | Browser* browser = Browser::Create(profile_); |
| 1578 | browser->tabstrip_model()->AddTabContents( |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1579 | current_tab, -1, content::PAGE_TRANSITION_LINK, |
| 1580 | TabStripModel::ADD_ACTIVE); |
[email protected] | bbafdc7 | 2011-07-06 22:27:17 | [diff] [blame] | 1581 | browser->window()->Show(); |
| 1582 | break; |
| 1583 | } |
| 1584 | default: |
| 1585 | break; |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1586 | } |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1587 | return current_tab->web_contents(); |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1588 | } |
| 1589 | |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1590 | bool Browser::SupportsWindowFeatureImpl(WindowFeature feature, |
| 1591 | bool check_fullscreen) const { |
| 1592 | // On Mac, fullscreen mode has most normal things (in a slide-down panel). On |
| 1593 | // other platforms, we hide some controls when in fullscreen mode. |
| 1594 | bool hide_ui_for_fullscreen = false; |
| 1595 | #if !defined(OS_MACOSX) |
| 1596 | hide_ui_for_fullscreen = check_fullscreen && window_ && |
| 1597 | window_->IsFullscreen(); |
| 1598 | #endif |
| 1599 | |
[email protected] | 3a80ea33 | 2012-01-09 19:53:29 | [diff] [blame] | 1600 | unsigned int features = FEATURE_INFOBAR; |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1601 | |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 1602 | #if !defined(OS_CHROMEOS) || defined(USE_AURA) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1603 | // Chrome OS opens a FileBrowse pop up instead of using download shelf. |
| 1604 | // So FEATURE_DOWNLOADSHELF is only added for non-chromeos platforms. |
| 1605 | features |= FEATURE_DOWNLOADSHELF; |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 1606 | #endif // !defined(OS_CHROMEOS) || defined(USE_AURA) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1607 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1608 | if (is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1609 | features |= FEATURE_BOOKMARKBAR; |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1610 | |
| 1611 | if (!hide_ui_for_fullscreen) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1612 | if (!is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1613 | features |= FEATURE_TITLEBAR; |
| 1614 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1615 | if (is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1616 | features |= FEATURE_TABSTRIP; |
| 1617 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1618 | if (is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1619 | features |= FEATURE_TOOLBAR; |
| 1620 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1621 | if (!is_app()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1622 | features |= FEATURE_LOCATIONBAR; |
| 1623 | } |
| 1624 | return !!(features & feature); |
| 1625 | } |
| 1626 | |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 1627 | bool Browser::IsClosingPermitted() { |
| 1628 | TabCloseableStateWatcher* watcher = |
| 1629 | g_browser_process->tab_closeable_state_watcher(); |
| 1630 | bool can_close = !watcher || watcher->CanCloseBrowser(this); |
| 1631 | if (!can_close && is_attempting_to_close_browser_) |
| 1632 | CancelWindowClose(); |
| 1633 | return can_close; |
| 1634 | } |
| 1635 | |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1636 | bool Browser::CanGoBack() const { |
[email protected] | 3c790d2 | 2012-01-30 19:06:35 | [diff] [blame] | 1637 | return GetSelectedWebContents()->GetController().CanGoBack(); |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1638 | } |
| 1639 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1640 | void Browser::GoBack(WindowOpenDisposition disposition) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1641 | content::RecordAction(UserMetricsAction("Back")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1642 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1643 | TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1644 | if (CanGoBack()) { |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1645 | WebContents* new_tab = GetOrCloneTabForDisposition(disposition); |
[email protected] | d497b078 | 2010-03-29 19:19:06 | [diff] [blame] | 1646 | // If we are on an interstitial page and clone the tab, it won't be copied |
| 1647 | // to the new tab, so we don't need to go back. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1648 | if (current_tab->web_contents()->ShowingInterstitialPage() && |
| 1649 | (new_tab != current_tab->web_contents())) |
[email protected] | d497b078 | 2010-03-29 19:19:06 | [diff] [blame] | 1650 | return; |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1651 | new_tab->GetController().GoBack(); |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1652 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1653 | } |
| 1654 | |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1655 | bool Browser::CanGoForward() const { |
[email protected] | 3c790d2 | 2012-01-30 19:06:35 | [diff] [blame] | 1656 | return GetSelectedWebContents()->GetController().CanGoForward(); |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1657 | } |
| 1658 | |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1659 | void Browser::GoForward(WindowOpenDisposition disposition) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1660 | content::RecordAction(UserMetricsAction("Forward")); |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1661 | if (CanGoForward()) |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1662 | GetOrCloneTabForDisposition(disposition)->GetController().GoForward(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1663 | } |
| 1664 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1665 | void Browser::Reload(WindowOpenDisposition disposition) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1666 | content::RecordAction(UserMetricsAction("Reload")); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1667 | ReloadInternal(disposition, false); |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 1668 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1669 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1670 | void Browser::ReloadIgnoringCache(WindowOpenDisposition disposition) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1671 | content::RecordAction(UserMetricsAction("ReloadIgnoringCache")); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1672 | ReloadInternal(disposition, true); |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 1673 | } |
| 1674 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1675 | void Browser::ReloadInternal(WindowOpenDisposition disposition, |
| 1676 | bool ignore_cache) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1677 | // If we are showing an interstitial, treat this as an OpenURL. |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1678 | WebContents* current_tab = GetSelectedWebContents(); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1679 | if (current_tab && current_tab->ShowingInterstitialPage()) { |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1680 | NavigationEntry* entry = current_tab->GetController().GetActiveEntry(); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1681 | DCHECK(entry); // Should exist if interstitial is showing. |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1682 | OpenURL(OpenURLParams( |
| 1683 | entry->GetURL(), Referrer(), disposition, |
| 1684 | content::PAGE_TRANSITION_RELOAD, false)); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1685 | return; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1686 | } |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1687 | |
| 1688 | // As this is caused by a user action, give the focus to the page. |
[email protected] | 6e3953dd | 2012-01-27 10:24:37 | [diff] [blame] | 1689 | // |
| 1690 | // Also notify RenderViewHostDelegate of the user gesture; this is |
| 1691 | // normally done in Browser::Navigate, but a reload bypasses Navigate. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1692 | WebContents* tab = GetOrCloneTabForDisposition(disposition); |
[email protected] | 6e3953dd | 2012-01-27 10:24:37 | [diff] [blame] | 1693 | tab->GetRenderViewHost()->delegate()->OnUserGesture(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1694 | if (!tab->FocusLocationBarByDefault()) |
| 1695 | tab->Focus(); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1696 | if (ignore_cache) |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1697 | tab->GetController().ReloadIgnoringCache(true); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1698 | else |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1699 | tab->GetController().Reload(true); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1700 | } |
| 1701 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1702 | void Browser::Home(WindowOpenDisposition disposition) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1703 | content::RecordAction(UserMetricsAction("Home")); |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1704 | OpenURL(OpenURLParams( |
| 1705 | profile_->GetHomePage(), Referrer(), disposition, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1706 | content::PageTransitionFromInt( |
| 1707 | content::PAGE_TRANSITION_AUTO_BOOKMARK | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1708 | content::PAGE_TRANSITION_HOME_PAGE), |
| 1709 | false)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1710 | } |
| 1711 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1712 | void Browser::OpenCurrentURL() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1713 | content::RecordAction(UserMetricsAction("LoadURL")); |
[email protected] | 7745b82 | 2009-01-27 20:15:35 | [diff] [blame] | 1714 | LocationBar* location_bar = window_->GetLocationBar(); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 1715 | if (!location_bar) |
| 1716 | return; |
| 1717 | |
[email protected] | 9d0306ea | 2009-09-02 19:38:39 | [diff] [blame] | 1718 | WindowOpenDisposition open_disposition = |
| 1719 | location_bar->GetWindowOpenDisposition(); |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 1720 | if (OpenInstant(open_disposition)) |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 1721 | return; |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 1722 | |
[email protected] | 537de68 | 2011-08-08 18:10:14 | [diff] [blame] | 1723 | GURL url(location_bar->GetInputString()); |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 1724 | |
| 1725 | if (open_disposition == CURRENT_TAB && TabFinder::IsEnabled()) { |
| 1726 | Browser* existing_browser = NULL; |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1727 | WebContents* existing_tab = TabFinder::GetInstance()->FindTab( |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 1728 | this, url, &existing_browser); |
| 1729 | if (existing_tab) { |
| 1730 | existing_browser->ActivateContents(existing_tab); |
| 1731 | return; |
| 1732 | } |
| 1733 | } |
| 1734 | |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1735 | browser::NavigateParams params(this, url, location_bar->GetPageTransition()); |
| 1736 | params.disposition = open_disposition; |
[email protected] | 514576a | 2010-07-01 22:51:25 | [diff] [blame] | 1737 | // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least |
| 1738 | // inherit the opener. In some cases the tabstrip will determine the group |
| 1739 | // should be inherited, in which case the group is inherited instead of the |
| 1740 | // opener. |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1741 | params.tabstrip_add_types = |
| 1742 | TabStripModel::ADD_FORCE_INDEX | TabStripModel::ADD_INHERIT_OPENER; |
| 1743 | browser::Navigate(¶ms); |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 1744 | |
[email protected] | 6e37fe3 | 2011-03-02 09:06:52 | [diff] [blame] | 1745 | DCHECK(profile_->GetExtensionService()); |
| 1746 | if (profile_->GetExtensionService()->IsInstalledApp(url)) { |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 1747 | UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, |
| 1748 | extension_misc::APP_LAUNCH_OMNIBOX_LOCATION, |
| 1749 | extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 1750 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1751 | } |
| 1752 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1753 | void Browser::Stop() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1754 | content::RecordAction(UserMetricsAction("Stop")); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1755 | GetSelectedWebContents()->Stop(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | void Browser::NewWindow() { |
[email protected] | eddcf750 | 2012-02-09 22:43:48 | [diff] [blame] | 1759 | NewEmptyWindow(profile_->GetOriginalProfile()); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | void Browser::NewIncognitoWindow() { |
[email protected] | eddcf750 | 2012-02-09 22:43:48 | [diff] [blame] | 1763 | NewEmptyWindow(profile_->GetOffTheRecordProfile()); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1764 | } |
| 1765 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1766 | void Browser::CloseWindow() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1767 | content::RecordAction(UserMetricsAction("CloseWindow")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1768 | window_->Close(); |
| 1769 | } |
| 1770 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1771 | void Browser::NewTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1772 | content::RecordAction(UserMetricsAction("NewTab")); |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 1773 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1774 | if (is_type_tabbed()) { |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1775 | AddBlankTab(true); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1776 | GetSelectedWebContents()->GetView()->RestoreFocus(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1777 | } else { |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 1778 | Browser* b = GetOrCreateTabbedBrowser(profile_); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1779 | b->AddBlankTab(true); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1780 | b->window()->Show(); |
[email protected] | e54f30d | 2009-01-14 21:17:11 | [diff] [blame] | 1781 | // The call to AddBlankTab above did not set the focus to the tab as its |
| 1782 | // window was not active, so we have to do it explicitly. |
| 1783 | // See http://crbug.com/6380. |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1784 | b->GetSelectedWebContents()->GetView()->RestoreFocus(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | void Browser::CloseTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1789 | content::RecordAction(UserMetricsAction("CloseTab_Accelerator")); |
[email protected] | 90b1a7a | 2011-03-17 21:28:21 | [diff] [blame] | 1790 | if (CanCloseTab()) |
| 1791 | tab_handler_->GetTabStripModel()->CloseSelectedTabs(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1792 | } |
| 1793 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1794 | void Browser::SelectNextTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1795 | content::RecordAction(UserMetricsAction("SelectNextTab")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1796 | tab_handler_->GetTabStripModel()->SelectNextTab(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | void Browser::SelectPreviousTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1800 | content::RecordAction(UserMetricsAction("SelectPrevTab")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1801 | tab_handler_->GetTabStripModel()->SelectPreviousTab(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1802 | } |
| 1803 | |
[email protected] | 91ac920 | 2010-07-30 18:32:35 | [diff] [blame] | 1804 | void Browser::OpenTabpose() { |
| 1805 | #if defined(OS_MACOSX) |
[email protected] | aac169d | 2011-03-18 19:53:03 | [diff] [blame] | 1806 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 1807 | switches::kEnableExposeForTabs)) { |
| 1808 | return; |
| 1809 | } |
| 1810 | |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1811 | content::RecordAction(UserMetricsAction("OpenTabpose")); |
[email protected] | 91ac920 | 2010-07-30 18:32:35 | [diff] [blame] | 1812 | window()->OpenTabpose(); |
| 1813 | #else |
| 1814 | NOTREACHED(); |
| 1815 | #endif |
| 1816 | } |
| 1817 | |
[email protected] | 9ac7fcb | 2009-09-14 18:22:52 | [diff] [blame] | 1818 | void Browser::MoveTabNext() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1819 | content::RecordAction(UserMetricsAction("MoveTabNext")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1820 | tab_handler_->GetTabStripModel()->MoveTabNext(); |
[email protected] | 9ac7fcb | 2009-09-14 18:22:52 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | void Browser::MoveTabPrevious() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1824 | content::RecordAction(UserMetricsAction("MoveTabPrevious")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1825 | tab_handler_->GetTabStripModel()->MoveTabPrevious(); |
[email protected] | 9ac7fcb | 2009-09-14 18:22:52 | [diff] [blame] | 1826 | } |
| 1827 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1828 | void Browser::SelectNumberedTab(int index) { |
| 1829 | if (index < tab_count()) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1830 | content::RecordAction(UserMetricsAction("SelectNumberedTab")); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1831 | ActivateTabAt(index, true); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | |
| 1835 | void Browser::SelectLastTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1836 | content::RecordAction(UserMetricsAction("SelectLastTab")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1837 | tab_handler_->GetTabStripModel()->SelectLastTab(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | void Browser::DuplicateTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1841 | content::RecordAction(UserMetricsAction("Duplicate")); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 1842 | DuplicateContentsAt(active_index()); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | void Browser::RestoreTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1846 | content::RecordAction(UserMetricsAction("RestoreTab")); |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1847 | TabRestoreService* service = |
| 1848 | TabRestoreServiceFactory::GetForProfile(profile_); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1849 | if (!service) |
| 1850 | return; |
| 1851 | |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 1852 | service->RestoreMostRecentEntry(tab_restore_service_delegate()); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1853 | } |
| 1854 | |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1855 | void Browser::WriteCurrentURLToClipboard() { |
| 1856 | // TODO(ericu): There isn't currently a metric for this. Should there be? |
| 1857 | // We don't appear to track the action when it comes from the |
| 1858 | // RenderContextViewMenu. |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1859 | |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1860 | WebContents* contents = GetSelectedWebContents(); |
[email protected] | cd8d90db | 2011-10-06 19:31:27 | [diff] [blame] | 1861 | if (!toolbar_model_.ShouldDisplayURL()) |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1862 | return; |
| 1863 | |
[email protected] | 90f3990 | 2009-10-03 04:25:37 | [diff] [blame] | 1864 | chrome_browser_net::WriteURLToClipboard( |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1865 | contents->GetURL(), |
[email protected] | 9f284f13 | 2010-08-31 06:14:17 | [diff] [blame] | 1866 | profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1867 | g_browser_process->clipboard()); |
| 1868 | } |
| 1869 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1870 | void Browser::ConvertPopupToTabbedBrowser() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1871 | content::RecordAction(UserMetricsAction("ShowAsTab")); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1872 | TabContentsWrapper* contents = |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1873 | tab_handler_->GetTabStripModel()->DetachTabContentsAt(active_index()); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1874 | Browser* browser = Browser::Create(profile_); |
| 1875 | browser->tabstrip_model()->AppendTabContents(contents, true); |
| 1876 | browser->window()->Show(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1877 | } |
| 1878 | |
[email protected] | 184717d5 | 2012-02-22 04:46:16 | [diff] [blame] | 1879 | void Browser::ToggleFullscreenMode() { |
| 1880 | fullscreen_controller_->ToggleFullscreenMode(); |
| 1881 | } |
| 1882 | |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame^] | 1883 | void Browser::ToggleFullscreenModeWithExtension(const GURL& extension_url) { |
| 1884 | fullscreen_controller_->ToggleFullscreenModeWithExtension(extension_url); |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 1885 | } |
| 1886 | |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 1887 | #if defined(OS_MACOSX) |
[email protected] | 184717d5 | 2012-02-22 04:46:16 | [diff] [blame] | 1888 | void Browser::TogglePresentationMode() { |
| 1889 | fullscreen_controller_->TogglePresentationMode(); |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 1890 | } |
| 1891 | #endif |
| 1892 | |
[email protected] | da17b37 | 2010-01-22 23:37:22 | [diff] [blame] | 1893 | #if defined(OS_CHROMEOS) |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 1894 | void Browser::Search() { |
[email protected] | 6455986 | 2010-09-23 19:00:16 | [diff] [blame] | 1895 | // Exit fullscreen to show omnibox. |
[email protected] | ebdda909 | 2010-10-22 17:59:10 | [diff] [blame] | 1896 | if (window_->IsFullscreen()) { |
[email protected] | 184717d5 | 2012-02-22 04:46:16 | [diff] [blame] | 1897 | ToggleFullscreenMode(); |
[email protected] | ebdda909 | 2010-10-22 17:59:10 | [diff] [blame] | 1898 | // ToggleFullscreenMode is asynchronous, so we don't have omnibox |
| 1899 | // visible at this point. Wait for next event cycle which toggles |
| 1900 | // the visibility of omnibox before creating new tab. |
| 1901 | MessageLoop::current()->PostTask( |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1902 | FROM_HERE, base::Bind(&Browser::Search, weak_factory_.GetWeakPtr())); |
[email protected] | ebdda909 | 2010-10-22 17:59:10 | [diff] [blame] | 1903 | return; |
| 1904 | } |
[email protected] | 6455986 | 2010-09-23 19:00:16 | [diff] [blame] | 1905 | |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1906 | const GURL& url = GetSelectedWebContents()->GetURL(); |
[email protected] | 0080c4f | 2011-10-03 21:56:37 | [diff] [blame] | 1907 | if (url.SchemeIs(chrome::kChromeUIScheme) && |
| 1908 | url.host() == chrome::kChromeUINewTabHost) { |
| 1909 | // If the NTP is showing, focus the omnibox. |
| 1910 | window_->SetFocusToLocationBar(true); |
| 1911 | } else { |
| 1912 | // Otherwise, open the NTP. |
| 1913 | NewTab(); |
| 1914 | } |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 1915 | } |
[email protected] | d14af52 | 2010-12-02 03:54:50 | [diff] [blame] | 1916 | |
| 1917 | void Browser::ShowKeyboardOverlay() { |
| 1918 | window_->ShowKeyboardOverlay(window_->GetNativeHandle()); |
| 1919 | } |
[email protected] | 20d1724 | 2009-10-26 20:21:05 | [diff] [blame] | 1920 | #endif |
| 1921 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1922 | void Browser::Exit() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1923 | content::RecordAction(UserMetricsAction("Exit")); |
[email protected] | b8b6008 | 2011-12-13 14:16:02 | [diff] [blame] | 1924 | BrowserList::AttemptUserExit(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1925 | } |
| 1926 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1927 | void Browser::BookmarkCurrentPage() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1928 | content::RecordAction(UserMetricsAction("Star")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1929 | |
[email protected] | 76624fde | 2009-10-09 18:13:23 | [diff] [blame] | 1930 | BookmarkModel* model = profile()->GetBookmarkModel(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1931 | if (!model || !model->IsLoaded()) |
| 1932 | return; // Ignore requests until bookmarks are loaded. |
| 1933 | |
[email protected] | 76624fde | 2009-10-09 18:13:23 | [diff] [blame] | 1934 | GURL url; |
[email protected] | 261cd76 | 2010-08-20 05:45:37 | [diff] [blame] | 1935 | string16 title; |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1936 | TabContentsWrapper* tab = GetSelectedTabContentsWrapper(); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1937 | bookmark_utils::GetURLAndTitleToBookmark(tab->web_contents(), &url, &title); |
[email protected] | c50d0d4 | 2009-03-03 17:37:44 | [diff] [blame] | 1938 | bool was_bookmarked = model->IsBookmarked(url); |
[email protected] | ef0d04c | 2010-12-15 23:34:21 | [diff] [blame] | 1939 | if (!was_bookmarked && profile_->IsOffTheRecord()) { |
[email protected] | 2c910b7 | 2011-03-08 21:16:32 | [diff] [blame] | 1940 | // If we're incognito the favicon may not have been saved. Save it now |
[email protected] | ef0d04c | 2010-12-15 23:34:21 | [diff] [blame] | 1941 | // so that bookmarks have an icon for the page. |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1942 | tab->favicon_tab_helper()->SaveFavicon(); |
[email protected] | ef0d04c | 2010-12-15 23:34:21 | [diff] [blame] | 1943 | } |
[email protected] | 4394f2b | 2011-09-03 03:07:56 | [diff] [blame] | 1944 | bookmark_utils::AddIfNotBookmarked(model, url, title); |
[email protected] | 11dbbd2 | 2009-11-06 18:55:04 | [diff] [blame] | 1945 | // Make sure the model actually added a bookmark before showing the star. A |
| 1946 | // bookmark isn't created if the url is invalid. |
| 1947 | if (window_->IsActive() && model->IsBookmarked(url)) { |
[email protected] | 5f2731c5 | 2009-02-28 00:41:27 | [diff] [blame] | 1948 | // Only show the bubble if the window is active, otherwise we may get into |
| 1949 | // weird situations were the bubble is deleted as soon as it is shown. |
[email protected] | c50d0d4 | 2009-03-03 17:37:44 | [diff] [blame] | 1950 | window_->ShowBookmarkBubble(url, was_bookmarked); |
[email protected] | 5f2731c5 | 2009-02-28 00:41:27 | [diff] [blame] | 1951 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1952 | } |
| 1953 | |
[email protected] | 40bdb6d9 | 2009-02-25 00:22:27 | [diff] [blame] | 1954 | void Browser::SavePage() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1955 | content::RecordAction(UserMetricsAction("SavePage")); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1956 | WebContents* current_tab = GetSelectedWebContents(); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1957 | if (current_tab && current_tab->GetContentsMimeType() == "application/pdf") |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1958 | content::RecordAction(UserMetricsAction("PDF.SavePage")); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1959 | GetSelectedWebContents()->OnSavePage(); |
[email protected] | 40bdb6d9 | 2009-02-25 00:22:27 | [diff] [blame] | 1960 | } |
| 1961 | |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 1962 | void Browser::ViewSelectedSource() { |
| 1963 | ViewSource(GetSelectedTabContentsWrapper()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1964 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1965 | |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1966 | void Browser::ShowFindBar() { |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 1967 | GetFindBarController()->Show(); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1968 | } |
| 1969 | |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 1970 | bool Browser::SupportsWindowFeature(WindowFeature feature) const { |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1971 | return SupportsWindowFeatureImpl(feature, true); |
| 1972 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1973 | |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1974 | bool Browser::CanSupportWindowFeature(WindowFeature feature) const { |
| 1975 | return SupportsWindowFeatureImpl(feature, false); |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 1976 | } |
| 1977 | |
[email protected] | 89d6e6e | 2009-12-03 23:06:51 | [diff] [blame] | 1978 | void Browser::EmailPageLocation() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1979 | content::RecordAction(UserMetricsAction("EmailPageLocation")); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1980 | WebContents* wc = GetSelectedWebContents(); |
| 1981 | DCHECK(wc); |
[email protected] | d221a39 | 2011-05-24 14:34:24 | [diff] [blame] | 1982 | |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 1983 | std::string title = net::EscapeQueryParamValue( |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1984 | UTF16ToUTF8(wc->GetTitle()), false); |
| 1985 | std::string page_url = net::EscapeQueryParamValue(wc->GetURL().spec(), false); |
[email protected] | d221a39 | 2011-05-24 14:34:24 | [diff] [blame] | 1986 | std::string mailto = std::string("mailto:?subject=Fwd:%20") + |
| 1987 | title + "&body=%0A%0A" + page_url; |
| 1988 | platform_util::OpenExternal(GURL(mailto)); |
[email protected] | 89d6e6e | 2009-12-03 23:06:51 | [diff] [blame] | 1989 | } |
| 1990 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1991 | void Browser::Print() { |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 1992 | if (g_browser_process->local_state()->GetBoolean( |
| 1993 | prefs::kPrintPreviewDisabled)) { |
[email protected] | 49fe226 | 2011-04-15 20:56:15 | [diff] [blame] | 1994 | GetSelectedTabContentsWrapper()->print_view_manager()->PrintNow(); |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 1995 | } else { |
| 1996 | GetSelectedTabContentsWrapper()->print_view_manager()->PrintPreviewNow(); |
| 1997 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1998 | } |
| 1999 | |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 2000 | void Browser::AdvancedPrint() { |
| 2001 | GetSelectedTabContentsWrapper()->print_view_manager()->AdvancedPrintNow(); |
| 2002 | } |
| 2003 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2004 | void Browser::ToggleEncodingAutoDetect() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2005 | content::RecordAction(UserMetricsAction("AutoDetectChange")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2006 | encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 2007 | // If "auto detect" is turned on, then any current override encoding |
| 2008 | // is cleared. This also implicitly performs a reload. |
| 2009 | // OTOH, if "auto detect" is turned off, we don't change the currently |
| 2010 | // active encoding. |
| 2011 | if (encoding_auto_detect_.GetValue()) { |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 2012 | WebContents* contents = GetSelectedWebContents(); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 2013 | if (contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 2014 | contents->ResetOverrideEncoding(); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 2015 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | void Browser::OverrideEncoding(int encoding_id) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2019 | content::RecordAction(UserMetricsAction("OverrideEncoding")); |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 2020 | const std::string selected_encoding = |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2021 | CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 2022 | WebContents* contents = GetSelectedWebContents(); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2023 | if (!selected_encoding.empty() && contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 2024 | contents->SetOverrideEncoding(selected_encoding); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2025 | // Update the list of recently selected encodings. |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 2026 | std::string new_selected_encoding_list; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2027 | if (CharacterEncoding::UpdateRecentlySelectedEncoding( |
| 2028 | profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding), |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 2029 | encoding_id, |
| 2030 | &new_selected_encoding_list)) { |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2031 | profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2032 | new_selected_encoding_list); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2033 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2034 | } |
| 2035 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2036 | void Browser::Cut() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2037 | content::RecordAction(UserMetricsAction("Cut")); |
[email protected] | 20012dd4 | 2010-01-25 04:46:23 | [diff] [blame] | 2038 | window()->Cut(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2039 | } |
| 2040 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2041 | void Browser::Copy() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2042 | content::RecordAction(UserMetricsAction("Copy")); |
[email protected] | 20012dd4 | 2010-01-25 04:46:23 | [diff] [blame] | 2043 | window()->Copy(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2044 | } |
| 2045 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2046 | void Browser::Paste() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2047 | content::RecordAction(UserMetricsAction("Paste")); |
[email protected] | 20012dd4 | 2010-01-25 04:46:23 | [diff] [blame] | 2048 | window()->Paste(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | void Browser::Find() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2052 | content::RecordAction(UserMetricsAction("Find")); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2053 | FindInPage(false, false); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | void Browser::FindNext() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2057 | content::RecordAction(UserMetricsAction("FindNext")); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2058 | FindInPage(true, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | void Browser::FindPrevious() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2062 | content::RecordAction(UserMetricsAction("FindPrevious")); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2063 | FindInPage(true, false); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2064 | } |
| 2065 | |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 2066 | void Browser::Zoom(content::PageZoom zoom) { |
[email protected] | 0bffaa32 | 2011-07-18 17:37:54 | [diff] [blame] | 2067 | if (is_devtools()) |
| 2068 | return; |
| 2069 | |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 2070 | RenderViewHost* host = GetSelectedWebContents()->GetRenderViewHost(); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 2071 | if (zoom == content::PAGE_ZOOM_RESET) { |
| 2072 | host->SetZoomLevel(0); |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2073 | content::RecordAction(UserMetricsAction("ZoomNormal")); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 2074 | return; |
| 2075 | } |
[email protected] | 89622004 | 2010-03-23 18:14:28 | [diff] [blame] | 2076 | |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 2077 | double current_zoom_level = GetSelectedWebContents()->GetZoomLevel(); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 2078 | double default_zoom_level = |
| 2079 | profile_->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); |
| 2080 | |
| 2081 | // Generate a vector of zoom levels from an array of known presets along with |
| 2082 | // the default level added if necessary. |
| 2083 | std::vector<double> zoom_levels = |
| 2084 | chrome_page_zoom::PresetZoomLevels(default_zoom_level); |
| 2085 | |
| 2086 | if (zoom == content::PAGE_ZOOM_OUT) { |
| 2087 | // Iterate through the zoom levels in reverse order to find the next |
| 2088 | // lower level based on the current zoom level for this page. |
| 2089 | for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); |
| 2090 | i != zoom_levels.rend(); ++i) { |
| 2091 | double zoom_level = *i; |
| 2092 | if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
| 2093 | continue; |
| 2094 | if (zoom_level < current_zoom_level) { |
| 2095 | host->SetZoomLevel(zoom_level); |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2096 | content::RecordAction(UserMetricsAction("ZoomMinus")); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 2097 | return; |
| 2098 | } |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2099 | content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 2100 | } |
| 2101 | } else { |
| 2102 | // Iterate through the zoom levels in normal order to find the next |
| 2103 | // higher level based on the current zoom level for this page. |
| 2104 | for (std::vector<double>::const_iterator i = zoom_levels.begin(); |
| 2105 | i != zoom_levels.end(); ++i) { |
| 2106 | double zoom_level = *i; |
| 2107 | if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
| 2108 | continue; |
| 2109 | if (zoom_level > current_zoom_level) { |
| 2110 | host->SetZoomLevel(zoom_level); |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2111 | content::RecordAction(UserMetricsAction("ZoomPlus")); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 2112 | return; |
| 2113 | } |
| 2114 | } |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2115 | content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 2116 | } |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | void Browser::FocusToolbar() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2120 | content::RecordAction(UserMetricsAction("FocusToolbar")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2121 | window_->FocusToolbar(); |
| 2122 | } |
| 2123 | |
[email protected] | bdb7ff6 | 2010-07-20 01:56:52 | [diff] [blame] | 2124 | void Browser::FocusAppMenu() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2125 | content::RecordAction(UserMetricsAction("FocusAppMenu")); |
[email protected] | bdb7ff6 | 2010-07-20 01:56:52 | [diff] [blame] | 2126 | window_->FocusAppMenu(); |
[email protected] | cc82437 | 2010-03-31 15:33:01 | [diff] [blame] | 2127 | } |
| 2128 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2129 | void Browser::FocusLocationBar() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2130 | content::RecordAction(UserMetricsAction("FocusLocation")); |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 2131 | window_->SetFocusToLocationBar(true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2132 | } |
| 2133 | |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2134 | void Browser::FocusBookmarksToolbar() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2135 | content::RecordAction(UserMetricsAction("FocusBookmarksToolbar")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2136 | window_->FocusBookmarksToolbar(); |
| 2137 | } |
| 2138 | |
| 2139 | void Browser::FocusChromeOSStatus() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2140 | content::RecordAction(UserMetricsAction("FocusChromeOSStatus")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2141 | window_->FocusChromeOSStatus(); |
| 2142 | } |
| 2143 | |
| 2144 | void Browser::FocusNextPane() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2145 | content::RecordAction(UserMetricsAction("FocusNextPane")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2146 | window_->RotatePaneFocus(true); |
| 2147 | } |
| 2148 | |
| 2149 | void Browser::FocusPreviousPane() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2150 | content::RecordAction(UserMetricsAction("FocusPreviousPane")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2151 | window_->RotatePaneFocus(false); |
| 2152 | } |
| 2153 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2154 | void Browser::FocusSearch() { |
| 2155 | // TODO(beng): replace this with FocusLocationBar |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2156 | content::RecordAction(UserMetricsAction("FocusSearch")); |
[email protected] | 7745b82 | 2009-01-27 20:15:35 | [diff] [blame] | 2157 | window_->GetLocationBar()->FocusSearch(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | void Browser::OpenFile() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2161 | content::RecordAction(UserMetricsAction("OpenFile")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2162 | if (!select_file_dialog_.get()) |
| 2163 | select_file_dialog_ = SelectFileDialog::Create(this); |
| 2164 | |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 2165 | const FilePath directory = profile_->last_selected_directory(); |
| 2166 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2167 | // TODO(beng): figure out how to juggle this. |
[email protected] | d56bcd2 | 2009-03-16 19:51:56 | [diff] [blame] | 2168 | gfx::NativeWindow parent_window = window_->GetNativeHandle(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2169 | select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 2170 | string16(), directory, |
[email protected] | b949f111 | 2009-04-12 20:03:08 | [diff] [blame] | 2171 | NULL, 0, FILE_PATH_LITERAL(""), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 2172 | GetSelectedWebContents(), |
[email protected] | d56bcd2 | 2009-03-16 19:51:56 | [diff] [blame] | 2173 | parent_window, NULL); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | void Browser::OpenCreateShortcutsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2177 | content::RecordAction(UserMetricsAction("CreateShortcut")); |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 2178 | #if !defined(OS_MACOSX) |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2179 | TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
| 2180 | DCHECK(current_tab && |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2181 | web_app::IsValidUrl(current_tab->web_contents()->GetURL())) << |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2182 | "Menu item should be disabled."; |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 2183 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2184 | NavigationEntry* entry = |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2185 | current_tab->web_contents()->GetController().GetLastCommittedEntry(); |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 2186 | if (!entry) |
| 2187 | return; |
| 2188 | |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 2189 | // RVH's GetApplicationInfo should not be called before it returns. |
| 2190 | DCHECK(pending_web_app_action_ == NONE); |
| 2191 | pending_web_app_action_ = CREATE_SHORTCUT; |
| 2192 | |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 2193 | // Start fetching web app info for CreateApplicationShortcut dialog and show |
| 2194 | // the dialog when the data is available in OnDidGetApplicationInfo. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2195 | current_tab->extension_tab_helper()->GetApplicationInfo(entry->GetPageID()); |
[email protected] | 98f6e02 | 2009-06-05 22:49:53 | [diff] [blame] | 2196 | #else |
| 2197 | NOTIMPLEMENTED(); |
| 2198 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2199 | } |
| 2200 | |
[email protected] | 2a8a9812 | 2010-07-16 11:58:48 | [diff] [blame] | 2201 | void Browser::ToggleDevToolsWindow(DevToolsToggleAction action) { |
[email protected] | e3791ce9 | 2011-08-09 01:03:32 | [diff] [blame] | 2202 | if (action == DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE) |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2203 | content::RecordAction(UserMetricsAction("DevTools_ToggleConsole")); |
[email protected] | e3791ce9 | 2011-08-09 01:03:32 | [diff] [blame] | 2204 | else |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2205 | content::RecordAction(UserMetricsAction("DevTools_ToggleWindow")); |
[email protected] | e3791ce9 | 2011-08-09 01:03:32 | [diff] [blame] | 2206 | |
[email protected] | aebdd07 | 2011-07-07 12:36:59 | [diff] [blame] | 2207 | DevToolsWindow::ToggleDevToolsWindow( |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 2208 | GetSelectedWebContents()->GetRenderViewHost(), |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 2209 | action); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2210 | } |
| 2211 | |
[email protected] | adb6a84d | 2011-02-07 16:58:40 | [diff] [blame] | 2212 | void Browser::OpenTaskManager(bool highlight_background_resources) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2213 | content::RecordAction(UserMetricsAction("TaskManager")); |
[email protected] | adb6a84d | 2011-02-07 16:58:40 | [diff] [blame] | 2214 | if (highlight_background_resources) |
| 2215 | window_->ShowBackgroundPages(); |
| 2216 | else |
| 2217 | window_->ShowTaskManager(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2218 | } |
| 2219 | |
[email protected] | daa9e38 | 2012-01-06 00:30:34 | [diff] [blame] | 2220 | void Browser::OpenFeedbackDialog() { |
| 2221 | content::RecordAction(UserMetricsAction("Feedback")); |
| 2222 | browser::ShowHtmlFeedbackView(this, std::string(), std::string()); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2223 | } |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 2224 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2225 | void Browser::ToggleBookmarkBar() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2226 | content::RecordAction(UserMetricsAction("ShowBookmarksBar")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2227 | window_->ToggleBookmarkBar(); |
| 2228 | } |
| 2229 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2230 | void Browser::OpenBookmarkManager() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2231 | content::RecordAction(UserMetricsAction("ShowBookmarkManager")); |
| 2232 | content::RecordAction(UserMetricsAction("ShowBookmarks")); |
[email protected] | 0af8f13 | 2011-07-16 01:37:02 | [diff] [blame] | 2233 | ShowSingletonTabOverwritingNTP( |
[email protected] | a179fac7 | 2011-08-29 22:22:42 | [diff] [blame] | 2234 | GetSingletonTabNavigateParams(GURL(chrome::kChromeUIBookmarksURL))); |
[email protected] | 0af8f13 | 2011-07-16 01:37:02 | [diff] [blame] | 2235 | } |
| 2236 | |
[email protected] | 4c9ee22 | 2011-08-17 19:51:35 | [diff] [blame] | 2237 | void Browser::OpenBookmarkManagerWithHash(const std::string& action, |
| 2238 | int64 node_id) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2239 | content::RecordAction(UserMetricsAction("ShowBookmarkManager")); |
| 2240 | content::RecordAction(UserMetricsAction("ShowBookmarks")); |
[email protected] | f6c1336 | 2011-08-16 12:39:52 | [diff] [blame] | 2241 | browser::NavigateParams params(GetSingletonTabNavigateParams( |
| 2242 | GURL(chrome::kChromeUIBookmarksURL).Resolve( |
[email protected] | 4c9ee22 | 2011-08-17 19:51:35 | [diff] [blame] | 2243 | StringPrintf("/#%s%s", action.c_str(), |
| 2244 | base::Int64ToString(node_id).c_str())))); |
[email protected] | f6c1336 | 2011-08-16 12:39:52 | [diff] [blame] | 2245 | params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
| 2246 | ShowSingletonTabOverwritingNTP(params); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2247 | } |
[email protected] | 8bf80e92 | 2009-03-09 20:56:36 | [diff] [blame] | 2248 | |
[email protected] | 4c9ee22 | 2011-08-17 19:51:35 | [diff] [blame] | 2249 | void Browser::OpenBookmarkManagerForNode(int64 node_id) { |
| 2250 | OpenBookmarkManagerWithHash("", node_id); |
| 2251 | } |
| 2252 | |
| 2253 | void Browser::OpenBookmarkManagerEditNode(int64 node_id) { |
| 2254 | OpenBookmarkManagerWithHash("e=", node_id); |
| 2255 | } |
| 2256 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 2257 | bool Browser::MaybeCreateBackgroundContents(int route_id, |
| 2258 | SiteInstance* site, |
| 2259 | const GURL& opener_url, |
| 2260 | const string16& frame_name) { |
| 2261 | ExtensionService* extensions_service = profile_->GetExtensionService(); |
| 2262 | |
| 2263 | if (!opener_url.is_valid() || |
| 2264 | frame_name.empty() || |
| 2265 | !extensions_service || |
| 2266 | !extensions_service->is_ready()) |
| 2267 | return false; |
| 2268 | |
| 2269 | // Only hosted apps have web extents, so this ensures that only hosted apps |
| 2270 | // can create BackgroundContents. We don't have to check for background |
| 2271 | // permission as that is checked in RenderMessageFilter when the CreateWindow |
| 2272 | // message is processed. |
| 2273 | const Extension* extension = |
| 2274 | extensions_service->extensions()->GetHostedAppByURL( |
| 2275 | ExtensionURLInfo(opener_url)); |
| 2276 | if (!extension) |
| 2277 | return false; |
| 2278 | |
| 2279 | // No BackgroundContents allowed if BackgroundContentsService doesn't exist. |
| 2280 | BackgroundContentsService* service = |
| 2281 | BackgroundContentsServiceFactory::GetForProfile(profile_); |
| 2282 | if (!service) |
| 2283 | return false; |
| 2284 | |
| 2285 | // Ensure that we're trying to open this from the extension's process. |
| 2286 | extensions::ProcessMap* process_map = extensions_service->process_map(); |
| 2287 | if (!site->GetProcess() || |
| 2288 | !process_map->Contains(extension->id(), site->GetProcess()->GetID())) { |
| 2289 | return false; |
| 2290 | } |
| 2291 | |
| 2292 | // Only allow a single background contents per app. If one already exists, |
| 2293 | // close it (even if it was specified in the manifest). |
| 2294 | BackgroundContents* existing = |
| 2295 | service->GetAppBackgroundContents(ASCIIToUTF16(extension->id())); |
| 2296 | if (existing) { |
| 2297 | DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url; |
| 2298 | delete existing; |
| 2299 | } |
| 2300 | |
| 2301 | // Passed all the checks, so this should be created as a BackgroundContents. |
| 2302 | BackgroundContents* contents = |
| 2303 | service->CreateBackgroundContents(site, route_id, profile_, frame_name, |
| 2304 | ASCIIToUTF16(extension->id())); |
| 2305 | return contents != NULL; |
| 2306 | } |
| 2307 | |
[email protected] | fdb9851 | 2009-08-26 01:37:10 | [diff] [blame] | 2308 | void Browser::ShowAppMenu() { |
[email protected] | 366069f | 2011-01-11 09:36:12 | [diff] [blame] | 2309 | // We record the user metric for this event in WrenchMenu::RunMenu. |
[email protected] | fdb9851 | 2009-08-26 01:37:10 | [diff] [blame] | 2310 | window_->ShowAppMenu(); |
| 2311 | } |
| 2312 | |
[email protected] | 7d2d0815 | 2011-10-25 22:58:47 | [diff] [blame] | 2313 | void Browser::ShowAvatarMenu() { |
| 2314 | window_->ShowAvatarBubbleFromAvatarButton(); |
| 2315 | } |
| 2316 | |
[email protected] | 8bf80e92 | 2009-03-09 20:56:36 | [diff] [blame] | 2317 | void Browser::ShowHistoryTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2318 | content::RecordAction(UserMetricsAction("ShowHistory")); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 2319 | ShowSingletonTabOverwritingNTP( |
| 2320 | GetSingletonTabNavigateParams(GURL(chrome::kChromeUIHistoryURL))); |
[email protected] | 8bf80e92 | 2009-03-09 20:56:36 | [diff] [blame] | 2321 | } |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2322 | |
| 2323 | void Browser::ShowDownloadsTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2324 | content::RecordAction(UserMetricsAction("ShowDownloads")); |
[email protected] | efda32f9 | 2011-07-06 22:47:04 | [diff] [blame] | 2325 | #if !defined(OS_CHROMEOS) |
| 2326 | // ChromiumOS uses ActiveDownloadsUI instead of of DownloadShelf. |
[email protected] | 3d037ce7 | 2011-04-04 17:43:45 | [diff] [blame] | 2327 | if (window()) { |
| 2328 | DownloadShelf* shelf = window()->GetDownloadShelf(); |
| 2329 | if (shelf->IsShowing()) |
| 2330 | shelf->Close(); |
| 2331 | } |
[email protected] | efda32f9 | 2011-07-06 22:47:04 | [diff] [blame] | 2332 | #endif |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 2333 | ShowSingletonTabOverwritingNTP( |
| 2334 | GetSingletonTabNavigateParams(GURL(chrome::kChromeUIDownloadsURL))); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2335 | } |
| 2336 | |
[email protected] | 34085a3 | 2009-11-06 22:49:48 | [diff] [blame] | 2337 | void Browser::ShowExtensionsTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2338 | content::RecordAction(UserMetricsAction("ShowExtensions")); |
[email protected] | fa12e2d | 2012-02-06 21:03:10 | [diff] [blame] | 2339 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableUberPage)) { |
[email protected] | f5ec724 | 2012-01-27 07:15:15 | [diff] [blame] | 2340 | ShowOptionsTab(chrome::kExtensionsSubPage); |
| 2341 | } else { |
| 2342 | browser::NavigateParams params(GetSingletonTabNavigateParams( |
| 2343 | GURL(std::string(chrome::kChromeUIUberURL) + |
| 2344 | chrome::kChromeUIExtensionsHost))); |
| 2345 | params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
| 2346 | ShowSingletonTabOverwritingNTP(params); |
| 2347 | } |
[email protected] | 34085a3 | 2009-11-06 22:49:48 | [diff] [blame] | 2348 | } |
| 2349 | |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 2350 | void Browser::ShowAboutConflictsTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2351 | content::RecordAction(UserMetricsAction("AboutConflicts")); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 2352 | ShowSingletonTab(GURL(chrome::kChromeUIConflictsURL)); |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 2353 | } |
| 2354 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2355 | void Browser::ShowBrokenPageTab(WebContents* contents) { |
[email protected] | daa9e38 | 2012-01-06 00:30:34 | [diff] [blame] | 2356 | content::RecordAction(UserMetricsAction("Feedback")); |
[email protected] | 10e457c | 2010-04-29 03:35:23 | [diff] [blame] | 2357 | string16 page_title = contents->GetTitle(); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2358 | NavigationEntry* entry = contents->GetController().GetActiveEntry(); |
[email protected] | 10e457c | 2010-04-29 03:35:23 | [diff] [blame] | 2359 | if (!entry) |
| 2360 | return; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2361 | std::string page_url = entry->GetURL().spec(); |
[email protected] | 10e457c | 2010-04-29 03:35:23 | [diff] [blame] | 2362 | std::vector<std::string> subst; |
| 2363 | subst.push_back(UTF16ToASCII(page_title)); |
| 2364 | subst.push_back(page_url); |
| 2365 | std::string report_page_url = |
| 2366 | ReplaceStringPlaceholders(kBrokenPageUrl, subst, NULL); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 2367 | ShowSingletonTab(GURL(report_page_url)); |
[email protected] | 10e457c | 2010-04-29 03:35:23 | [diff] [blame] | 2368 | } |
| 2369 | |
[email protected] | 12e816bde | 2010-09-14 19:59:29 | [diff] [blame] | 2370 | void Browser::ShowOptionsTab(const std::string& sub_page) { |
[email protected] | fa12e2d | 2012-02-06 21:03:10 | [diff] [blame] | 2371 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableUberPage)) { |
[email protected] | f5ec724 | 2012-01-27 07:15:15 | [diff] [blame] | 2372 | browser::NavigateParams params(GetSingletonTabNavigateParams( |
| 2373 | GURL(chrome::kChromeUISettingsURL + sub_page))); |
| 2374 | params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
| 2375 | ShowSingletonTabOverwritingNTP(params); |
| 2376 | } else { |
[email protected] | ba48113 | 2012-02-01 08:18:16 | [diff] [blame] | 2377 | std::string url; |
| 2378 | if (sub_page == chrome::kExtensionsSubPage) { |
| 2379 | url = std::string(chrome::kChromeUIUberURL) + |
| 2380 | chrome::kChromeUIExtensionsHost; |
| 2381 | } else { |
| 2382 | url = std::string(chrome::kChromeUIUberURL) + |
| 2383 | chrome::kChromeUISettingsHost + '/' + sub_page; |
| 2384 | } |
| 2385 | browser::NavigateParams params(GetSingletonTabNavigateParams(GURL(url))); |
[email protected] | f5ec724 | 2012-01-27 07:15:15 | [diff] [blame] | 2386 | params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
| 2387 | ShowSingletonTabOverwritingNTP(params); |
| 2388 | } |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 2389 | } |
| 2390 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2391 | void Browser::OpenClearBrowsingDataDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2392 | content::RecordAction(UserMetricsAction("ClearBrowsingData_ShowDlg")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2393 | ShowOptionsTab(chrome::kClearBrowserDataSubPage); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2394 | } |
| 2395 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2396 | void Browser::OpenOptionsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2397 | content::RecordAction(UserMetricsAction("ShowOptions")); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 2398 | ShowOptionsTab(""); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | void Browser::OpenPasswordManager() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2402 | content::RecordAction(UserMetricsAction("Options_ShowPasswordManager")); |
[email protected] | e8ce8bb | 2011-03-10 03:10:04 | [diff] [blame] | 2403 | ShowOptionsTab(chrome::kPasswordManagerSubPage); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2404 | } |
| 2405 | |
[email protected] | 1bdf29e | 2009-05-11 23:45:25 | [diff] [blame] | 2406 | void Browser::OpenImportSettingsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2407 | content::RecordAction(UserMetricsAction("Import_ShowDlg")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2408 | ShowOptionsTab(chrome::kImportDataSubPage); |
[email protected] | 1bdf29e | 2009-05-11 23:45:25 | [diff] [blame] | 2409 | } |
[email protected] | 1bdf29e | 2009-05-11 23:45:25 | [diff] [blame] | 2410 | |
[email protected] | b99081b | 2011-03-10 17:43:47 | [diff] [blame] | 2411 | void Browser::OpenInstantConfirmDialog() { |
| 2412 | ShowOptionsTab(chrome::kInstantConfirmPage); |
| 2413 | } |
| 2414 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2415 | void Browser::OpenAboutChromeDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2416 | content::RecordAction(UserMetricsAction("AboutChrome")); |
[email protected] | c3e589d | 2012-02-16 22:24:57 | [diff] [blame] | 2417 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableUberPage)) { |
[email protected] | 976e69f | 2010-08-13 18:28:17 | [diff] [blame] | 2418 | #if defined(OS_CHROMEOS) |
[email protected] | c3e589d | 2012-02-16 22:24:57 | [diff] [blame] | 2419 | std::string chrome_settings(chrome::kChromeUISettingsURL); |
| 2420 | ShowSingletonTab( |
| 2421 | GURL(chrome_settings.append(chrome::kAboutOptionsSubPage))); |
[email protected] | 976e69f | 2010-08-13 18:28:17 | [diff] [blame] | 2422 | #else |
[email protected] | c3e589d | 2012-02-16 22:24:57 | [diff] [blame] | 2423 | window_->ShowAboutChromeDialog(); |
[email protected] | 976e69f | 2010-08-13 18:28:17 | [diff] [blame] | 2424 | #endif |
[email protected] | c3e589d | 2012-02-16 22:24:57 | [diff] [blame] | 2425 | } else { |
[email protected] | 08b2596 | 2012-02-21 22:37:02 | [diff] [blame] | 2426 | #if !defined(OS_WIN) && !defined(OS_MACOSX) |
[email protected] | c3e589d | 2012-02-16 22:24:57 | [diff] [blame] | 2427 | ShowSingletonTab(GURL(chrome::kChromeUIUberURL)); |
[email protected] | 4ea8786 | 2012-02-21 19:45:10 | [diff] [blame] | 2428 | #else |
| 2429 | // crbug.com/115123. |
| 2430 | window_->ShowAboutChromeDialog(); |
| 2431 | #endif |
[email protected] | c3e589d | 2012-02-16 22:24:57 | [diff] [blame] | 2432 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2433 | } |
| 2434 | |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 2435 | void Browser::OpenUpdateChromeDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2436 | content::RecordAction(UserMetricsAction("UpdateChrome")); |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 2437 | window_->ShowUpdateChromeDialog(); |
| 2438 | } |
| 2439 | |
[email protected] | 202802e4 | 2011-07-06 11:40:46 | [diff] [blame] | 2440 | void Browser::ShowHelpTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2441 | content::RecordAction(UserMetricsAction("ShowHelpTab")); |
[email protected] | adc8e85 | 2012-01-29 08:58:22 | [diff] [blame] | 2442 | ShowSingletonTab(GURL(chrome::kChromeHelpURL)); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2443 | } |
| 2444 | |
[email protected] | 31cc1c02 | 2010-10-15 20:03:47 | [diff] [blame] | 2445 | void Browser::OpenPrivacyDashboardTabAndActivate() { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2446 | OpenURL(OpenURLParams( |
| 2447 | GURL(kPrivacyDashboardUrl), Referrer(), |
| 2448 | NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); |
[email protected] | 31cc1c02 | 2010-10-15 20:03:47 | [diff] [blame] | 2449 | window_->Activate(); |
| 2450 | } |
| 2451 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 2452 | void Browser::OpenAutofillHelpTabAndActivate() { |
[email protected] | adc8e85 | 2012-01-29 08:58:22 | [diff] [blame] | 2453 | AddSelectedTabWithURL(GURL(chrome::kAutofillHelpURL), |
| 2454 | content::PAGE_TRANSITION_LINK); |
[email protected] | bb8fe2d | 2010-06-28 20:04:22 | [diff] [blame] | 2455 | } |
| 2456 | |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 2457 | void Browser::OpenSearchEngineOptionsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2458 | content::RecordAction(UserMetricsAction("EditSearchEngines")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2459 | ShowOptionsTab(chrome::kSearchEnginesSubPage); |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 2460 | } |
| 2461 | |
[email protected] | 45c52c9d | 2011-07-19 12:08:14 | [diff] [blame] | 2462 | #if defined(FILE_MANAGER_EXTENSION) |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 2463 | void Browser::OpenFileManager() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2464 | content::RecordAction(UserMetricsAction("OpenFileManager")); |
[email protected] | fc31b4b | 2012-02-01 13:19:56 | [diff] [blame] | 2465 | OpenURL(OpenURLParams(GURL(chrome::kChromeUIFileManagerURL), Referrer(), |
| 2466 | NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 2467 | } |
[email protected] | 45c52c9d | 2011-07-19 12:08:14 | [diff] [blame] | 2468 | #endif |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 2469 | |
[email protected] | 45c52c9d | 2011-07-19 12:08:14 | [diff] [blame] | 2470 | #if defined(OS_CHROMEOS) |
[email protected] | 05a44b6e | 2011-12-01 07:52:32 | [diff] [blame] | 2471 | void Browser::LockScreen() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2472 | content::RecordAction(UserMetricsAction("LockScreen")); |
[email protected] | b0cfc1c | 2011-12-15 13:16:19 | [diff] [blame] | 2473 | chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
[email protected] | 05a44b6e | 2011-12-01 07:52:32 | [diff] [blame] | 2474 | NotifyScreenLockRequested(); |
| 2475 | } |
| 2476 | |
[email protected] | 2166c43 | 2011-12-07 20:18:28 | [diff] [blame] | 2477 | void Browser::Shutdown() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2478 | content::RecordAction(UserMetricsAction("Shutdown")); |
[email protected] | 2166c43 | 2011-12-07 20:18:28 | [diff] [blame] | 2479 | chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 2480 | RequestShutdown(); |
| 2481 | } |
| 2482 | |
[email protected] | b7a0efb1 | 2012-02-22 00:43:22 | [diff] [blame] | 2483 | void Browser::OpenAdvancedOptionsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2484 | content::RecordAction(UserMetricsAction("OpenSystemOptionsDialog")); |
[email protected] | b7a0efb1 | 2012-02-22 00:43:22 | [diff] [blame] | 2485 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableUberPage)) |
| 2486 | ShowOptionsTab(chrome::kSystemOptionsSubPage); |
| 2487 | else |
| 2488 | ShowOptionsTab(chrome::kAdvancedOptionsSubPage); |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | void Browser::OpenInternetOptionsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2492 | content::RecordAction(UserMetricsAction("OpenInternetOptionsDialog")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2493 | ShowOptionsTab(chrome::kInternetOptionsSubPage); |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | void Browser::OpenLanguageOptionsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2497 | content::RecordAction(UserMetricsAction("OpenLanguageOptionsDialog")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2498 | ShowOptionsTab(chrome::kLanguageOptionsSubPage); |
[email protected] | be71507 | 2009-07-07 15:43:20 | [diff] [blame] | 2499 | } |
[email protected] | 46b92f85 | 2010-10-06 13:12:05 | [diff] [blame] | 2500 | |
| 2501 | void Browser::OpenSystemTabAndActivate() { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2502 | OpenURL(OpenURLParams( |
| 2503 | GURL(chrome::kChromeUISystemInfoURL), Referrer(), NEW_FOREGROUND_TAB, |
| 2504 | content::PAGE_TRANSITION_LINK, false)); |
[email protected] | 46b92f85 | 2010-10-06 13:12:05 | [diff] [blame] | 2505 | window_->Activate(); |
| 2506 | } |
| 2507 | |
[email protected] | 3801761 | 2010-10-13 18:46:00 | [diff] [blame] | 2508 | void Browser::OpenMobilePlanTabAndActivate() { |
[email protected] | e7137b2c | 2011-10-24 20:16:55 | [diff] [blame] | 2509 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2510 | switches::kEnableMobileSetupDialog)) { |
| 2511 | window_->ShowMobileSetup(); |
| 2512 | } else { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2513 | OpenURL(OpenURLParams( |
| 2514 | GURL(chrome::kChromeUIMobileSetupURL), Referrer(), NEW_FOREGROUND_TAB, |
| 2515 | content::PAGE_TRANSITION_LINK, false)); |
[email protected] | e7137b2c | 2011-10-24 20:16:55 | [diff] [blame] | 2516 | window_->Activate(); |
| 2517 | } |
[email protected] | 3801761 | 2010-10-13 18:46:00 | [diff] [blame] | 2518 | } |
[email protected] | be71507 | 2009-07-07 15:43:20 | [diff] [blame] | 2519 | #endif |
| 2520 | |
[email protected] | 598e6c21 | 2012-02-01 04:57:56 | [diff] [blame] | 2521 | #if defined(OS_CHROMEOS) && defined(USE_AURA) |
| 2522 | void Browser::OpenCrosh() { |
| 2523 | GURL crosh_url = TerminalExtensionHelper::GetCroshExtensionURL(profile_); |
| 2524 | if (!crosh_url.is_valid()) |
| 2525 | return; |
| 2526 | OpenURL(OpenURLParams(crosh_url, Referrer(), NEW_FOREGROUND_TAB, |
| 2527 | content::PAGE_TRANSITION_GENERATED, |
| 2528 | false)); |
| 2529 | } |
| 2530 | #endif |
| 2531 | |
[email protected] | a003d8e | 2010-10-02 21:03:35 | [diff] [blame] | 2532 | void Browser::OpenPluginsTabAndActivate() { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2533 | OpenURL(OpenURLParams( |
| 2534 | GURL(chrome::kChromeUIPluginsURL), Referrer(), NEW_FOREGROUND_TAB, |
| 2535 | content::PAGE_TRANSITION_LINK, false)); |
[email protected] | a003d8e | 2010-10-02 21:03:35 | [diff] [blame] | 2536 | window_->Activate(); |
| 2537 | } |
| 2538 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2539 | /////////////////////////////////////////////////////////////////////////////// |
| 2540 | |
| 2541 | // static |
[email protected] | 7911717 | 2009-08-28 16:11:44 | [diff] [blame] | 2542 | void Browser::SetNewHomePagePrefs(PrefService* prefs) { |
[email protected] | 8fe6e1c | 2010-05-27 08:21:54 | [diff] [blame] | 2543 | const PrefService::Preference* home_page_pref = |
| 2544 | prefs->FindPreference(prefs::kHomePage); |
| 2545 | if (home_page_pref && |
| 2546 | !home_page_pref->IsManaged() && |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2547 | !prefs->HasPrefPath(prefs::kHomePage)) { |
[email protected] | b41eb73 | 2009-09-30 16:49:33 | [diff] [blame] | 2548 | prefs->SetString(prefs::kHomePage, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2549 | GoogleURLTracker::kDefaultGoogleHomepage); |
| 2550 | } |
[email protected] | 8fe6e1c | 2010-05-27 08:21:54 | [diff] [blame] | 2551 | const PrefService::Preference* home_page_is_new_tab_page_pref = |
| 2552 | prefs->FindPreference(prefs::kHomePageIsNewTabPage); |
| 2553 | if (home_page_is_new_tab_page_pref && |
| 2554 | !home_page_is_new_tab_page_pref->IsManaged() && |
| 2555 | !prefs->HasPrefPath(prefs::kHomePageIsNewTabPage)) |
[email protected] | b41eb73 | 2009-09-30 16:49:33 | [diff] [blame] | 2556 | prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false); |
[email protected] | 7911717 | 2009-08-28 16:11:44 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | // static |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2560 | void Browser::RegisterPrefs(PrefService* prefs) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2561 | prefs->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); |
[email protected] | d989891 | 2011-04-15 21:10:00 | [diff] [blame] | 2562 | prefs->RegisterBooleanPref(prefs::kAllowFileSelectionDialogs, true); |
[email protected] | 4e72ebb | 2011-10-18 05:02:18 | [diff] [blame] | 2563 | prefs->RegisterBooleanPref(prefs::kShouldShowFirstRunBubble, false); |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2564 | prefs->RegisterBooleanPref(prefs::kPrintPreviewDisabled, |
| 2565 | #if defined(GOOGLE_CHROME_BUILD) |
| 2566 | false |
| 2567 | #else |
| 2568 | true |
| 2569 | #endif |
| 2570 | ); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | // static |
| 2574 | void Browser::RegisterUserPrefs(PrefService* prefs) { |
[email protected] | 0d22083 | 2009-11-06 00:45:18 | [diff] [blame] | 2575 | prefs->RegisterStringPref(prefs::kHomePage, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2576 | chrome::kChromeUINewTabURL, |
| 2577 | PrefService::SYNCABLE_PREF); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 2578 | prefs->RegisterBooleanPref(prefs::kHomePageChanged, |
| 2579 | false, |
| 2580 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2581 | prefs->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, |
| 2582 | true, |
| 2583 | PrefService::SYNCABLE_PREF); |
| 2584 | prefs->RegisterBooleanPref(prefs::kShowHomeButton, |
| 2585 | false, |
| 2586 | PrefService::SYNCABLE_PREF); |
[email protected] | 93a2c724 | 2009-07-07 18:43:09 | [diff] [blame] | 2587 | #if defined(OS_MACOSX) |
| 2588 | // This really belongs in platform code, but there's no good place to |
| 2589 | // initialize it between the time when the AppController is created |
| 2590 | // (where there's no profile) and the time the controller gets another |
| 2591 | // crack at the start of the main event loop. By that time, BrowserInit |
| 2592 | // has already created the browser window, and it's too late: we need the |
| 2593 | // pref to be already initialized. Doing it here also saves us from having |
| 2594 | // to hard-code pref registration in the several unit tests that use |
| 2595 | // this preference. |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2596 | prefs->RegisterBooleanPref(prefs::kConfirmToQuitEnabled, |
| 2597 | false, |
| 2598 | PrefService::SYNCABLE_PREF); |
| 2599 | prefs->RegisterBooleanPref(prefs::kShowUpdatePromotionInfoBar, |
| 2600 | true, |
| 2601 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 93a2c724 | 2009-07-07 18:43:09 | [diff] [blame] | 2602 | #endif |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2603 | prefs->RegisterBooleanPref(prefs::kDeleteBrowsingHistory, |
| 2604 | true, |
| 2605 | PrefService::SYNCABLE_PREF); |
| 2606 | prefs->RegisterBooleanPref(prefs::kDeleteDownloadHistory, |
| 2607 | true, |
| 2608 | PrefService::SYNCABLE_PREF); |
| 2609 | prefs->RegisterBooleanPref(prefs::kDeleteCache, |
| 2610 | true, |
| 2611 | PrefService::SYNCABLE_PREF); |
| 2612 | prefs->RegisterBooleanPref(prefs::kDeleteCookies, |
| 2613 | true, |
| 2614 | PrefService::SYNCABLE_PREF); |
| 2615 | prefs->RegisterBooleanPref(prefs::kDeletePasswords, |
| 2616 | false, |
| 2617 | PrefService::SYNCABLE_PREF); |
| 2618 | prefs->RegisterBooleanPref(prefs::kDeleteFormData, |
| 2619 | false, |
| 2620 | PrefService::SYNCABLE_PREF); |
| 2621 | prefs->RegisterIntegerPref(prefs::kDeleteTimePeriod, |
| 2622 | 0, |
| 2623 | PrefService::SYNCABLE_PREF); |
| 2624 | prefs->RegisterBooleanPref(prefs::kCheckDefaultBrowser, |
| 2625 | true, |
| 2626 | PrefService::UNSYNCABLE_PREF); |
| 2627 | prefs->RegisterBooleanPref(prefs::kShowOmniboxSearchHint, |
| 2628 | true, |
| 2629 | PrefService::UNSYNCABLE_PREF); |
| 2630 | prefs->RegisterBooleanPref(prefs::kWebAppCreateOnDesktop, |
| 2631 | true, |
| 2632 | PrefService::UNSYNCABLE_PREF); |
| 2633 | prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, |
| 2634 | true, |
| 2635 | PrefService::UNSYNCABLE_PREF); |
| 2636 | prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, |
| 2637 | true, |
| 2638 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2639 | prefs->RegisterBooleanPref(prefs::kEnableTranslate, |
| 2640 | true, |
| 2641 | PrefService::SYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2642 | prefs->RegisterStringPref(prefs::kCloudPrintEmail, |
| 2643 | std::string(), |
| 2644 | PrefService::UNSYNCABLE_PREF); |
| 2645 | prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, |
| 2646 | true, |
| 2647 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 1af419c | 2011-10-31 23:45:41 | [diff] [blame] | 2648 | prefs->RegisterBooleanPref(prefs::kCloudPrintSubmitEnabled, |
| 2649 | true, |
| 2650 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2651 | prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, |
| 2652 | false, |
| 2653 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2654 | prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, |
| 2655 | -1, |
| 2656 | PrefService::UNSYNCABLE_PREF); |
| 2657 | prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement, |
| 2658 | PrefService::UNSYNCABLE_PREF); |
| 2659 | prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement, |
| 2660 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d5e5b2a5 | 2011-08-16 11:27:12 | [diff] [blame] | 2661 | prefs->RegisterBooleanPref(prefs::kImportBookmarks, |
| 2662 | true, |
| 2663 | PrefService::UNSYNCABLE_PREF); |
| 2664 | prefs->RegisterBooleanPref(prefs::kImportHistory, |
| 2665 | true, |
| 2666 | PrefService::UNSYNCABLE_PREF); |
| 2667 | prefs->RegisterBooleanPref(prefs::kImportHomepage, |
| 2668 | true, |
| 2669 | PrefService::UNSYNCABLE_PREF); |
| 2670 | prefs->RegisterBooleanPref(prefs::kImportSearchEngine, |
| 2671 | true, |
| 2672 | PrefService::UNSYNCABLE_PREF); |
| 2673 | prefs->RegisterBooleanPref(prefs::kImportSavedPasswords, |
| 2674 | true, |
| 2675 | PrefService::UNSYNCABLE_PREF); |
[email protected] | f6e68091 | 2011-09-21 20:26:19 | [diff] [blame] | 2676 | // The map of timestamps of the last used file browser handlers. |
| 2677 | prefs->RegisterDictionaryPref(prefs::kLastUsedFileBrowserHandlers, |
| 2678 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d5e5b2a5 | 2011-08-16 11:27:12 | [diff] [blame] | 2679 | |
[email protected] | 2bf2bd9 | 2011-03-31 07:12:44 | [diff] [blame] | 2680 | // We need to register the type of these preferences in order to query |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2681 | // them even though they're only typically controlled via policy. |
| 2682 | prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, |
| 2683 | false, |
| 2684 | PrefService::UNSYNCABLE_PREF); |
| 2685 | prefs->RegisterBooleanPref(prefs::kPluginsAllowOutdated, |
| 2686 | false, |
| 2687 | PrefService::UNSYNCABLE_PREF); |
| 2688 | prefs->RegisterBooleanPref(prefs::kPluginsAlwaysAuthorize, |
| 2689 | false, |
| 2690 | PrefService::UNSYNCABLE_PREF); |
| 2691 | prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, |
| 2692 | true, |
| 2693 | PrefService::UNSYNCABLE_PREF); |
| 2694 | prefs->RegisterBooleanPref(prefs::kEnableReferrers, |
| 2695 | true, |
| 2696 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 781be95 | 2011-08-31 20:22:14 | [diff] [blame] | 2697 | prefs->RegisterBooleanPref(prefs::kClearPluginLSODataEnabled, |
| 2698 | true, |
| 2699 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 80b0761 | 2011-12-12 16:04:30 | [diff] [blame] | 2700 | prefs->RegisterBooleanPref(prefs::kEnableMemoryInfo, |
| 2701 | false, |
| 2702 | PrefService::UNSYNCABLE_PREF); |
[email protected] | f2df311 | 2011-11-18 10:21:48 | [diff] [blame] | 2703 | |
| 2704 | // Initialize the disk cache prefs. |
| 2705 | prefs->RegisterFilePathPref(prefs::kDiskCacheDir, |
| 2706 | FilePath(), |
| 2707 | PrefService::UNSYNCABLE_PREF); |
| 2708 | prefs->RegisterIntegerPref(prefs::kDiskCacheSize, |
| 2709 | 0, |
| 2710 | PrefService::UNSYNCABLE_PREF); |
| 2711 | prefs->RegisterIntegerPref(prefs::kMediaCacheSize, |
| 2712 | 0, |
| 2713 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | // static |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2717 | bool Browser::RunUnloadEventsHelper(WebContents* contents) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2718 | // If the TabContents is not connected yet, then there's no unload |
| 2719 | // handler we can fire even if the TabContents has an unload listener. |
| 2720 | // One case where we hit this is in a tab that has an infinite loop |
| 2721 | // before load. |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 2722 | if (contents->NeedToFireBeforeUnload()) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2723 | // If the page has unload listeners, then we tell the renderer to fire |
| 2724 | // them. Once they have fired, we'll get a message back saying whether |
| 2725 | // 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] | 2726 | // with the NeedToFireBeforeUnload bit cleared. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2727 | contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2728 | return true; |
| 2729 | } |
| 2730 | return false; |
| 2731 | } |
| 2732 | |
| 2733 | // static |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2734 | Browser* Browser::GetBrowserForController( |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 2735 | const NavigationController* controller, int* index_result) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2736 | BrowserList::const_iterator it; |
| 2737 | for (it = BrowserList::begin(); it != BrowserList::end(); ++it) { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 2738 | int index = (*it)->GetIndexOfController(controller); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2739 | if (index != TabStripModel::kNoTab) { |
| 2740 | if (index_result) |
| 2741 | *index_result = index; |
| 2742 | return *it; |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | return NULL; |
| 2747 | } |
| 2748 | |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2749 | // static |
| 2750 | void Browser::RunFileChooserHelper( |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2751 | WebContents* tab, const content::FileChooserParams& params) { |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2752 | Profile* profile = |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 2753 | Profile::FromBrowserContext(tab->GetBrowserContext()); |
[email protected] | 9f054aa1 | 2011-09-29 19:13:45 | [diff] [blame] | 2754 | // FileSelectHelper adds a reference to itself and only releases it after |
| 2755 | // sending the result message. It won't be destroyed when this reference |
| 2756 | // goes out of scope. |
| 2757 | scoped_refptr<FileSelectHelper> file_select_helper( |
| 2758 | new FileSelectHelper(profile)); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2759 | file_select_helper->RunFileChooser(tab->GetRenderViewHost(), tab, params); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | // static |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2763 | void Browser::EnumerateDirectoryHelper(WebContents* tab, int request_id, |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2764 | const FilePath& path) { |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2765 | Profile* profile = |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 2766 | Profile::FromBrowserContext(tab->GetBrowserContext()); |
[email protected] | 9f054aa1 | 2011-09-29 19:13:45 | [diff] [blame] | 2767 | // FileSelectHelper adds a reference to itself and only releases it after |
| 2768 | // sending the result message. It won't be destroyed when this reference |
| 2769 | // goes out of scope. |
| 2770 | scoped_refptr<FileSelectHelper> file_select_helper( |
| 2771 | new FileSelectHelper(profile)); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2772 | file_select_helper->EnumerateDirectory(request_id, |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2773 | tab->GetRenderViewHost(), |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2774 | path); |
| 2775 | } |
| 2776 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2777 | // static |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2778 | void Browser::JSOutOfMemoryHelper(WebContents* tab) { |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2779 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2780 | tab); |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2781 | if (!tcw) |
| 2782 | return; |
| 2783 | |
| 2784 | InfoBarTabHelper* infobar_helper = tcw->infobar_tab_helper(); |
| 2785 | infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 2786 | infobar_helper, |
| 2787 | NULL, |
| 2788 | l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), |
| 2789 | true)); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | // static |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2793 | void Browser::RegisterProtocolHandlerHelper(WebContents* tab, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2794 | const std::string& protocol, |
| 2795 | const GURL& url, |
| 2796 | const string16& title) { |
| 2797 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2798 | tab); |
| 2799 | if (!tcw || tcw->profile()->IsOffTheRecord()) |
| 2800 | return; |
| 2801 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2802 | ProtocolHandler handler = |
| 2803 | ProtocolHandler::CreateProtocolHandler(protocol, url, title); |
| 2804 | |
| 2805 | ProtocolHandlerRegistry* registry = |
| 2806 | tcw->profile()->GetProtocolHandlerRegistry(); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2807 | |
[email protected] | a50af29 | 2011-10-25 03:07:40 | [diff] [blame] | 2808 | if (!registry->SilentlyHandleRegisterHandlerRequest(handler)) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2809 | content::RecordAction( |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2810 | UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 2811 | InfoBarTabHelper* infobar_helper = tcw->infobar_tab_helper(); |
[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 2812 | |
| 2813 | RegisterProtocolHandlerInfoBarDelegate* rph_delegate = |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 2814 | new RegisterProtocolHandlerInfoBarDelegate(infobar_helper, |
| 2815 | registry, |
[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 2816 | handler); |
| 2817 | |
| 2818 | for (size_t i = 0; i < infobar_helper->infobar_count(); i++) { |
| 2819 | InfoBarDelegate* delegate = infobar_helper->GetInfoBarDelegateAt(i); |
| 2820 | RegisterProtocolHandlerInfoBarDelegate* cast_delegate = |
| 2821 | delegate->AsRegisterProtocolHandlerInfoBarDelegate(); |
| 2822 | if (cast_delegate != NULL && cast_delegate->IsReplacedBy(rph_delegate)) { |
| 2823 | infobar_helper->ReplaceInfoBar(cast_delegate, rph_delegate); |
| 2824 | rph_delegate = NULL; |
| 2825 | break; |
| 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | if (rph_delegate != NULL) |
| 2830 | infobar_helper->AddInfoBar(rph_delegate); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2831 | } |
| 2832 | } |
| 2833 | |
| 2834 | // static |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2835 | void Browser::RegisterIntentHandlerHelper(WebContents* tab, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2836 | const string16& action, |
| 2837 | const string16& type, |
| 2838 | const string16& href, |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 2839 | const string16& title, |
| 2840 | const string16& disposition) { |
[email protected] | 8f0bbd6 | 2012-02-22 03:37:18 | [diff] [blame] | 2841 | if (!web_intents::IsWebIntentsEnabled()) |
[email protected] | 8229b5e | 2011-11-18 05:49:56 | [diff] [blame] | 2842 | return; |
| 2843 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2844 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2845 | tab); |
| 2846 | if (!tcw || tcw->profile()->IsOffTheRecord()) |
| 2847 | return; |
| 2848 | |
[email protected] | 8229b5e | 2011-11-18 05:49:56 | [diff] [blame] | 2849 | FaviconService* favicon_service = |
| 2850 | tcw->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2851 | |
[email protected] | 8229b5e | 2011-11-18 05:49:56 | [diff] [blame] | 2852 | // |href| can be relative to originating URL. Resolve if necessary. |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2853 | GURL service_url(href); |
| 2854 | if (!service_url.is_valid()) { |
| 2855 | const GURL& url = tab->GetURL(); |
| 2856 | service_url = url.Resolve(href); |
| 2857 | } |
| 2858 | |
[email protected] | 5662442 | 2011-11-01 22:11:27 | [diff] [blame] | 2859 | webkit_glue::WebIntentServiceData service; |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 2860 | service.service_url = service_url; |
| 2861 | service.action = action; |
| 2862 | service.type = type; |
| 2863 | service.title = title; |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 2864 | service.setDisposition(disposition); |
| 2865 | |
[email protected] | 3826a8a0 | 2011-11-11 17:03:31 | [diff] [blame] | 2866 | RegisterIntentHandlerInfoBarDelegate::MaybeShowIntentInfoBar( |
| 2867 | tcw->infobar_tab_helper(), |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 2868 | WebIntentsRegistryFactory::GetForProfile(tcw->profile()), |
[email protected] | 8229b5e | 2011-11-18 05:49:56 | [diff] [blame] | 2869 | service, |
| 2870 | favicon_service, |
| 2871 | tab->GetURL()); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2872 | } |
| 2873 | |
| 2874 | // static |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2875 | void Browser::FindReplyHelper(WebContents* tab, |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 2876 | int request_id, |
| 2877 | int number_of_matches, |
| 2878 | const gfx::Rect& selection_rect, |
| 2879 | int active_match_ordinal, |
| 2880 | bool final_update) { |
| 2881 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2882 | tab); |
| 2883 | if (!tcw || !tcw->find_tab_helper()) |
| 2884 | return; |
| 2885 | |
| 2886 | tcw->find_tab_helper()->HandleFindReply(request_id, number_of_matches, |
| 2887 | selection_rect, active_match_ordinal, |
| 2888 | final_update); |
| 2889 | } |
| 2890 | |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 2891 | // static |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2892 | void Browser::CrashedPluginHelper(WebContents* tab, |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 2893 | const FilePath& plugin_path) { |
| 2894 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2895 | tab); |
| 2896 | if (!tcw) |
| 2897 | return; |
| 2898 | |
| 2899 | DCHECK(!plugin_path.value().empty()); |
| 2900 | |
| 2901 | string16 plugin_name = plugin_path.LossyDisplayName(); |
| 2902 | webkit::WebPluginInfo plugin_info; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 2903 | if (PluginService::GetInstance()->GetPluginInfoByPath( |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 2904 | plugin_path, &plugin_info) && |
| 2905 | !plugin_info.name.empty()) { |
| 2906 | plugin_name = plugin_info.name; |
| 2907 | #if defined(OS_MACOSX) |
| 2908 | // Many plugins on the Mac have .plugin in the actual name, which looks |
| 2909 | // terrible, so look for that and strip it off if present. |
| 2910 | const std::string kPluginExtension = ".plugin"; |
| 2911 | if (EndsWith(plugin_name, ASCIIToUTF16(kPluginExtension), true)) |
| 2912 | plugin_name.erase(plugin_name.length() - kPluginExtension.length()); |
| 2913 | #endif // OS_MACOSX |
| 2914 | } |
| 2915 | gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 2916 | IDR_INFOBAR_PLUGIN_CRASHED); |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 2917 | InfoBarTabHelper* infobar_helper = tcw->infobar_tab_helper(); |
| 2918 | infobar_helper->AddInfoBar( |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 2919 | new SimpleAlertInfoBarDelegate( |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 2920 | infobar_helper, |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 2921 | icon, |
| 2922 | l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), |
| 2923 | true)); |
| 2924 | } |
| 2925 | |
| 2926 | // static |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2927 | void Browser::UpdateTargetURLHelper(WebContents* tab, int32 page_id, |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 2928 | const GURL& url) { |
| 2929 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2930 | tab); |
| 2931 | if (!tcw || !tcw->prerender_tab_helper()) |
| 2932 | return; |
| 2933 | tcw->prerender_tab_helper()->UpdateTargetURL(page_id, url); |
| 2934 | } |
| 2935 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 2936 | void Browser::ExecuteCommandWithDisposition( |
| 2937 | int id, WindowOpenDisposition disposition) { |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2938 | // No commands are enabled if there is not yet any selected tab. |
| 2939 | // TODO(pkasting): It seems like we should not need this, because either |
| 2940 | // most/all commands should not have been enabled yet anyway or the ones that |
| 2941 | // are enabled should be global, or safe themselves against having no selected |
| 2942 | // tab. However, Ben says he tried removing this before and got lots of |
| 2943 | // crashes, e.g. from Windows sending WM_COMMANDs at random times during |
| 2944 | // window construction. This probably could use closer examination someday. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2945 | if (!GetSelectedTabContentsWrapper()) |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2946 | return; |
| 2947 | |
[email protected] | 59c9f00 | 2010-11-19 00:38:05 | [diff] [blame] | 2948 | DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command " |
| 2949 | << id; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2950 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 2951 | // If command execution is blocked then just record the command and return. |
| 2952 | if (block_command_execution_) { |
| 2953 | // We actually only allow no more than one blocked command, otherwise some |
| 2954 | // commands maybe lost. |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 2955 | DCHECK_EQ(last_blocked_command_id_, -1); |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 2956 | last_blocked_command_id_ = id; |
| 2957 | last_blocked_command_disposition_ = disposition; |
| 2958 | return; |
| 2959 | } |
| 2960 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2961 | // The order of commands in this switch statement must match the function |
| 2962 | // declaration order in browser.h! |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2963 | switch (id) { |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2964 | // Navigation commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2965 | case IDC_BACK: GoBack(disposition); break; |
| 2966 | case IDC_FORWARD: GoForward(disposition); break; |
| 2967 | case IDC_RELOAD: Reload(disposition); break; |
| 2968 | case IDC_RELOAD_IGNORING_CACHE: ReloadIgnoringCache(disposition); break; |
| 2969 | case IDC_HOME: Home(disposition); break; |
| 2970 | case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2971 | case IDC_STOP: Stop(); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2972 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2973 | // Window management commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2974 | case IDC_NEW_WINDOW: NewWindow(); break; |
| 2975 | case IDC_NEW_INCOGNITO_WINDOW: NewIncognitoWindow(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2976 | case IDC_CLOSE_WINDOW: CloseWindow(); break; |
| 2977 | case IDC_NEW_TAB: NewTab(); break; |
| 2978 | case IDC_CLOSE_TAB: CloseTab(); break; |
| 2979 | case IDC_SELECT_NEXT_TAB: SelectNextTab(); break; |
| 2980 | case IDC_SELECT_PREVIOUS_TAB: SelectPreviousTab(); break; |
[email protected] | 91ac920 | 2010-07-30 18:32:35 | [diff] [blame] | 2981 | case IDC_TABPOSE: OpenTabpose(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2982 | case IDC_MOVE_TAB_NEXT: MoveTabNext(); break; |
| 2983 | case IDC_MOVE_TAB_PREVIOUS: MoveTabPrevious(); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2984 | case IDC_SELECT_TAB_0: |
| 2985 | case IDC_SELECT_TAB_1: |
| 2986 | case IDC_SELECT_TAB_2: |
| 2987 | case IDC_SELECT_TAB_3: |
| 2988 | case IDC_SELECT_TAB_4: |
| 2989 | case IDC_SELECT_TAB_5: |
| 2990 | case IDC_SELECT_TAB_6: |
[email protected] | cb525c8 | 2008-12-08 23:04:54 | [diff] [blame] | 2991 | case IDC_SELECT_TAB_7: SelectNumberedTab(id - IDC_SELECT_TAB_0); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2992 | break; |
| 2993 | case IDC_SELECT_LAST_TAB: SelectLastTab(); break; |
| 2994 | case IDC_DUPLICATE_TAB: DuplicateTab(); break; |
| 2995 | case IDC_RESTORE_TAB: RestoreTab(); break; |
| 2996 | case IDC_COPY_URL: WriteCurrentURLToClipboard(); break; |
| 2997 | case IDC_SHOW_AS_TAB: ConvertPopupToTabbedBrowser(); break; |
[email protected] | 184717d5 | 2012-02-22 04:46:16 | [diff] [blame] | 2998 | case IDC_FULLSCREEN: ToggleFullscreenMode(); break; |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 2999 | #if defined(OS_MACOSX) |
[email protected] | 184717d5 | 2012-02-22 04:46:16 | [diff] [blame] | 3000 | case IDC_PRESENTATION_MODE: TogglePresentationMode(); break; |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 3001 | #endif |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3002 | case IDC_EXIT: Exit(); break; |
[email protected] | da17b37 | 2010-01-22 23:37:22 | [diff] [blame] | 3003 | #if defined(OS_CHROMEOS) |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3004 | case IDC_SEARCH: Search(); break; |
[email protected] | d14af52 | 2010-12-02 03:54:50 | [diff] [blame] | 3005 | case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break; |
[email protected] | 20d1724 | 2009-10-26 20:21:05 | [diff] [blame] | 3006 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3007 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3008 | // Page-related commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3009 | case IDC_SAVE_PAGE: SavePage(); break; |
| 3010 | case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break; |
| 3011 | case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(); break; |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 3012 | case IDC_VIEW_SOURCE: ViewSelectedSource(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3013 | case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break; |
| 3014 | case IDC_PRINT: Print(); break; |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 3015 | case IDC_ADVANCED_PRINT: AdvancedPrint(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3016 | case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3017 | case IDC_ENCODING_UTF8: |
| 3018 | case IDC_ENCODING_UTF16LE: |
| 3019 | case IDC_ENCODING_ISO88591: |
| 3020 | case IDC_ENCODING_WINDOWS1252: |
[email protected] | 1c5bf63 | 2008-12-11 20:30:49 | [diff] [blame] | 3021 | case IDC_ENCODING_GBK: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3022 | case IDC_ENCODING_GB18030: |
| 3023 | case IDC_ENCODING_BIG5HKSCS: |
| 3024 | case IDC_ENCODING_BIG5: |
| 3025 | case IDC_ENCODING_KOREAN: |
| 3026 | case IDC_ENCODING_SHIFTJIS: |
| 3027 | case IDC_ENCODING_ISO2022JP: |
| 3028 | case IDC_ENCODING_EUCJP: |
| 3029 | case IDC_ENCODING_THAI: |
| 3030 | case IDC_ENCODING_ISO885915: |
| 3031 | case IDC_ENCODING_MACINTOSH: |
| 3032 | case IDC_ENCODING_ISO88592: |
| 3033 | case IDC_ENCODING_WINDOWS1250: |
| 3034 | case IDC_ENCODING_ISO88595: |
| 3035 | case IDC_ENCODING_WINDOWS1251: |
| 3036 | case IDC_ENCODING_KOI8R: |
| 3037 | case IDC_ENCODING_KOI8U: |
| 3038 | case IDC_ENCODING_ISO88597: |
| 3039 | case IDC_ENCODING_WINDOWS1253: |
| 3040 | case IDC_ENCODING_ISO88594: |
| 3041 | case IDC_ENCODING_ISO885913: |
| 3042 | case IDC_ENCODING_WINDOWS1257: |
| 3043 | case IDC_ENCODING_ISO88593: |
| 3044 | case IDC_ENCODING_ISO885910: |
| 3045 | case IDC_ENCODING_ISO885914: |
| 3046 | case IDC_ENCODING_ISO885916: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3047 | case IDC_ENCODING_WINDOWS1254: |
| 3048 | case IDC_ENCODING_ISO88596: |
| 3049 | case IDC_ENCODING_WINDOWS1256: |
| 3050 | case IDC_ENCODING_ISO88598: |
[email protected] | e13271f | 2009-03-07 00:26:00 | [diff] [blame] | 3051 | case IDC_ENCODING_ISO88598I: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3052 | case IDC_ENCODING_WINDOWS1255: |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3053 | case IDC_ENCODING_WINDOWS1258: OverrideEncoding(id); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3054 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3055 | // Clipboard commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3056 | case IDC_CUT: Cut(); break; |
| 3057 | case IDC_COPY: Copy(); break; |
| 3058 | case IDC_PASTE: Paste(); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3059 | |
| 3060 | // Find-in-page |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3061 | case IDC_FIND: Find(); break; |
| 3062 | case IDC_FIND_NEXT: FindNext(); break; |
| 3063 | case IDC_FIND_PREVIOUS: FindPrevious(); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3064 | |
| 3065 | // Zoom |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 3066 | case IDC_ZOOM_PLUS: Zoom(content::PAGE_ZOOM_IN); break; |
| 3067 | case IDC_ZOOM_NORMAL: Zoom(content::PAGE_ZOOM_RESET); break; |
| 3068 | case IDC_ZOOM_MINUS: Zoom(content::PAGE_ZOOM_OUT); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3069 | |
| 3070 | // Focus various bits of UI |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3071 | case IDC_FOCUS_TOOLBAR: FocusToolbar(); break; |
| 3072 | case IDC_FOCUS_LOCATION: FocusLocationBar(); break; |
| 3073 | case IDC_FOCUS_SEARCH: FocusSearch(); break; |
[email protected] | bdb7ff6 | 2010-07-20 01:56:52 | [diff] [blame] | 3074 | case IDC_FOCUS_MENU_BAR: FocusAppMenu(); break; |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 3075 | case IDC_FOCUS_BOOKMARKS: FocusBookmarksToolbar(); break; |
| 3076 | case IDC_FOCUS_CHROMEOS_STATUS: FocusChromeOSStatus(); break; |
| 3077 | case IDC_FOCUS_NEXT_PANE: FocusNextPane(); break; |
| 3078 | case IDC_FOCUS_PREVIOUS_PANE: FocusPreviousPane(); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3079 | |
| 3080 | // Show various bits of UI |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3081 | case IDC_OPEN_FILE: OpenFile(); break; |
| 3082 | case IDC_CREATE_SHORTCUTS: OpenCreateShortcutsDialog(); break; |
[email protected] | 2a8a9812 | 2010-07-16 11:58:48 | [diff] [blame] | 3083 | case IDC_DEV_TOOLS: ToggleDevToolsWindow( |
| 3084 | DEVTOOLS_TOGGLE_ACTION_NONE); |
| 3085 | break; |
| 3086 | case IDC_DEV_TOOLS_CONSOLE: ToggleDevToolsWindow( |
| 3087 | DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); |
| 3088 | break; |
| 3089 | case IDC_DEV_TOOLS_INSPECT: ToggleDevToolsWindow( |
| 3090 | DEVTOOLS_TOGGLE_ACTION_INSPECT); |
| 3091 | break; |
[email protected] | adb6a84d | 2011-02-07 16:58:40 | [diff] [blame] | 3092 | case IDC_TASK_MANAGER: OpenTaskManager(false); break; |
| 3093 | case IDC_VIEW_BACKGROUND_PAGES: OpenTaskManager(true); break; |
[email protected] | daa9e38 | 2012-01-06 00:30:34 | [diff] [blame] | 3094 | case IDC_FEEDBACK: OpenFeedbackDialog(); break; |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 3095 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3096 | case IDC_SHOW_BOOKMARK_BAR: ToggleBookmarkBar(); break; |
[email protected] | 7664ab3 | 2011-02-01 23:35:25 | [diff] [blame] | 3097 | case IDC_PROFILING_ENABLED: Profiling::Toggle(); break; |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 3098 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3099 | case IDC_SHOW_BOOKMARK_MANAGER: OpenBookmarkManager(); break; |
| 3100 | case IDC_SHOW_APP_MENU: ShowAppMenu(); break; |
[email protected] | 7d2d0815 | 2011-10-25 22:58:47 | [diff] [blame] | 3101 | case IDC_SHOW_AVATAR_MENU: ShowAvatarMenu(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3102 | case IDC_SHOW_HISTORY: ShowHistoryTab(); break; |
| 3103 | case IDC_SHOW_DOWNLOADS: ShowDownloadsTab(); break; |
| 3104 | case IDC_MANAGE_EXTENSIONS: ShowExtensionsTab(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3105 | case IDC_OPTIONS: OpenOptionsDialog(); break; |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 3106 | case IDC_EDIT_SEARCH_ENGINES: OpenSearchEngineOptionsDialog(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3107 | case IDC_VIEW_PASSWORDS: OpenPasswordManager(); break; |
| 3108 | case IDC_CLEAR_BROWSING_DATA: OpenClearBrowsingDataDialog(); break; |
| 3109 | case IDC_IMPORT_SETTINGS: OpenImportSettingsDialog(); break; |
[email protected] | b21d691 | 2010-08-31 19:22:41 | [diff] [blame] | 3110 | case IDC_ABOUT: OpenAboutChromeDialog(); break; |
| 3111 | case IDC_UPGRADE_DIALOG: OpenUpdateChromeDialog(); break; |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 3112 | case IDC_VIEW_INCOMPATIBILITIES: ShowAboutConflictsTab(); break; |
[email protected] | 202802e4 | 2011-07-06 11:40:46 | [diff] [blame] | 3113 | case IDC_HELP_PAGE: ShowHelpTab(); break; |
[email protected] | 1677984 | 2009-07-08 23:45:29 | [diff] [blame] | 3114 | #if defined(OS_CHROMEOS) |
[email protected] | 05a44b6e | 2011-12-01 07:52:32 | [diff] [blame] | 3115 | case IDC_LOCK_SCREEN: LockScreen(); break; |
[email protected] | 2166c43 | 2011-12-07 20:18:28 | [diff] [blame] | 3116 | case IDC_SHUTDOWN: Shutdown(); break; |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 3117 | case IDC_FILE_MANAGER: OpenFileManager(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 3118 | case IDC_INTERNET_OPTIONS: OpenInternetOptionsDialog(); break; |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 3119 | case IDC_LANGUAGE_OPTIONS: OpenLanguageOptionsDialog(); break; |
[email protected] | be71507 | 2009-07-07 15:43:20 | [diff] [blame] | 3120 | #endif |
[email protected] | 598e6c21 | 2012-02-01 04:57:56 | [diff] [blame] | 3121 | #if defined(OS_CHROMEOS) && defined(USE_AURA) |
| 3122 | case IDC_NEW_CROSH_TAB: OpenCrosh(); break; |
| 3123 | #endif |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 3124 | case IDC_SHOW_SYNC_SETUP: ShowSyncSetup(); break; |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 3125 | case IDC_TOGGLE_SPEECH_INPUT: ToggleSpeechInput(); break; |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 3126 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3127 | default: |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3128 | LOG(WARNING) << "Received Unimplemented Command: " << id; |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 3129 | break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3130 | } |
| 3131 | } |
| 3132 | |
[email protected] | dee1135 | 2011-09-05 13:34:08 | [diff] [blame] | 3133 | void Browser::ExecuteCommand(int id, int event_flags) { |
| 3134 | ExecuteCommandWithDisposition( |
| 3135 | id, browser::DispositionFromEventFlags(event_flags)); |
| 3136 | } |
| 3137 | |
[email protected] | 3ab6796d3 | 2010-12-21 23:56:07 | [diff] [blame] | 3138 | bool Browser::ExecuteCommandIfEnabled(int id) { |
| 3139 | if (command_updater_.SupportsCommand(id) && |
| 3140 | command_updater_.IsCommandEnabled(id)) { |
| 3141 | ExecuteCommand(id); |
| 3142 | return true; |
| 3143 | } |
| 3144 | return false; |
| 3145 | } |
| 3146 | |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 3147 | bool Browser::IsReservedCommandOrKey(int command_id, |
| 3148 | const NativeWebKeyboardEvent& event) { |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 3149 | #if defined(OS_CHROMEOS) |
| 3150 | // Chrome OS's top row of keys produces F1-10. Make sure that web pages |
| 3151 | // aren't able to block Chrome from performing the standard actions for F1-F4 |
| 3152 | // (F5-7 are grabbed by other X clients and hence don't need this protection, |
| 3153 | // and F8-10 are handled separately in Chrome via a GDK event filter, but |
| 3154 | // let's future-proof this). |
| 3155 | ui::KeyboardCode key_code = |
[email protected] | 6a1ae6cd | 2011-02-11 20:06:09 | [diff] [blame] | 3156 | static_cast<ui::KeyboardCode>(event.windowsKeyCode); |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 3157 | if (key_code == ui::VKEY_F1 || |
| 3158 | key_code == ui::VKEY_F2 || |
| 3159 | key_code == ui::VKEY_F3 || |
| 3160 | key_code == ui::VKEY_F4 || |
| 3161 | key_code == ui::VKEY_F5 || |
| 3162 | key_code == ui::VKEY_F6 || |
| 3163 | key_code == ui::VKEY_F7 || |
| 3164 | key_code == ui::VKEY_F8 || |
| 3165 | key_code == ui::VKEY_F9 || |
| 3166 | key_code == ui::VKEY_F10) { |
[email protected] | 6a1ae6cd | 2011-02-11 20:06:09 | [diff] [blame] | 3167 | return true; |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 3168 | } |
| 3169 | #endif |
| 3170 | |
[email protected] | fa2d2ce2 | 2011-09-19 08:21:06 | [diff] [blame] | 3171 | if (window_->IsFullscreen() && command_id == IDC_FULLSCREEN) |
| 3172 | return true; |
[email protected] | 6a1ae6cd | 2011-02-11 20:06:09 | [diff] [blame] | 3173 | return command_id == IDC_CLOSE_TAB || |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 3174 | command_id == IDC_CLOSE_WINDOW || |
| 3175 | command_id == IDC_NEW_INCOGNITO_WINDOW || |
| 3176 | command_id == IDC_NEW_TAB || |
| 3177 | command_id == IDC_NEW_WINDOW || |
| 3178 | command_id == IDC_RESTORE_TAB || |
| 3179 | command_id == IDC_SELECT_NEXT_TAB || |
| 3180 | command_id == IDC_SELECT_PREVIOUS_TAB || |
[email protected] | c1d0d81 | 2010-07-27 20:21:55 | [diff] [blame] | 3181 | command_id == IDC_TABPOSE || |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 3182 | command_id == IDC_EXIT || |
| 3183 | command_id == IDC_SEARCH; |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | void Browser::SetBlockCommandExecution(bool block) { |
| 3187 | block_command_execution_ = block; |
| 3188 | if (block) { |
| 3189 | last_blocked_command_id_ = -1; |
| 3190 | last_blocked_command_disposition_ = CURRENT_TAB; |
| 3191 | } |
| 3192 | } |
| 3193 | |
| 3194 | int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) { |
| 3195 | if (disposition) |
| 3196 | *disposition = last_blocked_command_disposition_; |
| 3197 | return last_blocked_command_id_; |
| 3198 | } |
| 3199 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3200 | void Browser::UpdateUIForNavigationInTab(TabContentsWrapper* contents, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3201 | content::PageTransition transition, |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 3202 | bool user_initiated) { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 3203 | tab_handler_->GetTabStripModel()->TabNavigating(contents, transition); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 3204 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3205 | bool contents_is_selected = contents == GetSelectedTabContentsWrapper(); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 3206 | if (user_initiated && contents_is_selected && window()->GetLocationBar()) { |
| 3207 | // Forcibly reset the location bar if the url is going to change in the |
| 3208 | // current tab, since otherwise it won't discard any ongoing user edits, |
| 3209 | // since it doesn't realize this is a user-initiated action. |
| 3210 | window()->GetLocationBar()->Revert(); |
| 3211 | } |
| 3212 | |
| 3213 | if (GetStatusBubble()) |
| 3214 | GetStatusBubble()->Hide(); |
| 3215 | |
| 3216 | // Update the location bar. This is synchronous. We specifically don't |
| 3217 | // update the load state since the load hasn't started yet and updating it |
| 3218 | // will put it out of sync with the actual state like whether we're |
| 3219 | // displaying a favicon, which controls the throbber. If we updated it here, |
| 3220 | // the throbber will show the default favicon for a split second when |
| 3221 | // navigating away from the new tab page. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3222 | ScheduleUIUpdate(contents->web_contents(), content::INVALIDATE_TYPE_URL); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 3223 | |
| 3224 | if (contents_is_selected) |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3225 | contents->web_contents()->Focus(); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 3226 | } |
| 3227 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3228 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3229 | // Browser, PageNavigator implementation: |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 3230 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 3231 | WebContents* Browser::OpenURL(const OpenURLParams& params) { |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 3232 | return OpenURLFromTab(NULL, params); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 3236 | // Browser, CommandUpdater::CommandUpdaterDelegate implementation: |
| 3237 | |
| 3238 | void Browser::ExecuteCommand(int id) { |
| 3239 | ExecuteCommandWithDisposition(id, CURRENT_TAB); |
| 3240 | } |
| 3241 | |
| 3242 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3243 | // Browser, TabHandlerDelegate implementation: |
| 3244 | |
| 3245 | Profile* Browser::GetProfile() const { |
| 3246 | return profile(); |
| 3247 | } |
| 3248 | |
| 3249 | Browser* Browser::AsBrowser() { |
| 3250 | return this; |
| 3251 | } |
| 3252 | |
| 3253 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3254 | // Browser, TabStripModelDelegate implementation: |
| 3255 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3256 | TabContentsWrapper* Browser::AddBlankTab(bool foreground) { |
[email protected] | 22735af6 | 2009-04-07 21:09:58 | [diff] [blame] | 3257 | return AddBlankTabAt(-1, foreground); |
| 3258 | } |
| 3259 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3260 | TabContentsWrapper* Browser::AddBlankTabAt(int index, bool foreground) { |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 3261 | // Time new tab page creation time. We keep track of the timing data in |
| 3262 | // TabContents, but we want to include the time it takes to create the |
| 3263 | // TabContents object too. |
| 3264 | base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3265 | browser::NavigateParams params(this, GURL(chrome::kChromeUINewTabURL), |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3266 | content::PAGE_TRANSITION_TYPED); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3267 | params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
| 3268 | params.tabstrip_index = index; |
| 3269 | browser::Navigate(¶ms); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3270 | params.target_contents->web_contents()->SetNewTabStartTime( |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3271 | new_tab_start_time); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3272 | return params.target_contents; |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 3273 | } |
| 3274 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3275 | Browser* Browser::CreateNewStripWithContents( |
| 3276 | TabContentsWrapper* detached_contents, |
| 3277 | const gfx::Rect& window_bounds, |
| 3278 | const DockInfo& dock_info, |
| 3279 | bool maximize) { |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 3280 | DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); |
[email protected] | adf650f | 2008-12-09 16:10:06 | [diff] [blame] | 3281 | |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 3282 | gfx::Rect new_window_bounds = window_bounds; |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 3283 | if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize)) |
| 3284 | dock_info.AdjustOtherWindowBounds(); |
| 3285 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3286 | // Create an empty new browser window the same size as the old one. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3287 | Browser* browser = new Browser(TYPE_TABBED, profile_); |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 3288 | browser->set_override_bounds(new_window_bounds); |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 3289 | browser->set_show_state( |
| 3290 | maximize ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 3291 | browser->InitBrowserWindow(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 3292 | browser->tabstrip_model()->AppendTabContents(detached_contents, true); |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 3293 | // Make sure the loading state is updated correctly, otherwise the throbber |
| 3294 | // won't start if the page is loading. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3295 | browser->LoadingStateChanged(detached_contents->web_contents()); |
[email protected] | 3d1104f | 2009-03-26 15:30:28 | [diff] [blame] | 3296 | return browser; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | int Browser::GetDragActions() const { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3300 | return TabStripModelDelegate::TAB_TEAROFF_ACTION | (tab_count() > 1 ? |
| 3301 | TabStripModelDelegate::TAB_MOVE_ACTION : 0); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3302 | } |
| 3303 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3304 | TabContentsWrapper* Browser::CreateTabContentsForURL( |
[email protected] | 3ebe558b | 2011-12-06 08:05:08 | [diff] [blame] | 3305 | const GURL& url, const content::Referrer& referrer, Profile* profile, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3306 | content::PageTransition transition, bool defer_load, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3307 | SiteInstance* instance) const { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3308 | TabContentsWrapper* contents = TabContentsFactory(profile, instance, |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3309 | MSG_ROUTING_NONE, |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 3310 | GetSelectedWebContents(), NULL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3311 | if (!defer_load) { |
| 3312 | // Load the initial URL before adding the new tab contents to the tab strip |
| 3313 | // so that the tab contents has navigation state. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3314 | contents->web_contents()->GetController().LoadURL( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 3315 | url, referrer, transition, std::string()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | return contents; |
| 3319 | } |
| 3320 | |
| 3321 | bool Browser::CanDuplicateContentsAt(int index) { |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 3322 | NavigationController& nc = GetWebContentsAt(index)->GetController(); |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 3323 | return nc.GetWebContents() && nc.GetLastCommittedEntry(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | void Browser::DuplicateContentsAt(int index) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3327 | TabContentsWrapper* contents = GetTabContentsWrapperAt(index); |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 3328 | CHECK(contents); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 3329 | TabContentsWrapper* contents_dupe = contents->Clone(); |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 3330 | |
| 3331 | bool pinned = false; |
| 3332 | if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
| 3333 | // If this is a tabbed browser, just create a duplicate tab inside the same |
| 3334 | // window next to the tab being duplicated. |
| 3335 | int index = tab_handler_->GetTabStripModel()-> |
| 3336 | GetIndexOfTabContents(contents); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 3337 | pinned = IsTabPinned(index); |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 3338 | int add_types = TabStripModel::ADD_ACTIVE | |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 3339 | TabStripModel::ADD_INHERIT_GROUP | |
| 3340 | (pinned ? TabStripModel::ADD_PINNED : 0); |
| 3341 | tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, |
| 3342 | contents_dupe, |
| 3343 | add_types); |
| 3344 | } else { |
| 3345 | Browser* browser = NULL; |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3346 | if (is_app()) { |
| 3347 | CHECK(!is_type_popup()); |
| 3348 | CHECK(!is_type_panel()); |
[email protected] | 5c20924 | 2011-06-06 20:36:17 | [diff] [blame] | 3349 | browser = Browser::CreateForApp(TYPE_POPUP, app_name_, gfx::Rect(), |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3350 | profile_); |
| 3351 | } else if (is_type_popup()) { |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 3352 | browser = Browser::CreateForType(TYPE_POPUP, profile_); |
| 3353 | } |
| 3354 | |
| 3355 | // Preserve the size of the original window. The new window has already |
| 3356 | // been given an offset by the OS, so we shouldn't copy the old bounds. |
| 3357 | BrowserWindow* new_window = browser->window(); |
| 3358 | new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 3359 | window()->GetRestoredBounds().size())); |
| 3360 | |
[email protected] | 4e59568 | 2011-02-09 17:07:02 | [diff] [blame] | 3361 | // We need to show the browser now. Otherwise ContainerWin assumes the |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 3362 | // TabContents is invisible and won't size it. |
| 3363 | browser->window()->Show(); |
| 3364 | |
| 3365 | // The page transition below is only for the purpose of inserting the tab. |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3366 | browser->AddTab(contents_dupe, content::PAGE_TRANSITION_LINK); |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 3367 | } |
| 3368 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3369 | SessionService* session_service = |
| 3370 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 3371 | if (session_service) |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 3372 | session_service->TabRestored(contents_dupe, pinned); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3373 | } |
| 3374 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3375 | void Browser::CloseFrameAfterDragSession() { |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 3376 | #if !defined(OS_MACOSX) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3377 | // This is scheduled to run after we return to the message loop because |
| 3378 | // otherwise the frame will think the drag session is still active and ignore |
| 3379 | // the request. |
[email protected] | d6a3c77 | 2009-01-27 19:41:20 | [diff] [blame] | 3380 | // TODO(port): figure out what is required here in a cross-platform world |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 3381 | MessageLoop::current()->PostTask( |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 3382 | FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); |
[email protected] | d6a3c77 | 2009-01-27 19:41:20 | [diff] [blame] | 3383 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3384 | } |
| 3385 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3386 | void Browser::CreateHistoricalTab(TabContentsWrapper* contents) { |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 3387 | // We don't create historical tabs for incognito windows or windows without |
| 3388 | // profiles. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3389 | if (!profile() || profile()->IsOffTheRecord()) |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 3390 | return; |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3391 | |
[email protected] | 0d4ef7f | 2011-05-12 22:38:57 | [diff] [blame] | 3392 | // We don't create historical tabs for print preview tabs. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3393 | if (contents->web_contents()->GetURL() == GURL(chrome::kChromeUIPrintURL)) |
[email protected] | 0d4ef7f | 2011-05-12 22:38:57 | [diff] [blame] | 3394 | return; |
| 3395 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3396 | TabRestoreService* service = |
| 3397 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 3398 | |
[email protected] | fb5ff42 | 2010-05-03 20:46:10 | [diff] [blame] | 3399 | // We only create historical tab entries for tabbed browser windows. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3400 | if (service && CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3401 | service->CreateHistoricalTab(&contents->web_contents()->GetController(), |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 3402 | tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents)); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 3403 | } |
| 3404 | } |
| 3405 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3406 | bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3407 | return Browser::RunUnloadEventsHelper(contents->web_contents()); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 3408 | } |
| 3409 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3410 | bool Browser::CanReloadContents(WebContents* source) const { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3411 | return !is_devtools(); |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 3412 | } |
| 3413 | |
[email protected] | 2db5a204 | 2011-04-26 17:13:47 | [diff] [blame] | 3414 | bool Browser::CanCloseContents(std::vector<int>* indices) { |
| 3415 | DCHECK(!indices->empty()); |
| 3416 | TabCloseableStateWatcher* watcher = |
| 3417 | g_browser_process->tab_closeable_state_watcher(); |
| 3418 | bool can_close_all = !watcher || watcher->CanCloseTabs(this, indices); |
| 3419 | if (indices->empty()) // Cannot close any tab. |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 3420 | return false; |
[email protected] | 2db5a204 | 2011-04-26 17:13:47 | [diff] [blame] | 3421 | // Now, handle cases where at least one tab can be closed. |
| 3422 | // If we are closing all the tabs for this browser, make sure to check for |
[email protected] | 940ccb2 | 2009-04-30 17:11:10 | [diff] [blame] | 3423 | // in-progress downloads. |
| 3424 | // Note that the next call when it returns false will ask the user for |
| 3425 | // confirmation before closing the browser if the user decides so. |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 3426 | if (tab_count() == static_cast<int>(indices->size()) && |
[email protected] | 2db5a204 | 2011-04-26 17:13:47 | [diff] [blame] | 3427 | !CanCloseWithInProgressDownloads()) { |
| 3428 | indices->clear(); |
| 3429 | can_close_all = false; |
| 3430 | } |
| 3431 | return can_close_all; |
[email protected] | 940ccb2 | 2009-04-30 17:11:10 | [diff] [blame] | 3432 | } |
[email protected] | d6a3c77 | 2009-01-27 19:41:20 | [diff] [blame] | 3433 | |
[email protected] | a206b44 | 2009-10-08 23:20:20 | [diff] [blame] | 3434 | bool Browser::CanBookmarkAllTabs() const { |
| 3435 | BookmarkModel* model = profile()->GetBookmarkModel(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 3436 | return (model && model->IsLoaded()) && |
| 3437 | tab_count() > 1 && |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 3438 | profile()->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled); |
[email protected] | a206b44 | 2009-10-08 23:20:20 | [diff] [blame] | 3439 | } |
| 3440 | |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 3441 | void Browser::BookmarkAllTabs() { |
[email protected] | 9d60339 | 2011-11-18 05:45:28 | [diff] [blame] | 3442 | BookmarkEditor::ShowBookmarkAllTabsDialog(this); |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 3443 | } |
| 3444 | |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 3445 | bool Browser::CanCloseTab() const { |
| 3446 | TabCloseableStateWatcher* watcher = |
| 3447 | g_browser_process->tab_closeable_state_watcher(); |
| 3448 | return !watcher || watcher->CanCloseTab(this); |
| 3449 | } |
| 3450 | |
[email protected] | b283a753 | 2010-08-12 21:24:59 | [diff] [blame] | 3451 | bool Browser::LargeIconsPermitted() const { |
[email protected] | af801acd | 2010-08-20 20:27:44 | [diff] [blame] | 3452 | // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because |
| 3453 | // for those windows, we already have a big icon in the top-left outside any |
| 3454 | // tab. Having big tab icons too looks kinda redonk. |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 3455 | return true; |
[email protected] | b283a753 | 2010-08-12 21:24:59 | [diff] [blame] | 3456 | } |
| 3457 | |
[email protected] | 2d46c84 | 2008-11-14 19:24:31 | [diff] [blame] | 3458 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3459 | // Browser, TabStripModelObserver implementation: |
| 3460 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3461 | void Browser::TabInsertedAt(TabContentsWrapper* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3462 | int index, |
| 3463 | bool foreground) { |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 3464 | SetAsDelegate(contents, this); |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 3465 | contents->restore_tab_helper()->SetWindowID(session_id()); |
[email protected] | e524ff9 | 2011-03-30 13:26:58 | [diff] [blame] | 3466 | |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3467 | SyncHistoryWithTabs(index); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3468 | |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 3469 | // Make sure the loading state is updated correctly, otherwise the throbber |
| 3470 | // won't start if the page is loading. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3471 | LoadingStateChanged(contents->web_contents()); |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 3472 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3473 | // If the tab crashes in the beforeunload or unload handler, it won't be |
| 3474 | // able to ack. But we know we can close it. |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 3475 | registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 3476 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 3477 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 3478 | registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 3479 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 3480 | |
| 3481 | registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 3482 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3483 | } |
| 3484 | |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 3485 | void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3486 | TabContentsWrapper* contents, |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 3487 | int index) { |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3488 | fullscreen_controller_->OnTabClosing(contents->web_contents()); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 3489 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 3490 | content::NOTIFICATION_TAB_CLOSING, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 3491 | content::Source<NavigationController>( |
[email protected] | cca0f1e | 2012-01-03 18:27:46 | [diff] [blame] | 3492 | &contents->web_contents()->GetController()), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 3493 | content::NotificationService::NoDetails()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3494 | |
| 3495 | // Sever the TabContents' connection back to us. |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 3496 | SetAsDelegate(contents, NULL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3497 | } |
| 3498 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3499 | void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3500 | TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3501 | } |
| 3502 | |
[email protected] | 9ac8a24 | 2011-06-07 19:42:52 | [diff] [blame] | 3503 | void Browser::TabDeactivated(TabContentsWrapper* contents) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 3504 | fullscreen_controller_->OnTabDeactivated(contents); |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 3505 | if (instant()) |
[email protected] | 3e48128 | 2011-10-15 15:39:50 | [diff] [blame] | 3506 | instant()->Hide(); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 3507 | |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 3508 | // Save what the user's currently typing, so it can be restored when we |
| 3509 | // switch back to this tab. |
[email protected] | 83a2610a | 2012-01-05 01:00:27 | [diff] [blame] | 3510 | window_->GetLocationBar()->SaveStateToContents(contents->web_contents()); |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 3511 | } |
| 3512 | |
[email protected] | 3aca95d4 | 2011-05-24 22:06:54 | [diff] [blame] | 3513 | void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, |
| 3514 | TabContentsWrapper* new_contents, |
| 3515 | int index, |
| 3516 | bool user_gesture) { |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 3517 | // On some platforms we want to automatically reload tabs that are |
| 3518 | // killed when the user selects them. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3519 | if (user_gesture && new_contents->web_contents()->GetCrashedStatus() == |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 3520 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 3521 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 3522 | if (parsed_command_line.HasSwitch(switches::kReloadKilledTabs)) { |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 3523 | Reload(CURRENT_TAB); |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 3524 | return; |
| 3525 | } |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 3526 | } |
| 3527 | |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 3528 | // Discarded tabs always get reloaded. |
| 3529 | if (IsTabDiscarded(index)) { |
| 3530 | Reload(CURRENT_TAB); |
| 3531 | return; |
| 3532 | } |
| 3533 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3534 | // If we have any update pending, do it now. |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 3535 | if (chrome_updater_factory_.HasWeakPtrs() && old_contents) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3536 | ProcessPendingUIUpdates(); |
| 3537 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3538 | // Propagate the profile to the location bar. |
| 3539 | UpdateToolbar(true); |
| 3540 | |
[email protected] | 943d812 | 2010-06-11 02:13:45 | [diff] [blame] | 3541 | // Update reload/stop state. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3542 | UpdateReloadStopState(new_contents->web_contents()->IsLoading(), true); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3543 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3544 | // Update commands to reflect current state. |
| 3545 | UpdateCommandsForTabState(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3546 | |
| 3547 | // Reset the status bubble. |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3548 | StatusBubble* status_bubble = GetStatusBubble(); |
| 3549 | if (status_bubble) { |
| 3550 | status_bubble->Hide(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3551 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3552 | // Show the loading state (if any). |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 3553 | status_bubble->SetStatus( |
| 3554 | GetSelectedTabContentsWrapper()->core_tab_helper()->GetStatusText()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3555 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3556 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 3557 | if (HasFindBarController()) { |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 3558 | find_bar_controller_->ChangeTabContents(new_contents); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 3559 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 3560 | } |
| 3561 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3562 | // Update sessions. Don't force creation of sessions. If sessions doesn't |
| 3563 | // exist, the change will be picked up by sessions when created. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3564 | SessionService* session_service = |
| 3565 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 3566 | if (session_service && !tab_handler_->GetTabStripModel()->closing_all()) { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 3567 | session_service->SetSelectedTabInWindow(session_id(), active_index()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3568 | } |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 3569 | |
| 3570 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3571 | } |
| 3572 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3573 | void Browser::TabMoved(TabContentsWrapper* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3574 | int from_index, |
[email protected] | 1a242c3 | 2010-02-02 21:20:54 | [diff] [blame] | 3575 | int to_index) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3576 | DCHECK(from_index >= 0 && to_index >= 0); |
| 3577 | // Notify the history service. |
| 3578 | SyncHistoryWithTabs(std::min(from_index, to_index)); |
| 3579 | } |
| 3580 | |
[email protected] | da25dd5 | 2011-01-11 19:06:30 | [diff] [blame] | 3581 | void Browser::TabReplacedAt(TabStripModel* tab_strip_model, |
| 3582 | TabContentsWrapper* old_contents, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3583 | TabContentsWrapper* new_contents, |
[email protected] | 8a34e660 | 2010-10-02 17:29:43 | [diff] [blame] | 3584 | int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3585 | TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 3586 | TabInsertedAt(new_contents, index, (index == active_index())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3587 | |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 3588 | int entry_count = |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3589 | new_contents->web_contents()->GetController().GetEntryCount(); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3590 | if (entry_count > 0) { |
| 3591 | // Send out notification so that observers are updated appropriately. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3592 | new_contents->web_contents()->GetController().NotifyEntryChanged( |
| 3593 | new_contents->web_contents()->GetController().GetEntryAtIndex( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 3594 | entry_count - 1), |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3595 | entry_count - 1); |
| 3596 | } |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 3597 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3598 | SessionService* session_service = |
| 3599 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 3600 | if (session_service) { |
| 3601 | // The new_contents may end up with a different navigation stack. Force |
| 3602 | // the session service to update itself. |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 3603 | session_service->TabRestored(new_contents, IsTabPinned(index)); |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 3604 | } |
[email protected] | 2914600d | 2011-01-31 23:25:14 | [diff] [blame] | 3605 | |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 3606 | content::DevToolsManager::GetInstance()->TabReplaced( |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3607 | old_contents->web_contents(), new_contents->web_contents()); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3608 | } |
| 3609 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3610 | void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3611 | SessionService* session_service = |
| 3612 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 3613 | if (session_service) { |
| 3614 | session_service->SetPinnedState( |
| 3615 | session_id(), |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 3616 | GetTabContentsWrapperAt(index)->restore_tab_helper()->session_id(), |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 3617 | IsTabPinned(index)); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 3618 | } |
| 3619 | } |
| 3620 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3621 | void Browser::TabStripEmpty() { |
| 3622 | // Close the frame after we return to the message loop (not immediately, |
| 3623 | // otherwise it will destroy this object before the stack has a chance to |
| 3624 | // cleanly unwind.) |
| 3625 | // Note: This will be called several times if TabStripEmpty is called several |
| 3626 | // times. This is because it does not close the window if tabs are |
| 3627 | // still present. |
| 3628 | // NOTE: If you change to be immediate (no invokeLater) then you'll need to |
| 3629 | // update BrowserList::CloseAllBrowsers. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 3630 | MessageLoop::current()->PostTask( |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 3631 | FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 3635 | // Browser, content::WebContentsDelegate implementation: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3636 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 3637 | WebContents* Browser::OpenURLFromTab(WebContents* source, |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 3638 | const OpenURLParams& params) { |
| 3639 | browser::NavigateParams nav_params(this, params.url, params.transition); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 3640 | nav_params.source_contents = GetTabContentsWrapperAt( |
| 3641 | tab_handler_->GetTabStripModel()->GetWrapperIndex(source)); |
[email protected] | cb8fb01a | 2011-12-05 21:01:14 | [diff] [blame] | 3642 | nav_params.referrer = params.referrer; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 3643 | nav_params.disposition = params.disposition; |
| 3644 | nav_params.tabstrip_add_types = TabStripModel::ADD_NONE; |
| 3645 | nav_params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 3646 | nav_params.user_gesture = true; |
| 3647 | nav_params.override_encoding = params.override_encoding; |
[email protected] | e47ae947 | 2011-10-13 19:48:34 | [diff] [blame] | 3648 | nav_params.is_renderer_initiated = params.is_renderer_initiated; |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 3649 | nav_params.transferred_global_request_id = |
| 3650 | params.transferred_global_request_id; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 3651 | browser::Navigate(&nav_params); |
| 3652 | |
| 3653 | return nav_params.target_contents ? |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3654 | nav_params.target_contents->web_contents() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3655 | } |
| 3656 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3657 | void Browser::NavigationStateChanged(const WebContents* source, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3658 | unsigned changed_flags) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3659 | // Only update the UI when something visible has changed. |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 3660 | if (changed_flags) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3661 | ScheduleUIUpdate(source, changed_flags); |
| 3662 | |
[email protected] | 83c2e23 | 2011-10-07 21:36:46 | [diff] [blame] | 3663 | // We can synchronously update commands since they will only change once per |
| 3664 | // navigation, so we don't have to worry about flickering. We do, however, |
| 3665 | // need to update the command state early on load to always present usable |
| 3666 | // actions in the face of slow-to-commit pages. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3667 | if (changed_flags & (content::INVALIDATE_TYPE_URL | |
| 3668 | content::INVALIDATE_TYPE_LOAD)) |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3669 | UpdateCommandsForTabState(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3670 | } |
| 3671 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3672 | void Browser::AddNewContents(WebContents* source, |
| 3673 | WebContents* new_contents, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3674 | WindowOpenDisposition disposition, |
| 3675 | const gfx::Rect& initial_pos, |
| 3676 | bool user_gesture) { |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3677 | // No code for this yet. |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3678 | DCHECK(disposition != SAVE_TO_DISK); |
| 3679 | // Can't create a new contents for the current tab - invalid case. |
| 3680 | DCHECK(disposition != CURRENT_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3681 | |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3682 | TabContentsWrapper* source_wrapper = NULL; |
| 3683 | BlockedContentTabHelper* source_blocked_content = NULL; |
[email protected] | ad1be159 | 2011-04-27 14:14:45 | [diff] [blame] | 3684 | TabContentsWrapper* new_wrapper = |
| 3685 | TabContentsWrapper::GetCurrentWrapperForContents(new_contents); |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3686 | if (!new_wrapper) { |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3687 | new_wrapper = new TabContentsWrapper(new_contents); |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3688 | } |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3689 | if (source) { |
| 3690 | source_wrapper = TabContentsWrapper::GetCurrentWrapperForContents(source); |
| 3691 | source_blocked_content = source_wrapper->blocked_content_tab_helper(); |
| 3692 | } |
| 3693 | |
| 3694 | if (source_wrapper) { |
| 3695 | // Handle blocking of all contents. |
| 3696 | if (source_blocked_content->all_contents_blocked()) { |
| 3697 | source_blocked_content->AddTabContents(new_wrapper, |
| 3698 | disposition, |
| 3699 | initial_pos, |
| 3700 | user_gesture); |
| 3701 | return; |
| 3702 | } |
| 3703 | |
| 3704 | // Handle blocking of popups. |
| 3705 | if ((disposition == NEW_POPUP) && !user_gesture && |
| 3706 | !CommandLine::ForCurrentProcess()->HasSwitch( |
| 3707 | switches::kDisablePopupBlocking)) { |
| 3708 | // Unrequested popups from normal pages are constrained unless they're in |
| 3709 | // the whitelist. The popup owner will handle checking this. |
[email protected] | 393c0ed0 | 2011-04-22 14:55:36 | [diff] [blame] | 3710 | GetConstrainingContentsWrapper(source_wrapper)-> |
| 3711 | blocked_content_tab_helper()-> |
| 3712 | AddPopup(new_wrapper, initial_pos, user_gesture); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3713 | return; |
| 3714 | } |
| 3715 | |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 3716 | new_contents->GetRenderViewHost()->DisassociateFromPopupCount(); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3717 | } |
| 3718 | |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3719 | browser::NavigateParams params(this, new_wrapper); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 3720 | params.source_contents = source ? GetTabContentsWrapperAt( |
| 3721 | tab_handler_->GetTabStripModel()->GetWrapperIndex(source)) |
| 3722 | : NULL; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3723 | params.disposition = disposition; |
| 3724 | params.window_bounds = initial_pos; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 3725 | params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 3726 | params.user_gesture = user_gesture; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3727 | browser::Navigate(¶ms); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3728 | } |
| 3729 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3730 | void Browser::ActivateContents(WebContents* contents) { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 3731 | ActivateTabAt(tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), |
| 3732 | false); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 3733 | window_->Activate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3734 | } |
| 3735 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3736 | void Browser::DeactivateContents(WebContents* contents) { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 3737 | window_->Deactivate(); |
| 3738 | } |
| 3739 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3740 | void Browser::LoadingStateChanged(WebContents* source) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3741 | window_->UpdateLoadingAnimations( |
| 3742 | tab_handler_->GetTabStripModel()->TabsAreLoading()); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 3743 | window_->UpdateTitleBar(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3744 | |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 3745 | WebContents* selected_contents = GetSelectedWebContents(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3746 | if (source == selected_contents) { |
[email protected] | f5d978c | 2011-07-21 14:43:51 | [diff] [blame] | 3747 | bool is_loading = source->IsLoading(); |
| 3748 | UpdateReloadStopState(is_loading, false); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 3749 | if (GetStatusBubble()) { |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 3750 | GetStatusBubble()->SetStatus( |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 3751 | GetSelectedTabContentsWrapper()->core_tab_helper()->GetStatusText()); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 3752 | } |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3753 | |
[email protected] | f5d978c | 2011-07-21 14:43:51 | [diff] [blame] | 3754 | if (!is_loading && pending_web_app_action_ == UPDATE_SHORTCUT) { |
[email protected] | 867dff8 | 2010-04-23 21:30:33 | [diff] [blame] | 3755 | // Schedule a shortcut update when web application info is available if |
| 3756 | // last committed entry is not NULL. Last committed entry could be NULL |
| 3757 | // when an interstitial page is injected (e.g. bad https certificate, |
| 3758 | // malware site etc). When this happens, we abort the shortcut update. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 3759 | NavigationEntry* entry = source->GetController().GetLastCommittedEntry(); |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3760 | if (entry) { |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 3761 | TabContentsWrapper::GetCurrentWrapperForContents(source)-> |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 3762 | extension_tab_helper()->GetApplicationInfo(entry->GetPageID()); |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3763 | } else { |
| 3764 | pending_web_app_action_ = NONE; |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3765 | } |
| 3766 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3767 | } |
| 3768 | } |
| 3769 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 3770 | void Browser::CloseContents(WebContents* source) { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 3771 | if (is_attempting_to_close_browser_) { |
| 3772 | // If we're trying to close the browser, just clear the state related to |
[email protected] | adf650f | 2008-12-09 16:10:06 | [diff] [blame] | 3773 | // waiting for unload to fire. Don't actually try to close the tab as it |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 3774 | // will go down the slow shutdown path instead of the fast path of killing |
| 3775 | // all the renderer processes. |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 3776 | ClearUnloadState(source, true); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 3777 | return; |
| 3778 | } |
| 3779 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3780 | int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3781 | if (index == TabStripModel::kNoTab) { |
| 3782 | NOTREACHED() << "CloseContents called for tab not in our strip"; |
| 3783 | return; |
| 3784 | } |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3785 | tab_handler_->GetTabStripModel()->CloseTabContentsAt( |
[email protected] | 0cce15f | 2010-05-21 16:58:39 | [diff] [blame] | 3786 | index, |
| 3787 | TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3788 | } |
| 3789 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3790 | void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3791 | if (!IsPopupOrPanel(source)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3792 | NOTREACHED() << "moving invalid browser type"; |
| 3793 | return; |
| 3794 | } |
[email protected] | e561e20 | 2010-03-24 17:57:12 | [diff] [blame] | 3795 | window_->SetBounds(pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3796 | } |
| 3797 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3798 | void Browser::DetachContents(WebContents* source) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3799 | int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 3800 | if (index >= 0) |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3801 | tab_handler_->GetTabStripModel()->DetachTabContentsAt(index); |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 3802 | } |
| 3803 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3804 | bool Browser::IsPopupOrPanel(const WebContents* source) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3805 | // A non-tabbed BROWSER is an unconstrained popup. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3806 | return is_type_popup() || is_type_panel(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3807 | } |
| 3808 | |
[email protected] | b8595e9 | 2009-11-14 01:18:00 | [diff] [blame] | 3809 | void Browser::ContentsMouseEvent( |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3810 | WebContents* source, const gfx::Point& location, bool motion) { |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3811 | if (!GetStatusBubble()) |
| 3812 | return; |
| 3813 | |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 3814 | if (source == GetSelectedWebContents()) { |
[email protected] | b8595e9 | 2009-11-14 01:18:00 | [diff] [blame] | 3815 | GetStatusBubble()->MouseMoved(location, !motion); |
| 3816 | if (!motion) |
[email protected] | 6523305 | 2011-08-22 19:02:48 | [diff] [blame] | 3817 | GetStatusBubble()->SetURL(GURL(), std::string()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3818 | } |
| 3819 | } |
| 3820 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3821 | void Browser::UpdateTargetURL(WebContents* source, int32 page_id, |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 3822 | const GURL& url) { |
| 3823 | Browser::UpdateTargetURLHelper(source, page_id, url); |
| 3824 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3825 | if (!GetStatusBubble()) |
| 3826 | return; |
| 3827 | |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 3828 | if (source == GetSelectedWebContents()) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3829 | PrefService* prefs = profile_->GetPrefs(); |
[email protected] | 6523305 | 2011-08-22 19:02:48 | [diff] [blame] | 3830 | GetStatusBubble()->SetURL(url, prefs->GetString(prefs::kAcceptLanguages)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3831 | } |
| 3832 | } |
| 3833 | |
[email protected] | 3a6a3b6 | 2009-05-27 21:36:20 | [diff] [blame] | 3834 | void Browser::UpdateDownloadShelfVisibility(bool visible) { |
[email protected] | 9b032bf | 2009-07-21 17:34:23 | [diff] [blame] | 3835 | if (GetStatusBubble()) |
| 3836 | GetStatusBubble()->UpdateDownloadShelfVisibility(visible); |
[email protected] | 3a6a3b6 | 2009-05-27 21:36:20 | [diff] [blame] | 3837 | } |
| 3838 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3839 | void Browser::ContentsZoomChange(bool zoom_in) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3840 | ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3841 | } |
| 3842 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3843 | void Browser::WebContentsFocused(WebContents* contents) { |
| 3844 | window_->WebContentsFocused(contents); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 3845 | } |
| 3846 | |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 3847 | bool Browser::TakeFocus(bool reverse) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 3848 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 3849 | chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 3850 | content::Source<Browser>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 3851 | content::NotificationService::NoDetails()); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 3852 | return false; |
| 3853 | } |
| 3854 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3855 | bool Browser::IsApplication() const { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3856 | return is_app(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3857 | } |
| 3858 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3859 | void Browser::ConvertContentsToApplication(WebContents* contents) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 3860 | const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 3861 | std::string app_name = web_app::GenerateApplicationNameFromURL(url); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3862 | |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 3863 | DetachContents(contents); |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 3864 | Browser* app_browser = Browser::CreateForApp( |
[email protected] | 5c20924 | 2011-06-06 20:36:17 | [diff] [blame] | 3865 | TYPE_POPUP, app_name, gfx::Rect(), profile_); |
[email protected] | ae2f2a77 | 2011-05-04 16:30:27 | [diff] [blame] | 3866 | TabContentsWrapper* wrapper = |
| 3867 | TabContentsWrapper::GetCurrentWrapperForContents(contents); |
| 3868 | if (!wrapper) |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3869 | wrapper = new TabContentsWrapper(contents); |
[email protected] | 75aef12 | 2010-12-06 21:48:32 | [diff] [blame] | 3870 | app_browser->tabstrip_model()->AppendTabContents(wrapper, true); |
| 3871 | |
| 3872 | contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 3873 | contents->GetRenderViewHost()->SyncRendererPrefs(); |
[email protected] | 75aef12 | 2010-12-06 21:48:32 | [diff] [blame] | 3874 | app_browser->window()->Show(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3875 | } |
| 3876 | |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 3877 | gfx::Rect Browser::GetRootWindowResizerRect() const { |
| 3878 | return window_->GetRootWindowResizerRect(); |
| 3879 | } |
| 3880 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3881 | void Browser::BeforeUnloadFired(WebContents* tab, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3882 | bool proceed, |
| 3883 | bool* proceed_to_fire_unload) { |
| 3884 | if (!is_attempting_to_close_browser_) { |
| 3885 | *proceed_to_fire_unload = proceed; |
[email protected] | 0cce15f | 2010-05-21 16:58:39 | [diff] [blame] | 3886 | if (!proceed) |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3887 | tab->SetClosedByUserGesture(false); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3888 | return; |
| 3889 | } |
| 3890 | |
| 3891 | if (!proceed) { |
| 3892 | CancelWindowClose(); |
| 3893 | *proceed_to_fire_unload = false; |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3894 | tab->SetClosedByUserGesture(false); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3895 | return; |
| 3896 | } |
| 3897 | |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 3898 | if (RemoveFromSet(&tabs_needing_before_unload_fired_, tab)) { |
[email protected] | 2d46c84 | 2008-11-14 19:24:31 | [diff] [blame] | 3899 | // Now that beforeunload has fired, put the tab on the queue to fire |
| 3900 | // unload. |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 3901 | tabs_needing_unload_fired_.insert(tab); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3902 | ProcessPendingTabs(); |
[email protected] | adf650f | 2008-12-09 16:10:06 | [diff] [blame] | 3903 | // We want to handle firing the unload event ourselves since we want to |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3904 | // fire all the beforeunload events before attempting to fire the unload |
| 3905 | // events should the user cancel closing the browser. |
| 3906 | *proceed_to_fire_unload = false; |
| 3907 | return; |
| 3908 | } |
| 3909 | |
| 3910 | *proceed_to_fire_unload = true; |
| 3911 | } |
| 3912 | |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 3913 | void Browser::SetFocusToLocationBar(bool select_all) { |
[email protected] | 1a38062 | 2009-02-17 17:33:13 | [diff] [blame] | 3914 | // Two differences between this and FocusLocationBar(): |
| 3915 | // (1) This doesn't get recorded in user metrics, since it's called |
| 3916 | // internally. |
| 3917 | // (2) This checks whether the location bar can be focused, and if not, clears |
| 3918 | // the focus. FocusLocationBar() is only reached when the location bar is |
| 3919 | // focusable, but this may be reached at other times, e.g. while in |
| 3920 | // fullscreen mode, where we need to leave focus in a consistent state. |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 3921 | window_->SetFocusToLocationBar(select_all); |
[email protected] | 4bcefee | 2009-01-29 15:57:57 | [diff] [blame] | 3922 | } |
| 3923 | |
[email protected] | 7d5925a | 2009-03-03 02:59:12 | [diff] [blame] | 3924 | void Browser::RenderWidgetShowing() { |
| 3925 | window_->DisableInactiveFrame(); |
| 3926 | } |
[email protected] | a239c3f | 2009-02-17 22:13:19 | [diff] [blame] | 3927 | |
[email protected] | 0a2aeb8 | 2009-05-15 21:52:48 | [diff] [blame] | 3928 | int Browser::GetExtraRenderViewHeight() const { |
| 3929 | return window_->GetExtraRenderViewHeight(); |
| 3930 | } |
| 3931 | |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3932 | namespace { |
| 3933 | |
| 3934 | bool DisplayOldDownloadsUI() { |
| 3935 | return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 3936 | switches::kDownloadsNewUI); |
| 3937 | } |
| 3938 | |
| 3939 | } // anonymous namespace |
| 3940 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 3941 | void Browser::OnStartDownload(WebContents* source, |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 3942 | content::DownloadItem* download) { |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3943 | TabContentsWrapper* wrapper = |
| 3944 | TabContentsWrapper::GetCurrentWrapperForContents(source); |
| 3945 | TabContentsWrapper* constrained = GetConstrainingContentsWrapper(wrapper); |
| 3946 | if (constrained != wrapper) { |
| 3947 | // Download in a constrained popup is shown in the tab that opened it. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 3948 | WebContents* constrained_tab = constrained->web_contents(); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 3949 | constrained_tab->GetDelegate()->OnStartDownload(constrained_tab, download); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3950 | return; |
| 3951 | } |
| 3952 | |
| 3953 | if (!window()) |
| 3954 | return; |
| 3955 | |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3956 | if (DisplayOldDownloadsUI()) { |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 3957 | #if defined(OS_CHROMEOS) && !defined(USE_AURA) |
[email protected] | 603a502a | 2011-12-15 20:18:17 | [diff] [blame] | 3958 | if (ActiveDownloadsUI::ShouldShowPopup(profile_, download)) |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3959 | ActiveDownloadsUI::OpenPopup(profile_); |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 3960 | #else |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3961 | // GetDownloadShelf creates the download shelf if it was not yet created. |
| 3962 | DownloadShelf* shelf = window()->GetDownloadShelf(); |
| 3963 | shelf->AddDownload(new DownloadItemModel(download)); |
| 3964 | // Don't show the animation for "Save file" downloads. |
| 3965 | // For non-theme extensions, we don't show the download animation. |
| 3966 | // Show animation in same window as the download shelf. Download shelf |
| 3967 | // may not be in the same window that initiated the download, e.g. |
| 3968 | // Panels. |
| 3969 | // Don't show the animation if the selected tab is not visible (i.e. the |
| 3970 | // window is minimized, we're in a unit test, etc.). |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 3971 | WebContents* shelf_tab = shelf->browser()->GetSelectedWebContents(); |
[email protected] | c09a8fd | 2011-11-21 19:54:50 | [diff] [blame] | 3972 | if ((download->GetTotalBytes() > 0) && |
[email protected] | b0cfcee | 2011-10-27 03:55:37 | [diff] [blame] | 3973 | !ChromeDownloadManagerDelegate::IsExtensionDownload(download) && |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3974 | platform_util::IsVisible(shelf_tab->GetNativeView()) && |
| 3975 | ui::Animation::ShouldRenderRichAnimation()) { |
| 3976 | DownloadStartedAnimation::Show(shelf_tab); |
| 3977 | } |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3978 | #endif |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3979 | } |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3980 | |
| 3981 | // If the download occurs in a new tab, close it. |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 3982 | if (source->GetController().IsInitialNavigation() && tab_count() > 1) |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3983 | CloseContents(source); |
| 3984 | } |
| 3985 | |
[email protected] | b8e681e8 | 2012-02-20 10:18:47 | [diff] [blame] | 3986 | void Browser::ShowPageInfo(content::WebContents* web_contents, |
| 3987 | const GURL& url, |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 3988 | const SSLStatus& ssl, |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 3989 | bool show_history) { |
[email protected] | b8e681e8 | 2012-02-20 10:18:47 | [diff] [blame] | 3990 | Profile* profile = Profile::FromBrowserContext( |
| 3991 | web_contents->GetBrowserContext()); |
| 3992 | TabContentsWrapper* wrapper = |
| 3993 | TabContentsWrapper::GetCurrentWrapperForContents(web_contents); |
| 3994 | |
| 3995 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 3996 | switches::kEnableWebsiteSettings)) { |
| 3997 | window()->ShowWebsiteSettings(profile, wrapper, url, ssl, show_history); |
| 3998 | } else { |
| 3999 | window()->ShowPageInfo(profile, url, ssl, show_history); |
| 4000 | } |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 4001 | } |
| 4002 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4003 | void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 4004 | DCHECK(source); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 4005 | TabContentsWrapper* wrapper = GetTabContentsWrapperAt( |
| 4006 | tab_handler_->GetTabStripModel()->GetWrapperIndex(source)); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 4007 | ViewSource(wrapper); |
| 4008 | } |
| 4009 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4010 | void Browser::ViewSourceForFrame(WebContents* source, |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 4011 | const GURL& frame_url, |
| 4012 | const std::string& frame_content_state) { |
| 4013 | DCHECK(source); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 4014 | TabContentsWrapper* wrapper = GetTabContentsWrapperAt( |
| 4015 | tab_handler_->GetTabStripModel()->GetWrapperIndex(source)); |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 4016 | ViewSource(wrapper, frame_url, frame_content_state); |
| 4017 | } |
| 4018 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 4019 | bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 4020 | bool* is_keyboard_shortcut) { |
[email protected] | 85804b5 | 2011-10-15 06:56:27 | [diff] [blame] | 4021 | // Escape exits tabbed fullscreen mode. |
| 4022 | // TODO(koz): Write a test for this http://crbug.com/100441. |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 4023 | if (event.windowsKeyCode == 27 && |
| 4024 | fullscreen_controller_->HandleUserPressedEscape()) { |
[email protected] | 85804b5 | 2011-10-15 06:56:27 | [diff] [blame] | 4025 | return true; |
| 4026 | } |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 4027 | return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 4028 | } |
[email protected] | 97df4b33 | 2009-10-02 01:25:41 | [diff] [blame] | 4029 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 4030 | void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 4031 | window()->HandleKeyboardEvent(event); |
[email protected] | 97df4b33 | 2009-10-02 01:25:41 | [diff] [blame] | 4032 | } |
| 4033 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 4034 | void Browser::ShowRepostFormWarningDialog(WebContents* source) { |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 4035 | browser::ShowTabModalConfirmDialog( |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4036 | new RepostFormWarningController(source), |
| 4037 | TabContentsWrapper::GetCurrentWrapperForContents(source)); |
[email protected] | 14f3408a | 2009-08-31 20:53:53 | [diff] [blame] | 4038 | } |
| 4039 | |
[email protected] | 579e319 | 2011-03-11 22:37:45 | [diff] [blame] | 4040 | void Browser::ShowContentSettingsPage(ContentSettingsType content_type) { |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 4041 | ShowOptionsTab( |
| 4042 | chrome::kContentSettingsExceptionsSubPage + std::string(kHashMark) + |
| 4043 | ContentSettingsHandler::ContentSettingsTypeToGroupName(content_type)); |
[email protected] | 6354314 | 2010-02-09 23:22:20 | [diff] [blame] | 4044 | } |
| 4045 | |
[email protected] | a3627e6 | 2011-09-07 00:04:57 | [diff] [blame] | 4046 | void Browser::ShowCollectedCookiesDialog(TabContentsWrapper* wrapper) { |
| 4047 | window()->ShowCollectedCookiesDialog(wrapper); |
[email protected] | a503c97c | 2010-07-16 13:05:48 | [diff] [blame] | 4048 | } |
| 4049 | |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 4050 | bool Browser::ShouldAddNavigationToHistory( |
| 4051 | const history::HistoryAddPageArgs& add_page_args, |
[email protected] | 610cbb8 | 2011-10-18 16:35:08 | [diff] [blame] | 4052 | content::NavigationType navigation_type) { |
[email protected] | 2e29d92 | 2009-10-22 22:13:35 | [diff] [blame] | 4053 | // Don't update history if running as app. |
| 4054 | return !IsApplication(); |
| 4055 | } |
| 4056 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 4057 | bool Browser::ShouldCreateWebContents( |
| 4058 | WebContents* web_contents, |
| 4059 | int route_id, |
| 4060 | WindowContainerType window_container_type, |
| 4061 | const string16& frame_name) { |
| 4062 | if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
| 4063 | // If a BackgroundContents is created, suppress the normal WebContents. |
| 4064 | return !MaybeCreateBackgroundContents( |
| 4065 | route_id, |
| 4066 | web_contents->GetSiteInstance(), |
| 4067 | web_contents->GetURL(), |
| 4068 | frame_name); |
| 4069 | } |
| 4070 | |
| 4071 | return true; |
| 4072 | } |
| 4073 | |
| 4074 | void Browser::WebContentsCreated(WebContents* source_contents, |
| 4075 | int64 source_frame_id, |
| 4076 | const GURL& target_url, |
| 4077 | WebContents* new_contents) { |
[email protected] | 80c7b80 | 2011-10-28 19:59:08 | [diff] [blame] | 4078 | // Create a TabContentsWrapper now, so all observers are in place, as the |
| 4079 | // network requests for its initial navigation will start immediately. The |
| 4080 | // TabContents will later be inserted into this browser using |
| 4081 | // Browser::Navigate via AddNewContents. The latter will retrieve the newly |
| 4082 | // created TabContentsWrapper from TabContents object. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 4083 | new TabContentsWrapper(new_contents); |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 4084 | |
| 4085 | // Notify. |
| 4086 | RetargetingDetails details; |
| 4087 | details.source_web_contents = source_contents; |
| 4088 | details.source_frame_id = source_frame_id; |
| 4089 | details.target_url = target_url; |
| 4090 | details.target_web_contents = new_contents; |
| 4091 | details.not_yet_in_tabstrip = true; |
| 4092 | content::NotificationService::current()->Notify( |
| 4093 | chrome::NOTIFICATION_RETARGETING, |
| 4094 | content::Source<Profile>(profile_), |
| 4095 | content::Details<RetargetingDetails>(&details)); |
[email protected] | 80c7b80 | 2011-10-28 19:59:08 | [diff] [blame] | 4096 | } |
| 4097 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4098 | void Browser::ContentRestrictionsChanged(WebContents* source) { |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4099 | UpdateCommandsForContentRestrictionState(); |
| 4100 | } |
| 4101 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4102 | void Browser::RendererUnresponsive(WebContents* source) { |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 4103 | // Ignore hangs if print preview is open. |
| 4104 | TabContentsWrapper* source_wrapper = |
| 4105 | TabContentsWrapper::GetCurrentWrapperForContents(source); |
| 4106 | if (source_wrapper) { |
| 4107 | printing::PrintPreviewTabController* controller = |
| 4108 | printing::PrintPreviewTabController::GetInstance(); |
| 4109 | if (controller) { |
| 4110 | TabContentsWrapper* preview_tab = |
| 4111 | controller->GetPrintPreviewForTab(source_wrapper); |
| 4112 | if (preview_tab && preview_tab != source_wrapper) { |
| 4113 | return; |
| 4114 | } |
| 4115 | } |
| 4116 | } |
| 4117 | |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 4118 | browser::ShowHungRendererDialog(source); |
| 4119 | } |
| 4120 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4121 | void Browser::RendererResponsive(WebContents* source) { |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 4122 | browser::HideHungRendererDialog(source); |
| 4123 | } |
| 4124 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4125 | void Browser::WorkerCrashed(WebContents* source) { |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 4126 | TabContentsWrapper* wrapper = |
| 4127 | TabContentsWrapper::GetCurrentWrapperForContents(source); |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 4128 | InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); |
| 4129 | infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 4130 | infobar_helper, |
| 4131 | NULL, |
| 4132 | l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 4133 | true)); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 4134 | } |
| 4135 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4136 | void Browser::DidNavigateMainFramePostCommit(WebContents* tab) { |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 4137 | if (tab == GetSelectedWebContents()) |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 4138 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 4139 | } |
| 4140 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4141 | void Browser::DidNavigateToPendingEntry(WebContents* tab) { |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 4142 | if (tab == GetSelectedWebContents()) |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 4143 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 4144 | } |
| 4145 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 4146 | content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { |
| 4147 | return GetJavaScriptDialogCreatorInstance(); |
| 4148 | } |
| 4149 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4150 | void Browser::RunFileChooser(WebContents* tab, |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 4151 | const content::FileChooserParams& params) { |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 4152 | RunFileChooserHelper(tab, params); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 4153 | } |
| 4154 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4155 | void Browser::EnumerateDirectory(WebContents* tab, int request_id, |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 4156 | const FilePath& path) { |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 4157 | EnumerateDirectoryHelper(tab, request_id, path); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 4158 | } |
| 4159 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4160 | void Browser::ToggleFullscreenModeForTab(WebContents* tab, |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 4161 | bool enter_fullscreen) { |
| 4162 | fullscreen_controller_->ToggleFullscreenModeForTab(tab, enter_fullscreen); |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 4163 | } |
| 4164 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4165 | bool Browser::IsFullscreenForTab(const WebContents* tab) const { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 4166 | return fullscreen_controller_->IsFullscreenForTab(tab); |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 4167 | } |
| 4168 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4169 | void Browser::JSOutOfMemory(WebContents* tab) { |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 4170 | JSOutOfMemoryHelper(tab); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 4171 | } |
| 4172 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4173 | void Browser::RegisterProtocolHandler(WebContents* tab, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 4174 | const std::string& protocol, |
| 4175 | const GURL& url, |
| 4176 | const string16& title) { |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 4177 | RegisterProtocolHandlerHelper(tab, protocol, url, title); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 4178 | } |
| 4179 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4180 | void Browser::RegisterIntentHandler(WebContents* tab, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 4181 | const string16& action, |
| 4182 | const string16& type, |
| 4183 | const string16& href, |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 4184 | const string16& title, |
| 4185 | const string16& disposition) { |
| 4186 | RegisterIntentHandlerHelper(tab, action, type, href, title, disposition); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 4187 | } |
| 4188 | |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 4189 | void Browser::WebIntentDispatch( |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4190 | WebContents* tab, content::WebIntentsDispatcher* intents_dispatcher) { |
[email protected] | 8f0bbd6 | 2012-02-22 03:37:18 | [diff] [blame] | 4191 | if (!web_intents::IsWebIntentsEnabled()) |
[email protected] | 828e61af | 2011-09-14 19:45:06 | [diff] [blame] | 4192 | return; |
| 4193 | |
| 4194 | TabContentsWrapper* tcw = |
| 4195 | TabContentsWrapper::GetCurrentWrapperForContents(tab); |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 4196 | tcw->web_intent_picker_controller()->SetIntentsDispatcher(intents_dispatcher); |
[email protected] | ada02b31 | 2011-12-01 21:54:53 | [diff] [blame] | 4197 | tcw->web_intent_picker_controller()->ShowDialog( |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 4198 | this, |
| 4199 | intents_dispatcher->GetIntent().action, |
| 4200 | intents_dispatcher->GetIntent().type); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 4201 | } |
| 4202 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4203 | void Browser::FindReply(WebContents* tab, |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 4204 | int request_id, |
| 4205 | int number_of_matches, |
| 4206 | const gfx::Rect& selection_rect, |
| 4207 | int active_match_ordinal, |
| 4208 | bool final_update) { |
| 4209 | FindReplyHelper(tab, request_id, number_of_matches, selection_rect, |
| 4210 | active_match_ordinal, final_update); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 4211 | } |
| 4212 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4213 | void Browser::CrashedPlugin(WebContents* tab, const FilePath& plugin_path) { |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 4214 | CrashedPluginHelper(tab, plugin_path); |
| 4215 | } |
| 4216 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4217 | void Browser::UpdatePreferredSize(WebContents* source, |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 4218 | const gfx::Size& pref_size) { |
| 4219 | window_->UpdatePreferredSize(source, pref_size); |
| 4220 | } |
| 4221 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 4222 | void Browser::RequestToLockMouse(WebContents* tab) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 4223 | fullscreen_controller_->RequestToLockMouse(tab); |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 4224 | } |
| 4225 | |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 4226 | void Browser::LostMouseLock() { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 4227 | fullscreen_controller_->LostMouseLock(); |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | void Browser::OnAcceptFullscreenPermission( |
| 4231 | const GURL& url, |
| 4232 | FullscreenExitBubbleType bubble_type) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 4233 | fullscreen_controller_->OnAcceptFullscreenPermission(url, bubble_type); |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 4234 | } |
| 4235 | |
| 4236 | void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 4237 | fullscreen_controller_->OnDenyFullscreenPermission(bubble_type); |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 4238 | } |
| 4239 | |
[email protected] | fc9bf18f | 2011-10-22 00:41:17 | [diff] [blame] | 4240 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4241 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 4242 | // Browser, CoreTabHelperDelegate implementation: |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 4243 | |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 4244 | void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
| 4245 | int32 page_id) { |
| 4246 | if (GetSelectedTabContentsWrapper() != source) |
| 4247 | return; |
| 4248 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 4249 | NavigationEntry* entry = |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 4250 | source->web_contents()->GetController().GetLastCommittedEntry(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 4251 | if (!entry || (entry->GetPageID() != page_id)) |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 4252 | return; |
| 4253 | |
| 4254 | switch (pending_web_app_action_) { |
| 4255 | case CREATE_SHORTCUT: { |
| 4256 | window()->ShowCreateWebAppShortcutsDialog(source); |
| 4257 | break; |
| 4258 | } |
| 4259 | case UPDATE_SHORTCUT: { |
| 4260 | web_app::UpdateShortcutForTabContents(source); |
| 4261 | break; |
| 4262 | } |
| 4263 | default: |
| 4264 | NOTREACHED(); |
| 4265 | break; |
| 4266 | } |
| 4267 | |
| 4268 | pending_web_app_action_ = NONE; |
| 4269 | } |
| 4270 | |
| 4271 | void Browser::OnInstallApplication(TabContentsWrapper* source, |
| 4272 | const WebApplicationInfo& web_app) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 4273 | ExtensionService* extension_service = profile()->GetExtensionService(); |
| 4274 | if (!extension_service) |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 4275 | return; |
| 4276 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4277 | scoped_refptr<CrxInstaller> installer(CrxInstaller::Create( |
| 4278 | extension_service, |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 4279 | extension_service->show_extensions_prompts() ? |
| 4280 | new ExtensionInstallUI(profile()) : NULL)); |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 4281 | installer->InstallWebApp(web_app); |
| 4282 | } |
| 4283 | |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 4284 | /////////////////////////////////////////////////////////////////////////////// |
| 4285 | // Browser, SearchEngineTabHelperDelegate implementation: |
| 4286 | |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 4287 | void Browser::ConfirmAddSearchProvider(const TemplateURL* template_url, |
| 4288 | Profile* profile) { |
[email protected] | a6420df | 2012-01-06 04:41:02 | [diff] [blame] | 4289 | window()->ConfirmAddSearchProvider(template_url, profile); |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 4290 | } |
| 4291 | |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 4292 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 4293 | // Browser, BlockedContentTabHelperDelegate implementation: |
| 4294 | |
[email protected] | 393c0ed0 | 2011-04-22 14:55:36 | [diff] [blame] | 4295 | TabContentsWrapper* Browser::GetConstrainingContentsWrapper( |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 4296 | TabContentsWrapper* source) { |
| 4297 | return source; |
| 4298 | } |
| 4299 | |
| 4300 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 4301 | // Browser, BookmarkTabHelperDelegate implementation: |
[email protected] | 52cc59b | 2011-05-06 14:42:38 | [diff] [blame] | 4302 | |
| 4303 | void Browser::URLStarredChanged(TabContentsWrapper* source, bool starred) { |
| 4304 | if (source == GetSelectedTabContentsWrapper()) |
| 4305 | window_->SetStarredState(starred); |
| 4306 | } |
| 4307 | |
| 4308 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4309 | // Browser, SelectFileDialog::Listener implementation: |
| 4310 | |
[email protected] | 561abe6 | 2009-04-06 18:08:34 | [diff] [blame] | 4311 | void Browser::FileSelected(const FilePath& path, int index, void* params) { |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 4312 | profile_->set_last_selected_directory(path.DirName()); |
[email protected] | 72cbd32 | 2009-04-07 10:17:12 | [diff] [blame] | 4313 | GURL file_url = net::FilePathToFileURL(path); |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 4314 | if (file_url.is_empty()) |
| 4315 | return; |
| 4316 | |
| 4317 | OpenURL(OpenURLParams( |
| 4318 | file_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, |
| 4319 | false)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4323 | // Browser, content::NotificationObserver implementation: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4324 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4325 | void Browser::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4326 | const content::NotificationSource& source, |
| 4327 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4328 | switch (type) { |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 4329 | case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 4330 | if (is_attempting_to_close_browser_) { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4331 | // Pass in false so that we delay processing. We need to delay the |
| 4332 | // processing as it may close the tab, which is currently on the call |
| 4333 | // stack above us. |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 4334 | ClearUnloadState(content::Source<WebContents>(source).ptr(), false); |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 4335 | } |
| 4336 | break; |
| 4337 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4338 | case content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED: |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 4339 | // 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] | 4340 | // bar to reflect the new state. Note that it's possible for the selected |
| 4341 | // tab contents to be NULL. This is because we listen for all sources |
| 4342 | // (NavigationControllers) for convenience, so the notification could |
| 4343 | // actually be for a different window while we're doing asynchronous |
| 4344 | // closing of this one. |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 4345 | if (GetSelectedWebContents() && |
| 4346 | &GetSelectedWebContents()->GetController() == |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 4347 | content::Source<NavigationController>(source).ptr()) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4348 | UpdateToolbar(false); |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 4349 | break; |
| 4350 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4351 | case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: { |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 4352 | // Show the UI if the extension was disabled for escalated permissions. |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4353 | Profile* profile = content::Source<Profile>(source).ptr(); |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 4354 | if (profile_->IsSameProfile(profile)) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4355 | ExtensionService* service = profile->GetExtensionService(); |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 4356 | DCHECK(service); |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4357 | const Extension* extension = |
| 4358 | content::Details<const Extension>(details).ptr(); |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 4359 | if (service->extension_prefs()->DidExtensionEscalatePermissions( |
| 4360 | extension->id())) |
| 4361 | ShowExtensionDisabledUI(service, profile_, extension); |
| 4362 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 4363 | break; |
| 4364 | } |
| 4365 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4366 | case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 4367 | if (window()->GetLocationBar()) |
| 4368 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 57f71b9 | 2009-09-11 19:31:38 | [diff] [blame] | 4369 | |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 4370 | // Close any tabs from the unloaded extension, unless it's terminated, |
| 4371 | // in which case let the sad tabs remain. |
| 4372 | if (content::Details<UnloadedExtensionInfo>(details)->reason != |
| 4373 | extension_misc::UNLOAD_REASON_TERMINATE) { |
| 4374 | const Extension* extension = |
| 4375 | content::Details<UnloadedExtensionInfo>(details)->extension; |
| 4376 | TabStripModel* model = tab_handler_->GetTabStripModel(); |
| 4377 | for (int i = model->count() - 1; i >= 0; --i) { |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 4378 | WebContents* tc = model->GetTabContentsAt(i)->web_contents(); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 4379 | bool close_tab_contents = |
| 4380 | tc->GetURL().SchemeIs(chrome::kExtensionScheme) && |
| 4381 | tc->GetURL().host() == extension->id(); |
| 4382 | // We want to close all panels originated by the unloaded extension. |
| 4383 | close_tab_contents = close_tab_contents || |
| 4384 | (type_ == TYPE_PANEL && |
| 4385 | (web_app::GetExtensionIdFromApplicationName(app_name_) == |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 4386 | extension->id())); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 4387 | if (close_tab_contents) { |
| 4388 | CloseTabContents(tc); |
| 4389 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4390 | } |
| 4391 | } |
| 4392 | break; |
| 4393 | } |
| 4394 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4395 | case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4396 | Profile* profile = content::Source<Profile>(source).ptr(); |
[email protected] | fe8944f | 2011-08-30 17:47:32 | [diff] [blame] | 4397 | if (profile_->IsSameProfile(profile) && window()->GetLocationBar()) |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 4398 | window()->GetLocationBar()->InvalidatePageActions(); |
[email protected] | 371ed7a | 2009-08-25 15:22:46 | [diff] [blame] | 4399 | break; |
| 4400 | } |
| 4401 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4402 | case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: |
| 4403 | case chrome::NOTIFICATION_EXTENSION_LOADED: |
[email protected] | 1797f4a | 2011-08-30 18:00:28 | [diff] [blame] | 4404 | // During window creation on Windows we may end up calling into |
| 4405 | // SHAppBarMessage, which internally spawns a nested message loop. This |
| 4406 | // makes it possible for us to end up here before window creation has |
| 4407 | // completed,at which point window_ is NULL. See 94752 for details. |
| 4408 | if (window() && window()->GetLocationBar()) |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 4409 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 4410 | break; |
[email protected] | ad0c2e1b | 2010-01-30 00:00:10 | [diff] [blame] | 4411 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4412 | case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 4413 | window()->UserChangedTheme(); |
| 4414 | break; |
| 4415 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4416 | case chrome::NOTIFICATION_PREF_CHANGED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4417 | const std::string& pref_name = |
| 4418 | *content::Details<std::string>(details).ptr(); |
[email protected] | 3cf345b | 2011-10-06 17:51:25 | [diff] [blame] | 4419 | if (pref_name == prefs::kPrintingEnabled) { |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 4420 | UpdatePrintingState(GetContentRestrictionsForSelectedTab()); |
[email protected] | 3819f2ee | 2011-08-21 09:44:38 | [diff] [blame] | 4421 | } else if (pref_name == prefs::kInstantEnabled || |
| 4422 | pref_name == prefs::kMetricsReportingEnabled || |
| 4423 | pref_name == prefs::kSearchSuggestEnabled) { |
[email protected] | 73de26a | 2010-10-17 03:23:25 | [diff] [blame] | 4424 | if (!InstantController::IsEnabled(profile())) { |
| 4425 | if (instant()) { |
| 4426 | instant()->DestroyPreviewContents(); |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 4427 | instant_.reset(); |
| 4428 | instant_unload_handler_.reset(); |
[email protected] | 73de26a | 2010-10-17 03:23:25 | [diff] [blame] | 4429 | } |
| 4430 | } else { |
| 4431 | CreateInstantIfNecessary(); |
| 4432 | } |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 4433 | } else if (pref_name == prefs::kIncognitoModeAvailability) { |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4434 | UpdateCommandsForIncognitoAvailability(); |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 4435 | } else if (pref_name == prefs::kDevToolsDisabled) { |
| 4436 | UpdateCommandsForDevTools(); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4437 | if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 4438 | content::DevToolsManager::GetInstance()->CloseAllClientHosts(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4439 | } else if (pref_name == prefs::kEditBookmarksEnabled) { |
| 4440 | UpdateCommandsForBookmarkEditing(); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 4441 | } else if (pref_name == prefs::kShowBookmarkBar) { |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 4442 | UpdateCommandsForBookmarkBar(); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 4443 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 4444 | } else if (pref_name == prefs::kHomePage) { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4445 | PrefService* pref_service = content::Source<PrefService>(source).ptr(); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 4446 | MarkHomePageAsChanged(pref_service); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4447 | } else if (pref_name == prefs::kAllowFileSelectionDialogs) { |
| 4448 | UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); |
| 4449 | UpdateOpenFileState(); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 4450 | } else { |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 4451 | NOTREACHED(); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 4452 | } |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 4453 | break; |
| 4454 | } |
| 4455 | |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 4456 | case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { |
| 4457 | WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 4458 | if (web_contents == GetSelectedWebContents()) { |
[email protected] | 9a9a9e2 | 2011-05-13 22:20:35 | [diff] [blame] | 4459 | LocationBar* location_bar = window()->GetLocationBar(); |
| 4460 | if (location_bar) |
| 4461 | location_bar->UpdateContentSettingsIcons(); |
| 4462 | } |
| 4463 | break; |
| 4464 | } |
| 4465 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4466 | case content::NOTIFICATION_INTERSTITIAL_ATTACHED: |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 4467 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 4468 | UpdateCommandsForTabState(); |
| 4469 | break; |
| 4470 | |
| 4471 | case content::NOTIFICATION_INTERSTITIAL_DETACHED: |
| 4472 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
| 4473 | UpdateCommandsForTabState(); |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 4474 | break; |
| 4475 | |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 4476 | default: |
| 4477 | NOTREACHED() << "Got a notification we didn't register for."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4478 | } |
| 4479 | } |
| 4480 | |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 4481 | /////////////////////////////////////////////////////////////////////////////// |
| 4482 | // Browser, ProfileSyncServiceObserver implementation: |
| 4483 | |
| 4484 | void Browser::OnStateChanged() { |
[email protected] | 5e61afb9 | 2012-01-27 20:09:13 | [diff] [blame] | 4485 | DCHECK(ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
| 4486 | profile_)); |
[email protected] | 99e652f | 2012-01-22 04:05:07 | [diff] [blame] | 4487 | // For unit tests, we don't have a window. |
| 4488 | if (!window_) |
| 4489 | return; |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4490 | const bool show_main_ui = IsShowingMainUI(window_->IsFullscreen()); |
[email protected] | 6554918 | 2012-02-25 00:45:40 | [diff] [blame] | 4491 | command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, |
[email protected] | 49385da69 | 2011-08-05 04:03:39 | [diff] [blame] | 4492 | show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible()); |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 4493 | } |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 4494 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4495 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 4496 | // Browser, InstantDelegate implementation: |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4497 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4498 | void Browser::ShowInstant(TabContentsWrapper* preview_contents) { |
| 4499 | DCHECK(instant_->tab_contents() == GetSelectedTabContentsWrapper()); |
[email protected] | e3690ed | 2011-03-25 20:25:14 | [diff] [blame] | 4500 | window_->ShowInstant(preview_contents); |
[email protected] | 42f027fb | 2011-10-27 16:37:48 | [diff] [blame] | 4501 | |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 4502 | GetSelectedWebContents()->HideContents(); |
| 4503 | preview_contents->web_contents()->ShowContents(); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4504 | } |
| 4505 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 4506 | void Browser::HideInstant() { |
[email protected] | 3e48128 | 2011-10-15 15:39:50 | [diff] [blame] | 4507 | window_->HideInstant(); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 4508 | if (GetSelectedWebContents()) |
| 4509 | GetSelectedWebContents()->ShowContents(); |
[email protected] | 42f027fb | 2011-10-27 16:37:48 | [diff] [blame] | 4510 | if (instant_->GetPreviewContents()) |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 4511 | instant_->GetPreviewContents()->web_contents()->HideContents(); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4512 | } |
| 4513 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4514 | void Browser::CommitInstant(TabContentsWrapper* preview_contents) { |
| 4515 | TabContentsWrapper* tab_contents = instant_->tab_contents(); |
| 4516 | int index = |
| 4517 | tab_handler_->GetTabStripModel()->GetIndexOfTabContents(tab_contents); |
| 4518 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4519 | // TabStripModel takes ownership of preview_contents. |
[email protected] | 4303234 | 2011-03-21 14:10:31 | [diff] [blame] | 4520 | tab_handler_->GetTabStripModel()->ReplaceTabContentsAt( |
| 4521 | index, preview_contents); |
| 4522 | // InstantUnloadHandler takes ownership of tab_contents. |
| 4523 | instant_unload_handler_->RunUnloadListenersOrDestroy(tab_contents, index); |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 4524 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 4525 | GURL url = preview_contents->web_contents()->GetURL(); |
[email protected] | 6e37fe3 | 2011-03-02 09:06:52 | [diff] [blame] | 4526 | DCHECK(profile_->GetExtensionService()); |
| 4527 | if (profile_->GetExtensionService()->IsInstalledApp(url)) { |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 4528 | UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, |
| 4529 | extension_misc::APP_LAUNCH_OMNIBOX_INSTANT, |
| 4530 | extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 4531 | } |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4532 | } |
| 4533 | |
[email protected] | c98fd5d8 | 2011-05-04 15:20:09 | [diff] [blame] | 4534 | void Browser::SwapTabContents(TabContentsWrapper* old_tab_contents, |
| 4535 | TabContentsWrapper* new_tab_contents) { |
| 4536 | int index = |
| 4537 | tab_handler_->GetTabStripModel()->GetIndexOfTabContents(old_tab_contents); |
[email protected] | 71b5d24 | 2011-04-30 02:27:20 | [diff] [blame] | 4538 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | c98fd5d8 | 2011-05-04 15:20:09 | [diff] [blame] | 4539 | tab_handler_->GetTabStripModel()->ReplaceTabContentsAt(index, |
| 4540 | new_tab_contents); |
[email protected] | 71b5d24 | 2011-04-30 02:27:20 | [diff] [blame] | 4541 | } |
| 4542 | |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 4543 | void Browser::SetTabContentBlocked(TabContentsWrapper* wrapper, bool blocked) { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 4544 | int index = tab_handler_->GetTabStripModel()->GetIndexOfTabContents(wrapper); |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 4545 | if (index == TabStripModel::kNoTab) { |
| 4546 | NOTREACHED(); |
| 4547 | return; |
| 4548 | } |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 4549 | tab_handler_->GetTabStripModel()->SetTabBlocked(index, blocked); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 4550 | UpdatePrintingState(wrapper->web_contents()->GetContentRestrictions()); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 4551 | if (!blocked && GetSelectedTabContentsWrapper() == wrapper) |
| 4552 | wrapper->web_contents()->Focus(); |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 4553 | } |
| 4554 | |
[email protected] | 33b8b8e | 2011-03-15 14:51:55 | [diff] [blame] | 4555 | void Browser::SetSuggestedText(const string16& text, |
| 4556 | InstantCompleteBehavior behavior) { |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 4557 | if (window()->GetLocationBar()) |
| 4558 | window()->GetLocationBar()->SetSuggestedText(text, behavior); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4559 | } |
| 4560 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 4561 | gfx::Rect Browser::GetInstantBounds() { |
| 4562 | return window()->GetInstantBounds(); |
[email protected] | 46fe8e9 | 2010-09-22 03:32:47 | [diff] [blame] | 4563 | } |
| 4564 | |
[email protected] | 43b9517 | 2012-02-04 01:36:00 | [diff] [blame] | 4565 | void Browser::OnWindowDidShow() { |
| 4566 | if (window_has_shown_) |
| 4567 | return; |
| 4568 | window_has_shown_ = true; |
| 4569 | |
| 4570 | // Nothing to do for non-tabbed windows. |
| 4571 | if (!is_type_tabbed()) |
| 4572 | return; |
| 4573 | |
| 4574 | // Show any pending global error bubble. |
| 4575 | GlobalErrorService* service = |
| 4576 | GlobalErrorServiceFactory::GetForProfile(profile()); |
| 4577 | GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
| 4578 | if (error) |
| 4579 | error->ShowBubbleView(this); |
| 4580 | } |
| 4581 | |
| 4582 | void Browser::ShowFirstRunBubble() { |
| 4583 | window()->GetLocationBar()->ShowFirstRunBubble(); |
| 4584 | } |
| 4585 | |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4586 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 4587 | // Browser, protected: |
| 4588 | |
| 4589 | BrowserWindow* Browser::CreateBrowserWindow() { |
[email protected] | d313bf6c | 2011-12-29 22:25:49 | [diff] [blame] | 4590 | bool create_panel = false; |
[email protected] | 815567d | 2012-02-15 18:47:42 | [diff] [blame] | 4591 | #if !defined(OS_CHROMEOS) || defined(USE_AURA) |
| 4592 | create_panel = is_type_panel(); |
[email protected] | d5c1406 | 2011-10-27 00:02:13 | [diff] [blame] | 4593 | #endif |
[email protected] | d313bf6c | 2011-12-29 22:25:49 | [diff] [blame] | 4594 | if (create_panel) |
| 4595 | return PanelManager::GetInstance()->CreatePanel(this); |
[email protected] | 011396a | 2011-04-13 23:35:28 | [diff] [blame] | 4596 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 4597 | return BrowserWindow::CreateBrowserWindow(this); |
| 4598 | } |
| 4599 | |
| 4600 | |
| 4601 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4602 | // Browser, Command and state updating (private): |
| 4603 | |
| 4604 | void Browser::InitCommandState() { |
| 4605 | // All browser commands whose state isn't set automagically some other way |
| 4606 | // (like Back & Forward with initial page load) must have their state |
| 4607 | // initialized here, otherwise they will be forever disabled. |
| 4608 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4609 | // Navigation commands |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4610 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 4611 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4612 | |
| 4613 | // Window management commands |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4614 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); |
| 4615 | command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); |
[email protected] | 598e6c21 | 2012-02-01 04:57:56 | [diff] [blame] | 4616 | #if defined(OS_CHROMEOS) && defined(USE_AURA) |
| 4617 | command_updater_.UpdateCommandEnabled(IDC_NEW_CROSH_TAB, true); |
| 4618 | #endif |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4619 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); |
| 4620 | command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 4621 | command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4622 | command_updater_.UpdateCommandEnabled(IDC_EXIT, true); |
[email protected] | cdc05ec | 2011-05-18 15:15:59 | [diff] [blame] | 4623 | command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4624 | |
| 4625 | // Page-related commands |
[email protected] | 89d6e6e | 2009-12-03 23:06:51 | [diff] [blame] | 4626 | command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4627 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true); |
| 4628 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true); |
| 4629 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true); |
| 4630 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88591, true); |
| 4631 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252, true); |
| 4632 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_GBK, true); |
| 4633 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_GB18030, true); |
| 4634 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5HKSCS, true); |
| 4635 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5, true); |
| 4636 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_THAI, true); |
| 4637 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOREAN, true); |
| 4638 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS, true); |
| 4639 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP, true); |
| 4640 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_EUCJP, true); |
| 4641 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885915, true); |
| 4642 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH, true); |
| 4643 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88592, true); |
| 4644 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250, true); |
| 4645 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88595, true); |
| 4646 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251, true); |
| 4647 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8R, true); |
| 4648 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8U, true); |
| 4649 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88597, true); |
| 4650 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253, true); |
| 4651 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88594, true); |
| 4652 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885913, true); |
| 4653 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257, true); |
| 4654 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88593, true); |
| 4655 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885910, true); |
| 4656 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885914, true); |
| 4657 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885916, true); |
| 4658 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254, true); |
| 4659 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88596, true); |
| 4660 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256, true); |
| 4661 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598, true); |
[email protected] | e13271f | 2009-03-07 00:26:00 | [diff] [blame] | 4662 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598I, true); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4663 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); |
| 4664 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4665 | |
[email protected] | 63b0293 | 2009-06-05 09:40:51 | [diff] [blame] | 4666 | // Zoom |
| 4667 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); |
| 4668 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); |
| 4669 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); |
| 4670 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); |
| 4671 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4672 | // Show various bits of UI |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4673 | UpdateOpenFileState(); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4674 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 4675 | UpdateCommandsForDevTools(); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4676 | command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, true); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4677 | command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4678 | command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
| 4679 | command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE, true); |
[email protected] | d6852fd | 2011-05-20 17:19:12 | [diff] [blame] | 4680 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, true); |
[email protected] | 9cd51a0 | 2009-10-23 22:30:29 | [diff] [blame] | 4681 | |
[email protected] | 96e3467 | 2010-02-09 21:40:29 | [diff] [blame] | 4682 | #if defined(OS_CHROMEOS) |
[email protected] | f41fc93 | 2012-01-20 21:17:33 | [diff] [blame] | 4683 | // Don't allow screen lock for guest sessions. |
| 4684 | command_updater_.UpdateCommandEnabled( |
| 4685 | IDC_LOCK_SCREEN, |
| 4686 | !CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)); |
[email protected] | 2166c43 | 2011-12-07 20:18:28 | [diff] [blame] | 4687 | command_updater_.UpdateCommandEnabled(IDC_SHUTDOWN, true); |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 4688 | command_updater_.UpdateCommandEnabled(IDC_FILE_MANAGER, true); |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 4689 | command_updater_.UpdateCommandEnabled(IDC_SEARCH, true); |
[email protected] | d14af52 | 2010-12-02 03:54:50 | [diff] [blame] | 4690 | command_updater_.UpdateCommandEnabled(IDC_SHOW_KEYBOARD_OVERLAY, true); |
[email protected] | c8b59f9 | 2010-05-28 21:45:47 | [diff] [blame] | 4691 | command_updater_.UpdateCommandEnabled(IDC_INTERNET_OPTIONS, true); |
[email protected] | 96e3467 | 2010-02-09 21:40:29 | [diff] [blame] | 4692 | #endif |
[email protected] | a038159b | 2011-08-18 02:55:36 | [diff] [blame] | 4693 | command_updater_.UpdateCommandEnabled( |
| 4694 | IDC_SHOW_SYNC_SETUP, profile_->GetOriginalProfile()->IsSyncAccessible()); |
[email protected] | c8b59f9 | 2010-05-28 21:45:47 | [diff] [blame] | 4695 | |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 4696 | // Initialize other commands based on the window type. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4697 | bool normal_window = is_type_tabbed(); |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 4698 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 4699 | // Navigation commands |
| 4700 | command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 4701 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 4702 | // Window management commands |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 4703 | // TODO(rohitrao): Disable fullscreen on non-Lion? |
[email protected] | cf299bc | 2010-08-12 20:27:09 | [diff] [blame] | 4704 | command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4705 | !(is_type_panel() && is_app())); |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 4706 | command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| 4707 | command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| 4708 | normal_window); |
| 4709 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window); |
| 4710 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window); |
| 4711 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window); |
| 4712 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window); |
| 4713 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window); |
| 4714 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window); |
| 4715 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window); |
| 4716 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window); |
| 4717 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window); |
| 4718 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window); |
| 4719 | command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window); |
[email protected] | c1d0d81 | 2010-07-27 20:21:55 | [diff] [blame] | 4720 | #if defined(OS_MACOSX) |
| 4721 | command_updater_.UpdateCommandEnabled(IDC_TABPOSE, normal_window); |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 4722 | command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE, |
| 4723 | !(is_type_panel() && is_app())); |
[email protected] | c1d0d81 | 2010-07-27 20:21:55 | [diff] [blame] | 4724 | #endif |
[email protected] | e662ade | 2009-06-08 18:20:14 | [diff] [blame] | 4725 | |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 4726 | // Clipboard commands |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4727 | command_updater_.UpdateCommandEnabled(IDC_COPY_URL, !is_devtools()); |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 4728 | |
| 4729 | // Find-in-page |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4730 | command_updater_.UpdateCommandEnabled(IDC_FIND, !is_devtools()); |
| 4731 | command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, !is_devtools()); |
| 4732 | command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, !is_devtools()); |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 4733 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 4734 | // Show various bits of UI |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 4735 | command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window); |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 4736 | |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 4737 | // The upgrade entry and the view incompatibility entry should always be |
| 4738 | // enabled. Whether they are visible is a separate matter determined on menu |
| 4739 | // show. |
[email protected] | b21d691 | 2010-08-31 19:22:41 | [diff] [blame] | 4740 | command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true); |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 4741 | command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true); |
[email protected] | b21d691 | 2010-08-31 19:22:41 | [diff] [blame] | 4742 | |
[email protected] | b569c11 | 2010-11-22 20:53:44 | [diff] [blame] | 4743 | // View Background Pages entry is always enabled, but is hidden if there are |
| 4744 | // no background pages. |
| 4745 | command_updater_.UpdateCommandEnabled(IDC_VIEW_BACKGROUND_PAGES, true); |
| 4746 | |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 4747 | // Toggle speech input |
| 4748 | command_updater_.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT, true); |
| 4749 | |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 4750 | // Initialize other commands whose state changes based on fullscreen mode. |
| 4751 | UpdateCommandsForFullscreenMode(false); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4752 | |
| 4753 | UpdateCommandsForContentRestrictionState(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4754 | |
| 4755 | UpdateCommandsForBookmarkEditing(); |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4756 | |
| 4757 | UpdateCommandsForIncognitoAvailability(); |
| 4758 | } |
| 4759 | |
| 4760 | bool Browser::IsShowingMainUI(bool is_fullscreen) { |
| 4761 | #if !defined(OS_MACOSX) |
| 4762 | return is_type_tabbed() && !is_fullscreen; |
| 4763 | #else |
| 4764 | return is_type_tabbed(); |
| 4765 | #endif |
| 4766 | } |
| 4767 | |
| 4768 | void Browser::UpdateCommandsForIncognitoAvailability() { |
| 4769 | IncognitoModePrefs::Availability incognito_availability = |
| 4770 | IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
| 4771 | command_updater_.UpdateCommandEnabled( |
| 4772 | IDC_NEW_WINDOW, |
| 4773 | incognito_availability != IncognitoModePrefs::FORCED); |
| 4774 | command_updater_.UpdateCommandEnabled( |
| 4775 | IDC_NEW_INCOGNITO_WINDOW, |
| 4776 | incognito_availability != IncognitoModePrefs::DISABLED); |
| 4777 | |
| 4778 | // Bookmark manager and settings page/subpages are forced to open in normal |
| 4779 | // mode. For this reason we disable these commands when incognito is forced. |
| 4780 | const bool command_enabled = |
| 4781 | incognito_availability != IncognitoModePrefs::FORCED; |
| 4782 | command_updater_.UpdateCommandEnabled( |
| 4783 | IDC_SHOW_BOOKMARK_MANAGER, |
| 4784 | browser_defaults::bookmarks_enabled && command_enabled); |
| 4785 | ExtensionService* extension_service = profile()->GetExtensionService(); |
| 4786 | bool enable_extensions = |
| 4787 | extension_service && extension_service->extensions_enabled(); |
| 4788 | command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, |
| 4789 | enable_extensions && command_enabled); |
| 4790 | |
| 4791 | const bool show_main_ui = IsShowingMainUI(window_ && window_->IsFullscreen()); |
| 4792 | command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, |
| 4793 | show_main_ui && command_enabled); |
| 4794 | command_updater_.UpdateCommandEnabled(IDC_OPTIONS, |
| 4795 | show_main_ui && command_enabled); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4796 | } |
| 4797 | |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4798 | void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4799 | const bool show_main_ui = IsShowingMainUI(is_fullscreen); |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4800 | bool main_not_fullscreen = show_main_ui && !is_fullscreen; |
| 4801 | |
| 4802 | // Navigation commands |
| 4803 | command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); |
| 4804 | |
| 4805 | // Window management commands |
| 4806 | command_updater_.UpdateCommandEnabled(IDC_SHOW_AS_TAB, |
| 4807 | type_ != TYPE_TABBED && !is_fullscreen); |
| 4808 | |
| 4809 | // Focus various bits of UI |
| 4810 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); |
| 4811 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui); |
| 4812 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); |
| 4813 | command_updater_.UpdateCommandEnabled( |
| 4814 | IDC_FOCUS_MENU_BAR, main_not_fullscreen); |
| 4815 | command_updater_.UpdateCommandEnabled( |
| 4816 | IDC_FOCUS_NEXT_PANE, main_not_fullscreen); |
| 4817 | command_updater_.UpdateCommandEnabled( |
| 4818 | IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); |
| 4819 | command_updater_.UpdateCommandEnabled( |
| 4820 | IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
| 4821 | command_updater_.UpdateCommandEnabled( |
| 4822 | IDC_FOCUS_CHROMEOS_STATUS, main_not_fullscreen); |
| 4823 | |
| 4824 | // Show various bits of UI |
| 4825 | command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| 4826 | command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
[email protected] | 6554918 | 2012-02-25 00:45:40 | [diff] [blame] | 4827 | command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, |
[email protected] | 49385da69 | 2011-08-05 04:03:39 | [diff] [blame] | 4828 | show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible()); |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4829 | |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4830 | // Settings page/subpages are forced to open in normal mode. We disable these |
| 4831 | // commands when incognito is forced. |
| 4832 | const bool options_enabled = show_main_ui && |
| 4833 | IncognitoModePrefs::GetAvailability( |
| 4834 | profile_->GetPrefs()) != IncognitoModePrefs::FORCED; |
| 4835 | command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); |
| 4836 | command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); |
| 4837 | |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4838 | command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 4839 | command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 4840 | command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| 4841 | command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
[email protected] | 7d2d0815 | 2011-10-25 22:58:47 | [diff] [blame] | 4842 | command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, |
| 4843 | show_main_ui && !profile()->IsOffTheRecord()); |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4844 | #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
| 4845 | command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| 4846 | #endif |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 4847 | |
| 4848 | UpdateCommandsForBookmarkBar(); |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4849 | } |
| 4850 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4851 | void Browser::UpdateCommandsForTabState() { |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 4852 | WebContents* current_tab = GetSelectedWebContents(); |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 4853 | TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); |
| 4854 | if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore. |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 4855 | return; |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 4856 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4857 | // Navigation commands |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 4858 | NavigationController& nc = current_tab->GetController(); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 4859 | command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack()); |
| 4860 | command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward()); |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 4861 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, |
| 4862 | CanReloadContents(current_tab)); |
| 4863 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, |
| 4864 | CanReloadContents(current_tab)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4865 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4866 | // Window management commands |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4867 | command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4868 | !is_app() && CanDuplicateContentsAt(active_index())); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4869 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 4870 | // Page-related commands |
[email protected] | 52cc59b | 2011-05-06 14:42:38 | [diff] [blame] | 4871 | window_->SetStarredState( |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 4872 | current_tab_wrapper->bookmark_tab_helper()->is_starred()); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 4873 | command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 4874 | current_tab->GetController().CanViewSource()); |
[email protected] | 151666e | 2010-10-21 17:05:25 | [diff] [blame] | 4875 | command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, |
[email protected] | cd8d90db | 2011-10-06 19:31:27 | [diff] [blame] | 4876 | toolbar_model_.ShouldDisplayURL() && current_tab->GetURL().is_valid()); |
[email protected] | af664c7 | 2011-05-17 14:33:40 | [diff] [blame] | 4877 | if (is_devtools()) |
| 4878 | command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false); |
[email protected] | 151666e | 2010-10-21 17:05:25 | [diff] [blame] | 4879 | |
| 4880 | // Changing the encoding is not possible on Chrome-internal webpages. |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 4881 | bool is_chrome_internal = HasInternalURL(nc.GetActiveEntry()) || |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4882 | current_tab->ShowingInterstitialPage(); |
[email protected] | c0f82ec5 | 2010-07-27 14:22:14 | [diff] [blame] | 4883 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 4884 | !is_chrome_internal && current_tab->IsSavable()); |
[email protected] | c0f82ec5 | 2010-07-27 14:22:14 | [diff] [blame] | 4885 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 4886 | // Show various bits of UI |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 4887 | // TODO(pinkerton): Disable app-mode in the model until we implement it |
| 4888 | // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 |
| 4889 | #if !defined(OS_MACOSX) |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 4890 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, |
[email protected] | 12ea22a | 2009-11-19 07:17:23 | [diff] [blame] | 4891 | web_app::IsValidUrl(current_tab->GetURL())); |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 4892 | #endif |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4893 | |
| 4894 | UpdateCommandsForContentRestrictionState(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4895 | UpdateCommandsForBookmarkEditing(); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4896 | } |
| 4897 | |
| 4898 | void Browser::UpdateCommandsForContentRestrictionState() { |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 4899 | int restrictions = GetContentRestrictionsForSelectedTab(); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4900 | |
| 4901 | command_updater_.UpdateCommandEnabled( |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 4902 | IDC_COPY, !(restrictions & content::CONTENT_RESTRICTION_COPY)); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4903 | command_updater_.UpdateCommandEnabled( |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 4904 | IDC_CUT, !(restrictions & content::CONTENT_RESTRICTION_CUT)); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4905 | command_updater_.UpdateCommandEnabled( |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 4906 | IDC_PASTE, !(restrictions & content::CONTENT_RESTRICTION_PASTE)); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4907 | UpdateSaveAsState(restrictions); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4908 | UpdatePrintingState(restrictions); |
| 4909 | } |
| 4910 | |
| 4911 | void Browser::UpdatePrintingState(int content_restrictions) { |
[email protected] | 43401bc0 | 2011-10-13 20:43:43 | [diff] [blame] | 4912 | bool print_enabled = true; |
| 4913 | bool advanced_print_enabled = true; |
| 4914 | if (g_browser_process->local_state()) { |
| 4915 | print_enabled = |
| 4916 | g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled); |
| 4917 | advanced_print_enabled = print_enabled; |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4918 | } |
[email protected] | 43401bc0 | 2011-10-13 20:43:43 | [diff] [blame] | 4919 | if (print_enabled) { |
| 4920 | // Do not print when a constrained window is showing. It's confusing. |
| 4921 | TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); |
| 4922 | bool has_constrained_window = (wrapper && |
| 4923 | wrapper->constrained_window_tab_helper()->constrained_window_count()); |
| 4924 | if (has_constrained_window || |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 4925 | content_restrictions & content::CONTENT_RESTRICTION_PRINT) { |
[email protected] | 43401bc0 | 2011-10-13 20:43:43 | [diff] [blame] | 4926 | print_enabled = false; |
| 4927 | advanced_print_enabled = false; |
| 4928 | } |
| 4929 | |
| 4930 | // The exception is print preview, |
| 4931 | // where advanced printing is always enabled. |
| 4932 | printing::PrintPreviewTabController* controller = |
| 4933 | printing::PrintPreviewTabController::GetInstance(); |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 4934 | if (controller && (controller->GetPrintPreviewForTab(wrapper) || |
| 4935 | controller->is_creating_print_preview_tab())) { |
[email protected] | 43401bc0 | 2011-10-13 20:43:43 | [diff] [blame] | 4936 | advanced_print_enabled = true; |
| 4937 | } |
| 4938 | } |
| 4939 | command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 4940 | command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT, |
[email protected] | 43401bc0 | 2011-10-13 20:43:43 | [diff] [blame] | 4941 | advanced_print_enabled); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4942 | } |
| 4943 | |
[email protected] | 943d812 | 2010-06-11 02:13:45 | [diff] [blame] | 4944 | void Browser::UpdateReloadStopState(bool is_loading, bool force) { |
| 4945 | window_->UpdateReloadStopState(is_loading, force); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4946 | command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 4947 | } |
| 4948 | |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 4949 | void Browser::UpdateCommandsForDevTools() { |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4950 | bool dev_tools_enabled = |
[email protected] | 5073f49 | 2011-05-03 09:36:42 | [diff] [blame] | 4951 | !profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 4952 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, |
| 4953 | dev_tools_enabled); |
| 4954 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE, |
| 4955 | dev_tools_enabled); |
| 4956 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT, |
| 4957 | dev_tools_enabled); |
| 4958 | } |
| 4959 | |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4960 | void Browser::UpdateCommandsForBookmarkEditing() { |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4961 | bool enabled = |
| 4962 | profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled) && |
| 4963 | browser_defaults::bookmarks_enabled; |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4964 | |
| 4965 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4966 | enabled && is_type_tabbed()); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4967 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS, |
| 4968 | enabled && CanBookmarkAllTabs()); |
| 4969 | } |
| 4970 | |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 4971 | void Browser::UpdateCommandsForBookmarkBar() { |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4972 | const bool show_main_ui = IsShowingMainUI(window_ && window_->IsFullscreen()); |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 4973 | command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, |
| 4974 | browser_defaults::bookmarks_enabled && |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 4975 | !profile_->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) && |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 4976 | show_main_ui); |
| 4977 | } |
| 4978 | |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 4979 | void Browser::MarkHomePageAsChanged(PrefService* pref_service) { |
| 4980 | pref_service->SetBoolean(prefs::kHomePageChanged, true); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 4981 | } |
| 4982 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4983 | void Browser::UpdateSaveAsState(int content_restrictions) { |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 4984 | bool enabled = !(content_restrictions & content::CONTENT_RESTRICTION_SAVE); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4985 | PrefService* state = g_browser_process->local_state(); |
| 4986 | if (state) |
| 4987 | enabled = enabled && state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 4988 | |
| 4989 | command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, enabled); |
| 4990 | } |
| 4991 | |
| 4992 | void Browser::UpdateOpenFileState() { |
| 4993 | bool enabled = true; |
| 4994 | PrefService* local_state = g_browser_process->local_state(); |
| 4995 | if (local_state) |
| 4996 | enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 4997 | |
| 4998 | command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
| 4999 | } |
| 5000 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5001 | /////////////////////////////////////////////////////////////////////////////// |
| 5002 | // Browser, UI update coalescing and handling (private): |
| 5003 | |
| 5004 | void Browser::UpdateToolbar(bool should_restore_state) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 5005 | window_->UpdateToolbar(GetSelectedTabContentsWrapper(), should_restore_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5006 | } |
| 5007 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 5008 | void Browser::ScheduleUIUpdate(const WebContents* source, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5009 | unsigned changed_flags) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 5010 | if (!source) |
| 5011 | return; |
| 5012 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 5013 | // Do some synchronous updates. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5014 | if (changed_flags & content::INVALIDATE_TYPE_URL && |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 5015 | source == GetSelectedWebContents()) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5016 | // Only update the URL for the current tab. Note that we do not update |
| 5017 | // the navigation commands since those would have already been updated |
| 5018 | // synchronously by NavigationStateChanged. |
| 5019 | UpdateToolbar(false); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5020 | changed_flags &= ~content::INVALIDATE_TYPE_URL; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5021 | } |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5022 | if (changed_flags & content::INVALIDATE_TYPE_LOAD) { |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 5023 | // Update the loading state synchronously. This is so the throbber will |
| 5024 | // immediately start/stop, which gives a more snappy feel. We want to do |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 5025 | // this for any tab so they start & stop quickly. |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 5026 | tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 5027 | GetIndexOfController(&source->GetController()), |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 5028 | TabStripModelObserver::LOADING_ONLY); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5029 | // The status bubble needs to be updated during INVALIDATE_TYPE_LOAD too, |
| 5030 | // but we do that asynchronously by not stripping INVALIDATE_TYPE_LOAD from |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 5031 | // changed_flags. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 5032 | } |
| 5033 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5034 | if (changed_flags & content::INVALIDATE_TYPE_TITLE && !source->IsLoading()) { |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 5035 | // To correctly calculate whether the title changed while not loading |
| 5036 | // we need to process the update synchronously. This state only matters for |
| 5037 | // the TabStripModel, so we notify the TabStripModel now and notify others |
| 5038 | // asynchronously. |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 5039 | tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 5040 | GetIndexOfController(&source->GetController()), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 5041 | TabStripModelObserver::TITLE_NOT_LOADING); |
| 5042 | } |
| 5043 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 5044 | // If the only updates were synchronously handled above, we're done. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 5045 | if (changed_flags == 0) |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 5046 | return; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5047 | |
| 5048 | // Save the dirty bits. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 5049 | scheduled_updates_[source] |= changed_flags; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5050 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 5051 | if (!chrome_updater_factory_.HasWeakPtrs()) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5052 | // No task currently scheduled, start another. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 5053 | MessageLoop::current()->PostDelayedTask( |
| 5054 | FROM_HERE, |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 5055 | base::Bind(&Browser::ProcessPendingUIUpdates, |
| 5056 | chrome_updater_factory_.GetWeakPtr()), |
[email protected] | 11d6ab1a | 2012-01-12 21:37:26 | [diff] [blame] | 5057 | base::TimeDelta::FromMilliseconds(kUIUpdateCoalescingTimeMS)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5058 | } |
| 5059 | } |
| 5060 | |
| 5061 | void Browser::ProcessPendingUIUpdates() { |
| 5062 | #ifndef NDEBUG |
| 5063 | // Validate that all tabs we have pending updates for exist. This is scary |
| 5064 | // because the pending list must be kept in sync with any detached or |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 5065 | // deleted tabs. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 5066 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 5067 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5068 | bool found = false; |
| 5069 | for (int tab = 0; tab < tab_count(); tab++) { |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 5070 | if (GetWebContentsAt(tab) == i->first) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5071 | found = true; |
| 5072 | break; |
| 5073 | } |
| 5074 | } |
| 5075 | DCHECK(found); |
| 5076 | } |
| 5077 | #endif |
| 5078 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 5079 | chrome_updater_factory_.InvalidateWeakPtrs(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5080 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 5081 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 5082 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5083 | // Do not dereference |contents|, it may be out-of-date! |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 5084 | const WebContents* contents = i->first; |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 5085 | unsigned flags = i->second; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5086 | |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 5087 | if (contents == GetSelectedWebContents()) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 5088 | // Updates that only matter when the tab is selected go here. |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 5089 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5090 | if (flags & content::INVALIDATE_TYPE_PAGE_ACTIONS) { |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 5091 | LocationBar* location_bar = window()->GetLocationBar(); |
| 5092 | if (location_bar) |
| 5093 | location_bar->UpdatePageActions(); |
| 5094 | } |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 5095 | // Updating the URL happens synchronously in ScheduleUIUpdate. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5096 | if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) { |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 5097 | GetStatusBubble()->SetStatus( |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 5098 | GetSelectedTabContentsWrapper()-> |
| 5099 | core_tab_helper()->GetStatusText()); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 5100 | } |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 5101 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5102 | if (flags & (content::INVALIDATE_TYPE_TAB | |
| 5103 | content::INVALIDATE_TYPE_TITLE)) { |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 5104 | // TODO(pinkerton): Disable app-mode in the model until we implement it |
| 5105 | // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 |
| 5106 | #if !defined(OS_MACOSX) |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 5107 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, |
[email protected] | 12ea22a | 2009-11-19 07:17:23 | [diff] [blame] | 5108 | web_app::IsValidUrl(contents->GetURL())); |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 5109 | #endif |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 5110 | window_->UpdateTitleBar(); |
| 5111 | } |
[email protected] | 4d34e2e | 2009-05-26 22:55:28 | [diff] [blame] | 5112 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5113 | |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 5114 | // Updates that don't depend upon the selected state go here. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5115 | if (flags & |
| 5116 | (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 5117 | tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 5118 | tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 5119 | TabStripModelObserver::ALL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | // We don't need to process INVALIDATE_STATE, since that's not visible. |
| 5123 | } |
| 5124 | |
| 5125 | scheduled_updates_.clear(); |
| 5126 | } |
| 5127 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5128 | void Browser::RemoveScheduledUpdatesFor(WebContents* contents) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5129 | if (!contents) |
| 5130 | return; |
| 5131 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 5132 | UpdateMap::iterator i = scheduled_updates_.find(contents); |
| 5133 | if (i != scheduled_updates_.end()) |
| 5134 | scheduled_updates_.erase(i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5135 | } |
| 5136 | |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 5137 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5138 | /////////////////////////////////////////////////////////////////////////////// |
| 5139 | // Browser, Getters for UI (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5140 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5141 | StatusBubble* Browser::GetStatusBubble() { |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 5142 | #if !defined(OS_MACOSX) |
| 5143 | // In kiosk mode, we want to always hide the status bubble. |
| 5144 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 5145 | return NULL; |
| 5146 | #endif |
[email protected] | 9b032bf | 2009-07-21 17:34:23 | [diff] [blame] | 5147 | return window_ ? window_->GetStatusBubble() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5148 | } |
| 5149 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5150 | /////////////////////////////////////////////////////////////////////////////// |
| 5151 | // Browser, Session restore functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5152 | |
| 5153 | void Browser::SyncHistoryWithTabs(int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 5154 | SessionService* session_service = |
| 5155 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5156 | if (session_service) { |
| 5157 | for (int i = index; i < tab_count(); ++i) { |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 5158 | TabContentsWrapper* tab = GetTabContentsWrapperAt(i); |
| 5159 | if (tab) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5160 | session_service->SetTabIndexInWindow( |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 5161 | session_id(), tab->restore_tab_helper()->session_id(), i); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 5162 | session_service->SetPinnedState( |
| 5163 | session_id(), |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 5164 | tab->restore_tab_helper()->session_id(), |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 5165 | IsTabPinned(i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5166 | } |
| 5167 | } |
| 5168 | } |
| 5169 | } |
| 5170 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5171 | /////////////////////////////////////////////////////////////////////////////// |
| 5172 | // Browser, OnBeforeUnload handling (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5173 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5174 | void Browser::ProcessPendingTabs() { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 5175 | if (!is_attempting_to_close_browser_) { |
| 5176 | // Because we might invoke this after a delay it's possible for the value of |
| 5177 | // is_attempting_to_close_browser_ to have changed since we scheduled the |
| 5178 | // task. |
| 5179 | return; |
| 5180 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5181 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5182 | if (HasCompletedUnloadProcessing()) { |
| 5183 | // We've finished all the unload events and can proceed to close the |
| 5184 | // browser. |
| 5185 | OnWindowClosing(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5186 | return; |
| 5187 | } |
| 5188 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5189 | // Process beforeunload tabs first. When that queue is empty, process |
| 5190 | // unload tabs. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5191 | if (!tabs_needing_before_unload_fired_.empty()) { |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 5192 | WebContents* tab = *(tabs_needing_before_unload_fired_.begin()); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 5193 | // Null check render_view_host here as this gets called on a PostTask and |
| 5194 | // the tab's render_view_host may have been nulled out. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 5195 | if (tab->GetRenderViewHost()) { |
| 5196 | tab->GetRenderViewHost()->FirePageBeforeUnload(false); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 5197 | } else { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 5198 | ClearUnloadState(tab, true); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 5199 | } |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5200 | } else if (!tabs_needing_unload_fired_.empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5201 | // We've finished firing all beforeunload events and can proceed with unload |
| 5202 | // events. |
| 5203 | // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting |
| 5204 | // somewhere around here so that we have accurate measurements of shutdown |
| 5205 | // time. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5206 | // TODO(ojan): We can probably fire all the unload events in parallel and |
| 5207 | // get a perf benefit from that in the cases where the tab hangs in it's |
| 5208 | // unload handler or takes a long time to page in. |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 5209 | WebContents* tab = *(tabs_needing_unload_fired_.begin()); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 5210 | // Null check render_view_host here as this gets called on a PostTask and |
| 5211 | // the tab's render_view_host may have been nulled out. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 5212 | if (tab->GetRenderViewHost()) { |
| 5213 | tab->GetRenderViewHost()->ClosePage(); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 5214 | } else { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 5215 | ClearUnloadState(tab, true); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 5216 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5217 | } else { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5218 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5219 | } |
| 5220 | } |
| 5221 | |
[email protected] | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 5222 | bool Browser::HasCompletedUnloadProcessing() const { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5223 | return is_attempting_to_close_browser_ && |
| 5224 | tabs_needing_before_unload_fired_.empty() && |
| 5225 | tabs_needing_unload_fired_.empty(); |
| 5226 | } |
| 5227 | |
| 5228 | void Browser::CancelWindowClose() { |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 5229 | // Closing of window can be canceled from: |
| 5230 | // - canceling beforeunload |
| 5231 | // - disallowing closing from IsClosingPermitted. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5232 | DCHECK(is_attempting_to_close_browser_); |
[email protected] | 8f673f3a | 2008-08-05 22:34:28 | [diff] [blame] | 5233 | tabs_needing_before_unload_fired_.clear(); |
| 5234 | tabs_needing_unload_fired_.clear(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5235 | is_attempting_to_close_browser_ = false; |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 5236 | |
| 5237 | // Inform TabCloseableStateWatcher that closing of window has been canceled. |
| 5238 | TabCloseableStateWatcher* watcher = |
| 5239 | g_browser_process->tab_closeable_state_watcher(); |
| 5240 | if (watcher) |
| 5241 | watcher->OnWindowCloseCanceled(this); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5242 | } |
| 5243 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 5244 | bool Browser::RemoveFromSet(UnloadListenerSet* set, WebContents* tab) { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5245 | DCHECK(is_attempting_to_close_browser_); |
| 5246 | |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 5247 | UnloadListenerSet::iterator iter = std::find(set->begin(), set->end(), tab); |
| 5248 | if (iter != set->end()) { |
| 5249 | set->erase(iter); |
| 5250 | return true; |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 5251 | } |
| 5252 | return false; |
| 5253 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5254 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 5255 | void Browser::ClearUnloadState(WebContents* tab, bool process_now) { |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 5256 | // Closing of browser could be canceled (via IsClosingPermitted) between the |
| 5257 | // time when request was initiated and when this method is called, so check |
| 5258 | // for is_attempting_to_close_browser_ flag before proceeding. |
| 5259 | if (is_attempting_to_close_browser_) { |
| 5260 | RemoveFromSet(&tabs_needing_before_unload_fired_, tab); |
| 5261 | RemoveFromSet(&tabs_needing_unload_fired_, tab); |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 5262 | if (process_now) { |
| 5263 | ProcessPendingTabs(); |
| 5264 | } else { |
| 5265 | MessageLoop::current()->PostTask( |
| 5266 | FROM_HERE, |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 5267 | base::Bind(&Browser::ProcessPendingTabs, weak_factory_.GetWeakPtr())); |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 5268 | } |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 5269 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5270 | } |
| 5271 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5272 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 5273 | // Browser, In-progress download termination handling (private): |
| 5274 | |
[email protected] | b6a4ac2b | 2011-10-17 20:05:48 | [diff] [blame] | 5275 | bool Browser::CanCloseWithInProgressDownloads() { |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 5276 | // If we've prompted, we need to hear from the user before we |
| 5277 | // can close. |
| 5278 | if (cancel_download_confirmation_state_ != NOT_PROMPTED) |
| 5279 | return cancel_download_confirmation_state_ != WAITING_FOR_RESPONSE; |
| 5280 | |
| 5281 | int num_downloads_blocking; |
| 5282 | if (DOWNLOAD_CLOSE_OK == |
| 5283 | OkToCloseWithInProgressDownloads(&num_downloads_blocking)) |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 5284 | return true; |
| 5285 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 5286 | // Closing this window will kill some downloads; prompt to make sure |
| 5287 | // that's ok. |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 5288 | cancel_download_confirmation_state_ = WAITING_FOR_RESPONSE; |
| 5289 | window_->ConfirmBrowserCloseWithPendingDownloads(); |
| 5290 | |
| 5291 | // Return false so the browser does not close. We'll close if the user |
| 5292 | // confirms in the dialog. |
| 5293 | return false; |
| 5294 | } |
| 5295 | |
| 5296 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5297 | // Browser, Assorted utility functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5298 | |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 5299 | // static |
[email protected] | de4e763 | 2010-09-01 06:24:04 | [diff] [blame] | 5300 | Browser* Browser::GetTabbedBrowser(Profile* profile, bool match_incognito) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 5301 | return BrowserList::FindTabbedBrowser(profile, match_incognito); |
[email protected] | de4e763 | 2010-09-01 06:24:04 | [diff] [blame] | 5302 | } |
| 5303 | |
| 5304 | // static |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 5305 | Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) { |
[email protected] | de4e763 | 2010-09-01 06:24:04 | [diff] [blame] | 5306 | Browser* browser = GetTabbedBrowser(profile, false); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 5307 | if (!browser) |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 5308 | browser = Browser::Create(profile); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5309 | return browser; |
| 5310 | } |
| 5311 | |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 5312 | void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 5313 | // TabContents... |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5314 | tab->web_contents()->SetDelegate(delegate); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 5315 | |
| 5316 | // ...and all the helpers. |
| 5317 | tab->blocked_content_tab_helper()->set_delegate(delegate); |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 5318 | tab->bookmark_tab_helper()->set_delegate(delegate); |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 5319 | tab->constrained_window_tab_helper()->set_delegate(delegate); |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 5320 | tab->core_tab_helper()->set_delegate(delegate); |
[email protected] | 1739e57d | 2011-11-30 21:18:25 | [diff] [blame] | 5321 | tab->extension_tab_helper()->set_delegate(delegate); |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 5322 | tab->search_engine_tab_helper()->set_delegate(delegate); |
| 5323 | } |
| 5324 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 5325 | void Browser::FindInPage(bool find_next, bool forward_direction) { |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 5326 | ShowFindBar(); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 5327 | if (find_next) { |
[email protected] | 6a4f5af2 | 2009-09-23 22:43:00 | [diff] [blame] | 5328 | string16 find_text; |
| 5329 | #if defined(OS_MACOSX) |
| 5330 | // We always want to search for the contents of the find pasteboard on OS X. |
| 5331 | find_text = GetFindPboardText(); |
| 5332 | #endif |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 5333 | GetSelectedTabContentsWrapper()-> |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 5334 | find_tab_helper()->StartFinding(find_text, |
| 5335 | forward_direction, |
| 5336 | false); // Not case sensitive. |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 5337 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 5338 | } |
[email protected] | cb17f7f | 2009-02-06 18:14:48 | [diff] [blame] | 5339 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5340 | void Browser::CloseFrame() { |
| 5341 | window_->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5342 | } |
| 5343 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 5344 | void Browser::TabDetachedAtImpl(TabContentsWrapper* contents, int index, |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5345 | DetachType type) { |
| 5346 | if (type == DETACH_TYPE_DETACH) { |
[email protected] | 5658085 | 2010-11-17 16:09:15 | [diff] [blame] | 5347 | // Save the current location bar state, but only if the tab being detached |
| 5348 | // is the selected tab. Because saving state can conditionally revert the |
| 5349 | // location bar, saving the current tab's location bar state to a |
| 5350 | // non-selected tab can corrupt both tabs. |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 5351 | if (contents == GetSelectedTabContentsWrapper()) { |
| 5352 | LocationBar* location_bar = window()->GetLocationBar(); |
| 5353 | if (location_bar) |
[email protected] | 83a2610a | 2012-01-05 01:00:27 | [diff] [blame] | 5354 | location_bar->SaveStateToContents(contents->web_contents()); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 5355 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5356 | |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 5357 | if (!tab_handler_->GetTabStripModel()->closing_all()) |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5358 | SyncHistoryWithTabs(0); |
| 5359 | } |
| 5360 | |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 5361 | SetAsDelegate(contents, NULL); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5362 | RemoveScheduledUpdatesFor(contents->web_contents()); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5363 | |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 5364 | if (find_bar_controller_.get() && index == active_index()) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5365 | find_bar_controller_->ChangeTabContents(NULL); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 5366 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5367 | |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 5368 | if (is_attempting_to_close_browser_) { |
| 5369 | // If this is the last tab with unload handlers, then ProcessPendingTabs |
| 5370 | // would call back into the TabStripModel (which is invoking this method on |
| 5371 | // us). Avoid that by passing in false so that the call to |
| 5372 | // ProcessPendingTabs is delayed. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5373 | ClearUnloadState(contents->web_contents(), false); |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 5374 | } |
| 5375 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 5376 | registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 5377 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 5378 | registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
[email protected] | 4b19ea5 | 2012-01-02 20:15:25 | [diff] [blame] | 5379 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 5380 | registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 5381 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5382 | } |
| 5383 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5384 | // static |
[email protected] | f87919d7 | 2011-02-02 18:46:16 | [diff] [blame] | 5385 | void Browser::RegisterAppPrefs(const std::string& app_name, Profile* profile) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5386 | // We need to register the window position pref. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 5387 | std::string window_pref(prefs::kBrowserWindowPlacement); |
| 5388 | window_pref.append("_"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5389 | window_pref.append(app_name); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 5390 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 5391 | if (!prefs->FindPreference(window_pref.c_str())) { |
| 5392 | prefs->RegisterDictionaryPref(window_pref.c_str(), |
| 5393 | PrefService::UNSYNCABLE_PREF); |
| 5394 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5395 | } |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 5396 | |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 5397 | void Browser::TabRestoreServiceChanged(TabRestoreService* service) { |
| 5398 | command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, |
| 5399 | !service->entries().empty()); |
| 5400 | } |
| 5401 | |
| 5402 | void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) { |
| 5403 | if (!tab_restore_service_) |
| 5404 | return; |
| 5405 | |
| 5406 | DCHECK_EQ(tab_restore_service_, service); |
| 5407 | tab_restore_service_->RemoveObserver(this); |
| 5408 | tab_restore_service_ = NULL; |
| 5409 | } |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5410 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 5411 | // Centralized method for creating a TabContents, configuring and installing |
| 5412 | // all its supporting objects and observers. |
| 5413 | TabContentsWrapper* Browser::TabContentsFactory( |
| 5414 | Profile* profile, |
| 5415 | SiteInstance* site_instance, |
| 5416 | int routing_id, |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 5417 | const WebContents* base_web_contents, |
[email protected] | adbfb8df | 2012-02-24 01:19:43 | [diff] [blame] | 5418 | content::SessionStorageNamespace* session_storage_namespace) { |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 5419 | WebContents* new_contents = WebContents::Create( |
| 5420 | profile, site_instance, routing_id, base_web_contents, |
| 5421 | session_storage_namespace); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5422 | TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 5423 | return wrapper; |
| 5424 | } |
| 5425 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 5426 | bool Browser::OpenInstant(WindowOpenDisposition disposition) { |
[email protected] | 3e48128 | 2011-10-15 15:39:50 | [diff] [blame] | 5427 | if (!instant() || !instant()->PrepareForCommit() || |
[email protected] | 3524260 | 2011-01-06 16:38:53 | [diff] [blame] | 5428 | disposition == NEW_BACKGROUND_TAB) { |
| 5429 | // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't |
| 5430 | // attempt to use the instant preview. |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5431 | return false; |
[email protected] | 3524260 | 2011-01-06 16:38:53 | [diff] [blame] | 5432 | } |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5433 | |
| 5434 | if (disposition == CURRENT_TAB) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 5435 | content::NotificationService::current()->Notify( |
[email protected] | 094b052 | 2011-10-06 00:55:27 | [diff] [blame] | 5436 | chrome::NOTIFICATION_INSTANT_COMMITTED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5437 | content::Source<TabContentsWrapper>(instant()->CommitCurrentPreview( |
[email protected] | 094b052 | 2011-10-06 00:55:27 | [diff] [blame] | 5438 | INSTANT_COMMIT_PRESSED_ENTER)), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 5439 | content::NotificationService::NoDetails()); |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5440 | return true; |
| 5441 | } |
[email protected] | 3524260 | 2011-01-06 16:38:53 | [diff] [blame] | 5442 | if (disposition == NEW_FOREGROUND_TAB) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 5443 | TabContentsWrapper* preview_contents = instant()->ReleasePreviewContents( |
[email protected] | 5419ff9 | 2012-01-06 21:17:15 | [diff] [blame] | 5444 | INSTANT_COMMIT_PRESSED_ENTER, NULL); |
[email protected] | a0df03c12 | 2011-01-05 00:22:55 | [diff] [blame] | 5445 | // HideInstant is invoked after release so that InstantController is not |
| 5446 | // active when HideInstant asks it for its state. |
| 5447 | HideInstant(); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5448 | preview_contents->web_contents()->GetController().PruneAllButActive(); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 5449 | tab_handler_->GetTabStripModel()->AddTabContents( |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5450 | preview_contents, |
| 5451 | -1, |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 5452 | instant()->last_transition_type(), |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 5453 | TabStripModel::ADD_ACTIVE); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 5454 | instant()->CompleteRelease(preview_contents); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 5455 | content::NotificationService::current()->Notify( |
[email protected] | 094b052 | 2011-10-06 00:55:27 | [diff] [blame] | 5456 | chrome::NOTIFICATION_INSTANT_COMMITTED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5457 | content::Source<TabContentsWrapper>(preview_contents), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 5458 | content::NotificationService::NoDetails()); |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5459 | return true; |
| 5460 | } |
| 5461 | // The omnibox currently doesn't use other dispositions, so we don't attempt |
| 5462 | // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add |
| 5463 | // support for the new disposition. |
| 5464 | NOTREACHED(); |
| 5465 | return false; |
| 5466 | } |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 5467 | |
| 5468 | void Browser::CreateInstantIfNecessary() { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 5469 | if (is_type_tabbed() && InstantController::IsEnabled(profile()) && |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 5470 | !profile()->IsOffTheRecord()) { |
[email protected] | fdf773c5 | 2010-11-01 20:58:19 | [diff] [blame] | 5471 | instant_.reset(new InstantController(profile_, this)); |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 5472 | instant_unload_handler_.reset(new InstantUnloadHandler(this)); |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 5473 | } |
| 5474 | } |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5475 | |
| 5476 | void Browser::ViewSource(TabContentsWrapper* contents) { |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 5477 | DCHECK(contents); |
| 5478 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 5479 | NavigationEntry* active_entry = |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5480 | contents->web_contents()->GetController().GetActiveEntry(); |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 5481 | if (!active_entry) |
| 5482 | return; |
| 5483 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 5484 | ViewSource(contents, active_entry->GetURL(), active_entry->GetContentState()); |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | void Browser::ViewSource(TabContentsWrapper* contents, |
| 5488 | const GURL& url, |
| 5489 | const std::string& content_state) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 5490 | content::RecordAction(UserMetricsAction("ViewSource")); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5491 | DCHECK(contents); |
| 5492 | |
| 5493 | TabContentsWrapper* view_source_contents = contents->Clone(); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5494 | view_source_contents->web_contents()->GetController().PruneAllButActive(); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 5495 | NavigationEntry* active_entry = |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 5496 | view_source_contents->web_contents()->GetController().GetActiveEntry(); |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 5497 | if (!active_entry) |
| 5498 | return; |
| 5499 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 5500 | GURL view_source_url = GURL(chrome::kViewSourceScheme + std::string(":") + |
| 5501 | url.spec()); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 5502 | active_entry->SetVirtualURL(view_source_url); |
[email protected] | 1436beff | 2010-12-16 19:47:04 | [diff] [blame] | 5503 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 5504 | // Do not restore scroller position. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 5505 | active_entry->SetContentState( |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 5506 | webkit_glue::RemoveScrollOffsetFromHistoryState(content_state)); |
| 5507 | |
[email protected] | cd3d50d | 2010-12-18 21:03:29 | [diff] [blame] | 5508 | // Do not restore title, derive it from the url. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 5509 | active_entry->SetTitle(string16()); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5510 | |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 5511 | // Now show view-source entry. |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5512 | if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
| 5513 | // If this is a tabbed browser, just create a duplicate tab inside the same |
| 5514 | // window next to the tab being duplicated. |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 5515 | int index = |
| 5516 | tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents); |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 5517 | int add_types = TabStripModel::ADD_ACTIVE | |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 5518 | TabStripModel::ADD_INHERIT_GROUP; |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5519 | tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 5520 | view_source_contents, |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5521 | add_types); |
| 5522 | } else { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 5523 | Browser* browser = Browser::CreateForType(TYPE_TABBED, profile_); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5524 | |
| 5525 | // Preserve the size of the original window. The new window has already |
| 5526 | // been given an offset by the OS, so we shouldn't copy the old bounds. |
| 5527 | BrowserWindow* new_window = browser->window(); |
| 5528 | new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 5529 | window()->GetRestoredBounds().size())); |
| 5530 | |
| 5531 | // We need to show the browser now. Otherwise ContainerWin assumes the |
| 5532 | // TabContents is invisible and won't size it. |
| 5533 | browser->window()->Show(); |
| 5534 | |
| 5535 | // The page transition below is only for the purpose of inserting the tab. |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 5536 | browser->AddTab(view_source_contents, content::PAGE_TRANSITION_LINK); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5537 | } |
| 5538 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 5539 | SessionService* session_service = |
| 5540 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 5541 | if (session_service) |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 5542 | session_service->TabRestored(view_source_contents, false); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5543 | } |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 5544 | |
| 5545 | int Browser::GetContentRestrictionsForSelectedTab() { |
| 5546 | int content_restrictions = 0; |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 5547 | WebContents* current_tab = GetSelectedWebContents(); |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 5548 | if (current_tab) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 5549 | content_restrictions = current_tab->GetContentRestrictions(); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 5550 | NavigationEntry* active_entry = |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 5551 | current_tab->GetController().GetActiveEntry(); |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 5552 | // See comment in UpdateCommandsForTabState about why we call url(). |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 5553 | if (!download_util::IsSavableURL( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 5554 | active_entry ? active_entry->GetURL() : GURL()) |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 5555 | || current_tab->ShowingInterstitialPage()) |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 5556 | content_restrictions |= content::CONTENT_RESTRICTION_SAVE; |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 5557 | if (current_tab->ShowingInterstitialPage()) |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 5558 | content_restrictions |= content::CONTENT_RESTRICTION_PRINT; |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 5559 | } |
| 5560 | return content_restrictions; |
| 5561 | } |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 5562 | |
| 5563 | void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { |
| 5564 | BookmarkBar::State state; |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 5565 | // 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] | 5566 | if (browser_defaults::bookmarks_enabled && |
| 5567 | profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) && |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 5568 | (!window_ || !window_->IsFullscreen())) { |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 5569 | state = BookmarkBar::SHOW; |
| 5570 | } else { |
| 5571 | TabContentsWrapper* tab = GetSelectedTabContentsWrapper(); |
| 5572 | if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar()) |
| 5573 | state = BookmarkBar::DETACHED; |
| 5574 | else |
| 5575 | state = BookmarkBar::HIDDEN; |
| 5576 | } |
| 5577 | if (state == bookmark_bar_state_) |
| 5578 | return; |
| 5579 | |
| 5580 | bookmark_bar_state_ = state; |
| 5581 | |
| 5582 | if (!window_) |
| 5583 | return; // This is called from the constructor when window_ is NULL. |
| 5584 | |
| 5585 | if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) { |
| 5586 | // Don't notify BrowserWindow on a tab switch as at the time this is invoked |
| 5587 | // BrowserWindow hasn't yet switched tabs. The BrowserWindow implementations |
| 5588 | // end up querying state once they process the tab switch. |
| 5589 | return; |
| 5590 | } |
| 5591 | |
| 5592 | BookmarkBar::AnimateChangeType animate_type = |
| 5593 | (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE) ? |
| 5594 | BookmarkBar::ANIMATE_STATE_CHANGE : |
| 5595 | BookmarkBar::DONT_ANIMATE_STATE_CHANGE; |
| 5596 | window_->BookmarkBarStateChanged(animate_type); |
| 5597 | } |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 5598 | |
| 5599 | void Browser::ShowSyncSetup() { |
[email protected] | e0dc2cb | 2011-08-04 03:22:57 | [diff] [blame] | 5600 | ProfileSyncService* service = |
[email protected] | 5e61afb9 | 2012-01-27 20:09:13 | [diff] [blame] | 5601 | ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 5602 | profile()->GetOriginalProfile()); |
[email protected] | 6554918 | 2012-02-25 00:45:40 | [diff] [blame] | 5603 | LoginUIService* login_service = |
| 5604 | LoginUIServiceFactory::GetForProfile(profile()->GetOriginalProfile()); |
[email protected] | aff3de2 | 2012-02-13 22:58:06 | [diff] [blame] | 5605 | if (service->HasSyncSetupCompleted()) { |
[email protected] | a981fd6 | 2011-10-08 03:09:04 | [diff] [blame] | 5606 | ShowOptionsTab(chrome::kPersonalOptionsSubPage); |
[email protected] | 6554918 | 2012-02-25 00:45:40 | [diff] [blame] | 5607 | } else if (SyncPromoUI::ShouldShowSyncPromo(profile()) && |
| 5608 | login_service->current_login_ui() == NULL) { |
| 5609 | // There is no currently active login UI, so display a new promo page. |
[email protected] | aff3de2 | 2012-02-13 22:58:06 | [diff] [blame] | 5610 | GURL url(SyncPromoUI::GetSyncPromoURL(GURL(), false, std::string())); |
| 5611 | browser::NavigateParams params(GetSingletonTabNavigateParams(GURL(url))); |
| 5612 | params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
| 5613 | ShowSingletonTabOverwritingNTP(params); |
| 5614 | } else { |
[email protected] | 6554918 | 2012-02-25 00:45:40 | [diff] [blame] | 5615 | LoginUIServiceFactory::GetForProfile( |
| 5616 | profile()->GetOriginalProfile())->ShowLoginUI(); |
[email protected] | aff3de2 | 2012-02-13 22:58:06 | [diff] [blame] | 5617 | } |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 5618 | } |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 5619 | |
| 5620 | void Browser::ToggleSpeechInput() { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 5621 | GetSelectedWebContents()->GetRenderViewHost()->ToggleSpeechInput(); |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 5622 | } |