[email protected] | 35d0615 | 2011-01-10 22:19:42 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 32 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 33 | #include "chrome/browser/bookmarks/bookmark_utils.h" |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 34 | #include "chrome/browser/browser_process.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 35 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | 40d59ce5 | 2009-03-06 23:20:14 | [diff] [blame] | 36 | #include "chrome/browser/character_encoding.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 37 | #include "chrome/browser/chrome_page_zoom.h" |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 38 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 39 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 40 | #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h" |
[email protected] | dce50276 | 2011-07-20 08:53:49 | [diff] [blame] | 41 | #include "chrome/browser/debugger/devtools_toggle_action.h" |
| 42 | #include "chrome/browser/debugger/devtools_window.h" |
[email protected] | 8a28271 | 2011-08-23 19:28:00 | [diff] [blame] | 43 | #include "chrome/browser/download/chrome_download_manager_delegate.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 44 | #include "chrome/browser/download/download_item_model.h" |
[email protected] | 9bb54ee | 2011-10-12 17:43:35 | [diff] [blame] | 45 | #include "chrome/browser/download/download_service.h" |
| 46 | #include "chrome/browser/download/download_service_factory.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 47 | #include "chrome/browser/download/download_started_animation.h" |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 48 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 49 | #include "chrome/browser/extensions/default_apps_trial.h" |
[email protected] | 9fd542df | 2009-09-30 07:32:01 | [diff] [blame] | 50 | #include "chrome/browser/extensions/extension_browser_event_router.h" |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 51 | #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
[email protected] | 6d7a604 | 2010-08-12 20:12:42 | [diff] [blame] | 52 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 53 | #include "chrome/browser/extensions/extension_prefs.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 54 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 55 | #include "chrome/browser/extensions/extension_tab_helper.h" |
[email protected] | b17d41c | 2011-02-17 22:09:59 | [diff] [blame] | 56 | #include "chrome/browser/extensions/extension_tabs_module.h" |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 57 | #include "chrome/browser/favicon/favicon_tab_helper.h" |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 58 | #include "chrome/browser/file_select_helper.h" |
[email protected] | 82073579 | 2010-07-29 23:40:01 | [diff] [blame] | 59 | #include "chrome/browser/first_run/first_run.h" |
[email protected] | f7578f5 | 2010-08-30 22:22:49 | [diff] [blame] | 60 | #include "chrome/browser/google/google_url_tracker.h" |
| 61 | #include "chrome/browser/google/google_util.h" |
[email protected] | 7e20412 | 2011-09-01 18:56:21 | [diff] [blame] | 62 | #include "chrome/browser/infobars/infobar_tab_helper.h" |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 63 | #include "chrome/browser/instant/instant_controller.h" |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 64 | #include "chrome/browser/instant/instant_unload_handler.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 65 | #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 66 | #include "chrome/browser/intents/web_intents_registry_factory.h" |
[email protected] | 90f3990 | 2009-10-03 04:25:37 | [diff] [blame] | 67 | #include "chrome/browser/net/browser_url_util.h" |
[email protected] | a239c3f | 2009-02-17 22:13:19 | [diff] [blame] | 68 | #include "chrome/browser/net/url_fixer_upper.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 69 | #include "chrome/browser/notifications/notification_ui_manager.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 70 | #include "chrome/browser/platform_util.h" |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 71 | #include "chrome/browser/prefs/incognito_mode_prefs.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 72 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 73 | #include "chrome/browser/prerender/prerender_tab_helper.h" |
[email protected] | 0233759 | 2010-09-27 18:38:25 | [diff] [blame] | 74 | #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 75 | #include "chrome/browser/printing/print_preview_tab_controller.h" |
[email protected] | 6876147 | 2011-08-31 18:55:14 | [diff] [blame] | 76 | #include "chrome/browser/printing/print_view_manager.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 77 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 78 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 79 | #include "chrome/browser/profiles/profile_metrics.h" |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 80 | #include "chrome/browser/repost_form_warning_controller.h" |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 81 | #include "chrome/browser/sessions/restore_tab_helper.h" |
[email protected] | 85e921fb8 | 2009-02-11 23:19:44 | [diff] [blame] | 82 | #include "chrome/browser/sessions/session_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 83 | #include "chrome/browser/sessions/session_service_factory.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 84 | #include "chrome/browser/sessions/session_types.h" |
[email protected] | 92926d9 | 2010-09-02 18:35:06 | [diff] [blame] | 85 | #include "chrome/browser/sessions/tab_restore_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 86 | #include "chrome/browser/sessions/tab_restore_service_factory.h" |
[email protected] | 066629f | 2009-10-17 00:28:13 | [diff] [blame] | 87 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | 40f04797 | 2009-11-25 03:54:40 | [diff] [blame] | 88 | #include "chrome/browser/sync/sync_ui_util.h" |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 89 | #include "chrome/browser/tab_closeable_state_watcher.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 90 | #include "chrome/browser/tab_contents/background_contents.h" |
[email protected] | 7cceebac | 2011-03-03 00:32:21 | [diff] [blame] | 91 | #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 92 | #include "chrome/browser/tab_contents/tab_util.h" |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 93 | #include "chrome/browser/tabs/tab_finder.h" |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 94 | #include "chrome/browser/tabs/tab_strip_model.h" |
[email protected] | ffa6f59 | 2011-06-24 22:03:57 | [diff] [blame] | 95 | #include "chrome/browser/themes/theme_service.h" |
| 96 | #include "chrome/browser/themes/theme_service_factory.h" |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 97 | #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 98 | #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 99 | #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 100 | #include "chrome/browser/ui/browser_dialogs.h" |
[email protected] | 6768ac0 | 2011-04-06 17:41:04 | [diff] [blame] | 101 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 102 | #include "chrome/browser/ui/browser_navigator.h" |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 103 | #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 104 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 105 | #include "chrome/browser/ui/constrained_window_tab_helper.h" |
[email protected] | 45300ad4 | 2010-12-02 15:51:14 | [diff] [blame] | 106 | #include "chrome/browser/ui/find_bar/find_bar.h" |
| 107 | #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 108 | #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
[email protected] | bf870869 | 2011-12-20 21:24:28 | [diff] [blame] | 109 | #include "chrome/browser/ui/fullscreen_controller.h" |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 110 | #include "chrome/browser/ui/global_error.h" |
| 111 | #include "chrome/browser/ui/global_error_service.h" |
| 112 | #include "chrome/browser/ui/global_error_service_factory.h" |
[email protected] | 943b861 | 2011-08-31 21:07:13 | [diff] [blame] | 113 | #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 114 | #include "chrome/browser/ui/omnibox/location_bar.h" |
[email protected] | fe90ca8e | 2011-04-08 20:40:43 | [diff] [blame] | 115 | #include "chrome/browser/ui/panels/panel.h" |
| 116 | #include "chrome/browser/ui/panels/panel_manager.h" |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 117 | #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 118 | #include "chrome/browser/ui/status_bubble.h" |
[email protected] | 3da95a10 | 2011-11-30 21:47:45 | [diff] [blame] | 119 | #include "chrome/browser/ui/sync/browser_synced_window_delegate.h" |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 120 | #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 121 | #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
[email protected] | 9a80065 | 2010-12-02 17:08:44 | [diff] [blame] | 122 | #include "chrome/browser/ui/tabs/dock_info.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 123 | #include "chrome/browser/ui/tabs/tab_menu_model.h" |
[email protected] | f847e608 | 2011-03-24 00:08:26 | [diff] [blame] | 124 | #include "chrome/browser/ui/web_applications/web_app_ui.h" |
[email protected] | 265a149 | 2011-02-27 05:58:07 | [diff] [blame] | 125 | #include "chrome/browser/ui/webui/bug_report_ui.h" |
[email protected] | 02b07597 | 2011-10-19 18:39:00 | [diff] [blame] | 126 | #include "chrome/browser/ui/webui/chrome_web_ui.h" |
[email protected] | 6a1622a | 2011-09-20 22:37:45 | [diff] [blame] | 127 | #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" |
[email protected] | 5c557f37 | 2011-02-26 15:09:20 | [diff] [blame] | 128 | #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
[email protected] | 9a80065 | 2010-12-02 17:08:44 | [diff] [blame] | 129 | #include "chrome/browser/ui/window_sizer.h" |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 130 | #include "chrome/browser/upgrade_detector.h" |
[email protected] | 86b5401 | 2009-11-19 09:18:50 | [diff] [blame] | 131 | #include "chrome/browser/web_applications/web_app.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 132 | #include "chrome/common/chrome_constants.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 133 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 134 | #include "chrome/common/chrome_switches.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 135 | #include "chrome/common/custom_handlers/protocol_handler.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 136 | #include "chrome/common/extensions/extension.h" |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 137 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 138 | #include "chrome/common/pref_names.h" |
[email protected] | 7664ab3 | 2011-02-01 23:35:25 | [diff] [blame] | 139 | #include "chrome/common/profiling.h" |
[email protected] | b689fce7 | 2009-03-17 22:45:34 | [diff] [blame] | 140 | #include "chrome/common/url_constants.h" |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 141 | #include "chrome/common/web_apps.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 142 | #include "content/browser/browser_url_handler.h" |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 143 | #include "content/browser/child_process_security_policy.h" |
[email protected] | 0ffaa48 | 2011-07-14 23:41:28 | [diff] [blame] | 144 | #include "content/browser/download/save_package.h" |
[email protected] | b6021d3 | 2011-02-26 01:25:54 | [diff] [blame] | 145 | #include "content/browser/host_zoom_map.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 146 | #include "content/browser/renderer_host/render_view_host.h" |
| 147 | #include "content/browser/site_instance.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 148 | #include "content/browser/tab_contents/interstitial_page.h" |
| 149 | #include "content/browser/tab_contents/navigation_controller.h" |
| 150 | #include "content/browser/tab_contents/navigation_entry.h" |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 151 | #include "content/browser/tab_contents/tab_contents.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 152 | #include "content/browser/tab_contents/tab_contents_view.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 153 | #include "content/public/browser/devtools_manager.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 154 | #include "content/public/browser/download_item.h" |
| 155 | #include "content/public/browser/download_manager.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 156 | #include "content/public/browser/notification_details.h" |
| 157 | #include "content/public/browser/notification_service.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 158 | #include "content/public/browser/plugin_service.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 159 | #include "content/public/browser/user_metrics.h" |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 160 | #include "content/public/browser/web_intents_dispatcher.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 161 | #include "content/public/common/content_restriction.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 162 | #include "content/public/common/content_switches.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 163 | #include "content/public/common/page_zoom.h" |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 164 | #include "grit/chromium_strings.h" |
| 165 | #include "grit/generated_resources.h" |
| 166 | #include "grit/locale_settings.h" |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 167 | #include "grit/theme_resources_standard.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 168 | #include "net/base/cookie_monster.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 169 | #include "net/base/net_util.h" |
| 170 | #include "net/base/registry_controlled_domain.h" |
| 171 | #include "net/url_request/url_request_context.h" |
[email protected] | f6767806 | 2011-01-07 17:33:39 | [diff] [blame] | 172 | #include "ui/base/animation/animation.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 173 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 174 | #include "ui/gfx/point.h" |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 175 | #include "webkit/glue/web_intent_data.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 176 | #include "webkit/glue/webkit_glue.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 177 | #include "webkit/glue/window_open_disposition.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 178 | #include "webkit/plugins/webplugininfo.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 179 | |
| 180 | #if defined(OS_WIN) |
[email protected] | 36d5e559 | 2010-11-15 20:45:59 | [diff] [blame] | 181 | #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 182 | #include "chrome/browser/shell_integration.h" |
[email protected] | b17d41c | 2011-02-17 22:09:59 | [diff] [blame] | 183 | #include "chrome/browser/ssl/ssl_error_info.h" |
[email protected] | a5d1e1e | 2010-09-23 19:34:12 | [diff] [blame] | 184 | #include "chrome/browser/task_manager/task_manager.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 185 | #include "chrome/browser/ui/view_ids.h" |
| 186 | #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
[email protected] | dcd5776 | 2011-06-25 12:18:51 | [diff] [blame] | 187 | #include "ui/base/win/shell.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 188 | #endif // OS_WIN |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 189 | |
[email protected] | 6a4f5af2 | 2009-09-23 22:43:00 | [diff] [blame] | 190 | #if defined(OS_MACOSX) |
[email protected] | 8aee8ed3 | 2011-06-14 20:16:41 | [diff] [blame] | 191 | #include "content/browser/find_pasteboard.h" |
[email protected] | 6a4f5af2 | 2009-09-23 22:43:00 | [diff] [blame] | 192 | #endif |
| 193 | |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 194 | #if defined(OS_CHROMEOS) |
[email protected] | 6a2a61d | 2010-11-22 03:25:35 | [diff] [blame] | 195 | #include "chrome/browser/chromeos/boot_times_loader.h" |
[email protected] | 2166c43 | 2011-12-07 20:18:28 | [diff] [blame] | 196 | #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 197 | #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
[email protected] | efda32f9 | 2011-07-06 22:47:04 | [diff] [blame] | 198 | #include "chrome/browser/ui/webui/active_downloads_ui.h" |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 199 | #endif |
| 200 | |
| 201 | #if !defined(OS_CHROMEOS) || defined(USE_AURA) |
[email protected] | efda32f9 | 2011-07-06 22:47:04 | [diff] [blame] | 202 | #include "chrome/browser/download/download_shelf.h" |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 203 | #endif |
| 204 | |
[email protected] | cb6dbc5 | 2011-08-10 17:34:39 | [diff] [blame] | 205 | #if defined(FILE_MANAGER_EXTENSION) |
[email protected] | 8baf0dbb | 2011-11-27 22:47:02 | [diff] [blame] | 206 | #include "chrome/browser/extensions/file_manager_util.h" |
[email protected] | cb6dbc5 | 2011-08-10 17:34:39 | [diff] [blame] | 207 | #endif |
| 208 | |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 209 | using base::TimeDelta; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 210 | using content::PluginService; |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 211 | using content::UserMetricsAction; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 212 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 213 | /////////////////////////////////////////////////////////////////////////////// |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 214 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 215 | namespace { |
| 216 | |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 217 | // The URL to be loaded to display Help. |
[email protected] | 8332c16 | 2011-01-26 12:01:54 | [diff] [blame] | 218 | const char kHelpContentUrl[] = |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 219 | #if defined(OS_CHROMEOS) |
[email protected] | 8332c16 | 2011-01-26 12:01:54 | [diff] [blame] | 220 | #if defined(OFFICIAL_BUILD) |
| 221 | "chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"; |
| 222 | #else |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 223 | "https://www.google.com/support/chromeos/"; |
[email protected] | 8332c16 | 2011-01-26 12:01:54 | [diff] [blame] | 224 | #endif |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 225 | #else |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 226 | "https://www.google.com/support/chrome/"; |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 227 | #endif |
| 228 | |
| 229 | // The URL to be opened when the Help link on the Autofill dialog is clicked. |
| 230 | const char kAutofillHelpUrl[] = |
| 231 | #if defined(OS_CHROMEOS) |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 232 | "https://www.google.com/support/chromeos/bin/answer.py?answer=142893"; |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 233 | #else |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 234 | "https://www.google.com/support/chrome/bin/answer.py?answer=142893"; |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 235 | #endif |
| 236 | |
| 237 | // The URL to be loaded to display the "Report a broken page" form. |
| 238 | const char kBrokenPageUrl[] = |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 239 | "https://www.google.com/support/chrome/bin/request.py?contact_type=" |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 240 | "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; |
| 241 | |
| 242 | // The URL for the privacy dashboard. |
| 243 | const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; |
| 244 | |
| 245 | // How long we wait before updating the browser chrome while loading a page. |
| 246 | const int kUIUpdateCoalescingTimeMS = 200; |
| 247 | |
| 248 | const char kHashMark[] = "#"; |
| 249 | |
[email protected] | 50dc3deb | 2011-07-07 01:07:19 | [diff] [blame] | 250 | // Returns |true| if entry has an internal chrome:// URL, |false| otherwise. |
| 251 | bool HasInternalURL(const NavigationEntry* entry) { |
| 252 | if (!entry) |
| 253 | return false; |
| 254 | |
| 255 | // Check the |virtual_url()| first. This catches regular chrome:// URLs |
| 256 | // including URLs that were rewritten (such as chrome://bookmarks). |
| 257 | if (entry->virtual_url().SchemeIs(chrome::kChromeUIScheme)) |
| 258 | return true; |
| 259 | |
| 260 | // If the |virtual_url()| isn't a chrome:// URL, check if it's actually |
| 261 | // view-source: of a chrome:// URL. |
| 262 | if (entry->virtual_url().SchemeIs(chrome::kViewSourceScheme)) |
| 263 | return entry->url().SchemeIs(chrome::kChromeUIScheme); |
| 264 | |
| 265 | return false; |
| 266 | } |
| 267 | |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 268 | // Get the launch URL for a given extension, with optional override/fallback. |
| 269 | // |override_url|, if non-empty, will be preferred over the extension's |
| 270 | // launch url. |
| 271 | GURL UrlForExtension(const Extension* extension, const GURL& override_url) { |
| 272 | if (!extension) |
| 273 | return override_url; |
| 274 | |
| 275 | GURL url; |
| 276 | if (!override_url.is_empty()) { |
| 277 | DCHECK(extension->web_extent().MatchesURL(override_url)); |
| 278 | url = override_url; |
| 279 | } else { |
| 280 | url = extension->GetFullLaunchURL(); |
| 281 | } |
| 282 | |
| 283 | // For extensions lacking launch urls, determine a reasonable fallback. |
| 284 | if (!url.is_valid()) { |
| 285 | url = extension->options_url(); |
| 286 | if (!url.is_valid()) { |
| 287 | url = GURL(std::string(chrome::kChromeUISettingsURL) + |
| 288 | chrome::kExtensionsSubPage); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | return url; |
| 293 | } |
| 294 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 295 | } // namespace |
| 296 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 297 | //////////////////////////////////////////////////////////////////////////////// |
| 298 | // Browser, CreateParams: |
| 299 | |
| 300 | Browser::CreateParams::CreateParams(Type type, Profile* profile) |
| 301 | : type(type), |
| 302 | profile(profile) { |
| 303 | } |
| 304 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 305 | /////////////////////////////////////////////////////////////////////////////// |
| 306 | // Browser, Constructors, Creation, Showing: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 307 | |
[email protected] | 299dabd | 2008-11-19 02:27:16 | [diff] [blame] | 308 | Browser::Browser(Type type, Profile* profile) |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 309 | : type_(type), |
| 310 | profile_(profile), |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 311 | window_(NULL), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 312 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 313 | tab_handler_(TabHandler::CreateTabHandler(this))), |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 314 | command_updater_(this), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 315 | toolbar_model_(this), |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 316 | chrome_updater_factory_(this), |
| 317 | is_attempting_to_close_browser_(false), |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 318 | cancel_download_confirmation_state_(NOT_PROMPTED), |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 319 | show_state_(ui::SHOW_STATE_DEFAULT), |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 320 | is_session_restore_(false), |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 321 | weak_factory_(this), |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 322 | block_command_execution_(false), |
| 323 | last_blocked_command_id_(-1), |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 324 | last_blocked_command_disposition_(CURRENT_TAB), |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 325 | pending_web_app_action_(NONE), |
| 326 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 327 | tab_restore_service_delegate_( |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 328 | new BrowserTabRestoreServiceDelegate(this))), |
[email protected] | afefa74e | 2011-07-26 05:04:23 | [diff] [blame] | 329 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 330 | synced_window_delegate_( |
| 331 | new BrowserSyncedWindowDelegate(this))), |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 332 | bookmark_bar_state_(BookmarkBar::HIDDEN), |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 333 | window_has_shown_(false) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 334 | registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 335 | content::NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 336 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 337 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 338 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 339 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 340 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 341 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 342 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 343 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 344 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 345 | content::NotificationService::AllSources()); |
[email protected] | ffa6f59 | 2011-06-24 22:03:57 | [diff] [blame] | 346 | registrar_.Add( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 347 | this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 348 | content::Source<ThemeService>( |
| 349 | ThemeServiceFactory::GetForProfile(profile_))); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 350 | registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 351 | content::NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 352 | |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 353 | PrefService* local_state = g_browser_process->local_state(); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 354 | if (local_state) { |
| 355 | local_pref_registrar_.Init(local_state); |
| 356 | local_pref_registrar_.Add(prefs::kPrintingEnabled, this); |
| 357 | local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); |
[email protected] | 3819f2ee | 2011-08-21 09:44:38 | [diff] [blame] | 358 | local_pref_registrar_.Add(prefs::kMetricsReportingEnabled, this); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | profile_pref_registrar_.Init(profile_->GetPrefs()); |
| 362 | profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); |
| 363 | profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 364 | profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 365 | profile_pref_registrar_.Add(prefs::kHomePage, this); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 366 | profile_pref_registrar_.Add(prefs::kInstantEnabled, this); |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 367 | profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this); |
[email protected] | 3819f2ee | 2011-08-21 09:44:38 | [diff] [blame] | 368 | profile_pref_registrar_.Add(prefs::kSearchSuggestEnabled, this); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 369 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 370 | InitCommandState(); |
| 371 | BrowserList::AddBrowser(this); |
| 372 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 373 | // NOTE: These prefs all need to be explicitly destroyed in the destructor |
| 374 | // or you'll get a nasty surprise when you run the incognito tests. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 375 | encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, |
| 376 | profile_->GetPrefs(), NULL); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 377 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 378 | tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 379 | if (tab_restore_service_) { |
| 380 | tab_restore_service_->AddObserver(this); |
| 381 | TabRestoreServiceChanged(tab_restore_service_); |
| 382 | } |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 383 | |
| 384 | if (profile_->GetProfileSyncService()) |
| 385 | profile_->GetProfileSyncService()->AddObserver(this); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 386 | |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 387 | CreateInstantIfNecessary(); |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 388 | |
| 389 | // Make sure TabFinder has been created. This does nothing if TabFinder is |
| 390 | // not enabled. |
| 391 | TabFinder::GetInstance(); |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 392 | |
| 393 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 394 | |
| 395 | FilePath profile_path = profile->GetPath(); |
| 396 | ProfileMetrics::LogProfileLaunch(profile_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | Browser::~Browser() { |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 400 | if (profile_->GetProfileSyncService()) |
| 401 | profile_->GetProfileSyncService()->RemoveObserver(this); |
| 402 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 403 | BrowserList::RemoveBrowser(this); |
| 404 | |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 405 | #if !defined(OS_MACOSX) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 406 | if (!BrowserList::HasBrowserWithProfile(profile_)) { |
| 407 | // We're the last browser window with this profile. We need to nuke the |
| 408 | // TabRestoreService, which will start the shutdown of the |
| 409 | // NavigationControllers and allow for proper shutdown. If we don't do this |
| 410 | // chrome won't shutdown cleanly, and may end up crashing when some |
| 411 | // thread tries to use the IO thread (or another thread) that is no longer |
| 412 | // valid. |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 413 | // This isn't a valid assumption for Mac OS, as it stays running after |
| 414 | // the last browser has closed. The Mac equivalent is in its app |
| 415 | // controller. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 416 | TabRestoreServiceFactory::ResetForProfile(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 417 | } |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 418 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 419 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 420 | SessionService* session_service = |
| 421 | SessionServiceFactory::GetForProfile(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 422 | if (session_service) |
| 423 | session_service->WindowClosed(session_id_); |
| 424 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 425 | TabRestoreService* tab_restore_service = |
| 426 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 427 | if (tab_restore_service) |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 428 | tab_restore_service->BrowserClosed(tab_restore_service_delegate()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 429 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 430 | profile_pref_registrar_.RemoveAll(); |
| 431 | local_pref_registrar_.RemoveAll(); |
| 432 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 433 | encoding_auto_detect_.Destroy(); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 434 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 435 | if (profile_->IsOffTheRecord() && |
[email protected] | 474e5db | 2011-08-12 13:02:23 | [diff] [blame] | 436 | !BrowserList::IsOffTheRecordSessionActiveForProfile(profile_)) { |
[email protected] | 0d1add3 | 2011-04-07 00:06:50 | [diff] [blame] | 437 | // An incognito profile is no longer needed, this indirectly |
[email protected] | 860f5549 | 2009-03-27 19:50:59 | [diff] [blame] | 438 | // frees its cache and cookies. |
| 439 | profile_->GetOriginalProfile()->DestroyOffTheRecordProfile(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | // There may be pending file dialogs, we need to tell them that we've gone |
| 443 | // away so they don't try and call back to us. |
| 444 | if (select_file_dialog_.get()) |
| 445 | select_file_dialog_->ListenerDestroyed(); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 446 | |
| 447 | TabRestoreServiceDestroyed(tab_restore_service_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 448 | } |
| 449 | |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 450 | bool Browser::IsFullscreenForTab() const { |
| 451 | return fullscreen_controller_->IsFullscreenForTab(); |
| 452 | } |
| 453 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 454 | // static |
| 455 | Browser* Browser::Create(Profile* profile) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 456 | Browser* browser = new Browser(TYPE_TABBED, profile); |
| 457 | browser->InitBrowserWindow(); |
| 458 | return browser; |
| 459 | } |
| 460 | |
| 461 | // static |
| 462 | Browser* Browser::CreateWithParams(const CreateParams& params) { |
| 463 | Browser* browser = new Browser(params.type, params.profile); |
| 464 | browser->app_name_ = params.app_name; |
[email protected] | 81b2b0ac | 2011-11-23 01:54:48 | [diff] [blame] | 465 | browser->set_override_bounds(params.initial_bounds); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 466 | browser->InitBrowserWindow(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 467 | return browser; |
| 468 | } |
[email protected] | 6104acf | 2008-11-11 22:27:34 | [diff] [blame] | 469 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 470 | // static |
[email protected] | 9ee17e8c | 2010-08-10 19:17:31 | [diff] [blame] | 471 | Browser* Browser::CreateForType(Type type, Profile* profile) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 472 | CreateParams params(type, profile); |
| 473 | return CreateWithParams(params); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | // static |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 477 | Browser* Browser::CreateForApp(Type type, |
| 478 | const std::string& app_name, |
[email protected] | 5c20924 | 2011-06-06 20:36:17 | [diff] [blame] | 479 | const gfx::Rect& window_bounds, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 480 | Profile* profile) { |
| 481 | DCHECK(type != TYPE_TABBED); |
| 482 | DCHECK(!app_name.empty()); |
[email protected] | f075fe0a2 | 2010-04-26 04:06:43 | [diff] [blame] | 483 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 484 | RegisterAppPrefs(app_name, profile); |
| 485 | |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 486 | #if !defined(OS_CHROMEOS) || defined(USE_AURA) |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 487 | if (type == TYPE_PANEL && |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 488 | !PanelManager::ShouldUsePanels( |
| 489 | web_app::GetExtensionIdFromApplicationName(app_name))) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 490 | type = TYPE_POPUP; |
[email protected] | 5530ac65 | 2010-09-25 05:35:49 | [diff] [blame] | 491 | } |
[email protected] | 384cb19 | 2011-10-14 20:46:51 | [diff] [blame] | 492 | #if defined(TOOLKIT_GTK) |
[email protected] | 4517b27 | 2011-11-09 01:58:05 | [diff] [blame] | 493 | // Panels are only supported on a white list of window managers for Linux. |
| 494 | if (type == TYPE_PANEL) { |
[email protected] | ca595c8f | 2011-11-10 19:30:58 | [diff] [blame] | 495 | ui::WindowManagerName wm_type = ui::GuessWindowManager(); |
| 496 | if (wm_type != ui::WM_COMPIZ && |
| 497 | wm_type != ui::WM_ICE_WM && |
| 498 | wm_type != ui::WM_KWIN && |
| 499 | wm_type != ui::WM_METACITY && |
| 500 | wm_type != ui::WM_MUTTER) { |
[email protected] | 4517b27 | 2011-11-09 01:58:05 | [diff] [blame] | 501 | type = TYPE_POPUP; |
| 502 | } |
| 503 | } |
[email protected] | 384cb19 | 2011-10-14 20:46:51 | [diff] [blame] | 504 | #endif // TOOLKIT_GTK |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 505 | #endif // !OS_CHROMEOS || USE_AURA |
[email protected] | f075fe0a2 | 2010-04-26 04:06:43 | [diff] [blame] | 506 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 507 | CreateParams params(type, profile); |
| 508 | params.app_name = app_name; |
[email protected] | 81b2b0ac | 2011-11-23 01:54:48 | [diff] [blame] | 509 | params.initial_bounds = window_bounds; |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 510 | return CreateWithParams(params); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 511 | } |
| 512 | |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 513 | // static |
| 514 | Browser* Browser::CreateForDevTools(Profile* profile) { |
[email protected] | 4befe2ec | 2011-08-31 16:13:39 | [diff] [blame] | 515 | #if defined(OS_CHROMEOS) |
| 516 | CreateParams params(TYPE_TABBED, profile); |
| 517 | #else |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 518 | CreateParams params(TYPE_POPUP, profile); |
[email protected] | 4befe2ec | 2011-08-31 16:13:39 | [diff] [blame] | 519 | #endif |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 520 | params.app_name = DevToolsWindow::kDevToolsApp; |
| 521 | return CreateWithParams(params); |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 522 | } |
| 523 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 524 | void Browser::InitBrowserWindow() { |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 525 | DCHECK(!window_); |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 526 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 527 | window_ = CreateBrowserWindow(); |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 528 | fullscreen_controller_ = new FullscreenController(window_, profile_, this); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 529 | |
[email protected] | 5e37c45 | 2011-09-06 19:31:39 | [diff] [blame] | 530 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | 45446a5 | 2010-11-04 17:41:00 | [diff] [blame] | 531 | { |
| 532 | // TODO: This might hit the disk |
| 533 | // http://code.google.com/p/chromium/issues/detail?id=61638 |
| 534 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 535 | |
| 536 | // Set the app user model id for this application to that of the application |
| 537 | // name. See http://crbug.com/7028. |
[email protected] | dcd5776 | 2011-06-25 12:18:51 | [diff] [blame] | 538 | ui::win::SetAppIdForWindow( |
[email protected] | 2de2d62 | 2011-10-21 22:07:37 | [diff] [blame] | 539 | is_app() && !is_type_panel() ? |
[email protected] | 45446a5 | 2010-11-04 17:41:00 | [diff] [blame] | 540 | ShellIntegration::GetAppId(UTF8ToWide(app_name_), profile_->GetPath()) : |
| 541 | ShellIntegration::GetChromiumAppId(profile_->GetPath()), |
| 542 | window()->GetNativeHandle()); |
[email protected] | 2de2d62 | 2011-10-21 22:07:37 | [diff] [blame] | 543 | |
| 544 | if (is_type_panel()) { |
| 545 | ui::win::SetAppIconForWindow( |
| 546 | ShellIntegration::GetChromiumIconPath(), |
| 547 | window()->GetNativeHandle()); |
| 548 | } |
[email protected] | 45446a5 | 2010-11-04 17:41:00 | [diff] [blame] | 549 | } |
[email protected] | 80cf356 | 2009-11-17 08:17:24 | [diff] [blame] | 550 | #endif |
| 551 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 552 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 553 | chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 554 | content::Source<Browser>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 555 | content::NotificationService::NoDetails()); |
[email protected] | 14d8c66e | 2009-09-22 00:32:52 | [diff] [blame] | 556 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 557 | PrefService* local_state = g_browser_process->local_state(); |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 558 | if (local_state && local_state->FindPreference( |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 559 | prefs::kAutofillPersonalDataManagerFirstRun) && |
| 560 | local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) { |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 561 | // Notify PDM that this is a first run. |
| 562 | #if defined(OS_WIN) |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 563 | ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_)); |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 564 | #endif // defined(OS_WIN) |
| 565 | // Reset the preference so we don't call it again for subsequent windows. |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 566 | local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun); |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 567 | } |
[email protected] | 6a1622a | 2011-09-20 22:37:45 | [diff] [blame] | 568 | |
| 569 | // Permanently dismiss ntp4 bubble for new users. |
| 570 | if (FirstRun::IsChromeFirstRun()) |
[email protected] | 27e96a97 | 2011-10-20 20:06:55 | [diff] [blame] | 571 | NewTabPageHandler::DismissIntroMessage(local_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 572 | } |
| 573 | |
[email protected] | bf870869 | 2011-12-20 21:24:28 | [diff] [blame] | 574 | void Browser::SetWindowForTesting(BrowserWindow* window) { |
| 575 | DCHECK(!window_); |
| 576 | window_ = window; |
| 577 | fullscreen_controller_ = new FullscreenController(window_, profile_, this); |
| 578 | } |
| 579 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 580 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 581 | // Getters & Setters |
| 582 | |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 583 | FindBarController* Browser::GetFindBarController() { |
| 584 | if (!find_bar_controller_.get()) { |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 585 | FindBar* find_bar = window_->CreateFindBar(); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 586 | find_bar_controller_.reset(new FindBarController(find_bar)); |
| 587 | find_bar->SetFindBarController(find_bar_controller_.get()); |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 588 | find_bar_controller_->ChangeTabContents(GetSelectedTabContentsWrapper()); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 589 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
| 590 | } |
| 591 | return find_bar_controller_.get(); |
| 592 | } |
| 593 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 594 | bool Browser::HasFindBarController() const { |
| 595 | return find_bar_controller_.get() != NULL; |
| 596 | } |
| 597 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 598 | bool Browser::is_app() const { |
| 599 | return !app_name_.empty(); |
| 600 | } |
| 601 | |
| 602 | bool Browser::is_devtools() const { |
| 603 | return app_name_ == DevToolsWindow::kDevToolsApp; |
| 604 | } |
| 605 | |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 606 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 607 | // Browser, Creation Helpers: |
| 608 | |
| 609 | // static |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 610 | void Browser::OpenEmptyWindow(Profile* profile) { |
| 611 | Browser* browser = Browser::Create(profile); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 612 | browser->AddBlankTab(true); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 613 | browser->window()->Show(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 614 | } |
| 615 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 616 | // static |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 617 | void Browser::OpenWindowWithRestoredTabs(Profile* profile) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 618 | TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile); |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 619 | if (service) |
| 620 | service->RestoreMostRecentEntry(NULL); |
| 621 | } |
| 622 | |
| 623 | // static |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 624 | void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 625 | Browser* browser = GetOrCreateTabbedBrowser( |
| 626 | profile->GetOffTheRecordProfile()); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 627 | browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 628 | browser->window()->Show(); |
[email protected] | 2baf83d | 2008-07-30 05:58:17 | [diff] [blame] | 629 | } |
| 630 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 631 | // static |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 632 | TabContents* Browser::OpenApplication( |
| 633 | Profile* profile, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 634 | const Extension* extension, |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 635 | extension_misc::LaunchContainer container, |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 636 | const GURL& override_url, |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 637 | WindowOpenDisposition disposition) { |
[email protected] | 5686938 | 2010-05-11 21:45:46 | [diff] [blame] | 638 | TabContents* tab = NULL; |
[email protected] | 4033bd9 | 2011-03-08 19:27:04 | [diff] [blame] | 639 | ExtensionPrefs* prefs = profile->GetExtensionService()->extension_prefs(); |
| 640 | prefs->SetActiveBit(extension->id(), true); |
[email protected] | e3acb7c | 2010-05-11 19:23:37 | [diff] [blame] | 641 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 642 | UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchContainer", container, 100); |
| 643 | |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 644 | switch (container) { |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 645 | case extension_misc::LAUNCH_WINDOW: |
| 646 | case extension_misc::LAUNCH_PANEL: |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 647 | case extension_misc::LAUNCH_SHELL: |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 648 | tab = Browser::OpenApplicationWindow(profile, extension, container, |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 649 | override_url, NULL); |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 650 | break; |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 651 | case extension_misc::LAUNCH_TAB: { |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 652 | tab = Browser::OpenApplicationTab(profile, extension, override_url, |
| 653 | disposition); |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 654 | break; |
| 655 | } |
| 656 | default: |
| 657 | NOTREACHED(); |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 658 | break; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 659 | } |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 660 | return tab; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | // static |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 664 | TabContents* Browser::OpenApplicationWindow( |
| 665 | Profile* profile, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 666 | const Extension* extension, |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 667 | extension_misc::LaunchContainer container, |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 668 | const GURL& url_input, |
| 669 | Browser** app_browser) { |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 670 | DCHECK(!url_input.is_empty() || extension); |
| 671 | GURL url = UrlForExtension(extension, url_input); |
[email protected] | f381dfa | 2010-04-29 04:41:37 | [diff] [blame] | 672 | |
[email protected] | 2f1c09d | 2011-01-14 14:58:14 | [diff] [blame] | 673 | std::string app_name; |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 674 | app_name = extension ? |
| 675 | web_app::GenerateApplicationNameFromExtensionId(extension->id()) : |
| 676 | web_app::GenerateApplicationNameFromURL(url); |
[email protected] | 2f1c09d | 2011-01-14 14:58:14 | [diff] [blame] | 677 | |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 678 | Type type = TYPE_POPUP; |
| 679 | if (extension) { |
| 680 | switch (container) { |
| 681 | case extension_misc::LAUNCH_PANEL: |
| 682 | type = TYPE_PANEL; |
| 683 | break; |
| 684 | case extension_misc::LAUNCH_SHELL: |
| 685 | type = TYPE_SHELL; |
| 686 | break; |
| 687 | default: break; |
| 688 | } |
| 689 | } |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 690 | |
[email protected] | 5c20924 | 2011-06-06 20:36:17 | [diff] [blame] | 691 | gfx::Rect window_bounds; |
| 692 | if (extension) { |
| 693 | window_bounds.set_width(extension->launch_width()); |
| 694 | window_bounds.set_height(extension->launch_height()); |
| 695 | } |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 696 | |
[email protected] | 5c20924 | 2011-06-06 20:36:17 | [diff] [blame] | 697 | Browser* browser = Browser::CreateForApp(type, app_name, window_bounds, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 698 | profile); |
[email protected] | 011396a | 2011-04-13 23:35:28 | [diff] [blame] | 699 | |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 700 | if (app_browser) |
| 701 | *app_browser = browser; |
| 702 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 703 | TabContentsWrapper* wrapper = |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 704 | browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_START_PAGE); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 705 | TabContents* contents = wrapper->tab_contents(); |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 706 | contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 707 | contents->GetRenderViewHost()->SyncRendererPrefs(); |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 708 | browser->window()->Show(); |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 709 | |
[email protected] | 68f009f | 2009-02-26 19:43:35 | [diff] [blame] | 710 | // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
| 711 | // focus explicitly. |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 712 | contents->GetView()->SetInitialFocus(); |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 713 | return contents; |
| 714 | } |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 715 | |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 716 | TabContents* Browser::OpenAppShortcutWindow(Profile* profile, |
| 717 | const GURL& url, |
| 718 | bool update_shortcut) { |
| 719 | Browser* app_browser; |
| 720 | TabContents* tab = OpenApplicationWindow( |
| 721 | profile, |
| 722 | NULL, // this is a URL app. No extension. |
| 723 | extension_misc::LAUNCH_WINDOW, |
| 724 | url, |
| 725 | &app_browser); |
| 726 | |
| 727 | if (!tab) |
| 728 | return NULL; |
| 729 | |
| 730 | if (update_shortcut) { |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 731 | // Set UPDATE_SHORTCUT as the pending web app action. This action is picked |
| 732 | // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
| 733 | // the web app info is available, TabContents notifies Browser via |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 734 | // OnDidGetApplicationInfo, which calls |
| 735 | // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
| 736 | // pending web app action. |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 737 | app_browser->pending_web_app_action_ = UPDATE_SHORTCUT; |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 738 | } |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 739 | return tab; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | // static |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 743 | TabContents* Browser::OpenApplicationTab(Profile* profile, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 744 | const Extension* extension, |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 745 | const GURL& override_url, |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 746 | WindowOpenDisposition disposition) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 747 | Browser* browser = BrowserList::FindTabbedBrowser(profile, false); |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 748 | TabContents* contents = NULL; |
[email protected] | 78d78a6 | 2011-09-29 18:24:33 | [diff] [blame] | 749 | if (!browser) { |
| 750 | // No browser for this profile, need to open a new one. |
| 751 | browser = Browser::Create(profile); |
| 752 | browser->window()->Show(); |
| 753 | // There's no current tab in this browser window, so add a new one. |
| 754 | disposition = NEW_FOREGROUND_TAB; |
| 755 | } |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 756 | |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 757 | // Check the prefs for overridden mode. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 758 | ExtensionService* extension_service = profile->GetExtensionService(); |
| 759 | DCHECK(extension_service); |
[email protected] | b283a753 | 2010-08-12 21:24:59 | [diff] [blame] | 760 | |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 761 | ExtensionPrefs::LaunchType launch_type = |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 762 | extension_service->extension_prefs()->GetLaunchType( |
[email protected] | 4e59568 | 2011-02-09 17:07:02 | [diff] [blame] | 763 | extension->id(), ExtensionPrefs::LAUNCH_DEFAULT); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 764 | UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 765 | |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 766 | static bool default_apps_trial_exists = |
[email protected] | 568c331 | 2011-12-06 15:36:04 | [diff] [blame] | 767 | base::FieldTrialList::TrialExists(kDefaultAppsTrialName); |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 768 | if (default_apps_trial_exists) { |
| 769 | UMA_HISTOGRAM_ENUMERATION( |
| 770 | base::FieldTrial::MakeName("Extensions.AppTabLaunchType", |
[email protected] | 568c331 | 2011-12-06 15:36:04 | [diff] [blame] | 771 | kDefaultAppsTrialName), |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 772 | launch_type, 100); |
| 773 | } |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 774 | |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 775 | int add_type = TabStripModel::ADD_ACTIVE; |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 776 | if (launch_type == ExtensionPrefs::LAUNCH_PINNED) |
| 777 | add_type |= TabStripModel::ADD_PINNED; |
| 778 | |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 779 | GURL extension_url = UrlForExtension(extension, override_url); |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 780 | // TODO(erikkay): START_PAGE doesn't seem like the right transition in all |
| 781 | // cases. |
[email protected] | 37fcf26 | 2011-01-26 19:39:15 | [diff] [blame] | 782 | browser::NavigateParams params(browser, extension_url, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 783 | content::PAGE_TRANSITION_START_PAGE); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 784 | params.tabstrip_add_types = add_type; |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 785 | params.disposition = disposition; |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 786 | |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 787 | if (disposition == CURRENT_TAB) { |
| 788 | TabContents* existing_tab = browser->GetSelectedTabContents(); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 789 | TabStripModel* model = browser->tabstrip_model(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 790 | int tab_index = model->GetWrapperIndex(existing_tab); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 791 | |
[email protected] | bce1f1c | 2011-12-05 15:11:58 | [diff] [blame] | 792 | existing_tab->OpenURL(OpenURLParams( |
| 793 | extension_url, |
| 794 | content::Referrer(existing_tab->GetURL(), |
| 795 | WebKit::WebReferrerPolicyDefault), |
| 796 | disposition, content::PAGE_TRANSITION_LINK, false)); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 797 | if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) { |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 798 | model->SetTabPinned(tab_index, true); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 799 | tab_index = model->GetWrapperIndex(existing_tab); |
[email protected] | 7dfec421 | 2010-11-01 22:12:26 | [diff] [blame] | 800 | } |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 801 | if (params.tabstrip_add_types & TabStripModel::ADD_ACTIVE) |
| 802 | model->ActivateTabAt(tab_index, true); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 803 | |
| 804 | contents = existing_tab; |
| 805 | } else { |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 806 | browser::Navigate(¶ms); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 807 | contents = params.target_contents->tab_contents(); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 808 | } |
| 809 | |
[email protected] | 7bd42fc | 2011-02-09 17:32:42 | [diff] [blame] | 810 | // TODO(skerner): If we are already in full screen mode, and the user |
| 811 | // set the app to open as a regular or pinned tab, what should happen? |
| 812 | // Today we open the tab, but stay in full screen mode. Should we leave |
| 813 | // full screen mode in this case? |
| 814 | if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 815 | !browser->window()->IsFullscreen()) { |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 816 | browser->ToggleFullscreenMode(false); |
[email protected] | b6cb770 | 2011-11-15 05:33:11 | [diff] [blame] | 817 | } |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 818 | |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 819 | return contents; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | // static |
[email protected] | 90a8bf25 | 2010-03-12 00:09:47 | [diff] [blame] | 823 | void Browser::OpenBookmarkManagerWindow(Profile* profile) { |
| 824 | Browser* browser = Browser::Create(profile); |
[email protected] | 0af8f13 | 2011-07-16 01:37:02 | [diff] [blame] | 825 | browser->OpenBookmarkManager(); |
[email protected] | 90a8bf25 | 2010-03-12 00:09:47 | [diff] [blame] | 826 | browser->window()->Show(); |
| 827 | } |
| 828 | |
[email protected] | 057d959a | 2010-03-12 02:56:20 | [diff] [blame] | 829 | #if defined(OS_MACOSX) |
[email protected] | 90a8bf25 | 2010-03-12 00:09:47 | [diff] [blame] | 830 | // static |
[email protected] | 91a5b3e | 2009-10-30 19:32:22 | [diff] [blame] | 831 | void Browser::OpenHistoryWindow(Profile* profile) { |
| 832 | Browser* browser = Browser::Create(profile); |
| 833 | browser->ShowHistoryTab(); |
| 834 | browser->window()->Show(); |
| 835 | } |
| 836 | |
| 837 | // static |
| 838 | void Browser::OpenDownloadsWindow(Profile* profile) { |
| 839 | Browser* browser = Browser::Create(profile); |
| 840 | browser->ShowDownloadsTab(); |
| 841 | browser->window()->Show(); |
| 842 | } |
| 843 | |
| 844 | // static |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 845 | void Browser::OpenHelpWindow(Profile* profile) { |
| 846 | Browser* browser = Browser::Create(profile); |
[email protected] | 202802e4 | 2011-07-06 11:40:46 | [diff] [blame] | 847 | browser->ShowHelpTab(); |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 848 | browser->window()->Show(); |
| 849 | } |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 850 | |
[email protected] | eca25813 | 2010-11-15 23:33:08 | [diff] [blame] | 851 | // static |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 852 | void Browser::OpenOptionsWindow(Profile* profile) { |
| 853 | Browser* browser = Browser::Create(profile); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 854 | browser->OpenOptionsDialog(); |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 855 | browser->window()->Show(); |
| 856 | } |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 857 | |
| 858 | // static |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 859 | void Browser::OpenClearBrowsingDataDialogWindow(Profile* profile) { |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 860 | Browser* browser = Browser::Create(profile); |
| 861 | browser->OpenClearBrowsingDataDialog(); |
| 862 | browser->window()->Show(); |
| 863 | } |
| 864 | |
| 865 | // static |
| 866 | void Browser::OpenImportSettingsDialogWindow(Profile* profile) { |
| 867 | Browser* browser = Browser::Create(profile); |
| 868 | browser->OpenImportSettingsDialog(); |
| 869 | browser->window()->Show(); |
| 870 | } |
[email protected] | b99081b | 2011-03-10 17:43:47 | [diff] [blame] | 871 | |
| 872 | // static |
| 873 | void Browser::OpenInstantConfirmDialogWindow(Profile* profile) { |
| 874 | Browser* browser = Browser::Create(profile); |
| 875 | browser->OpenInstantConfirmDialog(); |
| 876 | browser->window()->Show(); |
| 877 | } |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 878 | #endif |
| 879 | |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 880 | // static |
| 881 | void Browser::OpenExtensionsWindow(Profile* profile) { |
| 882 | Browser* browser = Browser::Create(profile); |
| 883 | browser->ShowExtensionsTab(); |
| 884 | browser->window()->Show(); |
| 885 | } |
| 886 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 887 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 888 | // Browser, State Storage and Retrieval for UI: |
| 889 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 890 | std::string Browser::GetWindowPlacementKey() const { |
| 891 | std::string name(prefs::kBrowserWindowPlacement); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 892 | if (!app_name_.empty()) { |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 893 | name.append("_"); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 894 | name.append(app_name_); |
| 895 | } |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 896 | return name; |
| 897 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 898 | |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 899 | bool Browser::ShouldSaveWindowPlacement() const { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 900 | switch (type_) { |
| 901 | case TYPE_TABBED: |
| 902 | return true; |
| 903 | case TYPE_POPUP: |
[email protected] | bd6cdf2 | 2011-06-21 08:11:51 | [diff] [blame] | 904 | // Only save the window placement of popups if they are restored, |
| 905 | // or the window belongs to DevTools. |
| 906 | return browser_defaults::kRestorePopups || is_devtools(); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 907 | case TYPE_PANEL: |
| 908 | // Do not save the window placement of panels. |
| 909 | return false; |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 910 | case TYPE_SHELL: |
| 911 | return true; |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 912 | default: |
| 913 | return false; |
| 914 | } |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 915 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 916 | |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 917 | void Browser::SaveWindowPlacement(const gfx::Rect& bounds, |
| 918 | ui::WindowShowState show_state) { |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 919 | // Save to the session storage service, used when reloading a past session. |
| 920 | // Note that we don't want to be the ones who cause lazy initialization of |
| 921 | // the session service. This function gets called during initial window |
| 922 | // 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] | 923 | SessionService* session_service = |
| 924 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
| 925 | if (session_service) |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 926 | session_service->SetWindowBounds(session_id_, bounds, show_state); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 927 | } |
| 928 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 929 | gfx::Rect Browser::GetSavedWindowBounds() const { |
[email protected] | bb97536 | 2009-01-21 01:00:22 | [diff] [blame] | 930 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 931 | bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode); |
| 932 | bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode); |
| 933 | if (record_mode || playback_mode) { |
| 934 | // In playback/record mode we always fix the size of the browser and |
| 935 | // move it to (0,0). The reason for this is two reasons: First we want |
| 936 | // resize/moves in the playback to still work, and Second we want |
| 937 | // playbacks to work (as much as possible) on machines w/ different |
| 938 | // screen sizes. |
| 939 | return gfx::Rect(0, 0, 800, 600); |
| 940 | } |
| 941 | |
| 942 | gfx::Rect restored_bounds = override_bounds_; |
[email protected] | f87919d7 | 2011-02-02 18:46:16 | [diff] [blame] | 943 | WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, |
[email protected] | ea9dad9 | 2011-11-17 16:10:00 | [diff] [blame] | 944 | &restored_bounds); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 945 | return restored_bounds; |
| 946 | } |
| 947 | |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 948 | ui::WindowShowState Browser::GetSavedWindowShowState() const { |
[email protected] | bb97536 | 2009-01-21 01:00:22 | [diff] [blame] | 949 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 950 | return ui::SHOW_STATE_MAXIMIZED; |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 951 | |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 952 | if (show_state_ != ui::SHOW_STATE_DEFAULT) |
| 953 | return show_state_; |
[email protected] | 2e71662 | 2009-03-09 21:11:01 | [diff] [blame] | 954 | |
[email protected] | 96f2010 | 2011-11-16 17:20:32 | [diff] [blame] | 955 | const DictionaryValue* window_pref = |
| 956 | profile()->GetPrefs()->GetDictionary(GetWindowPlacementKey().c_str()); |
[email protected] | 2e71662 | 2009-03-09 21:11:01 | [diff] [blame] | 957 | bool maximized = false; |
[email protected] | 96f2010 | 2011-11-16 17:20:32 | [diff] [blame] | 958 | window_pref->GetBoolean("maximized", &maximized); |
| 959 | |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 960 | return maximized ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | SkBitmap Browser::GetCurrentPageIcon() const { |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 964 | TabContentsWrapper* contents = GetSelectedTabContentsWrapper(); |
[email protected] | ce5348a8 | 2008-12-18 18:36:23 | [diff] [blame] | 965 | // |contents| can be NULL since GetCurrentPageIcon() is called by the window |
| 966 | // during the window's creation (before tabs have been added). |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 967 | return contents ? contents->favicon_tab_helper()->GetFavicon() : SkBitmap(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 968 | } |
| 969 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 970 | string16 Browser::GetWindowTitleForCurrentTab() const { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 971 | TabContents* contents = GetSelectedTabContents(); |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 972 | string16 title; |
[email protected] | c7c4233 | 2008-11-15 01:10:54 | [diff] [blame] | 973 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 974 | // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the |
| 975 | // window during the window's creation (before tabs have been added). |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 976 | if (contents) { |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 977 | title = contents->GetTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 978 | FormatTitleForDisplay(&title); |
| 979 | } |
| 980 | if (title.empty()) |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 981 | title = CoreTabHelper::GetDefaultTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 982 | |
[email protected] | 1677984 | 2009-07-08 23:45:29 | [diff] [blame] | 983 | #if defined(OS_MACOSX) || defined(OS_CHROMEOS) |
[email protected] | 22a3daa | 2009-11-09 22:03:33 | [diff] [blame] | 984 | // On Mac or ChromeOS, we don't want to suffix the page title with |
| 985 | // the application name. |
[email protected] | d904bc8 | 2009-07-07 00:41:04 | [diff] [blame] | 986 | return title; |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 987 | #else |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 988 | int string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT; |
[email protected] | dff52973 | 2010-04-01 23:50:55 | [diff] [blame] | 989 | // 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] | 990 | if (is_app()) |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 991 | string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT_NO_LOGO; |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 992 | return l10n_util::GetStringFUTF16(string_id, title); |
[email protected] | 57e68dba | 2009-05-15 21:30:50 | [diff] [blame] | 993 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | // static |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 997 | void Browser::FormatTitleForDisplay(string16* title) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 998 | size_t current_index = 0; |
| 999 | size_t match_index; |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 1000 | while ((match_index = title->find(L'\n', current_index)) != string16::npos) { |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 1001 | title->replace(match_index, 1, string16()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1002 | current_index = match_index; |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | /////////////////////////////////////////////////////////////////////////////// |
| 1007 | // Browser, OnBeforeUnload handling: |
| 1008 | |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 1009 | bool Browser::TabsNeedBeforeUnloadFired() { |
| 1010 | if (tabs_needing_before_unload_fired_.empty()) { |
| 1011 | for (int i = 0; i < tab_count(); ++i) { |
| 1012 | TabContents* contents = GetTabContentsAt(i); |
| 1013 | if (contents->NeedToFireBeforeUnload()) |
| 1014 | tabs_needing_before_unload_fired_.insert(contents); |
| 1015 | } |
| 1016 | } |
| 1017 | return !tabs_needing_before_unload_fired_.empty(); |
| 1018 | } |
| 1019 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1020 | bool Browser::ShouldCloseWindow() { |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 1021 | if (!CanCloseWithInProgressDownloads()) |
| 1022 | return false; |
| 1023 | |
| 1024 | if (HasCompletedUnloadProcessing()) |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 1025 | return IsClosingPermitted(); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 1026 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1027 | is_attempting_to_close_browser_ = true; |
| 1028 | |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 1029 | if (!TabsNeedBeforeUnloadFired()) |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 1030 | return IsClosingPermitted(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1031 | |
| 1032 | ProcessPendingTabs(); |
| 1033 | return false; |
| 1034 | } |
| 1035 | |
| 1036 | void Browser::OnWindowClosing() { |
| 1037 | if (!ShouldCloseWindow()) |
| 1038 | return; |
| 1039 | |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 1040 | bool exiting = false; |
| 1041 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 1042 | // Application should shutdown on last window close if the user is explicitly |
| 1043 | // trying to quit, or if there is nothing keeping the browser alive (such as |
| 1044 | // AppController on the Mac, or BackgroundContentsService for background |
| 1045 | // pages). |
| 1046 | bool should_quit_if_last_browser = |
| 1047 | browser_shutdown::IsTryingToQuit() || !BrowserList::WillKeepAlive(); |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 1048 | |
| 1049 | if (should_quit_if_last_browser && BrowserList::size() == 1) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1050 | browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 1051 | exiting = true; |
| 1052 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1053 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1054 | // Don't use GetForProfileIfExisting here, we want to force creation of the |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1055 | // session service so that user can restore what was open. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1056 | SessionService* session_service = |
| 1057 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1058 | if (session_service) |
| 1059 | session_service->WindowClosing(session_id()); |
| 1060 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1061 | TabRestoreService* tab_restore_service = |
| 1062 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1063 | if (tab_restore_service && is_type_tabbed() && tab_count()) |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 1064 | tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 1065 | |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 1066 | // TODO(sky): convert session/tab restore to use notification. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1067 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1068 | chrome::NOTIFICATION_BROWSER_CLOSING, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1069 | content::Source<Browser>(this), |
| 1070 | content::Details<bool>(&exiting)); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 1071 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1072 | CloseAllTabs(); |
| 1073 | } |
| 1074 | |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 1075 | void Browser::OnWindowActivated() { |
| 1076 | // On some platforms we want to automatically reload tabs that are |
| 1077 | // killed when the user selects them. |
| 1078 | TabContents* contents = GetSelectedTabContents(); |
| 1079 | if (contents && contents->crashed_status() == |
| 1080 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 1081 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1082 | switches::kReloadKilledTabs)) { |
| 1083 | Reload(CURRENT_TAB); |
| 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 1088 | //////////////////////////////////////////////////////////////////////////////// |
| 1089 | // In-progress download termination handling: |
| 1090 | |
| 1091 | void Browser::InProgressDownloadResponse(bool cancel_downloads) { |
| 1092 | if (cancel_downloads) { |
| 1093 | cancel_download_confirmation_state_ = RESPONSE_RECEIVED; |
| 1094 | CloseWindow(); |
| 1095 | return; |
| 1096 | } |
| 1097 | |
| 1098 | // Sets the confirmation state to NOT_PROMPTED so that if the user tries to |
| 1099 | // close again we'll show the warning again. |
| 1100 | cancel_download_confirmation_state_ = NOT_PROMPTED; |
| 1101 | |
| 1102 | // Show the download page so the user can figure-out what downloads are still |
| 1103 | // in-progress. |
| 1104 | ShowDownloadsTab(); |
| 1105 | } |
| 1106 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 1107 | Browser::DownloadClosePreventionType Browser::OkToCloseWithInProgressDownloads( |
| 1108 | int* num_downloads_blocking) const { |
| 1109 | DCHECK(num_downloads_blocking); |
| 1110 | *num_downloads_blocking = 0; |
| 1111 | |
| 1112 | if (is_attempting_to_close_browser_) |
| 1113 | return DOWNLOAD_CLOSE_OK; |
| 1114 | |
| 1115 | // If we're not running a full browser process with a profile manager |
| 1116 | // (testing), it's ok to close the browser. |
| 1117 | if (!g_browser_process->profile_manager()) |
| 1118 | return DOWNLOAD_CLOSE_OK; |
| 1119 | |
| 1120 | int total_download_count = DownloadService::DownloadCountAllProfiles(); |
| 1121 | if (total_download_count == 0) |
| 1122 | return DOWNLOAD_CLOSE_OK; // No downloads; can definitely close. |
| 1123 | |
| 1124 | // Figure out how many windows are open total, and associated with this |
| 1125 | // profile, that are relevant for the ok-to-close decision. |
| 1126 | int profile_window_count = 0; |
| 1127 | int total_window_count = 0; |
| 1128 | for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 1129 | iter != BrowserList::end(); ++iter) { |
| 1130 | // Don't count this browser window or any other in the process of closing. |
| 1131 | Browser* const browser = *iter; |
| 1132 | // Check is_attempting_to_close_browser_ as window closing may be |
| 1133 | // delayed, and windows that are in the process of closing don't |
| 1134 | // count against our totals. |
| 1135 | if (browser == this || browser->is_attempting_to_close_browser_) |
| 1136 | continue; |
| 1137 | |
| 1138 | if ((*iter)->profile() == profile()) |
| 1139 | profile_window_count++; |
| 1140 | total_window_count++; |
| 1141 | } |
| 1142 | |
| 1143 | // If there aren't any other windows, we're at browser shutdown, |
| 1144 | // which would cancel all current downloads. |
| 1145 | if (total_window_count == 0) { |
| 1146 | *num_downloads_blocking = total_download_count; |
| 1147 | return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN; |
| 1148 | } |
| 1149 | |
| 1150 | // If there aren't any other windows on our profile, and we're an incognito |
| 1151 | // profile, and there are downloads associated with that profile, |
| 1152 | // those downloads would be cancelled by our window (-> profile) close. |
| 1153 | DownloadService* download_service = |
| 1154 | DownloadServiceFactory::GetForProfile(profile()); |
| 1155 | if (profile_window_count == 0 && download_service->DownloadCount() > 0 && |
| 1156 | profile()->IsOffTheRecord()) { |
| 1157 | *num_downloads_blocking = download_service->DownloadCount(); |
| 1158 | return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE; |
| 1159 | } |
| 1160 | |
| 1161 | // Those are the only conditions under which we will block shutdown. |
| 1162 | return DOWNLOAD_CLOSE_OK; |
| 1163 | } |
| 1164 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 1165 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1166 | // Browser, TabStripModel pass-thrus: |
| 1167 | |
| 1168 | int Browser::tab_count() const { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1169 | return tab_handler_->GetTabStripModel()->count(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1170 | } |
| 1171 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 1172 | int Browser::active_index() const { |
| 1173 | return tab_handler_->GetTabStripModel()->active_index(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | int Browser::GetIndexOfController( |
| 1177 | const NavigationController* controller) const { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1178 | return tab_handler_->GetTabStripModel()->GetIndexOfController(controller); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1179 | } |
| 1180 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1181 | TabContentsWrapper* Browser::GetSelectedTabContentsWrapper() const { |
[email protected] | fb7e7492 | 2011-06-09 01:39:42 | [diff] [blame] | 1182 | return tabstrip_model()->GetActiveTabContents(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1183 | } |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1184 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1185 | TabContentsWrapper* Browser::GetTabContentsWrapperAt(int index) const { |
| 1186 | return tabstrip_model()->GetTabContentsAt(index); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | TabContents* Browser::GetSelectedTabContents() const { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1190 | TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); |
| 1191 | if (wrapper) |
| 1192 | return wrapper->tab_contents(); |
| 1193 | return NULL; |
| 1194 | } |
| 1195 | |
| 1196 | TabContents* Browser::GetTabContentsAt(int index) const { |
| 1197 | TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
| 1198 | if (wrapper) |
| 1199 | return wrapper->tab_contents(); |
| 1200 | return NULL; |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1201 | } |
| 1202 | |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1203 | void Browser::ActivateTabAt(int index, bool user_gesture) { |
| 1204 | tab_handler_->GetTabStripModel()->ActivateTabAt(index, user_gesture); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1205 | } |
| 1206 | |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 1207 | bool Browser::IsTabPinned(int index) const { |
| 1208 | return tabstrip_model()->IsTabPinned(index); |
| 1209 | } |
| 1210 | |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 1211 | bool Browser::IsTabDiscarded(int index) const { |
| 1212 | return tab_handler_->GetTabStripModel()->IsTabDiscarded(index); |
| 1213 | } |
| 1214 | |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1215 | void Browser::CloseAllTabs() { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1216 | tab_handler_->GetTabStripModel()->CloseAllTabs(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1220 | // Browser, Tab adding/showing functions: |
| 1221 | |
[email protected] | 95bf8a5b | 2010-12-22 16:04:07 | [diff] [blame] | 1222 | bool Browser::IsTabStripEditable() const { |
| 1223 | return window()->IsTabStripEditable(); |
| 1224 | } |
| 1225 | |
[email protected] | b334487 | 2010-05-03 15:52:29 | [diff] [blame] | 1226 | int Browser::GetIndexForInsertionDuringRestore(int relative_index) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1227 | return (tab_handler_->GetTabStripModel()->insertion_policy() == |
| 1228 | TabStripModel::INSERT_AFTER) ? tab_count() : relative_index; |
[email protected] | b334487 | 2010-05-03 15:52:29 | [diff] [blame] | 1229 | } |
| 1230 | |
[email protected] | dad09ce4 | 2011-08-25 23:11:30 | [diff] [blame] | 1231 | TabContentsWrapper* Browser::AddSelectedTabWithURL( |
| 1232 | const GURL& url, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1233 | content::PageTransition transition) { |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1234 | browser::NavigateParams params(this, url, transition); |
| 1235 | params.disposition = NEW_FOREGROUND_TAB; |
| 1236 | browser::Navigate(¶ms); |
| 1237 | return params.target_contents; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1238 | } |
| 1239 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1240 | TabContents* Browser::AddTab(TabContentsWrapper* tab_contents, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1241 | content::PageTransition type) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1242 | tab_handler_->GetTabStripModel()->AddTabContents( |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1243 | tab_contents, -1, type, TabStripModel::ADD_ACTIVE); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1244 | return tab_contents->tab_contents(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1245 | } |
| 1246 | |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 1247 | void Browser::AddTabContents(TabContents* new_contents, |
| 1248 | WindowOpenDisposition disposition, |
| 1249 | const gfx::Rect& initial_pos, |
| 1250 | bool user_gesture) { |
| 1251 | AddNewContents(NULL, new_contents, disposition, initial_pos, user_gesture); |
| 1252 | } |
| 1253 | |
| 1254 | void Browser::CloseTabContents(TabContents* contents) { |
| 1255 | CloseContents(contents); |
| 1256 | } |
| 1257 | |
[email protected] | b86451c | 2011-08-16 02:13:44 | [diff] [blame] | 1258 | gfx::NativeWindow Browser::BrowserShowHtmlDialog( |
[email protected] | 62c1f7a | 2011-10-01 01:12:04 | [diff] [blame] | 1259 | HtmlDialogUIDelegate* delegate, |
[email protected] | 22c830d | 2011-11-29 20:00:37 | [diff] [blame] | 1260 | gfx::NativeWindow parent_window, |
| 1261 | DialogStyle style) { |
[email protected] | 62c1f7a | 2011-10-01 01:12:04 | [diff] [blame] | 1262 | #if defined(OS_CHROMEOS) |
| 1263 | // For Chrome OS, first try to parent the dialog over the current browser -- |
| 1264 | // it's likely to be maximized onscreen. If it isn't tabbed (e.g. it's a |
| 1265 | // panel), find a browser that is. |
| 1266 | parent_window = window_->GetNativeHandle(); |
| 1267 | if (!is_type_tabbed()) { |
| 1268 | Browser* tabbed_browser = BrowserList::FindTabbedBrowser(profile_, true); |
| 1269 | if (tabbed_browser && tabbed_browser->window()) |
| 1270 | parent_window = tabbed_browser->window()->GetNativeHandle(); |
| 1271 | } |
| 1272 | #endif // defined(OS_CHROMEOS) |
| 1273 | if (!parent_window) |
| 1274 | parent_window = window_->GetNativeHandle(); |
| 1275 | |
[email protected] | 22c830d | 2011-11-29 20:00:37 | [diff] [blame] | 1276 | return browser::ShowHtmlDialog(parent_window, profile_, delegate, style); |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | void Browser::BrowserRenderWidgetShowing() { |
| 1280 | RenderWidgetShowing(); |
| 1281 | } |
| 1282 | |
[email protected] | c9bd2e8 | 2011-04-15 23:28:19 | [diff] [blame] | 1283 | void Browser::BookmarkBarSizeChanged(bool is_animating) { |
| 1284 | window_->ToolbarSizeChanged(is_animating); |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 1285 | } |
| 1286 | |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1287 | TabContents* Browser::AddRestoredTab( |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1288 | const std::vector<TabNavigation>& navigations, |
| 1289 | int tab_index, |
| 1290 | int selected_navigation, |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 1291 | const std::string& extension_app_id, |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1292 | bool select, |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1293 | bool pin, |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 1294 | bool from_last_session, |
| 1295 | SessionStorageNamespace* session_storage_namespace) { |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 1296 | GURL restore_url = navigations.at(selected_navigation).virtual_url(); |
| 1297 | TabContentsWrapper* wrapper = TabContentsFactory( |
| 1298 | profile(), |
| 1299 | tab_util::GetSiteInstanceForNewTab(NULL, profile_, restore_url), |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1300 | MSG_ROUTING_NONE, |
| 1301 | GetSelectedTabContents(), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1302 | session_storage_namespace); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1303 | TabContents* new_tab = wrapper->tab_contents(); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1304 | wrapper->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
[email protected] | 03838e2 | 2011-06-06 15:27:14 | [diff] [blame] | 1305 | std::vector<NavigationEntry*> entries; |
| 1306 | TabNavigation::CreateNavigationEntriesFromTabNavigations( |
| 1307 | profile_, navigations, &entries); |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 1308 | new_tab->controller().Restore( |
[email protected] | 03838e2 | 2011-06-06 15:27:14 | [diff] [blame] | 1309 | selected_navigation, from_last_session, &entries); |
| 1310 | DCHECK_EQ(0u, entries.size()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1311 | |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1312 | int add_types = select ? TabStripModel::ADD_ACTIVE : |
[email protected] | 981b992e | 2011-03-28 21:05:21 | [diff] [blame] | 1313 | TabStripModel::ADD_NONE; |
| 1314 | if (pin) { |
| 1315 | tab_index = std::min(tab_index, tabstrip_model()->IndexOfFirstNonMiniTab()); |
| 1316 | add_types |= TabStripModel::ADD_PINNED; |
| 1317 | } |
| 1318 | tab_handler_->GetTabStripModel()->InsertTabContentsAt(tab_index, wrapper, |
| 1319 | add_types); |
[email protected] | c93a9dd | 2010-04-22 20:25:18 | [diff] [blame] | 1320 | if (select) { |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 1321 | window_->Activate(); |
[email protected] | c93a9dd | 2010-04-22 20:25:18 | [diff] [blame] | 1322 | } else { |
| 1323 | // We set the size of the view here, before WebKit does its initial |
| 1324 | // layout. If we don't, the initial layout of background tabs will be |
| 1325 | // performed with a view width of 0, which may cause script outputs and |
| 1326 | // anchor link location calculations to be incorrect even after a new |
| 1327 | // layout with proper view dimensions. TabStripModel::AddTabContents() |
| 1328 | // contains similar logic. |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 1329 | new_tab->GetView()->SizeContents(window_->GetRestoredBounds().size()); |
[email protected] | c93a9dd | 2010-04-22 20:25:18 | [diff] [blame] | 1330 | new_tab->HideContents(); |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 1331 | new_tab->controller().LoadIfNecessary(); |
[email protected] | c93a9dd | 2010-04-22 20:25:18 | [diff] [blame] | 1332 | } |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1333 | SessionService* session_service = |
| 1334 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 1335 | if (session_service) |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 1336 | session_service->TabRestored(wrapper, pin); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1337 | return new_tab; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | void Browser::ReplaceRestoredTab( |
| 1341 | const std::vector<TabNavigation>& navigations, |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1342 | int selected_navigation, |
[email protected] | fca656c | 2010-02-10 20:30:10 | [diff] [blame] | 1343 | bool from_last_session, |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 1344 | const std::string& extension_app_id, |
| 1345 | SessionStorageNamespace* session_storage_namespace) { |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 1346 | GURL restore_url = navigations.at(selected_navigation).virtual_url(); |
| 1347 | TabContentsWrapper* wrapper = TabContentsFactory( |
| 1348 | profile(), |
| 1349 | tab_util::GetSiteInstanceForNewTab(NULL, profile_, restore_url), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1350 | MSG_ROUTING_NONE, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1351 | GetSelectedTabContents(), |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 1352 | session_storage_namespace); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1353 | wrapper->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1354 | TabContents* replacement = wrapper->tab_contents(); |
[email protected] | 03838e2 | 2011-06-06 15:27:14 | [diff] [blame] | 1355 | std::vector<NavigationEntry*> entries; |
| 1356 | TabNavigation::CreateNavigationEntriesFromTabNavigations( |
| 1357 | profile_, navigations, &entries); |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 1358 | replacement->controller().Restore( |
[email protected] | 03838e2 | 2011-06-06 15:27:14 | [diff] [blame] | 1359 | selected_navigation, from_last_session, &entries); |
| 1360 | DCHECK_EQ(0u, entries.size()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1361 | |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1362 | tab_handler_->GetTabStripModel()->ReplaceNavigationControllerAt( |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 1363 | tab_handler_->GetTabStripModel()->active_index(), |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1364 | wrapper); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1365 | } |
| 1366 | |
[email protected] | a8eff10 | 2009-04-14 15:23:43 | [diff] [blame] | 1367 | bool Browser::CanRestoreTab() { |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 1368 | return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB); |
[email protected] | a8eff10 | 2009-04-14 15:23:43 | [diff] [blame] | 1369 | } |
| 1370 | |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1371 | bool Browser::NavigateToIndexWithDisposition(int index, |
| 1372 | WindowOpenDisposition disp) { |
| 1373 | NavigationController& controller = |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 1374 | GetOrCloneTabForDisposition(disp)->controller(); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1375 | if (index < 0 || index >= controller.entry_count()) |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1376 | return false; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1377 | controller.GoToIndex(index); |
| 1378 | return true; |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1379 | } |
| 1380 | |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1381 | browser::NavigateParams Browser::GetSingletonTabNavigateParams( |
| 1382 | const GURL& url) { |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1383 | browser::NavigateParams params( |
| 1384 | this, url, content::PAGE_TRANSITION_AUTO_BOOKMARK); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1385 | params.disposition = SINGLETON_TAB; |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 1386 | params.window_action = browser::NavigateParams::SHOW_WINDOW; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 1387 | params.user_gesture = true; |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1388 | return params; |
| 1389 | } |
| 1390 | |
| 1391 | void Browser::ShowSingletonTab(const GURL& url) { |
| 1392 | browser::NavigateParams params(GetSingletonTabNavigateParams(url)); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1393 | browser::Navigate(¶ms); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1394 | } |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 1395 | |
[email protected] | 578c696 | 2011-08-24 22:06:40 | [diff] [blame] | 1396 | void Browser::ShowSingletonTabRespectRef(const GURL& url) { |
| 1397 | browser::NavigateParams params(GetSingletonTabNavigateParams(url)); |
| 1398 | params.ref_behavior = browser::NavigateParams::RESPECT_REF; |
| 1399 | browser::Navigate(¶ms); |
| 1400 | } |
| 1401 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1402 | void Browser::ShowSingletonTabOverwritingNTP( |
| 1403 | const browser::NavigateParams& params) { |
| 1404 | browser::NavigateParams local_params(params); |
| 1405 | TabContents* contents = GetSelectedTabContents(); |
[email protected] | 842a648c | 2011-07-20 23:23:16 | [diff] [blame] | 1406 | if (contents) { |
| 1407 | const GURL& contents_url = contents->GetURL(); |
| 1408 | if ((contents_url == GURL(chrome::kChromeUINewTabURL) || |
| 1409 | contents_url == GURL(chrome::kAboutBlankURL)) && |
| 1410 | browser::GetIndexOfSingletonTab(&local_params) < 0) { |
| 1411 | local_params.disposition = CURRENT_TAB; |
| 1412 | } |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | browser::Navigate(&local_params); |
| 1416 | } |
| 1417 | |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 1418 | void Browser::WindowFullscreenStateChanged() { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1419 | fullscreen_controller_->WindowFullscreenStateChanged(); |
[email protected] | 9adb8b1 | 2011-12-09 06:49:13 | [diff] [blame] | 1420 | UpdateCommandsForFullscreenMode(window_->IsFullscreen()); |
| 1421 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1422 | } |
| 1423 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1424 | /////////////////////////////////////////////////////////////////////////////// |
| 1425 | // Browser, Assorted browser commands: |
| 1426 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1427 | TabContents* Browser::GetOrCloneTabForDisposition( |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1428 | WindowOpenDisposition disposition) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1429 | TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
[email protected] | bbafdc7 | 2011-07-06 22:27:17 | [diff] [blame] | 1430 | switch (disposition) { |
| 1431 | case NEW_FOREGROUND_TAB: |
| 1432 | case NEW_BACKGROUND_TAB: { |
| 1433 | current_tab = current_tab->Clone(); |
| 1434 | tab_handler_->GetTabStripModel()->AddTabContents( |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1435 | current_tab, -1, content::PAGE_TRANSITION_LINK, |
[email protected] | bbafdc7 | 2011-07-06 22:27:17 | [diff] [blame] | 1436 | disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE : |
| 1437 | TabStripModel::ADD_NONE); |
| 1438 | break; |
| 1439 | } |
| 1440 | case NEW_WINDOW: { |
| 1441 | current_tab = current_tab->Clone(); |
| 1442 | Browser* browser = Browser::Create(profile_); |
| 1443 | browser->tabstrip_model()->AddTabContents( |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1444 | current_tab, -1, content::PAGE_TRANSITION_LINK, |
| 1445 | TabStripModel::ADD_ACTIVE); |
[email protected] | bbafdc7 | 2011-07-06 22:27:17 | [diff] [blame] | 1446 | browser->window()->Show(); |
| 1447 | break; |
| 1448 | } |
| 1449 | default: |
| 1450 | break; |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1451 | } |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1452 | return current_tab->tab_contents(); |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1453 | } |
| 1454 | |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1455 | bool Browser::SupportsWindowFeatureImpl(WindowFeature feature, |
| 1456 | bool check_fullscreen) const { |
| 1457 | // On Mac, fullscreen mode has most normal things (in a slide-down panel). On |
| 1458 | // other platforms, we hide some controls when in fullscreen mode. |
| 1459 | bool hide_ui_for_fullscreen = false; |
| 1460 | #if !defined(OS_MACOSX) |
| 1461 | hide_ui_for_fullscreen = check_fullscreen && window_ && |
| 1462 | window_->IsFullscreen(); |
| 1463 | #endif |
| 1464 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 1465 | unsigned int features = FEATURE_INFOBAR | FEATURE_SIDEBAR; |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1466 | |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 1467 | #if !defined(OS_CHROMEOS) || defined(USE_AURA) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1468 | // Chrome OS opens a FileBrowse pop up instead of using download shelf. |
| 1469 | // So FEATURE_DOWNLOADSHELF is only added for non-chromeos platforms. |
| 1470 | features |= FEATURE_DOWNLOADSHELF; |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 1471 | #endif // !defined(OS_CHROMEOS) || defined(USE_AURA) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1472 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1473 | if (is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1474 | features |= FEATURE_BOOKMARKBAR; |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1475 | |
| 1476 | if (!hide_ui_for_fullscreen) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1477 | if (!is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1478 | features |= FEATURE_TITLEBAR; |
| 1479 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1480 | if (is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1481 | features |= FEATURE_TABSTRIP; |
| 1482 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1483 | if (is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1484 | features |= FEATURE_TOOLBAR; |
| 1485 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1486 | if (!is_app()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1487 | features |= FEATURE_LOCATIONBAR; |
| 1488 | } |
| 1489 | return !!(features & feature); |
| 1490 | } |
| 1491 | |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 1492 | bool Browser::IsClosingPermitted() { |
| 1493 | TabCloseableStateWatcher* watcher = |
| 1494 | g_browser_process->tab_closeable_state_watcher(); |
| 1495 | bool can_close = !watcher || watcher->CanCloseBrowser(this); |
| 1496 | if (!can_close && is_attempting_to_close_browser_) |
| 1497 | CancelWindowClose(); |
| 1498 | return can_close; |
| 1499 | } |
| 1500 | |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1501 | bool Browser::CanGoBack() const { |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 1502 | return GetSelectedTabContentsWrapper()-> |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 1503 | tab_contents()->controller().CanGoBack(); |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1504 | } |
| 1505 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1506 | void Browser::GoBack(WindowOpenDisposition disposition) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1507 | content::RecordAction(UserMetricsAction("Back")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1508 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1509 | TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1510 | if (CanGoBack()) { |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1511 | TabContents* new_tab = GetOrCloneTabForDisposition(disposition); |
[email protected] | d497b078 | 2010-03-29 19:19:06 | [diff] [blame] | 1512 | // If we are on an interstitial page and clone the tab, it won't be copied |
| 1513 | // to the new tab, so we don't need to go back. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1514 | if (current_tab->tab_contents()->showing_interstitial_page() && |
| 1515 | (new_tab != current_tab->tab_contents())) |
[email protected] | d497b078 | 2010-03-29 19:19:06 | [diff] [blame] | 1516 | return; |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 1517 | new_tab->controller().GoBack(); |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1518 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1519 | } |
| 1520 | |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1521 | bool Browser::CanGoForward() const { |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 1522 | return GetSelectedTabContentsWrapper()-> |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 1523 | tab_contents()->controller().CanGoForward(); |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1524 | } |
| 1525 | |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1526 | void Browser::GoForward(WindowOpenDisposition disposition) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1527 | content::RecordAction(UserMetricsAction("Forward")); |
[email protected] | 43c9dc72 | 2011-08-20 02:05:09 | [diff] [blame] | 1528 | if (CanGoForward()) |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 1529 | GetOrCloneTabForDisposition(disposition)->controller().GoForward(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1530 | } |
| 1531 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1532 | void Browser::Reload(WindowOpenDisposition disposition) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1533 | content::RecordAction(UserMetricsAction("Reload")); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1534 | ReloadInternal(disposition, false); |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 1535 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1536 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1537 | void Browser::ReloadIgnoringCache(WindowOpenDisposition disposition) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1538 | content::RecordAction(UserMetricsAction("ReloadIgnoringCache")); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1539 | ReloadInternal(disposition, true); |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 1540 | } |
| 1541 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1542 | void Browser::ReloadInternal(WindowOpenDisposition disposition, |
| 1543 | bool ignore_cache) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1544 | // If we are showing an interstitial, treat this as an OpenURL. |
| 1545 | TabContents* current_tab = GetSelectedTabContents(); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1546 | if (current_tab && current_tab->showing_interstitial_page()) { |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 1547 | NavigationEntry* entry = current_tab->controller().GetActiveEntry(); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1548 | DCHECK(entry); // Should exist if interstitial is showing. |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1549 | OpenURL(entry->url(), GURL(), disposition, content::PAGE_TRANSITION_RELOAD); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1550 | return; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1551 | } |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1552 | |
| 1553 | // As this is caused by a user action, give the focus to the page. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1554 | TabContents* tab = GetOrCloneTabForDisposition(disposition); |
| 1555 | if (!tab->FocusLocationBarByDefault()) |
| 1556 | tab->Focus(); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1557 | if (ignore_cache) |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 1558 | tab->controller().ReloadIgnoringCache(true); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1559 | else |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 1560 | tab->controller().Reload(true); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1561 | } |
| 1562 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1563 | void Browser::Home(WindowOpenDisposition disposition) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1564 | content::RecordAction(UserMetricsAction("Home")); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1565 | OpenURL( |
[email protected] | 671f9c6 | 2011-10-28 19:22:07 | [diff] [blame] | 1566 | profile_->GetHomePage(), GURL(), disposition, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1567 | content::PageTransitionFromInt( |
| 1568 | content::PAGE_TRANSITION_AUTO_BOOKMARK | |
| 1569 | content::PAGE_TRANSITION_HOME_PAGE)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1570 | } |
| 1571 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1572 | void Browser::OpenCurrentURL() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1573 | content::RecordAction(UserMetricsAction("LoadURL")); |
[email protected] | 7745b82 | 2009-01-27 20:15:35 | [diff] [blame] | 1574 | LocationBar* location_bar = window_->GetLocationBar(); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 1575 | if (!location_bar) |
| 1576 | return; |
| 1577 | |
[email protected] | 9d0306ea | 2009-09-02 19:38:39 | [diff] [blame] | 1578 | WindowOpenDisposition open_disposition = |
| 1579 | location_bar->GetWindowOpenDisposition(); |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 1580 | if (OpenInstant(open_disposition)) |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 1581 | return; |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 1582 | |
[email protected] | 537de68 | 2011-08-08 18:10:14 | [diff] [blame] | 1583 | GURL url(location_bar->GetInputString()); |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 1584 | |
| 1585 | if (open_disposition == CURRENT_TAB && TabFinder::IsEnabled()) { |
| 1586 | Browser* existing_browser = NULL; |
| 1587 | TabContents* existing_tab = TabFinder::GetInstance()->FindTab( |
| 1588 | this, url, &existing_browser); |
| 1589 | if (existing_tab) { |
| 1590 | existing_browser->ActivateContents(existing_tab); |
| 1591 | return; |
| 1592 | } |
| 1593 | } |
| 1594 | |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1595 | browser::NavigateParams params(this, url, location_bar->GetPageTransition()); |
| 1596 | params.disposition = open_disposition; |
[email protected] | 514576a | 2010-07-01 22:51:25 | [diff] [blame] | 1597 | // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least |
| 1598 | // inherit the opener. In some cases the tabstrip will determine the group |
| 1599 | // should be inherited, in which case the group is inherited instead of the |
| 1600 | // opener. |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1601 | params.tabstrip_add_types = |
| 1602 | TabStripModel::ADD_FORCE_INDEX | TabStripModel::ADD_INHERIT_OPENER; |
| 1603 | browser::Navigate(¶ms); |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 1604 | |
[email protected] | 6e37fe3 | 2011-03-02 09:06:52 | [diff] [blame] | 1605 | DCHECK(profile_->GetExtensionService()); |
| 1606 | if (profile_->GetExtensionService()->IsInstalledApp(url)) { |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 1607 | UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, |
| 1608 | extension_misc::APP_LAUNCH_OMNIBOX_LOCATION, |
| 1609 | extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 1610 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1611 | } |
| 1612 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1613 | void Browser::Stop() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1614 | content::RecordAction(UserMetricsAction("Stop")); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1615 | GetSelectedTabContentsWrapper()->tab_contents()->Stop(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | void Browser::NewWindow() { |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 1619 | IncognitoModePrefs::Availability incognito_avail = |
| 1620 | IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
[email protected] | 047e727 | 2010-06-03 19:53:35 | [diff] [blame] | 1621 | if (browser_defaults::kAlwaysOpenIncognitoWindow && |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 1622 | incognito_avail != IncognitoModePrefs::DISABLED && |
[email protected] | 6b0dd2ab | 2011-07-26 02:31:08 | [diff] [blame] | 1623 | (CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) || |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 1624 | incognito_avail == IncognitoModePrefs::FORCED)) { |
[email protected] | 047e727 | 2010-06-03 19:53:35 | [diff] [blame] | 1625 | NewIncognitoWindow(); |
| 1626 | return; |
| 1627 | } |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1628 | content::RecordAction(UserMetricsAction("NewWindow")); |
[email protected] | c9b1994 | 2010-03-26 15:58:08 | [diff] [blame] | 1629 | SessionService* session_service = |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1630 | SessionServiceFactory::GetForProfile(profile_->GetOriginalProfile()); |
[email protected] | c9b1994 | 2010-03-26 15:58:08 | [diff] [blame] | 1631 | if (!session_service || |
| 1632 | !session_service->RestoreIfNecessary(std::vector<GURL>())) { |
| 1633 | Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); |
| 1634 | } |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | void Browser::NewIncognitoWindow() { |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 1638 | if (IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) == |
| 1639 | IncognitoModePrefs::DISABLED) { |
[email protected] | 6e6f6cb | 2011-01-27 13:26:55 | [diff] [blame] | 1640 | NewWindow(); |
| 1641 | return; |
| 1642 | } |
| 1643 | |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1644 | content::RecordAction(UserMetricsAction("NewIncognitoWindow")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1645 | Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); |
| 1646 | } |
| 1647 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1648 | void Browser::CloseWindow() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1649 | content::RecordAction(UserMetricsAction("CloseWindow")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1650 | window_->Close(); |
| 1651 | } |
| 1652 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1653 | void Browser::NewTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1654 | content::RecordAction(UserMetricsAction("NewTab")); |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 1655 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1656 | if (is_type_tabbed()) { |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1657 | AddBlankTab(true); |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 1658 | GetSelectedTabContentsWrapper()->tab_contents()->GetView()->RestoreFocus(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1659 | } else { |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 1660 | Browser* b = GetOrCreateTabbedBrowser(profile_); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1661 | b->AddBlankTab(true); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1662 | b->window()->Show(); |
[email protected] | e54f30d | 2009-01-14 21:17:11 | [diff] [blame] | 1663 | // The call to AddBlankTab above did not set the focus to the tab as its |
| 1664 | // window was not active, so we have to do it explicitly. |
| 1665 | // See http://crbug.com/6380. |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 1666 | b->GetSelectedTabContentsWrapper()->tab_contents()->GetView()->RestoreFocus(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | void Browser::CloseTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1671 | content::RecordAction(UserMetricsAction("CloseTab_Accelerator")); |
[email protected] | 90b1a7a | 2011-03-17 21:28:21 | [diff] [blame] | 1672 | if (CanCloseTab()) |
| 1673 | tab_handler_->GetTabStripModel()->CloseSelectedTabs(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1674 | } |
| 1675 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1676 | void Browser::SelectNextTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1677 | content::RecordAction(UserMetricsAction("SelectNextTab")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1678 | tab_handler_->GetTabStripModel()->SelectNextTab(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | void Browser::SelectPreviousTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1682 | content::RecordAction(UserMetricsAction("SelectPrevTab")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1683 | tab_handler_->GetTabStripModel()->SelectPreviousTab(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1684 | } |
| 1685 | |
[email protected] | 91ac920 | 2010-07-30 18:32:35 | [diff] [blame] | 1686 | void Browser::OpenTabpose() { |
| 1687 | #if defined(OS_MACOSX) |
[email protected] | aac169d | 2011-03-18 19:53:03 | [diff] [blame] | 1688 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 1689 | switches::kEnableExposeForTabs)) { |
| 1690 | return; |
| 1691 | } |
| 1692 | |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1693 | content::RecordAction(UserMetricsAction("OpenTabpose")); |
[email protected] | 91ac920 | 2010-07-30 18:32:35 | [diff] [blame] | 1694 | window()->OpenTabpose(); |
| 1695 | #else |
| 1696 | NOTREACHED(); |
| 1697 | #endif |
| 1698 | } |
| 1699 | |
[email protected] | 9ac7fcb | 2009-09-14 18:22:52 | [diff] [blame] | 1700 | void Browser::MoveTabNext() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1701 | content::RecordAction(UserMetricsAction("MoveTabNext")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1702 | tab_handler_->GetTabStripModel()->MoveTabNext(); |
[email protected] | 9ac7fcb | 2009-09-14 18:22:52 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | void Browser::MoveTabPrevious() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1706 | content::RecordAction(UserMetricsAction("MoveTabPrevious")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1707 | tab_handler_->GetTabStripModel()->MoveTabPrevious(); |
[email protected] | 9ac7fcb | 2009-09-14 18:22:52 | [diff] [blame] | 1708 | } |
| 1709 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1710 | void Browser::SelectNumberedTab(int index) { |
| 1711 | if (index < tab_count()) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1712 | content::RecordAction(UserMetricsAction("SelectNumberedTab")); |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1713 | tab_handler_->GetTabStripModel()->ActivateTabAt(index, true); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | void Browser::SelectLastTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1718 | content::RecordAction(UserMetricsAction("SelectLastTab")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1719 | tab_handler_->GetTabStripModel()->SelectLastTab(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | void Browser::DuplicateTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1723 | content::RecordAction(UserMetricsAction("Duplicate")); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 1724 | DuplicateContentsAt(active_index()); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | void Browser::RestoreTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1728 | content::RecordAction(UserMetricsAction("RestoreTab")); |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1729 | TabRestoreService* service = |
| 1730 | TabRestoreServiceFactory::GetForProfile(profile_); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1731 | if (!service) |
| 1732 | return; |
| 1733 | |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 1734 | service->RestoreMostRecentEntry(tab_restore_service_delegate()); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1735 | } |
| 1736 | |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1737 | void Browser::WriteCurrentURLToClipboard() { |
| 1738 | // TODO(ericu): There isn't currently a metric for this. Should there be? |
| 1739 | // We don't appear to track the action when it comes from the |
| 1740 | // RenderContextViewMenu. |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1741 | |
| 1742 | TabContents* contents = GetSelectedTabContents(); |
[email protected] | cd8d90db | 2011-10-06 19:31:27 | [diff] [blame] | 1743 | if (!toolbar_model_.ShouldDisplayURL()) |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1744 | return; |
| 1745 | |
[email protected] | 90f3990 | 2009-10-03 04:25:37 | [diff] [blame] | 1746 | chrome_browser_net::WriteURLToClipboard( |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1747 | contents->GetURL(), |
[email protected] | 9f284f13 | 2010-08-31 06:14:17 | [diff] [blame] | 1748 | profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1749 | g_browser_process->clipboard()); |
| 1750 | } |
| 1751 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1752 | void Browser::ConvertPopupToTabbedBrowser() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1753 | content::RecordAction(UserMetricsAction("ShowAsTab")); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 1754 | int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1755 | TabContentsWrapper* contents = |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1756 | tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1757 | Browser* browser = Browser::Create(profile_); |
| 1758 | browser->tabstrip_model()->AppendTabContents(contents, true); |
| 1759 | browser->window()->Show(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1760 | } |
| 1761 | |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 1762 | // TODO(koz): Change |for_tab| to an enum. |
| 1763 | void Browser::ToggleFullscreenMode(bool for_tab) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1764 | fullscreen_controller_->ToggleFullscreenMode(for_tab); |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 1765 | } |
| 1766 | |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 1767 | #if defined(OS_MACOSX) |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 1768 | void Browser::TogglePresentationMode(bool for_tab) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1769 | fullscreen_controller_->TogglePresentationMode(for_tab); |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 1770 | } |
| 1771 | #endif |
| 1772 | |
[email protected] | da17b37 | 2010-01-22 23:37:22 | [diff] [blame] | 1773 | #if defined(OS_CHROMEOS) |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 1774 | void Browser::Search() { |
[email protected] | 6455986 | 2010-09-23 19:00:16 | [diff] [blame] | 1775 | // Exit fullscreen to show omnibox. |
[email protected] | ebdda909 | 2010-10-22 17:59:10 | [diff] [blame] | 1776 | if (window_->IsFullscreen()) { |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 1777 | ToggleFullscreenMode(false); |
[email protected] | ebdda909 | 2010-10-22 17:59:10 | [diff] [blame] | 1778 | // ToggleFullscreenMode is asynchronous, so we don't have omnibox |
| 1779 | // visible at this point. Wait for next event cycle which toggles |
| 1780 | // the visibility of omnibox before creating new tab. |
| 1781 | MessageLoop::current()->PostTask( |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1782 | FROM_HERE, base::Bind(&Browser::Search, weak_factory_.GetWeakPtr())); |
[email protected] | ebdda909 | 2010-10-22 17:59:10 | [diff] [blame] | 1783 | return; |
| 1784 | } |
[email protected] | 6455986 | 2010-09-23 19:00:16 | [diff] [blame] | 1785 | |
[email protected] | 0080c4f | 2011-10-03 21:56:37 | [diff] [blame] | 1786 | const GURL& url = GetSelectedTabContents()->GetURL(); |
| 1787 | if (url.SchemeIs(chrome::kChromeUIScheme) && |
| 1788 | url.host() == chrome::kChromeUINewTabHost) { |
| 1789 | // If the NTP is showing, focus the omnibox. |
| 1790 | window_->SetFocusToLocationBar(true); |
| 1791 | } else { |
| 1792 | // Otherwise, open the NTP. |
| 1793 | NewTab(); |
| 1794 | } |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 1795 | } |
[email protected] | d14af52 | 2010-12-02 03:54:50 | [diff] [blame] | 1796 | |
| 1797 | void Browser::ShowKeyboardOverlay() { |
| 1798 | window_->ShowKeyboardOverlay(window_->GetNativeHandle()); |
| 1799 | } |
[email protected] | 20d1724 | 2009-10-26 20:21:05 | [diff] [blame] | 1800 | #endif |
| 1801 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1802 | void Browser::Exit() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1803 | content::RecordAction(UserMetricsAction("Exit")); |
[email protected] | b8b6008 | 2011-12-13 14:16:02 | [diff] [blame] | 1804 | BrowserList::AttemptUserExit(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1805 | } |
| 1806 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1807 | void Browser::BookmarkCurrentPage() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1808 | content::RecordAction(UserMetricsAction("Star")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1809 | |
[email protected] | 76624fde | 2009-10-09 18:13:23 | [diff] [blame] | 1810 | BookmarkModel* model = profile()->GetBookmarkModel(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1811 | if (!model || !model->IsLoaded()) |
| 1812 | return; // Ignore requests until bookmarks are loaded. |
| 1813 | |
[email protected] | 76624fde | 2009-10-09 18:13:23 | [diff] [blame] | 1814 | GURL url; |
[email protected] | 261cd76 | 2010-08-20 05:45:37 | [diff] [blame] | 1815 | string16 title; |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1816 | TabContentsWrapper* tab = GetSelectedTabContentsWrapper(); |
| 1817 | bookmark_utils::GetURLAndTitleToBookmark(tab->tab_contents(), &url, &title); |
[email protected] | c50d0d4 | 2009-03-03 17:37:44 | [diff] [blame] | 1818 | bool was_bookmarked = model->IsBookmarked(url); |
[email protected] | ef0d04c | 2010-12-15 23:34:21 | [diff] [blame] | 1819 | if (!was_bookmarked && profile_->IsOffTheRecord()) { |
[email protected] | 2c910b7 | 2011-03-08 21:16:32 | [diff] [blame] | 1820 | // 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] | 1821 | // so that bookmarks have an icon for the page. |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1822 | tab->favicon_tab_helper()->SaveFavicon(); |
[email protected] | ef0d04c | 2010-12-15 23:34:21 | [diff] [blame] | 1823 | } |
[email protected] | 4394f2b | 2011-09-03 03:07:56 | [diff] [blame] | 1824 | bookmark_utils::AddIfNotBookmarked(model, url, title); |
[email protected] | 11dbbd2 | 2009-11-06 18:55:04 | [diff] [blame] | 1825 | // Make sure the model actually added a bookmark before showing the star. A |
| 1826 | // bookmark isn't created if the url is invalid. |
| 1827 | if (window_->IsActive() && model->IsBookmarked(url)) { |
[email protected] | 5f2731c5 | 2009-02-28 00:41:27 | [diff] [blame] | 1828 | // Only show the bubble if the window is active, otherwise we may get into |
| 1829 | // weird situations were the bubble is deleted as soon as it is shown. |
[email protected] | c50d0d4 | 2009-03-03 17:37:44 | [diff] [blame] | 1830 | window_->ShowBookmarkBubble(url, was_bookmarked); |
[email protected] | 5f2731c5 | 2009-02-28 00:41:27 | [diff] [blame] | 1831 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1832 | } |
| 1833 | |
[email protected] | 40bdb6d9 | 2009-02-25 00:22:27 | [diff] [blame] | 1834 | void Browser::SavePage() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1835 | content::RecordAction(UserMetricsAction("SavePage")); |
[email protected] | 15d04ae | 2010-10-30 01:04:50 | [diff] [blame] | 1836 | TabContents* current_tab = GetSelectedTabContents(); |
| 1837 | if (current_tab && current_tab->contents_mime_type() == "application/pdf") |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1838 | content::RecordAction(UserMetricsAction("PDF.SavePage")); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 1839 | GetSelectedTabContents()->OnSavePage(); |
[email protected] | 40bdb6d9 | 2009-02-25 00:22:27 | [diff] [blame] | 1840 | } |
| 1841 | |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 1842 | void Browser::ViewSelectedSource() { |
| 1843 | ViewSource(GetSelectedTabContentsWrapper()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1844 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1845 | |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1846 | void Browser::ShowFindBar() { |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 1847 | GetFindBarController()->Show(); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1848 | } |
| 1849 | |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 1850 | bool Browser::SupportsWindowFeature(WindowFeature feature) const { |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1851 | return SupportsWindowFeatureImpl(feature, true); |
| 1852 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1853 | |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1854 | bool Browser::CanSupportWindowFeature(WindowFeature feature) const { |
| 1855 | return SupportsWindowFeatureImpl(feature, false); |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 1856 | } |
| 1857 | |
[email protected] | 89d6e6e | 2009-12-03 23:06:51 | [diff] [blame] | 1858 | void Browser::EmailPageLocation() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1859 | content::RecordAction(UserMetricsAction("EmailPageLocation")); |
[email protected] | d221a39 | 2011-05-24 14:34:24 | [diff] [blame] | 1860 | TabContents* tc = GetSelectedTabContents(); |
| 1861 | DCHECK(tc); |
| 1862 | |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 1863 | std::string title = net::EscapeQueryParamValue( |
| 1864 | UTF16ToUTF8(tc->GetTitle()), false); |
| 1865 | std::string page_url = net::EscapeQueryParamValue(tc->GetURL().spec(), false); |
[email protected] | d221a39 | 2011-05-24 14:34:24 | [diff] [blame] | 1866 | std::string mailto = std::string("mailto:?subject=Fwd:%20") + |
| 1867 | title + "&body=%0A%0A" + page_url; |
| 1868 | platform_util::OpenExternal(GURL(mailto)); |
[email protected] | 89d6e6e | 2009-12-03 23:06:51 | [diff] [blame] | 1869 | } |
| 1870 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1871 | void Browser::Print() { |
[email protected] | 8980e0d | 2011-05-27 19:16:23 | [diff] [blame] | 1872 | if (switches::IsPrintPreviewEnabled()) |
| 1873 | GetSelectedTabContentsWrapper()->print_view_manager()->PrintPreviewNow(); |
| 1874 | else |
[email protected] | 49fe226 | 2011-04-15 20:56:15 | [diff] [blame] | 1875 | GetSelectedTabContentsWrapper()->print_view_manager()->PrintNow(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1876 | } |
| 1877 | |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 1878 | void Browser::AdvancedPrint() { |
| 1879 | GetSelectedTabContentsWrapper()->print_view_manager()->AdvancedPrintNow(); |
| 1880 | } |
| 1881 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1882 | void Browser::ToggleEncodingAutoDetect() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1883 | content::RecordAction(UserMetricsAction("AutoDetectChange")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1884 | encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 1885 | // If "auto detect" is turned on, then any current override encoding |
| 1886 | // is cleared. This also implicitly performs a reload. |
| 1887 | // OTOH, if "auto detect" is turned off, we don't change the currently |
| 1888 | // active encoding. |
| 1889 | if (encoding_auto_detect_.GetValue()) { |
| 1890 | TabContents* contents = GetSelectedTabContents(); |
| 1891 | if (contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 1892 | contents->ResetOverrideEncoding(); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 1893 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | void Browser::OverrideEncoding(int encoding_id) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1897 | content::RecordAction(UserMetricsAction("OverrideEncoding")); |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1898 | const std::string selected_encoding = |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1899 | CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1900 | TabContents* contents = GetSelectedTabContents(); |
| 1901 | if (!selected_encoding.empty() && contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 1902 | contents->SetOverrideEncoding(selected_encoding); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1903 | // Update the list of recently selected encodings. |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1904 | std::string new_selected_encoding_list; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 1905 | if (CharacterEncoding::UpdateRecentlySelectedEncoding( |
| 1906 | profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding), |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1907 | encoding_id, |
| 1908 | &new_selected_encoding_list)) { |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1909 | profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 1910 | new_selected_encoding_list); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1911 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1912 | } |
| 1913 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1914 | void Browser::Cut() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1915 | content::RecordAction(UserMetricsAction("Cut")); |
[email protected] | 20012dd4 | 2010-01-25 04:46:23 | [diff] [blame] | 1916 | window()->Cut(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1917 | } |
| 1918 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1919 | void Browser::Copy() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1920 | content::RecordAction(UserMetricsAction("Copy")); |
[email protected] | 20012dd4 | 2010-01-25 04:46:23 | [diff] [blame] | 1921 | window()->Copy(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1922 | } |
| 1923 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1924 | void Browser::Paste() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1925 | content::RecordAction(UserMetricsAction("Paste")); |
[email protected] | 20012dd4 | 2010-01-25 04:46:23 | [diff] [blame] | 1926 | window()->Paste(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | void Browser::Find() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1930 | content::RecordAction(UserMetricsAction("Find")); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1931 | FindInPage(false, false); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | void Browser::FindNext() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1935 | content::RecordAction(UserMetricsAction("FindNext")); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1936 | FindInPage(true, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | void Browser::FindPrevious() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1940 | content::RecordAction(UserMetricsAction("FindPrevious")); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1941 | FindInPage(true, false); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1942 | } |
| 1943 | |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 1944 | void Browser::Zoom(content::PageZoom zoom) { |
[email protected] | 0bffaa32 | 2011-07-18 17:37:54 | [diff] [blame] | 1945 | if (is_devtools()) |
| 1946 | return; |
| 1947 | |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 1948 | RenderViewHost* host = |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1949 | GetSelectedTabContentsWrapper()->tab_contents()->GetRenderViewHost(); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1950 | if (zoom == content::PAGE_ZOOM_RESET) { |
| 1951 | host->SetZoomLevel(0); |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1952 | content::RecordAction(UserMetricsAction("ZoomNormal")); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1953 | return; |
| 1954 | } |
[email protected] | 89622004 | 2010-03-23 18:14:28 | [diff] [blame] | 1955 | |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1956 | double current_zoom_level = GetSelectedTabContents()->GetZoomLevel(); |
| 1957 | double default_zoom_level = |
| 1958 | profile_->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); |
| 1959 | |
| 1960 | // Generate a vector of zoom levels from an array of known presets along with |
| 1961 | // the default level added if necessary. |
| 1962 | std::vector<double> zoom_levels = |
| 1963 | chrome_page_zoom::PresetZoomLevels(default_zoom_level); |
| 1964 | |
| 1965 | if (zoom == content::PAGE_ZOOM_OUT) { |
| 1966 | // Iterate through the zoom levels in reverse order to find the next |
| 1967 | // lower level based on the current zoom level for this page. |
| 1968 | for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); |
| 1969 | i != zoom_levels.rend(); ++i) { |
| 1970 | double zoom_level = *i; |
| 1971 | if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
| 1972 | continue; |
| 1973 | if (zoom_level < current_zoom_level) { |
| 1974 | host->SetZoomLevel(zoom_level); |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1975 | content::RecordAction(UserMetricsAction("ZoomMinus")); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1976 | return; |
| 1977 | } |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1978 | content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1979 | } |
| 1980 | } else { |
| 1981 | // Iterate through the zoom levels in normal order to find the next |
| 1982 | // higher level based on the current zoom level for this page. |
| 1983 | for (std::vector<double>::const_iterator i = zoom_levels.begin(); |
| 1984 | i != zoom_levels.end(); ++i) { |
| 1985 | double zoom_level = *i; |
| 1986 | if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
| 1987 | continue; |
| 1988 | if (zoom_level > current_zoom_level) { |
| 1989 | host->SetZoomLevel(zoom_level); |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1990 | content::RecordAction(UserMetricsAction("ZoomPlus")); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1991 | return; |
| 1992 | } |
| 1993 | } |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1994 | content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1995 | } |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | void Browser::FocusToolbar() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1999 | content::RecordAction(UserMetricsAction("FocusToolbar")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2000 | window_->FocusToolbar(); |
| 2001 | } |
| 2002 | |
[email protected] | bdb7ff6 | 2010-07-20 01:56:52 | [diff] [blame] | 2003 | void Browser::FocusAppMenu() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2004 | content::RecordAction(UserMetricsAction("FocusAppMenu")); |
[email protected] | bdb7ff6 | 2010-07-20 01:56:52 | [diff] [blame] | 2005 | window_->FocusAppMenu(); |
[email protected] | cc82437 | 2010-03-31 15:33:01 | [diff] [blame] | 2006 | } |
| 2007 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2008 | void Browser::FocusLocationBar() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2009 | content::RecordAction(UserMetricsAction("FocusLocation")); |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 2010 | window_->SetFocusToLocationBar(true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2011 | } |
| 2012 | |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2013 | void Browser::FocusBookmarksToolbar() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2014 | content::RecordAction(UserMetricsAction("FocusBookmarksToolbar")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2015 | window_->FocusBookmarksToolbar(); |
| 2016 | } |
| 2017 | |
| 2018 | void Browser::FocusChromeOSStatus() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2019 | content::RecordAction(UserMetricsAction("FocusChromeOSStatus")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2020 | window_->FocusChromeOSStatus(); |
| 2021 | } |
| 2022 | |
| 2023 | void Browser::FocusNextPane() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2024 | content::RecordAction(UserMetricsAction("FocusNextPane")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2025 | window_->RotatePaneFocus(true); |
| 2026 | } |
| 2027 | |
| 2028 | void Browser::FocusPreviousPane() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2029 | content::RecordAction(UserMetricsAction("FocusPreviousPane")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2030 | window_->RotatePaneFocus(false); |
| 2031 | } |
| 2032 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2033 | void Browser::FocusSearch() { |
| 2034 | // TODO(beng): replace this with FocusLocationBar |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2035 | content::RecordAction(UserMetricsAction("FocusSearch")); |
[email protected] | 7745b82 | 2009-01-27 20:15:35 | [diff] [blame] | 2036 | window_->GetLocationBar()->FocusSearch(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | void Browser::OpenFile() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2040 | content::RecordAction(UserMetricsAction("OpenFile")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2041 | if (!select_file_dialog_.get()) |
| 2042 | select_file_dialog_ = SelectFileDialog::Create(this); |
| 2043 | |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 2044 | const FilePath directory = profile_->last_selected_directory(); |
| 2045 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2046 | // TODO(beng): figure out how to juggle this. |
[email protected] | d56bcd2 | 2009-03-16 19:51:56 | [diff] [blame] | 2047 | gfx::NativeWindow parent_window = window_->GetNativeHandle(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2048 | select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 2049 | string16(), directory, |
[email protected] | b949f111 | 2009-04-12 20:03:08 | [diff] [blame] | 2050 | NULL, 0, FILE_PATH_LITERAL(""), |
[email protected] | d989891 | 2011-04-15 21:10:00 | [diff] [blame] | 2051 | GetSelectedTabContents(), |
[email protected] | d56bcd2 | 2009-03-16 19:51:56 | [diff] [blame] | 2052 | parent_window, NULL); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | void Browser::OpenCreateShortcutsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2056 | content::RecordAction(UserMetricsAction("CreateShortcut")); |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 2057 | #if !defined(OS_MACOSX) |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2058 | TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
| 2059 | DCHECK(current_tab && |
| 2060 | web_app::IsValidUrl(current_tab->tab_contents()->GetURL())) << |
| 2061 | "Menu item should be disabled."; |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 2062 | |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 2063 | NavigationEntry* entry = |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 2064 | current_tab->tab_contents()->controller().GetLastCommittedEntry(); |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 2065 | if (!entry) |
| 2066 | return; |
| 2067 | |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 2068 | // RVH's GetApplicationInfo should not be called before it returns. |
| 2069 | DCHECK(pending_web_app_action_ == NONE); |
| 2070 | pending_web_app_action_ = CREATE_SHORTCUT; |
| 2071 | |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 2072 | // Start fetching web app info for CreateApplicationShortcut dialog and show |
| 2073 | // the dialog when the data is available in OnDidGetApplicationInfo. |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 2074 | current_tab->extension_tab_helper()->GetApplicationInfo(entry->page_id()); |
[email protected] | 98f6e02 | 2009-06-05 22:49:53 | [diff] [blame] | 2075 | #else |
| 2076 | NOTIMPLEMENTED(); |
| 2077 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2078 | } |
| 2079 | |
[email protected] | 2a8a9812 | 2010-07-16 11:58:48 | [diff] [blame] | 2080 | void Browser::ToggleDevToolsWindow(DevToolsToggleAction action) { |
[email protected] | e3791ce9 | 2011-08-09 01:03:32 | [diff] [blame] | 2081 | if (action == DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE) |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2082 | content::RecordAction(UserMetricsAction("DevTools_ToggleConsole")); |
[email protected] | e3791ce9 | 2011-08-09 01:03:32 | [diff] [blame] | 2083 | else |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2084 | content::RecordAction(UserMetricsAction("DevTools_ToggleWindow")); |
[email protected] | e3791ce9 | 2011-08-09 01:03:32 | [diff] [blame] | 2085 | |
[email protected] | aebdd07 | 2011-07-07 12:36:59 | [diff] [blame] | 2086 | DevToolsWindow::ToggleDevToolsWindow( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2087 | GetSelectedTabContentsWrapper()->tab_contents()->GetRenderViewHost(), |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 2088 | action); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2089 | } |
| 2090 | |
[email protected] | adb6a84d | 2011-02-07 16:58:40 | [diff] [blame] | 2091 | void Browser::OpenTaskManager(bool highlight_background_resources) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2092 | content::RecordAction(UserMetricsAction("TaskManager")); |
[email protected] | adb6a84d | 2011-02-07 16:58:40 | [diff] [blame] | 2093 | if (highlight_background_resources) |
| 2094 | window_->ShowBackgroundPages(); |
| 2095 | else |
| 2096 | window_->ShowTaskManager(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2097 | } |
| 2098 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2099 | void Browser::OpenBugReportDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2100 | content::RecordAction(UserMetricsAction("ReportBug")); |
[email protected] | 4091663 | 2011-07-02 01:11:01 | [diff] [blame] | 2101 | browser::ShowHtmlBugReportView(this, std::string(), 0); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2102 | } |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 2103 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2104 | void Browser::ToggleBookmarkBar() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2105 | content::RecordAction(UserMetricsAction("ShowBookmarksBar")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2106 | window_->ToggleBookmarkBar(); |
| 2107 | } |
| 2108 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2109 | void Browser::OpenBookmarkManager() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2110 | content::RecordAction(UserMetricsAction("ShowBookmarkManager")); |
| 2111 | content::RecordAction(UserMetricsAction("ShowBookmarks")); |
[email protected] | 0af8f13 | 2011-07-16 01:37:02 | [diff] [blame] | 2112 | ShowSingletonTabOverwritingNTP( |
[email protected] | a179fac7 | 2011-08-29 22:22:42 | [diff] [blame] | 2113 | GetSingletonTabNavigateParams(GURL(chrome::kChromeUIBookmarksURL))); |
[email protected] | 0af8f13 | 2011-07-16 01:37:02 | [diff] [blame] | 2114 | } |
| 2115 | |
[email protected] | 4c9ee22 | 2011-08-17 19:51:35 | [diff] [blame] | 2116 | void Browser::OpenBookmarkManagerWithHash(const std::string& action, |
| 2117 | int64 node_id) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2118 | content::RecordAction(UserMetricsAction("ShowBookmarkManager")); |
| 2119 | content::RecordAction(UserMetricsAction("ShowBookmarks")); |
[email protected] | f6c1336 | 2011-08-16 12:39:52 | [diff] [blame] | 2120 | browser::NavigateParams params(GetSingletonTabNavigateParams( |
| 2121 | GURL(chrome::kChromeUIBookmarksURL).Resolve( |
[email protected] | 4c9ee22 | 2011-08-17 19:51:35 | [diff] [blame] | 2122 | StringPrintf("/#%s%s", action.c_str(), |
| 2123 | base::Int64ToString(node_id).c_str())))); |
[email protected] | f6c1336 | 2011-08-16 12:39:52 | [diff] [blame] | 2124 | params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
| 2125 | ShowSingletonTabOverwritingNTP(params); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2126 | } |
[email protected] | 8bf80e92 | 2009-03-09 20:56:36 | [diff] [blame] | 2127 | |
[email protected] | 4c9ee22 | 2011-08-17 19:51:35 | [diff] [blame] | 2128 | void Browser::OpenBookmarkManagerForNode(int64 node_id) { |
| 2129 | OpenBookmarkManagerWithHash("", node_id); |
| 2130 | } |
| 2131 | |
| 2132 | void Browser::OpenBookmarkManagerEditNode(int64 node_id) { |
| 2133 | OpenBookmarkManagerWithHash("e=", node_id); |
| 2134 | } |
| 2135 | |
[email protected] | fdb9851 | 2009-08-26 01:37:10 | [diff] [blame] | 2136 | void Browser::ShowAppMenu() { |
[email protected] | 366069f | 2011-01-11 09:36:12 | [diff] [blame] | 2137 | // We record the user metric for this event in WrenchMenu::RunMenu. |
[email protected] | fdb9851 | 2009-08-26 01:37:10 | [diff] [blame] | 2138 | window_->ShowAppMenu(); |
| 2139 | } |
| 2140 | |
[email protected] | 7d2d0815 | 2011-10-25 22:58:47 | [diff] [blame] | 2141 | void Browser::ShowAvatarMenu() { |
| 2142 | window_->ShowAvatarBubbleFromAvatarButton(); |
| 2143 | } |
| 2144 | |
[email protected] | 8bf80e92 | 2009-03-09 20:56:36 | [diff] [blame] | 2145 | void Browser::ShowHistoryTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2146 | content::RecordAction(UserMetricsAction("ShowHistory")); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 2147 | ShowSingletonTabOverwritingNTP( |
| 2148 | GetSingletonTabNavigateParams(GURL(chrome::kChromeUIHistoryURL))); |
[email protected] | 8bf80e92 | 2009-03-09 20:56:36 | [diff] [blame] | 2149 | } |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2150 | |
| 2151 | void Browser::ShowDownloadsTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2152 | content::RecordAction(UserMetricsAction("ShowDownloads")); |
[email protected] | efda32f9 | 2011-07-06 22:47:04 | [diff] [blame] | 2153 | #if !defined(OS_CHROMEOS) |
| 2154 | // ChromiumOS uses ActiveDownloadsUI instead of of DownloadShelf. |
[email protected] | 3d037ce7 | 2011-04-04 17:43:45 | [diff] [blame] | 2155 | if (window()) { |
| 2156 | DownloadShelf* shelf = window()->GetDownloadShelf(); |
| 2157 | if (shelf->IsShowing()) |
| 2158 | shelf->Close(); |
| 2159 | } |
[email protected] | efda32f9 | 2011-07-06 22:47:04 | [diff] [blame] | 2160 | #endif |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 2161 | ShowSingletonTabOverwritingNTP( |
| 2162 | GetSingletonTabNavigateParams(GURL(chrome::kChromeUIDownloadsURL))); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2163 | } |
| 2164 | |
[email protected] | 34085a3 | 2009-11-06 22:49:48 | [diff] [blame] | 2165 | void Browser::ShowExtensionsTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2166 | content::RecordAction(UserMetricsAction("ShowExtensions")); |
[email protected] | f98bcde5 | 2011-09-13 09:55:52 | [diff] [blame] | 2167 | ShowOptionsTab(chrome::kExtensionsSubPage); |
[email protected] | 34085a3 | 2009-11-06 22:49:48 | [diff] [blame] | 2168 | } |
| 2169 | |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 2170 | void Browser::ShowAboutConflictsTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2171 | content::RecordAction(UserMetricsAction("AboutConflicts")); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 2172 | ShowSingletonTab(GURL(chrome::kChromeUIConflictsURL)); |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 2173 | } |
| 2174 | |
[email protected] | 10e457c | 2010-04-29 03:35:23 | [diff] [blame] | 2175 | void Browser::ShowBrokenPageTab(TabContents* contents) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2176 | content::RecordAction(UserMetricsAction("ReportBug")); |
[email protected] | 10e457c | 2010-04-29 03:35:23 | [diff] [blame] | 2177 | string16 page_title = contents->GetTitle(); |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 2178 | NavigationEntry* entry = contents->controller().GetActiveEntry(); |
[email protected] | 10e457c | 2010-04-29 03:35:23 | [diff] [blame] | 2179 | if (!entry) |
| 2180 | return; |
| 2181 | std::string page_url = entry->url().spec(); |
| 2182 | std::vector<std::string> subst; |
| 2183 | subst.push_back(UTF16ToASCII(page_title)); |
| 2184 | subst.push_back(page_url); |
| 2185 | std::string report_page_url = |
| 2186 | ReplaceStringPlaceholders(kBrokenPageUrl, subst, NULL); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 2187 | ShowSingletonTab(GURL(report_page_url)); |
[email protected] | 10e457c | 2010-04-29 03:35:23 | [diff] [blame] | 2188 | } |
| 2189 | |
[email protected] | 12e816bde | 2010-09-14 19:59:29 | [diff] [blame] | 2190 | void Browser::ShowOptionsTab(const std::string& sub_page) { |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 2191 | browser::NavigateParams params(GetSingletonTabNavigateParams( |
| 2192 | GURL(chrome::kChromeUISettingsURL + sub_page))); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 2193 | params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 2194 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 2195 | ShowSingletonTabOverwritingNTP(params); |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 2196 | } |
| 2197 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2198 | void Browser::OpenClearBrowsingDataDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2199 | content::RecordAction(UserMetricsAction("ClearBrowsingData_ShowDlg")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2200 | ShowOptionsTab(chrome::kClearBrowserDataSubPage); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2201 | } |
| 2202 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2203 | void Browser::OpenOptionsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2204 | content::RecordAction(UserMetricsAction("ShowOptions")); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 2205 | ShowOptionsTab(""); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | void Browser::OpenPasswordManager() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2209 | content::RecordAction(UserMetricsAction("Options_ShowPasswordManager")); |
[email protected] | e8ce8bb | 2011-03-10 03:10:04 | [diff] [blame] | 2210 | ShowOptionsTab(chrome::kPasswordManagerSubPage); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2211 | } |
| 2212 | |
[email protected] | 1bdf29e | 2009-05-11 23:45:25 | [diff] [blame] | 2213 | void Browser::OpenImportSettingsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2214 | content::RecordAction(UserMetricsAction("Import_ShowDlg")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2215 | ShowOptionsTab(chrome::kImportDataSubPage); |
[email protected] | 1bdf29e | 2009-05-11 23:45:25 | [diff] [blame] | 2216 | } |
[email protected] | 1bdf29e | 2009-05-11 23:45:25 | [diff] [blame] | 2217 | |
[email protected] | b99081b | 2011-03-10 17:43:47 | [diff] [blame] | 2218 | void Browser::OpenInstantConfirmDialog() { |
| 2219 | ShowOptionsTab(chrome::kInstantConfirmPage); |
| 2220 | } |
| 2221 | |
[email protected] | ca38d8e | 2009-08-20 18:08:16 | [diff] [blame] | 2222 | void Browser::OpenSyncMyBookmarksDialog() { |
[email protected] | 40f04797 | 2009-11-25 03:54:40 | [diff] [blame] | 2223 | sync_ui_util::OpenSyncMyBookmarksDialog( |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 2224 | profile_, this, ProfileSyncService::START_FROM_WRENCH); |
[email protected] | ca38d8e | 2009-08-20 18:08:16 | [diff] [blame] | 2225 | } |
[email protected] | ca38d8e | 2009-08-20 18:08:16 | [diff] [blame] | 2226 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2227 | void Browser::OpenAboutChromeDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2228 | content::RecordAction(UserMetricsAction("AboutChrome")); |
[email protected] | 976e69f | 2010-08-13 18:28:17 | [diff] [blame] | 2229 | #if defined(OS_CHROMEOS) |
[email protected] | 01c3857e | 2011-06-09 04:35:48 | [diff] [blame] | 2230 | std::string chrome_settings(chrome::kChromeUISettingsURL); |
| 2231 | ShowSingletonTab(GURL(chrome_settings.append(chrome::kAboutOptionsSubPage))); |
[email protected] | 976e69f | 2010-08-13 18:28:17 | [diff] [blame] | 2232 | #else |
[email protected] | 2d46c84 | 2008-11-14 19:24:31 | [diff] [blame] | 2233 | window_->ShowAboutChromeDialog(); |
[email protected] | 976e69f | 2010-08-13 18:28:17 | [diff] [blame] | 2234 | #endif |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2235 | } |
| 2236 | |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 2237 | void Browser::OpenUpdateChromeDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2238 | content::RecordAction(UserMetricsAction("UpdateChrome")); |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 2239 | window_->ShowUpdateChromeDialog(); |
| 2240 | } |
| 2241 | |
[email protected] | 202802e4 | 2011-07-06 11:40:46 | [diff] [blame] | 2242 | void Browser::ShowHelpTab() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2243 | content::RecordAction(UserMetricsAction("ShowHelpTab")); |
[email protected] | 0a4a0be | 2010-11-09 10:42:47 | [diff] [blame] | 2244 | GURL help_url(kHelpContentUrl); |
[email protected] | 0a4a0be | 2010-11-09 10:42:47 | [diff] [blame] | 2245 | GURL localized_help_url = google_util::AppendGoogleLocaleParam(help_url); |
[email protected] | 202802e4 | 2011-07-06 11:40:46 | [diff] [blame] | 2246 | ShowSingletonTab(localized_help_url); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2247 | } |
| 2248 | |
[email protected] | 31cc1c02 | 2010-10-15 20:03:47 | [diff] [blame] | 2249 | void Browser::OpenPrivacyDashboardTabAndActivate() { |
[email protected] | 3e050545 | 2010-11-02 21:45:24 | [diff] [blame] | 2250 | OpenURL(GURL(kPrivacyDashboardUrl), GURL(), |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2251 | NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK); |
[email protected] | 31cc1c02 | 2010-10-15 20:03:47 | [diff] [blame] | 2252 | window_->Activate(); |
| 2253 | } |
| 2254 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 2255 | void Browser::OpenAutofillHelpTabAndActivate() { |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 2256 | GURL help_url = google_util::AppendGoogleLocaleParam(GURL(kAutofillHelpUrl)); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2257 | AddSelectedTabWithURL(help_url, content::PAGE_TRANSITION_LINK); |
[email protected] | bb8fe2d | 2010-06-28 20:04:22 | [diff] [blame] | 2258 | } |
| 2259 | |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 2260 | void Browser::OpenSearchEngineOptionsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2261 | content::RecordAction(UserMetricsAction("EditSearchEngines")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2262 | ShowOptionsTab(chrome::kSearchEnginesSubPage); |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 2263 | } |
| 2264 | |
[email protected] | 45c52c9d | 2011-07-19 12:08:14 | [diff] [blame] | 2265 | #if defined(FILE_MANAGER_EXTENSION) |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 2266 | void Browser::OpenFileManager() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2267 | content::RecordAction(UserMetricsAction("OpenFileManager")); |
[email protected] | 7ffb161 | 2011-09-03 00:11:28 | [diff] [blame] | 2268 | ShowSingletonTabRespectRef(GURL(chrome::kChromeUIFileManagerURL)); |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 2269 | } |
[email protected] | 45c52c9d | 2011-07-19 12:08:14 | [diff] [blame] | 2270 | #endif |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 2271 | |
[email protected] | 45c52c9d | 2011-07-19 12:08:14 | [diff] [blame] | 2272 | #if defined(OS_CHROMEOS) |
[email protected] | 05a44b6e | 2011-12-01 07:52:32 | [diff] [blame] | 2273 | void Browser::LockScreen() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2274 | content::RecordAction(UserMetricsAction("LockScreen")); |
[email protected] | b0cfc1c | 2011-12-15 13:16:19 | [diff] [blame] | 2275 | chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
[email protected] | 05a44b6e | 2011-12-01 07:52:32 | [diff] [blame] | 2276 | NotifyScreenLockRequested(); |
| 2277 | } |
| 2278 | |
[email protected] | 2166c43 | 2011-12-07 20:18:28 | [diff] [blame] | 2279 | void Browser::Shutdown() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2280 | content::RecordAction(UserMetricsAction("Shutdown")); |
[email protected] | 2166c43 | 2011-12-07 20:18:28 | [diff] [blame] | 2281 | chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 2282 | RequestShutdown(); |
| 2283 | } |
| 2284 | |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 2285 | void Browser::OpenSystemOptionsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2286 | content::RecordAction(UserMetricsAction("OpenSystemOptionsDialog")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2287 | ShowOptionsTab(chrome::kSystemOptionsSubPage); |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | void Browser::OpenInternetOptionsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2291 | content::RecordAction(UserMetricsAction("OpenInternetOptionsDialog")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2292 | ShowOptionsTab(chrome::kInternetOptionsSubPage); |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | void Browser::OpenLanguageOptionsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2296 | content::RecordAction(UserMetricsAction("OpenLanguageOptionsDialog")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2297 | ShowOptionsTab(chrome::kLanguageOptionsSubPage); |
[email protected] | be71507 | 2009-07-07 15:43:20 | [diff] [blame] | 2298 | } |
[email protected] | 46b92f85 | 2010-10-06 13:12:05 | [diff] [blame] | 2299 | |
| 2300 | void Browser::OpenSystemTabAndActivate() { |
| 2301 | OpenURL(GURL(chrome::kChromeUISystemInfoURL), GURL(), |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2302 | NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK); |
[email protected] | 46b92f85 | 2010-10-06 13:12:05 | [diff] [blame] | 2303 | window_->Activate(); |
| 2304 | } |
| 2305 | |
[email protected] | 3801761 | 2010-10-13 18:46:00 | [diff] [blame] | 2306 | void Browser::OpenMobilePlanTabAndActivate() { |
[email protected] | e7137b2c | 2011-10-24 20:16:55 | [diff] [blame] | 2307 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2308 | switches::kEnableMobileSetupDialog)) { |
| 2309 | window_->ShowMobileSetup(); |
| 2310 | } else { |
| 2311 | OpenURL(GURL(chrome::kChromeUIMobileSetupURL), GURL(), |
| 2312 | NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK); |
| 2313 | window_->Activate(); |
| 2314 | } |
[email protected] | 3801761 | 2010-10-13 18:46:00 | [diff] [blame] | 2315 | } |
[email protected] | be71507 | 2009-07-07 15:43:20 | [diff] [blame] | 2316 | #endif |
| 2317 | |
[email protected] | a003d8e | 2010-10-02 21:03:35 | [diff] [blame] | 2318 | void Browser::OpenPluginsTabAndActivate() { |
[email protected] | 37ae3f2 | 2011-07-12 03:56:14 | [diff] [blame] | 2319 | OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(), |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2320 | NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK); |
[email protected] | a003d8e | 2010-10-02 21:03:35 | [diff] [blame] | 2321 | window_->Activate(); |
| 2322 | } |
| 2323 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2324 | /////////////////////////////////////////////////////////////////////////////// |
| 2325 | |
| 2326 | // static |
[email protected] | 7911717 | 2009-08-28 16:11:44 | [diff] [blame] | 2327 | void Browser::SetNewHomePagePrefs(PrefService* prefs) { |
[email protected] | 8fe6e1c | 2010-05-27 08:21:54 | [diff] [blame] | 2328 | const PrefService::Preference* home_page_pref = |
| 2329 | prefs->FindPreference(prefs::kHomePage); |
| 2330 | if (home_page_pref && |
| 2331 | !home_page_pref->IsManaged() && |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2332 | !prefs->HasPrefPath(prefs::kHomePage)) { |
[email protected] | b41eb73 | 2009-09-30 16:49:33 | [diff] [blame] | 2333 | prefs->SetString(prefs::kHomePage, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2334 | GoogleURLTracker::kDefaultGoogleHomepage); |
| 2335 | } |
[email protected] | 8fe6e1c | 2010-05-27 08:21:54 | [diff] [blame] | 2336 | const PrefService::Preference* home_page_is_new_tab_page_pref = |
| 2337 | prefs->FindPreference(prefs::kHomePageIsNewTabPage); |
| 2338 | if (home_page_is_new_tab_page_pref && |
| 2339 | !home_page_is_new_tab_page_pref->IsManaged() && |
| 2340 | !prefs->HasPrefPath(prefs::kHomePageIsNewTabPage)) |
[email protected] | b41eb73 | 2009-09-30 16:49:33 | [diff] [blame] | 2341 | prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false); |
[email protected] | 7911717 | 2009-08-28 16:11:44 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | // static |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2345 | void Browser::RegisterPrefs(PrefService* prefs) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2346 | prefs->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 2347 | prefs->RegisterIntegerPref(prefs::kExtensionSidebarWidth, -1); |
[email protected] | d989891 | 2011-04-15 21:10:00 | [diff] [blame] | 2348 | prefs->RegisterBooleanPref(prefs::kAllowFileSelectionDialogs, true); |
[email protected] | 4e72ebb | 2011-10-18 05:02:18 | [diff] [blame] | 2349 | prefs->RegisterBooleanPref(prefs::kShouldShowFirstRunBubble, false); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | // static |
| 2353 | void Browser::RegisterUserPrefs(PrefService* prefs) { |
[email protected] | 0d22083 | 2009-11-06 00:45:18 | [diff] [blame] | 2354 | prefs->RegisterStringPref(prefs::kHomePage, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2355 | chrome::kChromeUINewTabURL, |
| 2356 | PrefService::SYNCABLE_PREF); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 2357 | prefs->RegisterBooleanPref(prefs::kHomePageChanged, |
| 2358 | false, |
| 2359 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2360 | prefs->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, |
| 2361 | true, |
| 2362 | PrefService::SYNCABLE_PREF); |
| 2363 | prefs->RegisterBooleanPref(prefs::kShowHomeButton, |
| 2364 | false, |
| 2365 | PrefService::SYNCABLE_PREF); |
[email protected] | 93a2c724 | 2009-07-07 18:43:09 | [diff] [blame] | 2366 | #if defined(OS_MACOSX) |
| 2367 | // This really belongs in platform code, but there's no good place to |
| 2368 | // initialize it between the time when the AppController is created |
| 2369 | // (where there's no profile) and the time the controller gets another |
| 2370 | // crack at the start of the main event loop. By that time, BrowserInit |
| 2371 | // has already created the browser window, and it's too late: we need the |
| 2372 | // pref to be already initialized. Doing it here also saves us from having |
| 2373 | // to hard-code pref registration in the several unit tests that use |
| 2374 | // this preference. |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2375 | prefs->RegisterBooleanPref(prefs::kConfirmToQuitEnabled, |
| 2376 | false, |
| 2377 | PrefService::SYNCABLE_PREF); |
| 2378 | prefs->RegisterBooleanPref(prefs::kShowUpdatePromotionInfoBar, |
| 2379 | true, |
| 2380 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 93a2c724 | 2009-07-07 18:43:09 | [diff] [blame] | 2381 | #endif |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2382 | prefs->RegisterBooleanPref(prefs::kDeleteBrowsingHistory, |
| 2383 | true, |
| 2384 | PrefService::SYNCABLE_PREF); |
| 2385 | prefs->RegisterBooleanPref(prefs::kDeleteDownloadHistory, |
| 2386 | true, |
| 2387 | PrefService::SYNCABLE_PREF); |
| 2388 | prefs->RegisterBooleanPref(prefs::kDeleteCache, |
| 2389 | true, |
| 2390 | PrefService::SYNCABLE_PREF); |
| 2391 | prefs->RegisterBooleanPref(prefs::kDeleteCookies, |
| 2392 | true, |
| 2393 | PrefService::SYNCABLE_PREF); |
| 2394 | prefs->RegisterBooleanPref(prefs::kDeletePasswords, |
| 2395 | false, |
| 2396 | PrefService::SYNCABLE_PREF); |
| 2397 | prefs->RegisterBooleanPref(prefs::kDeleteFormData, |
| 2398 | false, |
| 2399 | PrefService::SYNCABLE_PREF); |
| 2400 | prefs->RegisterIntegerPref(prefs::kDeleteTimePeriod, |
| 2401 | 0, |
| 2402 | PrefService::SYNCABLE_PREF); |
| 2403 | prefs->RegisterBooleanPref(prefs::kCheckDefaultBrowser, |
| 2404 | true, |
| 2405 | PrefService::UNSYNCABLE_PREF); |
| 2406 | prefs->RegisterBooleanPref(prefs::kShowOmniboxSearchHint, |
| 2407 | true, |
| 2408 | PrefService::UNSYNCABLE_PREF); |
| 2409 | prefs->RegisterBooleanPref(prefs::kWebAppCreateOnDesktop, |
| 2410 | true, |
| 2411 | PrefService::UNSYNCABLE_PREF); |
| 2412 | prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, |
| 2413 | true, |
| 2414 | PrefService::UNSYNCABLE_PREF); |
| 2415 | prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, |
| 2416 | true, |
| 2417 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2418 | prefs->RegisterBooleanPref(prefs::kEnableTranslate, |
| 2419 | true, |
| 2420 | PrefService::SYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2421 | prefs->RegisterStringPref(prefs::kCloudPrintEmail, |
| 2422 | std::string(), |
| 2423 | PrefService::UNSYNCABLE_PREF); |
| 2424 | prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, |
| 2425 | true, |
| 2426 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 1af419c | 2011-10-31 23:45:41 | [diff] [blame] | 2427 | prefs->RegisterBooleanPref(prefs::kCloudPrintSubmitEnabled, |
| 2428 | true, |
| 2429 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2430 | prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, |
| 2431 | false, |
| 2432 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2433 | prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, |
| 2434 | -1, |
| 2435 | PrefService::UNSYNCABLE_PREF); |
| 2436 | prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement, |
| 2437 | PrefService::UNSYNCABLE_PREF); |
| 2438 | prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement, |
| 2439 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d5e5b2a5 | 2011-08-16 11:27:12 | [diff] [blame] | 2440 | prefs->RegisterBooleanPref(prefs::kImportBookmarks, |
| 2441 | true, |
| 2442 | PrefService::UNSYNCABLE_PREF); |
| 2443 | prefs->RegisterBooleanPref(prefs::kImportHistory, |
| 2444 | true, |
| 2445 | PrefService::UNSYNCABLE_PREF); |
| 2446 | prefs->RegisterBooleanPref(prefs::kImportHomepage, |
| 2447 | true, |
| 2448 | PrefService::UNSYNCABLE_PREF); |
| 2449 | prefs->RegisterBooleanPref(prefs::kImportSearchEngine, |
| 2450 | true, |
| 2451 | PrefService::UNSYNCABLE_PREF); |
| 2452 | prefs->RegisterBooleanPref(prefs::kImportSavedPasswords, |
| 2453 | true, |
| 2454 | PrefService::UNSYNCABLE_PREF); |
[email protected] | f6e68091 | 2011-09-21 20:26:19 | [diff] [blame] | 2455 | // The map of timestamps of the last used file browser handlers. |
| 2456 | prefs->RegisterDictionaryPref(prefs::kLastUsedFileBrowserHandlers, |
| 2457 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d5e5b2a5 | 2011-08-16 11:27:12 | [diff] [blame] | 2458 | |
[email protected] | 2bf2bd9 | 2011-03-31 07:12:44 | [diff] [blame] | 2459 | // We need to register the type of these preferences in order to query |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2460 | // them even though they're only typically controlled via policy. |
| 2461 | prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, |
| 2462 | false, |
| 2463 | PrefService::UNSYNCABLE_PREF); |
| 2464 | prefs->RegisterBooleanPref(prefs::kPluginsAllowOutdated, |
| 2465 | false, |
| 2466 | PrefService::UNSYNCABLE_PREF); |
| 2467 | prefs->RegisterBooleanPref(prefs::kPluginsAlwaysAuthorize, |
| 2468 | false, |
| 2469 | PrefService::UNSYNCABLE_PREF); |
| 2470 | prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, |
| 2471 | true, |
| 2472 | PrefService::UNSYNCABLE_PREF); |
| 2473 | prefs->RegisterBooleanPref(prefs::kEnableReferrers, |
| 2474 | true, |
| 2475 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 781be95 | 2011-08-31 20:22:14 | [diff] [blame] | 2476 | prefs->RegisterBooleanPref(prefs::kClearPluginLSODataEnabled, |
| 2477 | true, |
| 2478 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 80b0761 | 2011-12-12 16:04:30 | [diff] [blame] | 2479 | prefs->RegisterBooleanPref(prefs::kEnableMemoryInfo, |
| 2480 | false, |
| 2481 | PrefService::UNSYNCABLE_PREF); |
[email protected] | f2df311 | 2011-11-18 10:21:48 | [diff] [blame] | 2482 | |
| 2483 | // Initialize the disk cache prefs. |
| 2484 | prefs->RegisterFilePathPref(prefs::kDiskCacheDir, |
| 2485 | FilePath(), |
| 2486 | PrefService::UNSYNCABLE_PREF); |
| 2487 | prefs->RegisterIntegerPref(prefs::kDiskCacheSize, |
| 2488 | 0, |
| 2489 | PrefService::UNSYNCABLE_PREF); |
| 2490 | prefs->RegisterIntegerPref(prefs::kMediaCacheSize, |
| 2491 | 0, |
| 2492 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | // static |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2496 | bool Browser::RunUnloadEventsHelper(TabContents* contents) { |
| 2497 | // If the TabContents is not connected yet, then there's no unload |
| 2498 | // handler we can fire even if the TabContents has an unload listener. |
| 2499 | // One case where we hit this is in a tab that has an infinite loop |
| 2500 | // before load. |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 2501 | if (contents->NeedToFireBeforeUnload()) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2502 | // If the page has unload listeners, then we tell the renderer to fire |
| 2503 | // them. Once they have fired, we'll get a message back saying whether |
| 2504 | // 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] | 2505 | // with the NeedToFireBeforeUnload bit cleared. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2506 | contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2507 | return true; |
| 2508 | } |
| 2509 | return false; |
| 2510 | } |
| 2511 | |
| 2512 | // static |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2513 | Browser* Browser::GetBrowserForController( |
| 2514 | const NavigationController* controller, int* index_result) { |
| 2515 | BrowserList::const_iterator it; |
| 2516 | for (it = BrowserList::begin(); it != BrowserList::end(); ++it) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2517 | int index = (*it)->tab_handler_->GetTabStripModel()->GetIndexOfController( |
| 2518 | controller); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2519 | if (index != TabStripModel::kNoTab) { |
| 2520 | if (index_result) |
| 2521 | *index_result = index; |
| 2522 | return *it; |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | return NULL; |
| 2527 | } |
| 2528 | |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2529 | // static |
| 2530 | void Browser::RunFileChooserHelper( |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 2531 | TabContents* tab, const content::FileChooserParams& params) { |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2532 | Profile* profile = |
| 2533 | Profile::FromBrowserContext(tab->browser_context()); |
[email protected] | 9f054aa1 | 2011-09-29 19:13:45 | [diff] [blame] | 2534 | // FileSelectHelper adds a reference to itself and only releases it after |
| 2535 | // sending the result message. It won't be destroyed when this reference |
| 2536 | // goes out of scope. |
| 2537 | scoped_refptr<FileSelectHelper> file_select_helper( |
| 2538 | new FileSelectHelper(profile)); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2539 | file_select_helper->RunFileChooser(tab->GetRenderViewHost(), tab, params); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | // static |
| 2543 | void Browser::EnumerateDirectoryHelper(TabContents* tab, int request_id, |
| 2544 | const FilePath& path) { |
| 2545 | ChildProcessSecurityPolicy* policy = |
| 2546 | ChildProcessSecurityPolicy::GetInstance(); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2547 | if (!policy->CanReadDirectory(tab->GetRenderProcessHost()->GetID(), path)) |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2548 | return; |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2549 | |
| 2550 | Profile* profile = |
| 2551 | Profile::FromBrowserContext(tab->browser_context()); |
[email protected] | 9f054aa1 | 2011-09-29 19:13:45 | [diff] [blame] | 2552 | // FileSelectHelper adds a reference to itself and only releases it after |
| 2553 | // sending the result message. It won't be destroyed when this reference |
| 2554 | // goes out of scope. |
| 2555 | scoped_refptr<FileSelectHelper> file_select_helper( |
| 2556 | new FileSelectHelper(profile)); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2557 | file_select_helper->EnumerateDirectory(request_id, |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2558 | tab->GetRenderViewHost(), |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 2559 | path); |
| 2560 | } |
| 2561 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2562 | // static |
| 2563 | void Browser::JSOutOfMemoryHelper(TabContents* tab) { |
| 2564 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2565 | tab); |
| 2566 | if (tcw) { |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 2567 | InfoBarTabHelper* infobar_helper = tcw->infobar_tab_helper(); |
| 2568 | infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 2569 | infobar_helper, |
| 2570 | NULL, |
| 2571 | l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2572 | true)); |
| 2573 | } |
| 2574 | } |
| 2575 | |
| 2576 | // static |
| 2577 | void Browser::RegisterProtocolHandlerHelper(TabContents* tab, |
| 2578 | const std::string& protocol, |
| 2579 | const GURL& url, |
| 2580 | const string16& title) { |
| 2581 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2582 | tab); |
| 2583 | if (!tcw || tcw->profile()->IsOffTheRecord()) |
| 2584 | return; |
| 2585 | |
| 2586 | ChildProcessSecurityPolicy* policy = |
| 2587 | ChildProcessSecurityPolicy::GetInstance(); |
| 2588 | if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol)) |
| 2589 | return; |
| 2590 | |
| 2591 | ProtocolHandler handler = |
| 2592 | ProtocolHandler::CreateProtocolHandler(protocol, url, title); |
| 2593 | |
| 2594 | ProtocolHandlerRegistry* registry = |
| 2595 | tcw->profile()->GetProtocolHandlerRegistry(); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2596 | |
[email protected] | a50af29 | 2011-10-25 03:07:40 | [diff] [blame] | 2597 | if (!registry->SilentlyHandleRegisterHandlerRequest(handler)) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 2598 | content::RecordAction( |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2599 | UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 2600 | InfoBarTabHelper* infobar_helper = tcw->infobar_tab_helper(); |
| 2601 | infobar_helper->AddInfoBar( |
| 2602 | new RegisterProtocolHandlerInfoBarDelegate(infobar_helper, |
| 2603 | registry, |
| 2604 | handler)); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2605 | } |
| 2606 | } |
| 2607 | |
| 2608 | // static |
| 2609 | void Browser::RegisterIntentHandlerHelper(TabContents* tab, |
| 2610 | const string16& action, |
| 2611 | const string16& type, |
| 2612 | const string16& href, |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 2613 | const string16& title, |
| 2614 | const string16& disposition) { |
[email protected] | 8229b5e | 2011-11-18 05:49:56 | [diff] [blame] | 2615 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) |
| 2616 | return; |
| 2617 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2618 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2619 | tab); |
| 2620 | if (!tcw || tcw->profile()->IsOffTheRecord()) |
| 2621 | return; |
| 2622 | |
[email protected] | 8229b5e | 2011-11-18 05:49:56 | [diff] [blame] | 2623 | FaviconService* favicon_service = |
| 2624 | tcw->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2625 | |
[email protected] | 8229b5e | 2011-11-18 05:49:56 | [diff] [blame] | 2626 | // |href| can be relative to originating URL. Resolve if necessary. |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2627 | GURL service_url(href); |
| 2628 | if (!service_url.is_valid()) { |
| 2629 | const GURL& url = tab->GetURL(); |
| 2630 | service_url = url.Resolve(href); |
| 2631 | } |
| 2632 | |
[email protected] | 5662442 | 2011-11-01 22:11:27 | [diff] [blame] | 2633 | webkit_glue::WebIntentServiceData service; |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 2634 | service.service_url = service_url; |
| 2635 | service.action = action; |
| 2636 | service.type = type; |
| 2637 | service.title = title; |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 2638 | service.setDisposition(disposition); |
| 2639 | |
[email protected] | 3826a8a0 | 2011-11-11 17:03:31 | [diff] [blame] | 2640 | RegisterIntentHandlerInfoBarDelegate::MaybeShowIntentInfoBar( |
| 2641 | tcw->infobar_tab_helper(), |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 2642 | WebIntentsRegistryFactory::GetForProfile(tcw->profile()), |
[email protected] | 8229b5e | 2011-11-18 05:49:56 | [diff] [blame] | 2643 | service, |
| 2644 | favicon_service, |
| 2645 | tab->GetURL()); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | // static |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 2649 | void Browser::FindReplyHelper(TabContents* tab, |
| 2650 | int request_id, |
| 2651 | int number_of_matches, |
| 2652 | const gfx::Rect& selection_rect, |
| 2653 | int active_match_ordinal, |
| 2654 | bool final_update) { |
| 2655 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2656 | tab); |
| 2657 | if (!tcw || !tcw->find_tab_helper()) |
| 2658 | return; |
| 2659 | |
| 2660 | tcw->find_tab_helper()->HandleFindReply(request_id, number_of_matches, |
| 2661 | selection_rect, active_match_ordinal, |
| 2662 | final_update); |
| 2663 | } |
| 2664 | |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 2665 | // static |
| 2666 | void Browser::CrashedPluginHelper(TabContents* tab, |
| 2667 | const FilePath& plugin_path) { |
| 2668 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2669 | tab); |
| 2670 | if (!tcw) |
| 2671 | return; |
| 2672 | |
| 2673 | DCHECK(!plugin_path.value().empty()); |
| 2674 | |
| 2675 | string16 plugin_name = plugin_path.LossyDisplayName(); |
| 2676 | webkit::WebPluginInfo plugin_info; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 2677 | if (PluginService::GetInstance()->GetPluginInfoByPath( |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 2678 | plugin_path, &plugin_info) && |
| 2679 | !plugin_info.name.empty()) { |
| 2680 | plugin_name = plugin_info.name; |
| 2681 | #if defined(OS_MACOSX) |
| 2682 | // Many plugins on the Mac have .plugin in the actual name, which looks |
| 2683 | // terrible, so look for that and strip it off if present. |
| 2684 | const std::string kPluginExtension = ".plugin"; |
| 2685 | if (EndsWith(plugin_name, ASCIIToUTF16(kPluginExtension), true)) |
| 2686 | plugin_name.erase(plugin_name.length() - kPluginExtension.length()); |
| 2687 | #endif // OS_MACOSX |
| 2688 | } |
| 2689 | gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 2690 | IDR_INFOBAR_PLUGIN_CRASHED); |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 2691 | InfoBarTabHelper* infobar_helper = tcw->infobar_tab_helper(); |
| 2692 | infobar_helper->AddInfoBar( |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 2693 | new SimpleAlertInfoBarDelegate( |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 2694 | infobar_helper, |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 2695 | icon, |
| 2696 | l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), |
| 2697 | true)); |
| 2698 | } |
| 2699 | |
| 2700 | // static |
| 2701 | void Browser::UpdateTargetURLHelper(TabContents* tab, int32 page_id, |
| 2702 | const GURL& url) { |
| 2703 | TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( |
| 2704 | tab); |
| 2705 | if (!tcw || !tcw->prerender_tab_helper()) |
| 2706 | return; |
| 2707 | tcw->prerender_tab_helper()->UpdateTargetURL(page_id, url); |
| 2708 | } |
| 2709 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 2710 | void Browser::ExecuteCommandWithDisposition( |
| 2711 | int id, WindowOpenDisposition disposition) { |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2712 | // No commands are enabled if there is not yet any selected tab. |
| 2713 | // TODO(pkasting): It seems like we should not need this, because either |
| 2714 | // most/all commands should not have been enabled yet anyway or the ones that |
| 2715 | // are enabled should be global, or safe themselves against having no selected |
| 2716 | // tab. However, Ben says he tried removing this before and got lots of |
| 2717 | // crashes, e.g. from Windows sending WM_COMMANDs at random times during |
| 2718 | // window construction. This probably could use closer examination someday. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2719 | if (!GetSelectedTabContentsWrapper()) |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2720 | return; |
| 2721 | |
[email protected] | 59c9f00 | 2010-11-19 00:38:05 | [diff] [blame] | 2722 | DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command " |
| 2723 | << id; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2724 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 2725 | // If command execution is blocked then just record the command and return. |
| 2726 | if (block_command_execution_) { |
| 2727 | // We actually only allow no more than one blocked command, otherwise some |
| 2728 | // commands maybe lost. |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 2729 | DCHECK_EQ(last_blocked_command_id_, -1); |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 2730 | last_blocked_command_id_ = id; |
| 2731 | last_blocked_command_disposition_ = disposition; |
| 2732 | return; |
| 2733 | } |
| 2734 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2735 | // The order of commands in this switch statement must match the function |
| 2736 | // declaration order in browser.h! |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2737 | switch (id) { |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2738 | // Navigation commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2739 | case IDC_BACK: GoBack(disposition); break; |
| 2740 | case IDC_FORWARD: GoForward(disposition); break; |
| 2741 | case IDC_RELOAD: Reload(disposition); break; |
| 2742 | case IDC_RELOAD_IGNORING_CACHE: ReloadIgnoringCache(disposition); break; |
| 2743 | case IDC_HOME: Home(disposition); break; |
| 2744 | case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2745 | case IDC_STOP: Stop(); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2746 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2747 | // Window management commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2748 | case IDC_NEW_WINDOW: NewWindow(); break; |
| 2749 | case IDC_NEW_INCOGNITO_WINDOW: NewIncognitoWindow(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2750 | case IDC_CLOSE_WINDOW: CloseWindow(); break; |
| 2751 | case IDC_NEW_TAB: NewTab(); break; |
| 2752 | case IDC_CLOSE_TAB: CloseTab(); break; |
| 2753 | case IDC_SELECT_NEXT_TAB: SelectNextTab(); break; |
| 2754 | case IDC_SELECT_PREVIOUS_TAB: SelectPreviousTab(); break; |
[email protected] | 91ac920 | 2010-07-30 18:32:35 | [diff] [blame] | 2755 | case IDC_TABPOSE: OpenTabpose(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2756 | case IDC_MOVE_TAB_NEXT: MoveTabNext(); break; |
| 2757 | case IDC_MOVE_TAB_PREVIOUS: MoveTabPrevious(); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2758 | case IDC_SELECT_TAB_0: |
| 2759 | case IDC_SELECT_TAB_1: |
| 2760 | case IDC_SELECT_TAB_2: |
| 2761 | case IDC_SELECT_TAB_3: |
| 2762 | case IDC_SELECT_TAB_4: |
| 2763 | case IDC_SELECT_TAB_5: |
| 2764 | case IDC_SELECT_TAB_6: |
[email protected] | cb525c8 | 2008-12-08 23:04:54 | [diff] [blame] | 2765 | case IDC_SELECT_TAB_7: SelectNumberedTab(id - IDC_SELECT_TAB_0); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2766 | break; |
| 2767 | case IDC_SELECT_LAST_TAB: SelectLastTab(); break; |
| 2768 | case IDC_DUPLICATE_TAB: DuplicateTab(); break; |
| 2769 | case IDC_RESTORE_TAB: RestoreTab(); break; |
| 2770 | case IDC_COPY_URL: WriteCurrentURLToClipboard(); break; |
| 2771 | case IDC_SHOW_AS_TAB: ConvertPopupToTabbedBrowser(); break; |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 2772 | case IDC_FULLSCREEN: ToggleFullscreenMode(false); break; |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 2773 | #if defined(OS_MACOSX) |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 2774 | case IDC_PRESENTATION_MODE: TogglePresentationMode(false); break; |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 2775 | #endif |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2776 | case IDC_EXIT: Exit(); break; |
[email protected] | da17b37 | 2010-01-22 23:37:22 | [diff] [blame] | 2777 | #if defined(OS_CHROMEOS) |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2778 | case IDC_SEARCH: Search(); break; |
[email protected] | d14af52 | 2010-12-02 03:54:50 | [diff] [blame] | 2779 | case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break; |
[email protected] | 20d1724 | 2009-10-26 20:21:05 | [diff] [blame] | 2780 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2781 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2782 | // Page-related commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2783 | case IDC_SAVE_PAGE: SavePage(); break; |
| 2784 | case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break; |
| 2785 | case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(); break; |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 2786 | case IDC_VIEW_SOURCE: ViewSelectedSource(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2787 | case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break; |
| 2788 | case IDC_PRINT: Print(); break; |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 2789 | case IDC_ADVANCED_PRINT: AdvancedPrint(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2790 | case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2791 | case IDC_ENCODING_UTF8: |
| 2792 | case IDC_ENCODING_UTF16LE: |
| 2793 | case IDC_ENCODING_ISO88591: |
| 2794 | case IDC_ENCODING_WINDOWS1252: |
[email protected] | 1c5bf63 | 2008-12-11 20:30:49 | [diff] [blame] | 2795 | case IDC_ENCODING_GBK: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2796 | case IDC_ENCODING_GB18030: |
| 2797 | case IDC_ENCODING_BIG5HKSCS: |
| 2798 | case IDC_ENCODING_BIG5: |
| 2799 | case IDC_ENCODING_KOREAN: |
| 2800 | case IDC_ENCODING_SHIFTJIS: |
| 2801 | case IDC_ENCODING_ISO2022JP: |
| 2802 | case IDC_ENCODING_EUCJP: |
| 2803 | case IDC_ENCODING_THAI: |
| 2804 | case IDC_ENCODING_ISO885915: |
| 2805 | case IDC_ENCODING_MACINTOSH: |
| 2806 | case IDC_ENCODING_ISO88592: |
| 2807 | case IDC_ENCODING_WINDOWS1250: |
| 2808 | case IDC_ENCODING_ISO88595: |
| 2809 | case IDC_ENCODING_WINDOWS1251: |
| 2810 | case IDC_ENCODING_KOI8R: |
| 2811 | case IDC_ENCODING_KOI8U: |
| 2812 | case IDC_ENCODING_ISO88597: |
| 2813 | case IDC_ENCODING_WINDOWS1253: |
| 2814 | case IDC_ENCODING_ISO88594: |
| 2815 | case IDC_ENCODING_ISO885913: |
| 2816 | case IDC_ENCODING_WINDOWS1257: |
| 2817 | case IDC_ENCODING_ISO88593: |
| 2818 | case IDC_ENCODING_ISO885910: |
| 2819 | case IDC_ENCODING_ISO885914: |
| 2820 | case IDC_ENCODING_ISO885916: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2821 | case IDC_ENCODING_WINDOWS1254: |
| 2822 | case IDC_ENCODING_ISO88596: |
| 2823 | case IDC_ENCODING_WINDOWS1256: |
| 2824 | case IDC_ENCODING_ISO88598: |
[email protected] | e13271f | 2009-03-07 00:26:00 | [diff] [blame] | 2825 | case IDC_ENCODING_ISO88598I: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2826 | case IDC_ENCODING_WINDOWS1255: |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2827 | case IDC_ENCODING_WINDOWS1258: OverrideEncoding(id); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2828 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2829 | // Clipboard commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2830 | case IDC_CUT: Cut(); break; |
| 2831 | case IDC_COPY: Copy(); break; |
| 2832 | case IDC_PASTE: Paste(); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2833 | |
| 2834 | // Find-in-page |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2835 | case IDC_FIND: Find(); break; |
| 2836 | case IDC_FIND_NEXT: FindNext(); break; |
| 2837 | case IDC_FIND_PREVIOUS: FindPrevious(); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2838 | |
| 2839 | // Zoom |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 2840 | case IDC_ZOOM_PLUS: Zoom(content::PAGE_ZOOM_IN); break; |
| 2841 | case IDC_ZOOM_NORMAL: Zoom(content::PAGE_ZOOM_RESET); break; |
| 2842 | case IDC_ZOOM_MINUS: Zoom(content::PAGE_ZOOM_OUT); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2843 | |
| 2844 | // Focus various bits of UI |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2845 | case IDC_FOCUS_TOOLBAR: FocusToolbar(); break; |
| 2846 | case IDC_FOCUS_LOCATION: FocusLocationBar(); break; |
| 2847 | case IDC_FOCUS_SEARCH: FocusSearch(); break; |
[email protected] | bdb7ff6 | 2010-07-20 01:56:52 | [diff] [blame] | 2848 | case IDC_FOCUS_MENU_BAR: FocusAppMenu(); break; |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2849 | case IDC_FOCUS_BOOKMARKS: FocusBookmarksToolbar(); break; |
| 2850 | case IDC_FOCUS_CHROMEOS_STATUS: FocusChromeOSStatus(); break; |
| 2851 | case IDC_FOCUS_NEXT_PANE: FocusNextPane(); break; |
| 2852 | case IDC_FOCUS_PREVIOUS_PANE: FocusPreviousPane(); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2853 | |
| 2854 | // Show various bits of UI |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2855 | case IDC_OPEN_FILE: OpenFile(); break; |
| 2856 | case IDC_CREATE_SHORTCUTS: OpenCreateShortcutsDialog(); break; |
[email protected] | 2a8a9812 | 2010-07-16 11:58:48 | [diff] [blame] | 2857 | case IDC_DEV_TOOLS: ToggleDevToolsWindow( |
| 2858 | DEVTOOLS_TOGGLE_ACTION_NONE); |
| 2859 | break; |
| 2860 | case IDC_DEV_TOOLS_CONSOLE: ToggleDevToolsWindow( |
| 2861 | DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); |
| 2862 | break; |
| 2863 | case IDC_DEV_TOOLS_INSPECT: ToggleDevToolsWindow( |
| 2864 | DEVTOOLS_TOGGLE_ACTION_INSPECT); |
| 2865 | break; |
[email protected] | adb6a84d | 2011-02-07 16:58:40 | [diff] [blame] | 2866 | case IDC_TASK_MANAGER: OpenTaskManager(false); break; |
| 2867 | case IDC_VIEW_BACKGROUND_PAGES: OpenTaskManager(true); break; |
[email protected] | 1c41a93 | 2010-11-22 23:41:23 | [diff] [blame] | 2868 | case IDC_FEEDBACK: OpenBugReportDialog(); break; |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 2869 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2870 | case IDC_SHOW_BOOKMARK_BAR: ToggleBookmarkBar(); break; |
[email protected] | 7664ab3 | 2011-02-01 23:35:25 | [diff] [blame] | 2871 | case IDC_PROFILING_ENABLED: Profiling::Toggle(); break; |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 2872 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2873 | case IDC_SHOW_BOOKMARK_MANAGER: OpenBookmarkManager(); break; |
| 2874 | case IDC_SHOW_APP_MENU: ShowAppMenu(); break; |
[email protected] | 7d2d0815 | 2011-10-25 22:58:47 | [diff] [blame] | 2875 | case IDC_SHOW_AVATAR_MENU: ShowAvatarMenu(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2876 | case IDC_SHOW_HISTORY: ShowHistoryTab(); break; |
| 2877 | case IDC_SHOW_DOWNLOADS: ShowDownloadsTab(); break; |
| 2878 | case IDC_MANAGE_EXTENSIONS: ShowExtensionsTab(); break; |
| 2879 | case IDC_SYNC_BOOKMARKS: OpenSyncMyBookmarksDialog(); break; |
| 2880 | case IDC_OPTIONS: OpenOptionsDialog(); break; |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2881 | case IDC_EDIT_SEARCH_ENGINES: OpenSearchEngineOptionsDialog(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2882 | case IDC_VIEW_PASSWORDS: OpenPasswordManager(); break; |
| 2883 | case IDC_CLEAR_BROWSING_DATA: OpenClearBrowsingDataDialog(); break; |
| 2884 | case IDC_IMPORT_SETTINGS: OpenImportSettingsDialog(); break; |
[email protected] | b21d691 | 2010-08-31 19:22:41 | [diff] [blame] | 2885 | case IDC_ABOUT: OpenAboutChromeDialog(); break; |
| 2886 | case IDC_UPGRADE_DIALOG: OpenUpdateChromeDialog(); break; |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 2887 | case IDC_VIEW_INCOMPATIBILITIES: ShowAboutConflictsTab(); break; |
[email protected] | 202802e4 | 2011-07-06 11:40:46 | [diff] [blame] | 2888 | case IDC_HELP_PAGE: ShowHelpTab(); break; |
[email protected] | 1677984 | 2009-07-08 23:45:29 | [diff] [blame] | 2889 | #if defined(OS_CHROMEOS) |
[email protected] | 05a44b6e | 2011-12-01 07:52:32 | [diff] [blame] | 2890 | case IDC_LOCK_SCREEN: LockScreen(); break; |
[email protected] | 2166c43 | 2011-12-07 20:18:28 | [diff] [blame] | 2891 | case IDC_SHUTDOWN: Shutdown(); break; |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 2892 | case IDC_FILE_MANAGER: OpenFileManager(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2893 | case IDC_SYSTEM_OPTIONS: OpenSystemOptionsDialog(); break; |
| 2894 | case IDC_INTERNET_OPTIONS: OpenInternetOptionsDialog(); break; |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 2895 | case IDC_LANGUAGE_OPTIONS: OpenLanguageOptionsDialog(); break; |
[email protected] | be71507 | 2009-07-07 15:43:20 | [diff] [blame] | 2896 | #endif |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 2897 | case IDC_SHOW_SYNC_SETUP: ShowSyncSetup(); break; |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 2898 | case IDC_TOGGLE_SPEECH_INPUT: ToggleSpeechInput(); break; |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 2899 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2900 | default: |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2901 | LOG(WARNING) << "Received Unimplemented Command: " << id; |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2902 | break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2903 | } |
| 2904 | } |
| 2905 | |
[email protected] | dee1135 | 2011-09-05 13:34:08 | [diff] [blame] | 2906 | void Browser::ExecuteCommand(int id, int event_flags) { |
| 2907 | ExecuteCommandWithDisposition( |
| 2908 | id, browser::DispositionFromEventFlags(event_flags)); |
| 2909 | } |
| 2910 | |
[email protected] | 3ab6796d3 | 2010-12-21 23:56:07 | [diff] [blame] | 2911 | bool Browser::ExecuteCommandIfEnabled(int id) { |
| 2912 | if (command_updater_.SupportsCommand(id) && |
| 2913 | command_updater_.IsCommandEnabled(id)) { |
| 2914 | ExecuteCommand(id); |
| 2915 | return true; |
| 2916 | } |
| 2917 | return false; |
| 2918 | } |
| 2919 | |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 2920 | bool Browser::IsReservedCommandOrKey(int command_id, |
| 2921 | const NativeWebKeyboardEvent& event) { |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 2922 | #if defined(OS_CHROMEOS) |
| 2923 | // Chrome OS's top row of keys produces F1-10. Make sure that web pages |
| 2924 | // aren't able to block Chrome from performing the standard actions for F1-F4 |
| 2925 | // (F5-7 are grabbed by other X clients and hence don't need this protection, |
| 2926 | // and F8-10 are handled separately in Chrome via a GDK event filter, but |
| 2927 | // let's future-proof this). |
| 2928 | ui::KeyboardCode key_code = |
[email protected] | 6a1ae6cd | 2011-02-11 20:06:09 | [diff] [blame] | 2929 | static_cast<ui::KeyboardCode>(event.windowsKeyCode); |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 2930 | if (key_code == ui::VKEY_F1 || |
| 2931 | key_code == ui::VKEY_F2 || |
| 2932 | key_code == ui::VKEY_F3 || |
| 2933 | key_code == ui::VKEY_F4 || |
| 2934 | key_code == ui::VKEY_F5 || |
| 2935 | key_code == ui::VKEY_F6 || |
| 2936 | key_code == ui::VKEY_F7 || |
| 2937 | key_code == ui::VKEY_F8 || |
| 2938 | key_code == ui::VKEY_F9 || |
| 2939 | key_code == ui::VKEY_F10) { |
[email protected] | 6a1ae6cd | 2011-02-11 20:06:09 | [diff] [blame] | 2940 | return true; |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 2941 | } |
| 2942 | #endif |
| 2943 | |
[email protected] | fa2d2ce2 | 2011-09-19 08:21:06 | [diff] [blame] | 2944 | if (window_->IsFullscreen() && command_id == IDC_FULLSCREEN) |
| 2945 | return true; |
[email protected] | 6a1ae6cd | 2011-02-11 20:06:09 | [diff] [blame] | 2946 | return command_id == IDC_CLOSE_TAB || |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 2947 | command_id == IDC_CLOSE_WINDOW || |
| 2948 | command_id == IDC_NEW_INCOGNITO_WINDOW || |
| 2949 | command_id == IDC_NEW_TAB || |
| 2950 | command_id == IDC_NEW_WINDOW || |
| 2951 | command_id == IDC_RESTORE_TAB || |
| 2952 | command_id == IDC_SELECT_NEXT_TAB || |
| 2953 | command_id == IDC_SELECT_PREVIOUS_TAB || |
[email protected] | c1d0d81 | 2010-07-27 20:21:55 | [diff] [blame] | 2954 | command_id == IDC_TABPOSE || |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 2955 | command_id == IDC_EXIT || |
| 2956 | command_id == IDC_SEARCH; |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | void Browser::SetBlockCommandExecution(bool block) { |
| 2960 | block_command_execution_ = block; |
| 2961 | if (block) { |
| 2962 | last_blocked_command_id_ = -1; |
| 2963 | last_blocked_command_disposition_ = CURRENT_TAB; |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) { |
| 2968 | if (disposition) |
| 2969 | *disposition = last_blocked_command_disposition_; |
| 2970 | return last_blocked_command_id_; |
| 2971 | } |
| 2972 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2973 | void Browser::UpdateUIForNavigationInTab(TabContentsWrapper* contents, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2974 | content::PageTransition transition, |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 2975 | bool user_initiated) { |
| 2976 | tabstrip_model()->TabNavigating(contents, transition); |
| 2977 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2978 | bool contents_is_selected = contents == GetSelectedTabContentsWrapper(); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 2979 | if (user_initiated && contents_is_selected && window()->GetLocationBar()) { |
| 2980 | // Forcibly reset the location bar if the url is going to change in the |
| 2981 | // current tab, since otherwise it won't discard any ongoing user edits, |
| 2982 | // since it doesn't realize this is a user-initiated action. |
| 2983 | window()->GetLocationBar()->Revert(); |
| 2984 | } |
| 2985 | |
| 2986 | if (GetStatusBubble()) |
| 2987 | GetStatusBubble()->Hide(); |
| 2988 | |
| 2989 | // Update the location bar. This is synchronous. We specifically don't |
| 2990 | // update the load state since the load hasn't started yet and updating it |
| 2991 | // will put it out of sync with the actual state like whether we're |
| 2992 | // displaying a favicon, which controls the throbber. If we updated it here, |
| 2993 | // the throbber will show the default favicon for a split second when |
| 2994 | // navigating away from the new tab page. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2995 | ScheduleUIUpdate(contents->tab_contents(), TabContents::INVALIDATE_URL); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 2996 | |
| 2997 | if (contents_is_selected) |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2998 | contents->tab_contents()->Focus(); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 2999 | } |
| 3000 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3001 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3002 | // Browser, PageNavigator implementation: |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 3003 | |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 3004 | // TODO(adriansc): Remove this method once refactoring changed all call sites. |
[email protected] | 992e454 | 2011-07-20 23:09:25 | [diff] [blame] | 3005 | TabContents* Browser::OpenURL(const GURL& url, |
| 3006 | const GURL& referrer, |
| 3007 | WindowOpenDisposition disposition, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3008 | content::PageTransition transition) { |
[email protected] | 39c90bb | 2011-12-02 15:44:10 | [diff] [blame] | 3009 | // For specifying a referrer, use the version of OpenURL taking OpenURLParams. |
| 3010 | DCHECK(referrer.is_empty()); |
[email protected] | bce1f1c | 2011-12-05 15:11:58 | [diff] [blame] | 3011 | return OpenURLFromTab(NULL, OpenURLParams( |
| 3012 | url, content::Referrer(), disposition, transition, false)); |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | TabContents* Browser::OpenURL(const OpenURLParams& params) { |
| 3016 | return OpenURLFromTab(NULL, params); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 3020 | // Browser, CommandUpdater::CommandUpdaterDelegate implementation: |
| 3021 | |
| 3022 | void Browser::ExecuteCommand(int id) { |
| 3023 | ExecuteCommandWithDisposition(id, CURRENT_TAB); |
| 3024 | } |
| 3025 | |
| 3026 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3027 | // Browser, TabHandlerDelegate implementation: |
| 3028 | |
| 3029 | Profile* Browser::GetProfile() const { |
| 3030 | return profile(); |
| 3031 | } |
| 3032 | |
| 3033 | Browser* Browser::AsBrowser() { |
| 3034 | return this; |
| 3035 | } |
| 3036 | |
| 3037 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3038 | // Browser, TabStripModelDelegate implementation: |
| 3039 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3040 | TabContentsWrapper* Browser::AddBlankTab(bool foreground) { |
[email protected] | 22735af6 | 2009-04-07 21:09:58 | [diff] [blame] | 3041 | return AddBlankTabAt(-1, foreground); |
| 3042 | } |
| 3043 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3044 | TabContentsWrapper* Browser::AddBlankTabAt(int index, bool foreground) { |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 3045 | // Time new tab page creation time. We keep track of the timing data in |
| 3046 | // TabContents, but we want to include the time it takes to create the |
| 3047 | // TabContents object too. |
| 3048 | base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3049 | browser::NavigateParams params(this, GURL(chrome::kChromeUINewTabURL), |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3050 | content::PAGE_TRANSITION_TYPED); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3051 | params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
| 3052 | params.tabstrip_index = index; |
| 3053 | browser::Navigate(¶ms); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3054 | params.target_contents->tab_contents()->set_new_tab_start_time( |
| 3055 | new_tab_start_time); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3056 | return params.target_contents; |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 3057 | } |
| 3058 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3059 | Browser* Browser::CreateNewStripWithContents( |
| 3060 | TabContentsWrapper* detached_contents, |
| 3061 | const gfx::Rect& window_bounds, |
| 3062 | const DockInfo& dock_info, |
| 3063 | bool maximize) { |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 3064 | DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); |
[email protected] | adf650f | 2008-12-09 16:10:06 | [diff] [blame] | 3065 | |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 3066 | gfx::Rect new_window_bounds = window_bounds; |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 3067 | if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize)) |
| 3068 | dock_info.AdjustOtherWindowBounds(); |
| 3069 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3070 | // Create an empty new browser window the same size as the old one. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3071 | Browser* browser = new Browser(TYPE_TABBED, profile_); |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 3072 | browser->set_override_bounds(new_window_bounds); |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 3073 | browser->set_show_state( |
| 3074 | maximize ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 3075 | browser->InitBrowserWindow(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 3076 | browser->tabstrip_model()->AppendTabContents(detached_contents, true); |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 3077 | // Make sure the loading state is updated correctly, otherwise the throbber |
| 3078 | // won't start if the page is loading. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3079 | browser->LoadingStateChanged(detached_contents->tab_contents()); |
[email protected] | 3d1104f | 2009-03-26 15:30:28 | [diff] [blame] | 3080 | return browser; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | int Browser::GetDragActions() const { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3084 | return TabStripModelDelegate::TAB_TEAROFF_ACTION | (tab_count() > 1 ? |
| 3085 | TabStripModelDelegate::TAB_MOVE_ACTION : 0); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3086 | } |
| 3087 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3088 | TabContentsWrapper* Browser::CreateTabContentsForURL( |
[email protected] | 3ebe558b | 2011-12-06 08:05:08 | [diff] [blame] | 3089 | const GURL& url, const content::Referrer& referrer, Profile* profile, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3090 | content::PageTransition transition, bool defer_load, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3091 | SiteInstance* instance) const { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3092 | TabContentsWrapper* contents = TabContentsFactory(profile, instance, |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3093 | MSG_ROUTING_NONE, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3094 | GetSelectedTabContents(), NULL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3095 | if (!defer_load) { |
| 3096 | // Load the initial URL before adding the new tab contents to the tab strip |
| 3097 | // so that the tab contents has navigation state. |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 3098 | contents->tab_contents()->controller().LoadURL( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 3099 | url, referrer, transition, std::string()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3100 | } |
| 3101 | |
| 3102 | return contents; |
| 3103 | } |
| 3104 | |
| 3105 | bool Browser::CanDuplicateContentsAt(int index) { |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 3106 | NavigationController& nc = GetTabContentsAt(index)->controller(); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 3107 | return nc.tab_contents() && nc.GetLastCommittedEntry(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | void Browser::DuplicateContentsAt(int index) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3111 | TabContentsWrapper* contents = GetTabContentsWrapperAt(index); |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 3112 | CHECK(contents); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 3113 | TabContentsWrapper* contents_dupe = contents->Clone(); |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 3114 | |
| 3115 | bool pinned = false; |
| 3116 | if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
| 3117 | // If this is a tabbed browser, just create a duplicate tab inside the same |
| 3118 | // window next to the tab being duplicated. |
| 3119 | int index = tab_handler_->GetTabStripModel()-> |
| 3120 | GetIndexOfTabContents(contents); |
| 3121 | pinned = tab_handler_->GetTabStripModel()->IsTabPinned(index); |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 3122 | int add_types = TabStripModel::ADD_ACTIVE | |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 3123 | TabStripModel::ADD_INHERIT_GROUP | |
| 3124 | (pinned ? TabStripModel::ADD_PINNED : 0); |
| 3125 | tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, |
| 3126 | contents_dupe, |
| 3127 | add_types); |
| 3128 | } else { |
| 3129 | Browser* browser = NULL; |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3130 | if (is_app()) { |
| 3131 | CHECK(!is_type_popup()); |
| 3132 | CHECK(!is_type_panel()); |
[email protected] | 5c20924 | 2011-06-06 20:36:17 | [diff] [blame] | 3133 | browser = Browser::CreateForApp(TYPE_POPUP, app_name_, gfx::Rect(), |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3134 | profile_); |
| 3135 | } else if (is_type_popup()) { |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 3136 | browser = Browser::CreateForType(TYPE_POPUP, profile_); |
| 3137 | } |
| 3138 | |
| 3139 | // Preserve the size of the original window. The new window has already |
| 3140 | // been given an offset by the OS, so we shouldn't copy the old bounds. |
| 3141 | BrowserWindow* new_window = browser->window(); |
| 3142 | new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 3143 | window()->GetRestoredBounds().size())); |
| 3144 | |
[email protected] | 4e59568 | 2011-02-09 17:07:02 | [diff] [blame] | 3145 | // We need to show the browser now. Otherwise ContainerWin assumes the |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 3146 | // TabContents is invisible and won't size it. |
| 3147 | browser->window()->Show(); |
| 3148 | |
| 3149 | // The page transition below is only for the purpose of inserting the tab. |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3150 | browser->AddTab(contents_dupe, content::PAGE_TRANSITION_LINK); |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 3151 | } |
| 3152 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3153 | SessionService* session_service = |
| 3154 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 3155 | if (session_service) |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 3156 | session_service->TabRestored(contents_dupe, pinned); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3157 | } |
| 3158 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3159 | void Browser::CloseFrameAfterDragSession() { |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 3160 | #if !defined(OS_MACOSX) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3161 | // This is scheduled to run after we return to the message loop because |
| 3162 | // otherwise the frame will think the drag session is still active and ignore |
| 3163 | // the request. |
[email protected] | d6a3c77 | 2009-01-27 19:41:20 | [diff] [blame] | 3164 | // TODO(port): figure out what is required here in a cross-platform world |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 3165 | MessageLoop::current()->PostTask( |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 3166 | FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); |
[email protected] | d6a3c77 | 2009-01-27 19:41:20 | [diff] [blame] | 3167 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3168 | } |
| 3169 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3170 | void Browser::CreateHistoricalTab(TabContentsWrapper* contents) { |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 3171 | // We don't create historical tabs for incognito windows or windows without |
| 3172 | // profiles. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3173 | if (!profile() || profile()->IsOffTheRecord()) |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 3174 | return; |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3175 | |
[email protected] | 0d4ef7f | 2011-05-12 22:38:57 | [diff] [blame] | 3176 | // We don't create historical tabs for print preview tabs. |
| 3177 | if (contents->tab_contents()->GetURL() == GURL(chrome::kChromeUIPrintURL)) |
| 3178 | return; |
| 3179 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3180 | TabRestoreService* service = |
| 3181 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 3182 | |
[email protected] | fb5ff42 | 2010-05-03 20:46:10 | [diff] [blame] | 3183 | // We only create historical tab entries for tabbed browser windows. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3184 | if (service && CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 3185 | service->CreateHistoricalTab(&contents->tab_contents()->controller(), |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 3186 | tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents)); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 3187 | } |
| 3188 | } |
| 3189 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3190 | bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { |
| 3191 | return Browser::RunUnloadEventsHelper(contents->tab_contents()); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 3192 | } |
| 3193 | |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 3194 | bool Browser::CanReloadContents(TabContents* source) const { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3195 | return !is_devtools(); |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 3196 | } |
| 3197 | |
[email protected] | 2db5a204 | 2011-04-26 17:13:47 | [diff] [blame] | 3198 | bool Browser::CanCloseContents(std::vector<int>* indices) { |
| 3199 | DCHECK(!indices->empty()); |
| 3200 | TabCloseableStateWatcher* watcher = |
| 3201 | g_browser_process->tab_closeable_state_watcher(); |
| 3202 | bool can_close_all = !watcher || watcher->CanCloseTabs(this, indices); |
| 3203 | if (indices->empty()) // Cannot close any tab. |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 3204 | return false; |
[email protected] | 2db5a204 | 2011-04-26 17:13:47 | [diff] [blame] | 3205 | // Now, handle cases where at least one tab can be closed. |
| 3206 | // 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] | 3207 | // in-progress downloads. |
| 3208 | // Note that the next call when it returns false will ask the user for |
| 3209 | // confirmation before closing the browser if the user decides so. |
[email protected] | 2db5a204 | 2011-04-26 17:13:47 | [diff] [blame] | 3210 | if (tab_handler_->GetTabStripModel()->count() == |
| 3211 | static_cast<int>(indices->size()) && |
| 3212 | !CanCloseWithInProgressDownloads()) { |
| 3213 | indices->clear(); |
| 3214 | can_close_all = false; |
| 3215 | } |
| 3216 | return can_close_all; |
[email protected] | 940ccb2 | 2009-04-30 17:11:10 | [diff] [blame] | 3217 | } |
[email protected] | d6a3c77 | 2009-01-27 19:41:20 | [diff] [blame] | 3218 | |
[email protected] | a206b44 | 2009-10-08 23:20:20 | [diff] [blame] | 3219 | bool Browser::CanBookmarkAllTabs() const { |
| 3220 | BookmarkModel* model = profile()->GetBookmarkModel(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 3221 | return (model && model->IsLoaded()) && |
| 3222 | tab_count() > 1 && |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 3223 | profile()->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled); |
[email protected] | a206b44 | 2009-10-08 23:20:20 | [diff] [blame] | 3224 | } |
| 3225 | |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 3226 | void Browser::BookmarkAllTabs() { |
[email protected] | 9d60339 | 2011-11-18 05:45:28 | [diff] [blame] | 3227 | BookmarkEditor::ShowBookmarkAllTabsDialog(this); |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 3228 | } |
| 3229 | |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 3230 | bool Browser::CanCloseTab() const { |
| 3231 | TabCloseableStateWatcher* watcher = |
| 3232 | g_browser_process->tab_closeable_state_watcher(); |
| 3233 | return !watcher || watcher->CanCloseTab(this); |
| 3234 | } |
| 3235 | |
[email protected] | b283a753 | 2010-08-12 21:24:59 | [diff] [blame] | 3236 | bool Browser::LargeIconsPermitted() const { |
[email protected] | af801acd | 2010-08-20 20:27:44 | [diff] [blame] | 3237 | // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because |
| 3238 | // for those windows, we already have a big icon in the top-left outside any |
| 3239 | // tab. Having big tab icons too looks kinda redonk. |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 3240 | return true; |
[email protected] | b283a753 | 2010-08-12 21:24:59 | [diff] [blame] | 3241 | } |
| 3242 | |
[email protected] | 2d46c84 | 2008-11-14 19:24:31 | [diff] [blame] | 3243 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3244 | // Browser, TabStripModelObserver implementation: |
| 3245 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3246 | void Browser::TabInsertedAt(TabContentsWrapper* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3247 | int index, |
| 3248 | bool foreground) { |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 3249 | SetAsDelegate(contents, this); |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 3250 | contents->restore_tab_helper()->SetWindowID(session_id()); |
[email protected] | e524ff9 | 2011-03-30 13:26:58 | [diff] [blame] | 3251 | |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3252 | SyncHistoryWithTabs(index); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3253 | |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 3254 | // Make sure the loading state is updated correctly, otherwise the throbber |
| 3255 | // won't start if the page is loading. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3256 | LoadingStateChanged(contents->tab_contents()); |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 3257 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3258 | // If the tab crashes in the beforeunload or unload handler, it won't be |
| 3259 | // able to ack. But we know we can close it. |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 3260 | registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 3261 | content::Source<TabContents>(contents->tab_contents())); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 3262 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 3263 | registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 3264 | content::Source<TabContents>(contents->tab_contents())); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame^] | 3265 | |
| 3266 | registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
| 3267 | content::Source<TabContents>(contents->tab_contents())); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3268 | } |
| 3269 | |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 3270 | void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3271 | TabContentsWrapper* contents, |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 3272 | int index) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 3273 | fullscreen_controller_->OnTabClosing(contents->tab_contents()); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 3274 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 3275 | content::NOTIFICATION_TAB_CLOSING, |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 3276 | content::Source<NavigationController>( |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 3277 | &contents->tab_contents()->controller()), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 3278 | content::NotificationService::NoDetails()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3279 | |
| 3280 | // Sever the TabContents' connection back to us. |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 3281 | SetAsDelegate(contents, NULL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3282 | } |
| 3283 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3284 | void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3285 | TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3286 | } |
| 3287 | |
[email protected] | 9ac8a24 | 2011-06-07 19:42:52 | [diff] [blame] | 3288 | void Browser::TabDeactivated(TabContentsWrapper* contents) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 3289 | fullscreen_controller_->OnTabDeactivated(contents); |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 3290 | if (instant()) |
[email protected] | 3e48128 | 2011-10-15 15:39:50 | [diff] [blame] | 3291 | instant()->Hide(); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 3292 | |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 3293 | // Save what the user's currently typing, so it can be restored when we |
| 3294 | // switch back to this tab. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3295 | window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 3296 | } |
| 3297 | |
[email protected] | 3aca95d4 | 2011-05-24 22:06:54 | [diff] [blame] | 3298 | void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, |
| 3299 | TabContentsWrapper* new_contents, |
| 3300 | int index, |
| 3301 | bool user_gesture) { |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 3302 | // On some platforms we want to automatically reload tabs that are |
| 3303 | // killed when the user selects them. |
| 3304 | if (user_gesture && new_contents->tab_contents()->crashed_status() == |
| 3305 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 3306 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 3307 | if (parsed_command_line.HasSwitch(switches::kReloadKilledTabs)) { |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 3308 | Reload(CURRENT_TAB); |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 3309 | return; |
| 3310 | } |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 3311 | } |
| 3312 | |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 3313 | // Discarded tabs always get reloaded. |
| 3314 | if (IsTabDiscarded(index)) { |
| 3315 | Reload(CURRENT_TAB); |
| 3316 | return; |
| 3317 | } |
| 3318 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3319 | // If we have any update pending, do it now. |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 3320 | if (chrome_updater_factory_.HasWeakPtrs() && old_contents) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3321 | ProcessPendingUIUpdates(); |
| 3322 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3323 | // Propagate the profile to the location bar. |
| 3324 | UpdateToolbar(true); |
| 3325 | |
[email protected] | 943d812 | 2010-06-11 02:13:45 | [diff] [blame] | 3326 | // Update reload/stop state. |
[email protected] | f5d978c | 2011-07-21 14:43:51 | [diff] [blame] | 3327 | UpdateReloadStopState(new_contents->tab_contents()->IsLoading(), true); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3328 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3329 | // Update commands to reflect current state. |
| 3330 | UpdateCommandsForTabState(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3331 | |
| 3332 | // Reset the status bubble. |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3333 | StatusBubble* status_bubble = GetStatusBubble(); |
| 3334 | if (status_bubble) { |
| 3335 | status_bubble->Hide(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3336 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3337 | // Show the loading state (if any). |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 3338 | status_bubble->SetStatus( |
| 3339 | GetSelectedTabContentsWrapper()->core_tab_helper()->GetStatusText()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3340 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3341 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 3342 | if (HasFindBarController()) { |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 3343 | find_bar_controller_->ChangeTabContents(new_contents); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 3344 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 3345 | } |
| 3346 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3347 | // Update sessions. Don't force creation of sessions. If sessions doesn't |
| 3348 | // exist, the change will be picked up by sessions when created. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3349 | SessionService* session_service = |
| 3350 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 3351 | if (session_service && !tab_handler_->GetTabStripModel()->closing_all()) { |
| 3352 | session_service->SetSelectedTabInWindow( |
| 3353 | session_id(), tab_handler_->GetTabStripModel()->active_index()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3354 | } |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 3355 | |
| 3356 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3357 | } |
| 3358 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3359 | void Browser::TabMoved(TabContentsWrapper* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3360 | int from_index, |
[email protected] | 1a242c3 | 2010-02-02 21:20:54 | [diff] [blame] | 3361 | int to_index) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3362 | DCHECK(from_index >= 0 && to_index >= 0); |
| 3363 | // Notify the history service. |
| 3364 | SyncHistoryWithTabs(std::min(from_index, to_index)); |
| 3365 | } |
| 3366 | |
[email protected] | da25dd5 | 2011-01-11 19:06:30 | [diff] [blame] | 3367 | void Browser::TabReplacedAt(TabStripModel* tab_strip_model, |
| 3368 | TabContentsWrapper* old_contents, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3369 | TabContentsWrapper* new_contents, |
[email protected] | 8a34e660 | 2010-10-02 17:29:43 | [diff] [blame] | 3370 | int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3371 | TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); |
| 3372 | TabInsertedAt(new_contents, index, |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 3373 | (index == tab_handler_->GetTabStripModel()->active_index())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3374 | |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 3375 | int entry_count = new_contents->tab_contents()->controller().entry_count(); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3376 | if (entry_count > 0) { |
| 3377 | // Send out notification so that observers are updated appropriately. |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 3378 | new_contents->tab_contents()->controller().NotifyEntryChanged( |
| 3379 | new_contents->tab_contents()->controller().GetEntryAtIndex( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 3380 | entry_count - 1), |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3381 | entry_count - 1); |
| 3382 | } |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 3383 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3384 | SessionService* session_service = |
| 3385 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 3386 | if (session_service) { |
| 3387 | // The new_contents may end up with a different navigation stack. Force |
| 3388 | // the session service to update itself. |
| 3389 | session_service->TabRestored( |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 3390 | new_contents, tab_handler_->GetTabStripModel()->IsTabPinned(index)); |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 3391 | } |
[email protected] | 2914600d | 2011-01-31 23:25:14 | [diff] [blame] | 3392 | |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 3393 | content::DevToolsManager::GetInstance()->TabReplaced( |
| 3394 | old_contents->tab_contents(), new_contents->tab_contents()); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 3395 | } |
| 3396 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3397 | void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 3398 | SessionService* session_service = |
| 3399 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 3400 | if (session_service) { |
| 3401 | session_service->SetPinnedState( |
| 3402 | session_id(), |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 3403 | GetTabContentsWrapperAt(index)->restore_tab_helper()->session_id(), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3404 | tab_handler_->GetTabStripModel()->IsTabPinned(index)); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 3405 | } |
| 3406 | } |
| 3407 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3408 | void Browser::TabStripEmpty() { |
| 3409 | // Close the frame after we return to the message loop (not immediately, |
| 3410 | // otherwise it will destroy this object before the stack has a chance to |
| 3411 | // cleanly unwind.) |
| 3412 | // Note: This will be called several times if TabStripEmpty is called several |
| 3413 | // times. This is because it does not close the window if tabs are |
| 3414 | // still present. |
| 3415 | // NOTE: If you change to be immediate (no invokeLater) then you'll need to |
| 3416 | // update BrowserList::CloseAllBrowsers. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 3417 | MessageLoop::current()->PostTask( |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 3418 | FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 3422 | // Browser, content::WebContentsDelegate implementation: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3423 | |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 3424 | TabContents* Browser::OpenURLFromTab(TabContents* source, |
| 3425 | const OpenURLParams& params) { |
| 3426 | browser::NavigateParams nav_params(this, params.url, params.transition); |
| 3427 | nav_params.source_contents = |
| 3428 | tabstrip_model()->GetTabContentsAt( |
| 3429 | tabstrip_model()->GetWrapperIndex(source)); |
[email protected] | cb8fb01a | 2011-12-05 21:01:14 | [diff] [blame] | 3430 | nav_params.referrer = params.referrer; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 3431 | nav_params.disposition = params.disposition; |
| 3432 | nav_params.tabstrip_add_types = TabStripModel::ADD_NONE; |
| 3433 | nav_params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 3434 | nav_params.user_gesture = true; |
| 3435 | nav_params.override_encoding = params.override_encoding; |
[email protected] | e47ae947 | 2011-10-13 19:48:34 | [diff] [blame] | 3436 | nav_params.is_renderer_initiated = params.is_renderer_initiated; |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 3437 | nav_params.transferred_global_request_id = |
| 3438 | params.transferred_global_request_id; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 3439 | browser::Navigate(&nav_params); |
| 3440 | |
| 3441 | return nav_params.target_contents ? |
| 3442 | nav_params.target_contents->tab_contents() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | void Browser::NavigationStateChanged(const TabContents* source, |
| 3446 | unsigned changed_flags) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3447 | // Only update the UI when something visible has changed. |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 3448 | if (changed_flags) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3449 | ScheduleUIUpdate(source, changed_flags); |
| 3450 | |
[email protected] | 83c2e23 | 2011-10-07 21:36:46 | [diff] [blame] | 3451 | // We can synchronously update commands since they will only change once per |
| 3452 | // navigation, so we don't have to worry about flickering. We do, however, |
| 3453 | // need to update the command state early on load to always present usable |
| 3454 | // actions in the face of slow-to-commit pages. |
| 3455 | if (changed_flags & (TabContents::INVALIDATE_URL | |
| 3456 | TabContents::INVALIDATE_LOAD)) |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3457 | UpdateCommandsForTabState(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3458 | } |
| 3459 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3460 | void Browser::AddNewContents(TabContents* source, |
| 3461 | TabContents* new_contents, |
| 3462 | WindowOpenDisposition disposition, |
| 3463 | const gfx::Rect& initial_pos, |
| 3464 | bool user_gesture) { |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3465 | // No code for this yet. |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3466 | DCHECK(disposition != SAVE_TO_DISK); |
| 3467 | // Can't create a new contents for the current tab - invalid case. |
| 3468 | DCHECK(disposition != CURRENT_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3469 | |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3470 | TabContentsWrapper* source_wrapper = NULL; |
| 3471 | BlockedContentTabHelper* source_blocked_content = NULL; |
[email protected] | ad1be159 | 2011-04-27 14:14:45 | [diff] [blame] | 3472 | TabContentsWrapper* new_wrapper = |
| 3473 | TabContentsWrapper::GetCurrentWrapperForContents(new_contents); |
| 3474 | if (!new_wrapper) |
| 3475 | new_wrapper = new TabContentsWrapper(new_contents); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3476 | if (source) { |
| 3477 | source_wrapper = TabContentsWrapper::GetCurrentWrapperForContents(source); |
| 3478 | source_blocked_content = source_wrapper->blocked_content_tab_helper(); |
| 3479 | } |
| 3480 | |
| 3481 | if (source_wrapper) { |
| 3482 | // Handle blocking of all contents. |
| 3483 | if (source_blocked_content->all_contents_blocked()) { |
| 3484 | source_blocked_content->AddTabContents(new_wrapper, |
| 3485 | disposition, |
| 3486 | initial_pos, |
| 3487 | user_gesture); |
| 3488 | return; |
| 3489 | } |
| 3490 | |
| 3491 | // Handle blocking of popups. |
| 3492 | if ((disposition == NEW_POPUP) && !user_gesture && |
| 3493 | !CommandLine::ForCurrentProcess()->HasSwitch( |
| 3494 | switches::kDisablePopupBlocking)) { |
| 3495 | // Unrequested popups from normal pages are constrained unless they're in |
| 3496 | // the whitelist. The popup owner will handle checking this. |
[email protected] | 393c0ed0 | 2011-04-22 14:55:36 | [diff] [blame] | 3497 | GetConstrainingContentsWrapper(source_wrapper)-> |
| 3498 | blocked_content_tab_helper()-> |
| 3499 | AddPopup(new_wrapper, initial_pos, user_gesture); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3500 | return; |
| 3501 | } |
| 3502 | |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 3503 | new_contents->GetRenderViewHost()->DisassociateFromPopupCount(); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3504 | } |
| 3505 | |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3506 | browser::NavigateParams params(this, new_wrapper); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3507 | params.source_contents = |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3508 | source ? tabstrip_model()->GetTabContentsAt( |
| 3509 | tabstrip_model()->GetWrapperIndex(source)) |
| 3510 | : NULL; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3511 | params.disposition = disposition; |
| 3512 | params.window_bounds = initial_pos; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 3513 | params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 3514 | params.user_gesture = user_gesture; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3515 | browser::Navigate(¶ms); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3516 | } |
| 3517 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3518 | void Browser::ActivateContents(TabContents* contents) { |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 3519 | tab_handler_->GetTabStripModel()->ActivateTabAt( |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3520 | tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), false); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 3521 | window_->Activate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3522 | } |
| 3523 | |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 3524 | void Browser::DeactivateContents(TabContents* contents) { |
| 3525 | window_->Deactivate(); |
| 3526 | } |
| 3527 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3528 | void Browser::LoadingStateChanged(TabContents* source) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3529 | window_->UpdateLoadingAnimations( |
| 3530 | tab_handler_->GetTabStripModel()->TabsAreLoading()); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 3531 | window_->UpdateTitleBar(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3532 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3533 | TabContents* selected_contents = GetSelectedTabContents(); |
| 3534 | if (source == selected_contents) { |
[email protected] | f5d978c | 2011-07-21 14:43:51 | [diff] [blame] | 3535 | bool is_loading = source->IsLoading(); |
| 3536 | UpdateReloadStopState(is_loading, false); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 3537 | if (GetStatusBubble()) { |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 3538 | GetStatusBubble()->SetStatus( |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 3539 | GetSelectedTabContentsWrapper()->core_tab_helper()->GetStatusText()); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 3540 | } |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3541 | |
[email protected] | f5d978c | 2011-07-21 14:43:51 | [diff] [blame] | 3542 | if (!is_loading && pending_web_app_action_ == UPDATE_SHORTCUT) { |
[email protected] | 867dff8 | 2010-04-23 21:30:33 | [diff] [blame] | 3543 | // Schedule a shortcut update when web application info is available if |
| 3544 | // last committed entry is not NULL. Last committed entry could be NULL |
| 3545 | // when an interstitial page is injected (e.g. bad https certificate, |
| 3546 | // malware site etc). When this happens, we abort the shortcut update. |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 3547 | NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3548 | if (entry) { |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 3549 | TabContentsWrapper::GetCurrentWrapperForContents(source)-> |
| 3550 | extension_tab_helper()->GetApplicationInfo(entry->page_id()); |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3551 | } else { |
| 3552 | pending_web_app_action_ = NONE; |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3553 | } |
| 3554 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3555 | } |
| 3556 | } |
| 3557 | |
| 3558 | void Browser::CloseContents(TabContents* source) { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 3559 | if (is_attempting_to_close_browser_) { |
| 3560 | // 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] | 3561 | // 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] | 3562 | // will go down the slow shutdown path instead of the fast path of killing |
| 3563 | // all the renderer processes. |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 3564 | ClearUnloadState(source, true); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 3565 | return; |
| 3566 | } |
| 3567 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3568 | int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3569 | if (index == TabStripModel::kNoTab) { |
| 3570 | NOTREACHED() << "CloseContents called for tab not in our strip"; |
| 3571 | return; |
| 3572 | } |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3573 | tab_handler_->GetTabStripModel()->CloseTabContentsAt( |
[email protected] | 0cce15f | 2010-05-21 16:58:39 | [diff] [blame] | 3574 | index, |
| 3575 | TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3576 | } |
| 3577 | |
[email protected] | 15e8abe | 2008-08-20 22:40:40 | [diff] [blame] | 3578 | void Browser::MoveContents(TabContents* source, const gfx::Rect& pos) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3579 | if (!IsPopupOrPanel(source)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3580 | NOTREACHED() << "moving invalid browser type"; |
| 3581 | return; |
| 3582 | } |
[email protected] | e561e20 | 2010-03-24 17:57:12 | [diff] [blame] | 3583 | window_->SetBounds(pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3584 | } |
| 3585 | |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 3586 | void Browser::DetachContents(TabContents* source) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3587 | int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 3588 | if (index >= 0) |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3589 | tab_handler_->GetTabStripModel()->DetachTabContentsAt(index); |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 3590 | } |
| 3591 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3592 | bool Browser::IsPopupOrPanel(const TabContents* source) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3593 | // A non-tabbed BROWSER is an unconstrained popup. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3594 | return is_type_popup() || is_type_panel(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3595 | } |
| 3596 | |
[email protected] | b8595e9 | 2009-11-14 01:18:00 | [diff] [blame] | 3597 | void Browser::ContentsMouseEvent( |
| 3598 | TabContents* source, const gfx::Point& location, bool motion) { |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3599 | if (!GetStatusBubble()) |
| 3600 | return; |
| 3601 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3602 | if (source == GetSelectedTabContents()) { |
[email protected] | b8595e9 | 2009-11-14 01:18:00 | [diff] [blame] | 3603 | GetStatusBubble()->MouseMoved(location, !motion); |
| 3604 | if (!motion) |
[email protected] | 6523305 | 2011-08-22 19:02:48 | [diff] [blame] | 3605 | GetStatusBubble()->SetURL(GURL(), std::string()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3606 | } |
| 3607 | } |
| 3608 | |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 3609 | void Browser::UpdateTargetURL(TabContents* source, int32 page_id, |
| 3610 | const GURL& url) { |
| 3611 | Browser::UpdateTargetURLHelper(source, page_id, url); |
| 3612 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3613 | if (!GetStatusBubble()) |
| 3614 | return; |
| 3615 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3616 | if (source == GetSelectedTabContents()) { |
| 3617 | PrefService* prefs = profile_->GetPrefs(); |
[email protected] | 6523305 | 2011-08-22 19:02:48 | [diff] [blame] | 3618 | GetStatusBubble()->SetURL(url, prefs->GetString(prefs::kAcceptLanguages)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3619 | } |
| 3620 | } |
| 3621 | |
[email protected] | 3a6a3b6 | 2009-05-27 21:36:20 | [diff] [blame] | 3622 | void Browser::UpdateDownloadShelfVisibility(bool visible) { |
[email protected] | 9b032bf | 2009-07-21 17:34:23 | [diff] [blame] | 3623 | if (GetStatusBubble()) |
| 3624 | GetStatusBubble()->UpdateDownloadShelfVisibility(visible); |
[email protected] | 3a6a3b6 | 2009-05-27 21:36:20 | [diff] [blame] | 3625 | } |
| 3626 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3627 | void Browser::ContentsZoomChange(bool zoom_in) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3628 | ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3629 | } |
| 3630 | |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 3631 | void Browser::TabContentsFocused(TabContents* tab_content) { |
| 3632 | window_->TabContentsFocused(tab_content); |
| 3633 | } |
| 3634 | |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 3635 | bool Browser::TakeFocus(bool reverse) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 3636 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 3637 | chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 3638 | content::Source<Browser>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 3639 | content::NotificationService::NoDetails()); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 3640 | return false; |
| 3641 | } |
| 3642 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3643 | bool Browser::IsApplication() const { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3644 | return is_app(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | void Browser::ConvertContentsToApplication(TabContents* contents) { |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 3648 | const GURL& url = contents->controller().GetActiveEntry()->url(); |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 3649 | std::string app_name = web_app::GenerateApplicationNameFromURL(url); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3650 | |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 3651 | DetachContents(contents); |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 3652 | Browser* app_browser = Browser::CreateForApp( |
[email protected] | 5c20924 | 2011-06-06 20:36:17 | [diff] [blame] | 3653 | TYPE_POPUP, app_name, gfx::Rect(), profile_); |
[email protected] | ae2f2a77 | 2011-05-04 16:30:27 | [diff] [blame] | 3654 | TabContentsWrapper* wrapper = |
| 3655 | TabContentsWrapper::GetCurrentWrapperForContents(contents); |
| 3656 | if (!wrapper) |
| 3657 | wrapper = new TabContentsWrapper(contents); |
[email protected] | 75aef12 | 2010-12-06 21:48:32 | [diff] [blame] | 3658 | app_browser->tabstrip_model()->AppendTabContents(wrapper, true); |
| 3659 | |
| 3660 | contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 3661 | contents->GetRenderViewHost()->SyncRendererPrefs(); |
[email protected] | 75aef12 | 2010-12-06 21:48:32 | [diff] [blame] | 3662 | app_browser->window()->Show(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3663 | } |
| 3664 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3665 | void Browser::BeforeUnloadFired(TabContents* tab, |
| 3666 | bool proceed, |
| 3667 | bool* proceed_to_fire_unload) { |
| 3668 | if (!is_attempting_to_close_browser_) { |
| 3669 | *proceed_to_fire_unload = proceed; |
[email protected] | 0cce15f | 2010-05-21 16:58:39 | [diff] [blame] | 3670 | if (!proceed) |
| 3671 | tab->set_closed_by_user_gesture(false); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3672 | return; |
| 3673 | } |
| 3674 | |
| 3675 | if (!proceed) { |
| 3676 | CancelWindowClose(); |
| 3677 | *proceed_to_fire_unload = false; |
[email protected] | 0cce15f | 2010-05-21 16:58:39 | [diff] [blame] | 3678 | tab->set_closed_by_user_gesture(false); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3679 | return; |
| 3680 | } |
| 3681 | |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 3682 | if (RemoveFromSet(&tabs_needing_before_unload_fired_, tab)) { |
[email protected] | 2d46c84 | 2008-11-14 19:24:31 | [diff] [blame] | 3683 | // Now that beforeunload has fired, put the tab on the queue to fire |
| 3684 | // unload. |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 3685 | tabs_needing_unload_fired_.insert(tab); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3686 | ProcessPendingTabs(); |
[email protected] | adf650f | 2008-12-09 16:10:06 | [diff] [blame] | 3687 | // We want to handle firing the unload event ourselves since we want to |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3688 | // fire all the beforeunload events before attempting to fire the unload |
| 3689 | // events should the user cancel closing the browser. |
| 3690 | *proceed_to_fire_unload = false; |
| 3691 | return; |
| 3692 | } |
| 3693 | |
| 3694 | *proceed_to_fire_unload = true; |
| 3695 | } |
| 3696 | |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 3697 | void Browser::SetFocusToLocationBar(bool select_all) { |
[email protected] | 1a38062 | 2009-02-17 17:33:13 | [diff] [blame] | 3698 | // Two differences between this and FocusLocationBar(): |
| 3699 | // (1) This doesn't get recorded in user metrics, since it's called |
| 3700 | // internally. |
| 3701 | // (2) This checks whether the location bar can be focused, and if not, clears |
| 3702 | // the focus. FocusLocationBar() is only reached when the location bar is |
| 3703 | // focusable, but this may be reached at other times, e.g. while in |
| 3704 | // fullscreen mode, where we need to leave focus in a consistent state. |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 3705 | window_->SetFocusToLocationBar(select_all); |
[email protected] | 4bcefee | 2009-01-29 15:57:57 | [diff] [blame] | 3706 | } |
| 3707 | |
[email protected] | 7d5925a | 2009-03-03 02:59:12 | [diff] [blame] | 3708 | void Browser::RenderWidgetShowing() { |
| 3709 | window_->DisableInactiveFrame(); |
| 3710 | } |
[email protected] | a239c3f | 2009-02-17 22:13:19 | [diff] [blame] | 3711 | |
[email protected] | 0a2aeb8 | 2009-05-15 21:52:48 | [diff] [blame] | 3712 | int Browser::GetExtraRenderViewHeight() const { |
| 3713 | return window_->GetExtraRenderViewHeight(); |
| 3714 | } |
| 3715 | |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3716 | namespace { |
| 3717 | |
| 3718 | bool DisplayOldDownloadsUI() { |
| 3719 | return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 3720 | switches::kDownloadsNewUI); |
| 3721 | } |
| 3722 | |
| 3723 | } // anonymous namespace |
| 3724 | |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 3725 | void Browser::OnStartDownload(TabContents* source, |
| 3726 | content::DownloadItem* download) { |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3727 | TabContentsWrapper* wrapper = |
| 3728 | TabContentsWrapper::GetCurrentWrapperForContents(source); |
| 3729 | TabContentsWrapper* constrained = GetConstrainingContentsWrapper(wrapper); |
| 3730 | if (constrained != wrapper) { |
| 3731 | // Download in a constrained popup is shown in the tab that opened it. |
| 3732 | TabContents* constrained_tab = constrained->tab_contents(); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 3733 | constrained_tab->GetDelegate()->OnStartDownload(constrained_tab, download); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3734 | return; |
| 3735 | } |
| 3736 | |
| 3737 | if (!window()) |
| 3738 | return; |
| 3739 | |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3740 | if (DisplayOldDownloadsUI()) { |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 3741 | #if defined(OS_CHROMEOS) && !defined(USE_AURA) |
[email protected] | 603a502a | 2011-12-15 20:18:17 | [diff] [blame] | 3742 | if (ActiveDownloadsUI::ShouldShowPopup(profile_, download)) |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3743 | ActiveDownloadsUI::OpenPopup(profile_); |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 3744 | #else |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3745 | // GetDownloadShelf creates the download shelf if it was not yet created. |
| 3746 | DownloadShelf* shelf = window()->GetDownloadShelf(); |
| 3747 | shelf->AddDownload(new DownloadItemModel(download)); |
| 3748 | // Don't show the animation for "Save file" downloads. |
| 3749 | // For non-theme extensions, we don't show the download animation. |
| 3750 | // Show animation in same window as the download shelf. Download shelf |
| 3751 | // may not be in the same window that initiated the download, e.g. |
| 3752 | // Panels. |
| 3753 | // Don't show the animation if the selected tab is not visible (i.e. the |
| 3754 | // window is minimized, we're in a unit test, etc.). |
| 3755 | TabContents* shelf_tab = shelf->browser()->GetSelectedTabContents(); |
[email protected] | c09a8fd | 2011-11-21 19:54:50 | [diff] [blame] | 3756 | if ((download->GetTotalBytes() > 0) && |
[email protected] | b0cfcee | 2011-10-27 03:55:37 | [diff] [blame] | 3757 | !ChromeDownloadManagerDelegate::IsExtensionDownload(download) && |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3758 | platform_util::IsVisible(shelf_tab->GetNativeView()) && |
| 3759 | ui::Animation::ShouldRenderRichAnimation()) { |
| 3760 | DownloadStartedAnimation::Show(shelf_tab); |
| 3761 | } |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3762 | #endif |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 3763 | } |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3764 | |
| 3765 | // If the download occurs in a new tab, close it. |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 3766 | if (source->controller().IsInitialNavigation() && tab_count() > 1) |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3767 | CloseContents(source); |
| 3768 | } |
| 3769 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 3770 | void Browser::ShowPageInfo(content::BrowserContext* browser_context, |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 3771 | const GURL& url, |
| 3772 | const NavigationEntry::SSLStatus& ssl, |
| 3773 | bool show_history) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 3774 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | bb67833 | 2009-07-21 00:15:50 | [diff] [blame] | 3775 | window()->ShowPageInfo(profile, url, ssl, show_history); |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 3776 | } |
| 3777 | |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 3778 | void Browser::ViewSourceForTab(TabContents* source, const GURL& page_url) { |
| 3779 | DCHECK(source); |
| 3780 | int index = tabstrip_model()->GetWrapperIndex(source); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 3781 | TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
| 3782 | ViewSource(wrapper); |
| 3783 | } |
| 3784 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 3785 | void Browser::ViewSourceForFrame(TabContents* source, |
| 3786 | const GURL& frame_url, |
| 3787 | const std::string& frame_content_state) { |
| 3788 | DCHECK(source); |
| 3789 | int index = tabstrip_model()->GetWrapperIndex(source); |
| 3790 | TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
| 3791 | ViewSource(wrapper, frame_url, frame_content_state); |
| 3792 | } |
| 3793 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 3794 | bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 3795 | bool* is_keyboard_shortcut) { |
[email protected] | 85804b5 | 2011-10-15 06:56:27 | [diff] [blame] | 3796 | // Escape exits tabbed fullscreen mode. |
| 3797 | // TODO(koz): Write a test for this http://crbug.com/100441. |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 3798 | if (event.windowsKeyCode == 27 && |
| 3799 | fullscreen_controller_->HandleUserPressedEscape()) { |
[email protected] | 85804b5 | 2011-10-15 06:56:27 | [diff] [blame] | 3800 | return true; |
| 3801 | } |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 3802 | return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 3803 | } |
[email protected] | 97df4b33 | 2009-10-02 01:25:41 | [diff] [blame] | 3804 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 3805 | void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 3806 | window()->HandleKeyboardEvent(event); |
[email protected] | 97df4b33 | 2009-10-02 01:25:41 | [diff] [blame] | 3807 | } |
| 3808 | |
[email protected] | 14f3408a | 2009-08-31 20:53:53 | [diff] [blame] | 3809 | void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 3810 | browser::ShowTabModalConfirmDialog( |
| 3811 | new RepostFormWarningController(tab_contents), |
| 3812 | TabContentsWrapper::GetCurrentWrapperForContents(tab_contents)); |
[email protected] | 14f3408a | 2009-08-31 20:53:53 | [diff] [blame] | 3813 | } |
| 3814 | |
[email protected] | 579e319 | 2011-03-11 22:37:45 | [diff] [blame] | 3815 | void Browser::ShowContentSettingsPage(ContentSettingsType content_type) { |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 3816 | ShowOptionsTab( |
| 3817 | chrome::kContentSettingsExceptionsSubPage + std::string(kHashMark) + |
| 3818 | ContentSettingsHandler::ContentSettingsTypeToGroupName(content_type)); |
[email protected] | 6354314 | 2010-02-09 23:22:20 | [diff] [blame] | 3819 | } |
| 3820 | |
[email protected] | a3627e6 | 2011-09-07 00:04:57 | [diff] [blame] | 3821 | void Browser::ShowCollectedCookiesDialog(TabContentsWrapper* wrapper) { |
| 3822 | window()->ShowCollectedCookiesDialog(wrapper); |
[email protected] | a503c97c | 2010-07-16 13:05:48 | [diff] [blame] | 3823 | } |
| 3824 | |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 3825 | bool Browser::ShouldAddNavigationToHistory( |
| 3826 | const history::HistoryAddPageArgs& add_page_args, |
[email protected] | 610cbb8 | 2011-10-18 16:35:08 | [diff] [blame] | 3827 | content::NavigationType navigation_type) { |
[email protected] | 2e29d92 | 2009-10-22 22:13:35 | [diff] [blame] | 3828 | // Don't update history if running as app. |
| 3829 | return !IsApplication(); |
| 3830 | } |
| 3831 | |
[email protected] | 80c7b80 | 2011-10-28 19:59:08 | [diff] [blame] | 3832 | void Browser::TabContentsCreated(TabContents* new_contents) { |
| 3833 | // Create a TabContentsWrapper now, so all observers are in place, as the |
| 3834 | // network requests for its initial navigation will start immediately. The |
| 3835 | // TabContents will later be inserted into this browser using |
| 3836 | // Browser::Navigate via AddNewContents. The latter will retrieve the newly |
| 3837 | // created TabContentsWrapper from TabContents object. |
| 3838 | new TabContentsWrapper(new_contents); |
| 3839 | } |
| 3840 | |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 3841 | void Browser::ContentRestrictionsChanged(TabContents* source) { |
| 3842 | UpdateCommandsForContentRestrictionState(); |
| 3843 | } |
| 3844 | |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 3845 | void Browser::RendererUnresponsive(TabContents* source) { |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 3846 | // Ignore hangs if print preview is open. |
| 3847 | TabContentsWrapper* source_wrapper = |
| 3848 | TabContentsWrapper::GetCurrentWrapperForContents(source); |
| 3849 | if (source_wrapper) { |
| 3850 | printing::PrintPreviewTabController* controller = |
| 3851 | printing::PrintPreviewTabController::GetInstance(); |
| 3852 | if (controller) { |
| 3853 | TabContentsWrapper* preview_tab = |
| 3854 | controller->GetPrintPreviewForTab(source_wrapper); |
| 3855 | if (preview_tab && preview_tab != source_wrapper) { |
| 3856 | return; |
| 3857 | } |
| 3858 | } |
| 3859 | } |
| 3860 | |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 3861 | browser::ShowHungRendererDialog(source); |
| 3862 | } |
| 3863 | |
| 3864 | void Browser::RendererResponsive(TabContents* source) { |
| 3865 | browser::HideHungRendererDialog(source); |
| 3866 | } |
| 3867 | |
| 3868 | void Browser::WorkerCrashed(TabContents* source) { |
| 3869 | TabContentsWrapper* wrapper = |
| 3870 | TabContentsWrapper::GetCurrentWrapperForContents(source); |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 3871 | InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); |
| 3872 | infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 3873 | infobar_helper, |
| 3874 | NULL, |
| 3875 | l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 3876 | true)); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 3877 | } |
| 3878 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 3879 | void Browser::DidNavigateMainFramePostCommit(TabContents* tab) { |
| 3880 | if (tab == GetSelectedTabContents()) |
| 3881 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 3882 | } |
| 3883 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 3884 | void Browser::DidNavigateToPendingEntry(TabContents* tab) { |
| 3885 | if (tab == GetSelectedTabContents()) |
| 3886 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 3887 | } |
| 3888 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 3889 | content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { |
| 3890 | return GetJavaScriptDialogCreatorInstance(); |
| 3891 | } |
| 3892 | |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 3893 | void Browser::RunFileChooser(TabContents* tab, |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 3894 | const content::FileChooserParams& params) { |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 3895 | RunFileChooserHelper(tab, params); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | void Browser::EnumerateDirectory(TabContents* tab, int request_id, |
| 3899 | const FilePath& path) { |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 3900 | EnumerateDirectoryHelper(tab, request_id, path); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 3901 | } |
| 3902 | |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 3903 | void Browser::ToggleFullscreenModeForTab(TabContents* tab, |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 3904 | bool enter_fullscreen) { |
| 3905 | fullscreen_controller_->ToggleFullscreenModeForTab(tab, enter_fullscreen); |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 3906 | } |
| 3907 | |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 3908 | bool Browser::IsFullscreenForTab(const TabContents* tab) const { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 3909 | return fullscreen_controller_->IsFullscreenForTab(tab); |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 3910 | } |
| 3911 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 3912 | void Browser::JSOutOfMemory(TabContents* tab) { |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 3913 | JSOutOfMemoryHelper(tab); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | void Browser::RegisterProtocolHandler(TabContents* tab, |
| 3917 | const std::string& protocol, |
| 3918 | const GURL& url, |
| 3919 | const string16& title) { |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 3920 | RegisterProtocolHandlerHelper(tab, protocol, url, title); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | void Browser::RegisterIntentHandler(TabContents* tab, |
| 3924 | const string16& action, |
| 3925 | const string16& type, |
| 3926 | const string16& href, |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 3927 | const string16& title, |
| 3928 | const string16& disposition) { |
| 3929 | RegisterIntentHandlerHelper(tab, action, type, href, title, disposition); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 3930 | } |
| 3931 | |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 3932 | void Browser::WebIntentDispatch( |
| 3933 | TabContents* tab, content::WebIntentsDispatcher* intents_dispatcher) { |
[email protected] | 828e61af | 2011-09-14 19:45:06 | [diff] [blame] | 3934 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) |
| 3935 | return; |
| 3936 | |
| 3937 | TabContentsWrapper* tcw = |
| 3938 | TabContentsWrapper::GetCurrentWrapperForContents(tab); |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 3939 | tcw->web_intent_picker_controller()->SetIntentsDispatcher(intents_dispatcher); |
[email protected] | ada02b31 | 2011-12-01 21:54:53 | [diff] [blame] | 3940 | tcw->web_intent_picker_controller()->ShowDialog( |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 3941 | this, |
| 3942 | intents_dispatcher->GetIntent().action, |
| 3943 | intents_dispatcher->GetIntent().type); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | void Browser::FindReply(TabContents* tab, |
| 3947 | int request_id, |
| 3948 | int number_of_matches, |
| 3949 | const gfx::Rect& selection_rect, |
| 3950 | int active_match_ordinal, |
| 3951 | bool final_update) { |
| 3952 | FindReplyHelper(tab, request_id, number_of_matches, selection_rect, |
| 3953 | active_match_ordinal, final_update); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 3954 | } |
| 3955 | |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 3956 | void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { |
| 3957 | CrashedPluginHelper(tab, plugin_path); |
| 3958 | } |
| 3959 | |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 3960 | void Browser::UpdatePreferredSize(TabContents* source, |
| 3961 | const gfx::Size& pref_size) { |
| 3962 | window_->UpdatePreferredSize(source, pref_size); |
| 3963 | } |
| 3964 | |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 3965 | void Browser::RequestToLockMouse(TabContents* tab) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 3966 | fullscreen_controller_->RequestToLockMouse(tab); |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 3967 | } |
| 3968 | |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 3969 | void Browser::LostMouseLock() { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 3970 | fullscreen_controller_->LostMouseLock(); |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 3971 | } |
| 3972 | |
| 3973 | void Browser::OnAcceptFullscreenPermission( |
| 3974 | const GURL& url, |
| 3975 | FullscreenExitBubbleType bubble_type) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 3976 | fullscreen_controller_->OnAcceptFullscreenPermission(url, bubble_type); |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 3980 | fullscreen_controller_->OnDenyFullscreenPermission(bubble_type); |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 3981 | } |
| 3982 | |
[email protected] | fc9bf18f | 2011-10-22 00:41:17 | [diff] [blame] | 3983 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3984 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 3985 | // Browser, CoreTabHelperDelegate implementation: |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 3986 | |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 3987 | void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
| 3988 | int32 page_id) { |
| 3989 | if (GetSelectedTabContentsWrapper() != source) |
| 3990 | return; |
| 3991 | |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 3992 | NavigationEntry* entry = |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 3993 | source->tab_contents()->controller().GetLastCommittedEntry(); |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 3994 | if (!entry || (entry->page_id() != page_id)) |
| 3995 | return; |
| 3996 | |
| 3997 | switch (pending_web_app_action_) { |
| 3998 | case CREATE_SHORTCUT: { |
| 3999 | window()->ShowCreateWebAppShortcutsDialog(source); |
| 4000 | break; |
| 4001 | } |
| 4002 | case UPDATE_SHORTCUT: { |
| 4003 | web_app::UpdateShortcutForTabContents(source); |
| 4004 | break; |
| 4005 | } |
| 4006 | default: |
| 4007 | NOTREACHED(); |
| 4008 | break; |
| 4009 | } |
| 4010 | |
| 4011 | pending_web_app_action_ = NONE; |
| 4012 | } |
| 4013 | |
| 4014 | void Browser::OnInstallApplication(TabContentsWrapper* source, |
| 4015 | const WebApplicationInfo& web_app) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 4016 | ExtensionService* extension_service = profile()->GetExtensionService(); |
| 4017 | if (!extension_service) |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 4018 | return; |
| 4019 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4020 | scoped_refptr<CrxInstaller> installer(CrxInstaller::Create( |
| 4021 | extension_service, |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 4022 | extension_service->show_extensions_prompts() ? |
| 4023 | new ExtensionInstallUI(profile()) : NULL)); |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 4024 | installer->InstallWebApp(web_app); |
| 4025 | } |
| 4026 | |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 4027 | /////////////////////////////////////////////////////////////////////////////// |
| 4028 | // Browser, SearchEngineTabHelperDelegate implementation: |
| 4029 | |
[email protected] | 9b0e63e5 | 2011-10-12 23:08:10 | [diff] [blame] | 4030 | void Browser::ConfirmSetDefaultSearchProvider(TabContents* tab_contents, |
| 4031 | TemplateURL* template_url, |
| 4032 | Profile* profile) { |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 4033 | window()->ConfirmSetDefaultSearchProvider(tab_contents, template_url, |
[email protected] | 9b0e63e5 | 2011-10-12 23:08:10 | [diff] [blame] | 4034 | profile); |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | void Browser::ConfirmAddSearchProvider(const TemplateURL* template_url, |
| 4038 | Profile* profile) { |
[email protected] | 8f23e2b | 2011-11-03 17:30:41 | [diff] [blame] | 4039 | #if defined(OS_CHROMEOS) || defined(USE_AURA) |
| 4040 | // Use a WebUI implementation of the dialog. |
| 4041 | browser::ConfirmAddSearchProvider(template_url, profile); |
| 4042 | #else |
| 4043 | // TODO(rbyers): Remove the IsMoreWebUI check and (ideally) all #ifdefs once |
| 4044 | // we can select exactly one version of this dialog to use for each platform |
| 4045 | // at build time. |
| 4046 | if (ChromeWebUI::IsMoreWebUI()) |
[email protected] | 02b07597 | 2011-10-19 18:39:00 | [diff] [blame] | 4047 | browser::ConfirmAddSearchProvider(template_url, profile); |
[email protected] | 8f23e2b | 2011-11-03 17:30:41 | [diff] [blame] | 4048 | else |
| 4049 | // Platform-specific implementation of the dialog. |
[email protected] | 02b07597 | 2011-10-19 18:39:00 | [diff] [blame] | 4050 | window()->ConfirmAddSearchProvider(template_url, profile); |
[email protected] | 8f23e2b | 2011-11-03 17:30:41 | [diff] [blame] | 4051 | #endif |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 4052 | } |
| 4053 | |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 4054 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 4055 | // Browser, BlockedContentTabHelperDelegate implementation: |
| 4056 | |
[email protected] | 393c0ed0 | 2011-04-22 14:55:36 | [diff] [blame] | 4057 | TabContentsWrapper* Browser::GetConstrainingContentsWrapper( |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 4058 | TabContentsWrapper* source) { |
| 4059 | return source; |
| 4060 | } |
| 4061 | |
| 4062 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 4063 | // Browser, BookmarkTabHelperDelegate implementation: |
[email protected] | 52cc59b | 2011-05-06 14:42:38 | [diff] [blame] | 4064 | |
| 4065 | void Browser::URLStarredChanged(TabContentsWrapper* source, bool starred) { |
| 4066 | if (source == GetSelectedTabContentsWrapper()) |
| 4067 | window_->SetStarredState(starred); |
| 4068 | } |
| 4069 | |
| 4070 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4071 | // Browser, SelectFileDialog::Listener implementation: |
| 4072 | |
[email protected] | 561abe6 | 2009-04-06 18:08:34 | [diff] [blame] | 4073 | void Browser::FileSelected(const FilePath& path, int index, void* params) { |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 4074 | profile_->set_last_selected_directory(path.DirName()); |
[email protected] | 72cbd32 | 2009-04-07 10:17:12 | [diff] [blame] | 4075 | GURL file_url = net::FilePathToFileURL(path); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4076 | if (!file_url.is_empty()) |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 4077 | OpenURL(file_url, GURL(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4081 | // Browser, content::NotificationObserver implementation: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4082 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4083 | void Browser::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4084 | const content::NotificationSource& source, |
| 4085 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4086 | switch (type) { |
| 4087 | case content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED: |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 4088 | if (is_attempting_to_close_browser_) { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4089 | // Pass in false so that we delay processing. We need to delay the |
| 4090 | // processing as it may close the tab, which is currently on the call |
| 4091 | // stack above us. |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4092 | ClearUnloadState(content::Source<TabContents>(source).ptr(), false); |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 4093 | } |
| 4094 | break; |
| 4095 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4096 | case content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED: |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 4097 | // 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] | 4098 | // bar to reflect the new state. Note that it's possible for the selected |
| 4099 | // tab contents to be NULL. This is because we listen for all sources |
| 4100 | // (NavigationControllers) for convenience, so the notification could |
| 4101 | // actually be for a different window while we're doing asynchronous |
| 4102 | // closing of this one. |
| 4103 | if (GetSelectedTabContents() && |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 4104 | &GetSelectedTabContents()->controller() == |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4105 | content::Source<NavigationController>(source).ptr()) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4106 | UpdateToolbar(false); |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 4107 | break; |
| 4108 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4109 | case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: { |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 4110 | // Show the UI if the extension was disabled for escalated permissions. |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4111 | Profile* profile = content::Source<Profile>(source).ptr(); |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 4112 | if (profile_->IsSameProfile(profile)) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4113 | ExtensionService* service = profile->GetExtensionService(); |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 4114 | DCHECK(service); |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4115 | const Extension* extension = |
| 4116 | content::Details<const Extension>(details).ptr(); |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 4117 | if (service->extension_prefs()->DidExtensionEscalatePermissions( |
| 4118 | extension->id())) |
| 4119 | ShowExtensionDisabledUI(service, profile_, extension); |
| 4120 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 4121 | break; |
| 4122 | } |
| 4123 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4124 | case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 4125 | if (window()->GetLocationBar()) |
| 4126 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 57f71b9 | 2009-09-11 19:31:38 | [diff] [blame] | 4127 | |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 4128 | // Close any tabs from the unloaded extension, unless it's terminated, |
| 4129 | // in which case let the sad tabs remain. |
| 4130 | if (content::Details<UnloadedExtensionInfo>(details)->reason != |
| 4131 | extension_misc::UNLOAD_REASON_TERMINATE) { |
| 4132 | const Extension* extension = |
| 4133 | content::Details<UnloadedExtensionInfo>(details)->extension; |
| 4134 | TabStripModel* model = tab_handler_->GetTabStripModel(); |
| 4135 | for (int i = model->count() - 1; i >= 0; --i) { |
| 4136 | TabContents* tc = model->GetTabContentsAt(i)->tab_contents(); |
| 4137 | bool close_tab_contents = |
| 4138 | tc->GetURL().SchemeIs(chrome::kExtensionScheme) && |
| 4139 | tc->GetURL().host() == extension->id(); |
| 4140 | // We want to close all panels originated by the unloaded extension. |
| 4141 | close_tab_contents = close_tab_contents || |
| 4142 | (type_ == TYPE_PANEL && |
| 4143 | (web_app::GetExtensionIdFromApplicationName(app_name_) == |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 4144 | extension->id())); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 4145 | if (close_tab_contents) { |
| 4146 | CloseTabContents(tc); |
| 4147 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4148 | } |
| 4149 | } |
| 4150 | break; |
| 4151 | } |
| 4152 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4153 | case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4154 | Profile* profile = content::Source<Profile>(source).ptr(); |
[email protected] | fe8944f | 2011-08-30 17:47:32 | [diff] [blame] | 4155 | if (profile_->IsSameProfile(profile) && window()->GetLocationBar()) |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 4156 | window()->GetLocationBar()->InvalidatePageActions(); |
[email protected] | 371ed7a | 2009-08-25 15:22:46 | [diff] [blame] | 4157 | break; |
| 4158 | } |
| 4159 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4160 | case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: |
| 4161 | case chrome::NOTIFICATION_EXTENSION_LOADED: |
[email protected] | 1797f4a | 2011-08-30 18:00:28 | [diff] [blame] | 4162 | // During window creation on Windows we may end up calling into |
| 4163 | // SHAppBarMessage, which internally spawns a nested message loop. This |
| 4164 | // makes it possible for us to end up here before window creation has |
| 4165 | // completed,at which point window_ is NULL. See 94752 for details. |
| 4166 | if (window() && window()->GetLocationBar()) |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 4167 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 4168 | break; |
[email protected] | ad0c2e1b | 2010-01-30 00:00:10 | [diff] [blame] | 4169 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4170 | case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 4171 | window()->UserChangedTheme(); |
| 4172 | break; |
| 4173 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4174 | case chrome::NOTIFICATION_PREF_CHANGED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4175 | const std::string& pref_name = |
| 4176 | *content::Details<std::string>(details).ptr(); |
[email protected] | 3cf345b | 2011-10-06 17:51:25 | [diff] [blame] | 4177 | if (pref_name == prefs::kPrintingEnabled) { |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 4178 | UpdatePrintingState(GetContentRestrictionsForSelectedTab()); |
[email protected] | 3819f2ee | 2011-08-21 09:44:38 | [diff] [blame] | 4179 | } else if (pref_name == prefs::kInstantEnabled || |
| 4180 | pref_name == prefs::kMetricsReportingEnabled || |
| 4181 | pref_name == prefs::kSearchSuggestEnabled) { |
[email protected] | 73de26a | 2010-10-17 03:23:25 | [diff] [blame] | 4182 | if (!InstantController::IsEnabled(profile())) { |
| 4183 | if (instant()) { |
| 4184 | instant()->DestroyPreviewContents(); |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 4185 | instant_.reset(); |
| 4186 | instant_unload_handler_.reset(); |
[email protected] | 73de26a | 2010-10-17 03:23:25 | [diff] [blame] | 4187 | } |
| 4188 | } else { |
| 4189 | CreateInstantIfNecessary(); |
| 4190 | } |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 4191 | } else if (pref_name == prefs::kIncognitoModeAvailability) { |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4192 | UpdateCommandsForIncognitoAvailability(); |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 4193 | } else if (pref_name == prefs::kDevToolsDisabled) { |
| 4194 | UpdateCommandsForDevTools(); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4195 | if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 4196 | content::DevToolsManager::GetInstance()->CloseAllClientHosts(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4197 | } else if (pref_name == prefs::kEditBookmarksEnabled) { |
| 4198 | UpdateCommandsForBookmarkEditing(); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 4199 | } else if (pref_name == prefs::kShowBookmarkBar) { |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 4200 | UpdateCommandsForBookmarkBar(); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 4201 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 4202 | } else if (pref_name == prefs::kHomePage) { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4203 | PrefService* pref_service = content::Source<PrefService>(source).ptr(); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 4204 | MarkHomePageAsChanged(pref_service); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4205 | } else if (pref_name == prefs::kAllowFileSelectionDialogs) { |
| 4206 | UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); |
| 4207 | UpdateOpenFileState(); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 4208 | } else { |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 4209 | NOTREACHED(); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 4210 | } |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 4211 | break; |
| 4212 | } |
| 4213 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4214 | case chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4215 | TabContents* tab_contents = content::Source<TabContents>(source).ptr(); |
[email protected] | 9a9a9e2 | 2011-05-13 22:20:35 | [diff] [blame] | 4216 | if (tab_contents == GetSelectedTabContents()) { |
| 4217 | LocationBar* location_bar = window()->GetLocationBar(); |
| 4218 | if (location_bar) |
| 4219 | location_bar->UpdateContentSettingsIcons(); |
| 4220 | } |
| 4221 | break; |
| 4222 | } |
| 4223 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4224 | case content::NOTIFICATION_INTERSTITIAL_ATTACHED: |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 4225 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame^] | 4226 | UpdateCommandsForTabState(); |
| 4227 | break; |
| 4228 | |
| 4229 | case content::NOTIFICATION_INTERSTITIAL_DETACHED: |
| 4230 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
| 4231 | UpdateCommandsForTabState(); |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 4232 | break; |
| 4233 | |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 4234 | default: |
| 4235 | NOTREACHED() << "Got a notification we didn't register for."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4236 | } |
| 4237 | } |
| 4238 | |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 4239 | /////////////////////////////////////////////////////////////////////////////// |
| 4240 | // Browser, ProfileSyncServiceObserver implementation: |
| 4241 | |
| 4242 | void Browser::OnStateChanged() { |
| 4243 | DCHECK(profile_->GetProfileSyncService()); |
| 4244 | |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4245 | const bool show_main_ui = IsShowingMainUI(window_->IsFullscreen()); |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 4246 | command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, |
[email protected] | 49385da69 | 2011-08-05 04:03:39 | [diff] [blame] | 4247 | show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible()); |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 4248 | } |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 4249 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4250 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 4251 | // Browser, InstantDelegate implementation: |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4252 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4253 | void Browser::ShowInstant(TabContentsWrapper* preview_contents) { |
| 4254 | DCHECK(instant_->tab_contents() == GetSelectedTabContentsWrapper()); |
[email protected] | e3690ed | 2011-03-25 20:25:14 | [diff] [blame] | 4255 | window_->ShowInstant(preview_contents); |
[email protected] | 42f027fb | 2011-10-27 16:37:48 | [diff] [blame] | 4256 | |
| 4257 | GetSelectedTabContents()->HideContents(); |
| 4258 | preview_contents->tab_contents()->ShowContents(); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4259 | } |
| 4260 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 4261 | void Browser::HideInstant() { |
[email protected] | 3e48128 | 2011-10-15 15:39:50 | [diff] [blame] | 4262 | window_->HideInstant(); |
[email protected] | 42f027fb | 2011-10-27 16:37:48 | [diff] [blame] | 4263 | if (GetSelectedTabContents()) |
| 4264 | GetSelectedTabContents()->ShowContents(); |
| 4265 | if (instant_->GetPreviewContents()) |
| 4266 | instant_->GetPreviewContents()->tab_contents()->HideContents(); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4267 | } |
| 4268 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4269 | void Browser::CommitInstant(TabContentsWrapper* preview_contents) { |
| 4270 | TabContentsWrapper* tab_contents = instant_->tab_contents(); |
| 4271 | int index = |
| 4272 | tab_handler_->GetTabStripModel()->GetIndexOfTabContents(tab_contents); |
| 4273 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4274 | // TabStripModel takes ownership of preview_contents. |
[email protected] | 4303234 | 2011-03-21 14:10:31 | [diff] [blame] | 4275 | tab_handler_->GetTabStripModel()->ReplaceTabContentsAt( |
| 4276 | index, preview_contents); |
| 4277 | // InstantUnloadHandler takes ownership of tab_contents. |
| 4278 | instant_unload_handler_->RunUnloadListenersOrDestroy(tab_contents, index); |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 4279 | |
| 4280 | GURL url = preview_contents->tab_contents()->GetURL(); |
[email protected] | 6e37fe3 | 2011-03-02 09:06:52 | [diff] [blame] | 4281 | DCHECK(profile_->GetExtensionService()); |
| 4282 | if (profile_->GetExtensionService()->IsInstalledApp(url)) { |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 4283 | UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, |
| 4284 | extension_misc::APP_LAUNCH_OMNIBOX_INSTANT, |
| 4285 | extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 4286 | } |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4287 | } |
| 4288 | |
[email protected] | c98fd5d8 | 2011-05-04 15:20:09 | [diff] [blame] | 4289 | void Browser::SwapTabContents(TabContentsWrapper* old_tab_contents, |
| 4290 | TabContentsWrapper* new_tab_contents) { |
| 4291 | int index = |
| 4292 | tab_handler_->GetTabStripModel()->GetIndexOfTabContents(old_tab_contents); |
[email protected] | 71b5d24 | 2011-04-30 02:27:20 | [diff] [blame] | 4293 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | c98fd5d8 | 2011-05-04 15:20:09 | [diff] [blame] | 4294 | tab_handler_->GetTabStripModel()->ReplaceTabContentsAt(index, |
| 4295 | new_tab_contents); |
[email protected] | 71b5d24 | 2011-04-30 02:27:20 | [diff] [blame] | 4296 | } |
| 4297 | |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 4298 | void Browser::SetTabContentBlocked(TabContentsWrapper* wrapper, bool blocked) { |
| 4299 | int index = tabstrip_model()->GetIndexOfTabContents(wrapper); |
| 4300 | if (index == TabStripModel::kNoTab) { |
| 4301 | NOTREACHED(); |
| 4302 | return; |
| 4303 | } |
| 4304 | tabstrip_model()->SetTabBlocked(index, blocked); |
[email protected] | 43401bc0 | 2011-10-13 20:43:43 | [diff] [blame] | 4305 | UpdatePrintingState(wrapper->tab_contents()->content_restrictions()); |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 4306 | } |
| 4307 | |
[email protected] | 33b8b8e | 2011-03-15 14:51:55 | [diff] [blame] | 4308 | void Browser::SetSuggestedText(const string16& text, |
| 4309 | InstantCompleteBehavior behavior) { |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 4310 | if (window()->GetLocationBar()) |
| 4311 | window()->GetLocationBar()->SetSuggestedText(text, behavior); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4312 | } |
| 4313 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 4314 | gfx::Rect Browser::GetInstantBounds() { |
| 4315 | return window()->GetInstantBounds(); |
[email protected] | 46fe8e9 | 2010-09-22 03:32:47 | [diff] [blame] | 4316 | } |
| 4317 | |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 4318 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 4319 | // Browser, protected: |
| 4320 | |
| 4321 | BrowserWindow* Browser::CreateBrowserWindow() { |
[email protected] | 517d574 | 2011-11-14 16:50:21 | [diff] [blame] | 4322 | #if !defined(OS_CHROMEOS) || defined(USE_AURA) |
[email protected] | d5c1406 | 2011-10-27 00:02:13 | [diff] [blame] | 4323 | if (type_ == TYPE_PANEL) { |
[email protected] | 011396a | 2011-04-13 23:35:28 | [diff] [blame] | 4324 | return PanelManager::GetInstance()->CreatePanel(this); |
[email protected] | d5c1406 | 2011-10-27 00:02:13 | [diff] [blame] | 4325 | } |
| 4326 | #endif |
[email protected] | 011396a | 2011-04-13 23:35:28 | [diff] [blame] | 4327 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 4328 | return BrowserWindow::CreateBrowserWindow(this); |
| 4329 | } |
| 4330 | |
| 4331 | |
| 4332 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4333 | // Browser, Command and state updating (private): |
| 4334 | |
| 4335 | void Browser::InitCommandState() { |
| 4336 | // All browser commands whose state isn't set automagically some other way |
| 4337 | // (like Back & Forward with initial page load) must have their state |
| 4338 | // initialized here, otherwise they will be forever disabled. |
| 4339 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4340 | // Navigation commands |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4341 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 4342 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4343 | |
| 4344 | // Window management commands |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4345 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); |
| 4346 | command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); |
| 4347 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); |
| 4348 | command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 4349 | command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4350 | command_updater_.UpdateCommandEnabled(IDC_EXIT, true); |
[email protected] | cdc05ec | 2011-05-18 15:15:59 | [diff] [blame] | 4351 | command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4352 | |
| 4353 | // Page-related commands |
[email protected] | 89d6e6e | 2009-12-03 23:06:51 | [diff] [blame] | 4354 | command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4355 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true); |
| 4356 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true); |
| 4357 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true); |
| 4358 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88591, true); |
| 4359 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252, true); |
| 4360 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_GBK, true); |
| 4361 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_GB18030, true); |
| 4362 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5HKSCS, true); |
| 4363 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5, true); |
| 4364 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_THAI, true); |
| 4365 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOREAN, true); |
| 4366 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS, true); |
| 4367 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP, true); |
| 4368 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_EUCJP, true); |
| 4369 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885915, true); |
| 4370 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH, true); |
| 4371 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88592, true); |
| 4372 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250, true); |
| 4373 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88595, true); |
| 4374 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251, true); |
| 4375 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8R, true); |
| 4376 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8U, true); |
| 4377 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88597, true); |
| 4378 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253, true); |
| 4379 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88594, true); |
| 4380 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885913, true); |
| 4381 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257, true); |
| 4382 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88593, true); |
| 4383 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885910, true); |
| 4384 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885914, true); |
| 4385 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885916, true); |
| 4386 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254, true); |
| 4387 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88596, true); |
| 4388 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256, true); |
| 4389 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598, true); |
[email protected] | e13271f | 2009-03-07 00:26:00 | [diff] [blame] | 4390 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598I, true); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4391 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); |
| 4392 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4393 | |
[email protected] | 63b0293 | 2009-06-05 09:40:51 | [diff] [blame] | 4394 | // Zoom |
| 4395 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); |
| 4396 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); |
| 4397 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); |
| 4398 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); |
| 4399 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4400 | // Show various bits of UI |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4401 | UpdateOpenFileState(); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4402 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 4403 | UpdateCommandsForDevTools(); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4404 | command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, true); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4405 | command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4406 | command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
| 4407 | command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE, true); |
[email protected] | d6852fd | 2011-05-20 17:19:12 | [diff] [blame] | 4408 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, true); |
[email protected] | 9cd51a0 | 2009-10-23 22:30:29 | [diff] [blame] | 4409 | |
[email protected] | 96e3467 | 2010-02-09 21:40:29 | [diff] [blame] | 4410 | #if defined(OS_CHROMEOS) |
[email protected] | 05a44b6e | 2011-12-01 07:52:32 | [diff] [blame] | 4411 | command_updater_.UpdateCommandEnabled(IDC_LOCK_SCREEN, true); |
[email protected] | 2166c43 | 2011-12-07 20:18:28 | [diff] [blame] | 4412 | command_updater_.UpdateCommandEnabled(IDC_SHUTDOWN, true); |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 4413 | command_updater_.UpdateCommandEnabled(IDC_FILE_MANAGER, true); |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 4414 | command_updater_.UpdateCommandEnabled(IDC_SEARCH, true); |
[email protected] | d14af52 | 2010-12-02 03:54:50 | [diff] [blame] | 4415 | command_updater_.UpdateCommandEnabled(IDC_SHOW_KEYBOARD_OVERLAY, true); |
[email protected] | c8b59f9 | 2010-05-28 21:45:47 | [diff] [blame] | 4416 | command_updater_.UpdateCommandEnabled(IDC_SYSTEM_OPTIONS, true); |
| 4417 | command_updater_.UpdateCommandEnabled(IDC_INTERNET_OPTIONS, true); |
[email protected] | 96e3467 | 2010-02-09 21:40:29 | [diff] [blame] | 4418 | #endif |
[email protected] | a038159b | 2011-08-18 02:55:36 | [diff] [blame] | 4419 | command_updater_.UpdateCommandEnabled( |
| 4420 | IDC_SHOW_SYNC_SETUP, profile_->GetOriginalProfile()->IsSyncAccessible()); |
[email protected] | c8b59f9 | 2010-05-28 21:45:47 | [diff] [blame] | 4421 | |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 4422 | // Initialize other commands based on the window type. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4423 | bool normal_window = is_type_tabbed(); |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 4424 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 4425 | // Navigation commands |
| 4426 | command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 4427 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 4428 | // Window management commands |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 4429 | // TODO(rohitrao): Disable fullscreen on non-Lion? |
[email protected] | cf299bc | 2010-08-12 20:27:09 | [diff] [blame] | 4430 | command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4431 | !(is_type_panel() && is_app())); |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 4432 | command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| 4433 | command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| 4434 | normal_window); |
| 4435 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window); |
| 4436 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window); |
| 4437 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window); |
| 4438 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window); |
| 4439 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window); |
| 4440 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window); |
| 4441 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window); |
| 4442 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window); |
| 4443 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window); |
| 4444 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window); |
| 4445 | command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window); |
[email protected] | c1d0d81 | 2010-07-27 20:21:55 | [diff] [blame] | 4446 | #if defined(OS_MACOSX) |
| 4447 | command_updater_.UpdateCommandEnabled(IDC_TABPOSE, normal_window); |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 4448 | command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE, |
| 4449 | !(is_type_panel() && is_app())); |
[email protected] | c1d0d81 | 2010-07-27 20:21:55 | [diff] [blame] | 4450 | #endif |
[email protected] | e662ade | 2009-06-08 18:20:14 | [diff] [blame] | 4451 | |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 4452 | // Clipboard commands |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4453 | command_updater_.UpdateCommandEnabled(IDC_COPY_URL, !is_devtools()); |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 4454 | |
| 4455 | // Find-in-page |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4456 | command_updater_.UpdateCommandEnabled(IDC_FIND, !is_devtools()); |
| 4457 | command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, !is_devtools()); |
| 4458 | command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, !is_devtools()); |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 4459 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 4460 | // Show various bits of UI |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 4461 | command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window); |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 4462 | |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 4463 | // The upgrade entry and the view incompatibility entry should always be |
| 4464 | // enabled. Whether they are visible is a separate matter determined on menu |
| 4465 | // show. |
[email protected] | b21d691 | 2010-08-31 19:22:41 | [diff] [blame] | 4466 | command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true); |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 4467 | command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true); |
[email protected] | b21d691 | 2010-08-31 19:22:41 | [diff] [blame] | 4468 | |
[email protected] | b569c11 | 2010-11-22 20:53:44 | [diff] [blame] | 4469 | // View Background Pages entry is always enabled, but is hidden if there are |
| 4470 | // no background pages. |
| 4471 | command_updater_.UpdateCommandEnabled(IDC_VIEW_BACKGROUND_PAGES, true); |
| 4472 | |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 4473 | // Toggle speech input |
| 4474 | command_updater_.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT, true); |
| 4475 | |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 4476 | // Initialize other commands whose state changes based on fullscreen mode. |
| 4477 | UpdateCommandsForFullscreenMode(false); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4478 | |
| 4479 | UpdateCommandsForContentRestrictionState(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4480 | |
| 4481 | UpdateCommandsForBookmarkEditing(); |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4482 | |
| 4483 | UpdateCommandsForIncognitoAvailability(); |
| 4484 | } |
| 4485 | |
| 4486 | bool Browser::IsShowingMainUI(bool is_fullscreen) { |
| 4487 | #if !defined(OS_MACOSX) |
| 4488 | return is_type_tabbed() && !is_fullscreen; |
| 4489 | #else |
| 4490 | return is_type_tabbed(); |
| 4491 | #endif |
| 4492 | } |
| 4493 | |
| 4494 | void Browser::UpdateCommandsForIncognitoAvailability() { |
| 4495 | IncognitoModePrefs::Availability incognito_availability = |
| 4496 | IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
| 4497 | command_updater_.UpdateCommandEnabled( |
| 4498 | IDC_NEW_WINDOW, |
| 4499 | incognito_availability != IncognitoModePrefs::FORCED); |
| 4500 | command_updater_.UpdateCommandEnabled( |
| 4501 | IDC_NEW_INCOGNITO_WINDOW, |
| 4502 | incognito_availability != IncognitoModePrefs::DISABLED); |
| 4503 | |
| 4504 | // Bookmark manager and settings page/subpages are forced to open in normal |
| 4505 | // mode. For this reason we disable these commands when incognito is forced. |
| 4506 | const bool command_enabled = |
| 4507 | incognito_availability != IncognitoModePrefs::FORCED; |
| 4508 | command_updater_.UpdateCommandEnabled( |
| 4509 | IDC_SHOW_BOOKMARK_MANAGER, |
| 4510 | browser_defaults::bookmarks_enabled && command_enabled); |
| 4511 | ExtensionService* extension_service = profile()->GetExtensionService(); |
| 4512 | bool enable_extensions = |
| 4513 | extension_service && extension_service->extensions_enabled(); |
| 4514 | command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, |
| 4515 | enable_extensions && command_enabled); |
| 4516 | |
| 4517 | const bool show_main_ui = IsShowingMainUI(window_ && window_->IsFullscreen()); |
| 4518 | command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, |
| 4519 | show_main_ui && command_enabled); |
| 4520 | command_updater_.UpdateCommandEnabled(IDC_OPTIONS, |
| 4521 | show_main_ui && command_enabled); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4522 | } |
| 4523 | |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4524 | void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4525 | const bool show_main_ui = IsShowingMainUI(is_fullscreen); |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4526 | bool main_not_fullscreen = show_main_ui && !is_fullscreen; |
| 4527 | |
| 4528 | // Navigation commands |
| 4529 | command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); |
| 4530 | |
| 4531 | // Window management commands |
| 4532 | command_updater_.UpdateCommandEnabled(IDC_SHOW_AS_TAB, |
| 4533 | type_ != TYPE_TABBED && !is_fullscreen); |
| 4534 | |
| 4535 | // Focus various bits of UI |
| 4536 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); |
| 4537 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui); |
| 4538 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); |
| 4539 | command_updater_.UpdateCommandEnabled( |
| 4540 | IDC_FOCUS_MENU_BAR, main_not_fullscreen); |
| 4541 | command_updater_.UpdateCommandEnabled( |
| 4542 | IDC_FOCUS_NEXT_PANE, main_not_fullscreen); |
| 4543 | command_updater_.UpdateCommandEnabled( |
| 4544 | IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); |
| 4545 | command_updater_.UpdateCommandEnabled( |
| 4546 | IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
| 4547 | command_updater_.UpdateCommandEnabled( |
| 4548 | IDC_FOCUS_CHROMEOS_STATUS, main_not_fullscreen); |
| 4549 | |
| 4550 | // Show various bits of UI |
| 4551 | command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| 4552 | command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4553 | command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, |
[email protected] | 49385da69 | 2011-08-05 04:03:39 | [diff] [blame] | 4554 | show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible()); |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4555 | |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4556 | // Settings page/subpages are forced to open in normal mode. We disable these |
| 4557 | // commands when incognito is forced. |
| 4558 | const bool options_enabled = show_main_ui && |
| 4559 | IncognitoModePrefs::GetAvailability( |
| 4560 | profile_->GetPrefs()) != IncognitoModePrefs::FORCED; |
| 4561 | command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); |
| 4562 | command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); |
| 4563 | |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4564 | command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 4565 | command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 4566 | command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| 4567 | command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
[email protected] | 7d2d0815 | 2011-10-25 22:58:47 | [diff] [blame] | 4568 | command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, |
| 4569 | show_main_ui && !profile()->IsOffTheRecord()); |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4570 | #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
| 4571 | command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| 4572 | #endif |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 4573 | |
| 4574 | UpdateCommandsForBookmarkBar(); |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 4575 | } |
| 4576 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4577 | void Browser::UpdateCommandsForTabState() { |
[email protected] | c7c4233 | 2008-11-15 01:10:54 | [diff] [blame] | 4578 | TabContents* current_tab = GetSelectedTabContents(); |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 4579 | TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); |
| 4580 | if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore. |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 4581 | return; |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 4582 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4583 | // Navigation commands |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 4584 | NavigationController& nc = current_tab->controller(); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 4585 | command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack()); |
| 4586 | command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward()); |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 4587 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, |
| 4588 | CanReloadContents(current_tab)); |
| 4589 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, |
| 4590 | CanReloadContents(current_tab)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4591 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4592 | // Window management commands |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4593 | command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4594 | !is_app() && CanDuplicateContentsAt(active_index())); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 4595 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 4596 | // Page-related commands |
[email protected] | 52cc59b | 2011-05-06 14:42:38 | [diff] [blame] | 4597 | window_->SetStarredState( |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 4598 | current_tab_wrapper->bookmark_tab_helper()->is_starred()); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 4599 | command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 4600 | current_tab->controller().CanViewSource()); |
[email protected] | 151666e | 2010-10-21 17:05:25 | [diff] [blame] | 4601 | command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, |
[email protected] | cd8d90db | 2011-10-06 19:31:27 | [diff] [blame] | 4602 | toolbar_model_.ShouldDisplayURL() && current_tab->GetURL().is_valid()); |
[email protected] | af664c7 | 2011-05-17 14:33:40 | [diff] [blame] | 4603 | if (is_devtools()) |
| 4604 | command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false); |
[email protected] | 151666e | 2010-10-21 17:05:25 | [diff] [blame] | 4605 | |
| 4606 | // Changing the encoding is not possible on Chrome-internal webpages. |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame^] | 4607 | bool is_chrome_internal = HasInternalURL(nc.GetActiveEntry()) || |
| 4608 | current_tab->showing_interstitial_page(); |
[email protected] | c0f82ec5 | 2010-07-27 14:22:14 | [diff] [blame] | 4609 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, |
| 4610 | !is_chrome_internal && SavePackage::IsSavableContents( |
| 4611 | current_tab->contents_mime_type())); |
| 4612 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 4613 | // Show various bits of UI |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 4614 | // TODO(pinkerton): Disable app-mode in the model until we implement it |
| 4615 | // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 |
| 4616 | #if !defined(OS_MACOSX) |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 4617 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, |
[email protected] | 12ea22a | 2009-11-19 07:17:23 | [diff] [blame] | 4618 | web_app::IsValidUrl(current_tab->GetURL())); |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 4619 | #endif |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4620 | |
| 4621 | UpdateCommandsForContentRestrictionState(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4622 | UpdateCommandsForBookmarkEditing(); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | void Browser::UpdateCommandsForContentRestrictionState() { |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 4626 | int restrictions = GetContentRestrictionsForSelectedTab(); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4627 | |
| 4628 | command_updater_.UpdateCommandEnabled( |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 4629 | IDC_COPY, !(restrictions & content::CONTENT_RESTRICTION_COPY)); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4630 | command_updater_.UpdateCommandEnabled( |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 4631 | IDC_CUT, !(restrictions & content::CONTENT_RESTRICTION_CUT)); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4632 | command_updater_.UpdateCommandEnabled( |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 4633 | IDC_PASTE, !(restrictions & content::CONTENT_RESTRICTION_PASTE)); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4634 | UpdateSaveAsState(restrictions); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4635 | UpdatePrintingState(restrictions); |
| 4636 | } |
| 4637 | |
| 4638 | void Browser::UpdatePrintingState(int content_restrictions) { |
[email protected] | 43401bc0 | 2011-10-13 20:43:43 | [diff] [blame] | 4639 | bool print_enabled = true; |
| 4640 | bool advanced_print_enabled = true; |
| 4641 | if (g_browser_process->local_state()) { |
| 4642 | print_enabled = |
| 4643 | g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled); |
| 4644 | advanced_print_enabled = print_enabled; |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4645 | } |
[email protected] | 43401bc0 | 2011-10-13 20:43:43 | [diff] [blame] | 4646 | if (print_enabled) { |
| 4647 | // Do not print when a constrained window is showing. It's confusing. |
| 4648 | TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); |
| 4649 | bool has_constrained_window = (wrapper && |
| 4650 | wrapper->constrained_window_tab_helper()->constrained_window_count()); |
| 4651 | if (has_constrained_window || |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 4652 | content_restrictions & content::CONTENT_RESTRICTION_PRINT) { |
[email protected] | 43401bc0 | 2011-10-13 20:43:43 | [diff] [blame] | 4653 | print_enabled = false; |
| 4654 | advanced_print_enabled = false; |
| 4655 | } |
| 4656 | |
| 4657 | // The exception is print preview, |
| 4658 | // where advanced printing is always enabled. |
| 4659 | printing::PrintPreviewTabController* controller = |
| 4660 | printing::PrintPreviewTabController::GetInstance(); |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 4661 | if (controller && (controller->GetPrintPreviewForTab(wrapper) || |
| 4662 | controller->is_creating_print_preview_tab())) { |
[email protected] | 43401bc0 | 2011-10-13 20:43:43 | [diff] [blame] | 4663 | advanced_print_enabled = true; |
| 4664 | } |
| 4665 | } |
| 4666 | command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 4667 | command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT, |
[email protected] | 43401bc0 | 2011-10-13 20:43:43 | [diff] [blame] | 4668 | advanced_print_enabled); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4669 | } |
| 4670 | |
[email protected] | 943d812 | 2010-06-11 02:13:45 | [diff] [blame] | 4671 | void Browser::UpdateReloadStopState(bool is_loading, bool force) { |
| 4672 | window_->UpdateReloadStopState(is_loading, force); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4673 | command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 4674 | } |
| 4675 | |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 4676 | void Browser::UpdateCommandsForDevTools() { |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4677 | bool dev_tools_enabled = |
[email protected] | 5073f49 | 2011-05-03 09:36:42 | [diff] [blame] | 4678 | !profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 4679 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, |
| 4680 | dev_tools_enabled); |
| 4681 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE, |
| 4682 | dev_tools_enabled); |
| 4683 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT, |
| 4684 | dev_tools_enabled); |
| 4685 | } |
| 4686 | |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4687 | void Browser::UpdateCommandsForBookmarkEditing() { |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4688 | bool enabled = |
| 4689 | profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled) && |
| 4690 | browser_defaults::bookmarks_enabled; |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4691 | |
| 4692 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4693 | enabled && is_type_tabbed()); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4694 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS, |
| 4695 | enabled && CanBookmarkAllTabs()); |
| 4696 | } |
| 4697 | |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 4698 | void Browser::UpdateCommandsForBookmarkBar() { |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 4699 | const bool show_main_ui = IsShowingMainUI(window_ && window_->IsFullscreen()); |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 4700 | command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, |
| 4701 | browser_defaults::bookmarks_enabled && |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 4702 | !profile_->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) && |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 4703 | show_main_ui); |
| 4704 | } |
| 4705 | |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 4706 | void Browser::MarkHomePageAsChanged(PrefService* pref_service) { |
| 4707 | pref_service->SetBoolean(prefs::kHomePageChanged, true); |
| 4708 | pref_service->ScheduleSavePersistentPrefs(); |
| 4709 | } |
| 4710 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4711 | void Browser::UpdateSaveAsState(int content_restrictions) { |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 4712 | bool enabled = !(content_restrictions & content::CONTENT_RESTRICTION_SAVE); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4713 | PrefService* state = g_browser_process->local_state(); |
| 4714 | if (state) |
| 4715 | enabled = enabled && state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 4716 | |
| 4717 | command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, enabled); |
| 4718 | } |
| 4719 | |
| 4720 | void Browser::UpdateOpenFileState() { |
| 4721 | bool enabled = true; |
| 4722 | PrefService* local_state = g_browser_process->local_state(); |
| 4723 | if (local_state) |
| 4724 | enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 4725 | |
| 4726 | command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
| 4727 | } |
| 4728 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4729 | /////////////////////////////////////////////////////////////////////////////// |
| 4730 | // Browser, UI update coalescing and handling (private): |
| 4731 | |
| 4732 | void Browser::UpdateToolbar(bool should_restore_state) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4733 | window_->UpdateToolbar(GetSelectedTabContentsWrapper(), should_restore_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4734 | } |
| 4735 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4736 | void Browser::ScheduleUIUpdate(const TabContents* source, |
| 4737 | unsigned changed_flags) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4738 | if (!source) |
| 4739 | return; |
| 4740 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 4741 | // Do some synchronous updates. |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4742 | if (changed_flags & TabContents::INVALIDATE_URL && |
| 4743 | source == GetSelectedTabContents()) { |
| 4744 | // Only update the URL for the current tab. Note that we do not update |
| 4745 | // the navigation commands since those would have already been updated |
| 4746 | // synchronously by NavigationStateChanged. |
| 4747 | UpdateToolbar(false); |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 4748 | changed_flags &= ~TabContents::INVALIDATE_URL; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4749 | } |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4750 | if (changed_flags & TabContents::INVALIDATE_LOAD) { |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 4751 | // Update the loading state synchronously. This is so the throbber will |
| 4752 | // immediately start/stop, which gives a more snappy feel. We want to do |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4753 | // this for any tab so they start & stop quickly. |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4754 | tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( |
| 4755 | tab_handler_->GetTabStripModel()->GetIndexOfController( |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 4756 | &source->controller()), |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 4757 | TabStripModelObserver::LOADING_ONLY); |
| 4758 | // The status bubble needs to be updated during INVALIDATE_LOAD too, but |
| 4759 | // we do that asynchronously by not stripping INVALIDATE_LOAD from |
| 4760 | // changed_flags. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 4761 | } |
| 4762 | |
[email protected] | f5d978c | 2011-07-21 14:43:51 | [diff] [blame] | 4763 | if (changed_flags & TabContents::INVALIDATE_TITLE && !source->IsLoading()) { |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 4764 | // To correctly calculate whether the title changed while not loading |
| 4765 | // we need to process the update synchronously. This state only matters for |
| 4766 | // the TabStripModel, so we notify the TabStripModel now and notify others |
| 4767 | // asynchronously. |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4768 | tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( |
| 4769 | tab_handler_->GetTabStripModel()->GetIndexOfController( |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 4770 | &source->controller()), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 4771 | TabStripModelObserver::TITLE_NOT_LOADING); |
| 4772 | } |
| 4773 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 4774 | // If the only updates were synchronously handled above, we're done. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 4775 | if (changed_flags == 0) |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 4776 | return; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4777 | |
| 4778 | // Save the dirty bits. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 4779 | scheduled_updates_[source] |= changed_flags; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4780 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 4781 | if (!chrome_updater_factory_.HasWeakPtrs()) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4782 | // No task currently scheduled, start another. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 4783 | MessageLoop::current()->PostDelayedTask( |
| 4784 | FROM_HERE, |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 4785 | base::Bind(&Browser::ProcessPendingUIUpdates, |
| 4786 | chrome_updater_factory_.GetWeakPtr()), |
| 4787 | kUIUpdateCoalescingTimeMS); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4788 | } |
| 4789 | } |
| 4790 | |
| 4791 | void Browser::ProcessPendingUIUpdates() { |
| 4792 | #ifndef NDEBUG |
| 4793 | // Validate that all tabs we have pending updates for exist. This is scary |
| 4794 | // because the pending list must be kept in sync with any detached or |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4795 | // deleted tabs. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 4796 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 4797 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4798 | bool found = false; |
| 4799 | for (int tab = 0; tab < tab_count(); tab++) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4800 | if (GetTabContentsAt(tab) == i->first) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4801 | found = true; |
| 4802 | break; |
| 4803 | } |
| 4804 | } |
| 4805 | DCHECK(found); |
| 4806 | } |
| 4807 | #endif |
| 4808 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 4809 | chrome_updater_factory_.InvalidateWeakPtrs(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4810 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 4811 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 4812 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4813 | // Do not dereference |contents|, it may be out-of-date! |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 4814 | const TabContents* contents = i->first; |
| 4815 | unsigned flags = i->second; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4816 | |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4817 | if (contents == GetSelectedTabContents()) { |
| 4818 | // Updates that only matter when the tab is selected go here. |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 4819 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 4820 | if (flags & TabContents::INVALIDATE_PAGE_ACTIONS) { |
| 4821 | LocationBar* location_bar = window()->GetLocationBar(); |
| 4822 | if (location_bar) |
| 4823 | location_bar->UpdatePageActions(); |
| 4824 | } |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 4825 | // Updating the URL happens synchronously in ScheduleUIUpdate. |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 4826 | if (flags & TabContents::INVALIDATE_LOAD && GetStatusBubble()) { |
| 4827 | GetStatusBubble()->SetStatus( |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 4828 | GetSelectedTabContentsWrapper()-> |
| 4829 | core_tab_helper()->GetStatusText()); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 4830 | } |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4831 | |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 4832 | if (flags & (TabContents::INVALIDATE_TAB | |
| 4833 | TabContents::INVALIDATE_TITLE)) { |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 4834 | // TODO(pinkerton): Disable app-mode in the model until we implement it |
| 4835 | // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 |
| 4836 | #if !defined(OS_MACOSX) |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4837 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, |
[email protected] | 12ea22a | 2009-11-19 07:17:23 | [diff] [blame] | 4838 | web_app::IsValidUrl(contents->GetURL())); |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 4839 | #endif |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4840 | window_->UpdateTitleBar(); |
| 4841 | } |
[email protected] | 4d34e2e | 2009-05-26 22:55:28 | [diff] [blame] | 4842 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4843 | |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4844 | // Updates that don't depend upon the selected state go here. |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 4845 | if (flags & (TabContents::INVALIDATE_TAB | TabContents::INVALIDATE_TITLE)) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4846 | tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4847 | tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 4848 | TabStripModelObserver::ALL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | // We don't need to process INVALIDATE_STATE, since that's not visible. |
| 4852 | } |
| 4853 | |
| 4854 | scheduled_updates_.clear(); |
| 4855 | } |
| 4856 | |
| 4857 | void Browser::RemoveScheduledUpdatesFor(TabContents* contents) { |
| 4858 | if (!contents) |
| 4859 | return; |
| 4860 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 4861 | UpdateMap::iterator i = scheduled_updates_.find(contents); |
| 4862 | if (i != scheduled_updates_.end()) |
| 4863 | scheduled_updates_.erase(i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4864 | } |
| 4865 | |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 4866 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4867 | /////////////////////////////////////////////////////////////////////////////// |
| 4868 | // Browser, Getters for UI (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4869 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4870 | StatusBubble* Browser::GetStatusBubble() { |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 4871 | #if !defined(OS_MACOSX) |
| 4872 | // In kiosk mode, we want to always hide the status bubble. |
| 4873 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 4874 | return NULL; |
| 4875 | #endif |
[email protected] | 9b032bf | 2009-07-21 17:34:23 | [diff] [blame] | 4876 | return window_ ? window_->GetStatusBubble() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4877 | } |
| 4878 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4879 | /////////////////////////////////////////////////////////////////////////////// |
| 4880 | // Browser, Session restore functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4881 | |
| 4882 | void Browser::SyncHistoryWithTabs(int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 4883 | SessionService* session_service = |
| 4884 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4885 | if (session_service) { |
| 4886 | for (int i = index; i < tab_count(); ++i) { |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 4887 | TabContentsWrapper* tab = GetTabContentsWrapperAt(i); |
| 4888 | if (tab) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4889 | session_service->SetTabIndexInWindow( |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 4890 | session_id(), tab->restore_tab_helper()->session_id(), i); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4891 | session_service->SetPinnedState( |
| 4892 | session_id(), |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 4893 | tab->restore_tab_helper()->session_id(), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4894 | tab_handler_->GetTabStripModel()->IsTabPinned(i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4895 | } |
| 4896 | } |
| 4897 | } |
| 4898 | } |
| 4899 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4900 | /////////////////////////////////////////////////////////////////////////////// |
| 4901 | // Browser, OnBeforeUnload handling (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4902 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4903 | void Browser::ProcessPendingTabs() { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4904 | if (!is_attempting_to_close_browser_) { |
| 4905 | // Because we might invoke this after a delay it's possible for the value of |
| 4906 | // is_attempting_to_close_browser_ to have changed since we scheduled the |
| 4907 | // task. |
| 4908 | return; |
| 4909 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4910 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4911 | if (HasCompletedUnloadProcessing()) { |
| 4912 | // We've finished all the unload events and can proceed to close the |
| 4913 | // browser. |
| 4914 | OnWindowClosing(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4915 | return; |
| 4916 | } |
| 4917 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4918 | // Process beforeunload tabs first. When that queue is empty, process |
| 4919 | // unload tabs. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4920 | if (!tabs_needing_before_unload_fired_.empty()) { |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 4921 | TabContents* tab = *(tabs_needing_before_unload_fired_.begin()); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4922 | // Null check render_view_host here as this gets called on a PostTask and |
| 4923 | // the tab's render_view_host may have been nulled out. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 4924 | if (tab->GetRenderViewHost()) { |
| 4925 | tab->GetRenderViewHost()->FirePageBeforeUnload(false); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4926 | } else { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4927 | ClearUnloadState(tab, true); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4928 | } |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4929 | } else if (!tabs_needing_unload_fired_.empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4930 | // We've finished firing all beforeunload events and can proceed with unload |
| 4931 | // events. |
| 4932 | // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting |
| 4933 | // somewhere around here so that we have accurate measurements of shutdown |
| 4934 | // time. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4935 | // TODO(ojan): We can probably fire all the unload events in parallel and |
| 4936 | // get a perf benefit from that in the cases where the tab hangs in it's |
| 4937 | // unload handler or takes a long time to page in. |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 4938 | TabContents* tab = *(tabs_needing_unload_fired_.begin()); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4939 | // Null check render_view_host here as this gets called on a PostTask and |
| 4940 | // the tab's render_view_host may have been nulled out. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 4941 | if (tab->GetRenderViewHost()) { |
| 4942 | tab->GetRenderViewHost()->ClosePage(); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4943 | } else { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4944 | ClearUnloadState(tab, true); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4945 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4946 | } else { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4947 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4948 | } |
| 4949 | } |
| 4950 | |
[email protected] | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 4951 | bool Browser::HasCompletedUnloadProcessing() const { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4952 | return is_attempting_to_close_browser_ && |
| 4953 | tabs_needing_before_unload_fired_.empty() && |
| 4954 | tabs_needing_unload_fired_.empty(); |
| 4955 | } |
| 4956 | |
| 4957 | void Browser::CancelWindowClose() { |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 4958 | // Closing of window can be canceled from: |
| 4959 | // - canceling beforeunload |
| 4960 | // - disallowing closing from IsClosingPermitted. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4961 | DCHECK(is_attempting_to_close_browser_); |
[email protected] | 8f673f3a | 2008-08-05 22:34:28 | [diff] [blame] | 4962 | tabs_needing_before_unload_fired_.clear(); |
| 4963 | tabs_needing_unload_fired_.clear(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4964 | is_attempting_to_close_browser_ = false; |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 4965 | |
| 4966 | // Inform TabCloseableStateWatcher that closing of window has been canceled. |
| 4967 | TabCloseableStateWatcher* watcher = |
| 4968 | g_browser_process->tab_closeable_state_watcher(); |
| 4969 | if (watcher) |
| 4970 | watcher->OnWindowCloseCanceled(this); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4971 | } |
| 4972 | |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 4973 | bool Browser::RemoveFromSet(UnloadListenerSet* set, TabContents* tab) { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4974 | DCHECK(is_attempting_to_close_browser_); |
| 4975 | |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 4976 | UnloadListenerSet::iterator iter = std::find(set->begin(), set->end(), tab); |
| 4977 | if (iter != set->end()) { |
| 4978 | set->erase(iter); |
| 4979 | return true; |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4980 | } |
| 4981 | return false; |
| 4982 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4983 | |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4984 | void Browser::ClearUnloadState(TabContents* tab, bool process_now) { |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 4985 | // Closing of browser could be canceled (via IsClosingPermitted) between the |
| 4986 | // time when request was initiated and when this method is called, so check |
| 4987 | // for is_attempting_to_close_browser_ flag before proceeding. |
| 4988 | if (is_attempting_to_close_browser_) { |
| 4989 | RemoveFromSet(&tabs_needing_before_unload_fired_, tab); |
| 4990 | RemoveFromSet(&tabs_needing_unload_fired_, tab); |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4991 | if (process_now) { |
| 4992 | ProcessPendingTabs(); |
| 4993 | } else { |
| 4994 | MessageLoop::current()->PostTask( |
| 4995 | FROM_HERE, |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 4996 | base::Bind(&Browser::ProcessPendingTabs, weak_factory_.GetWeakPtr())); |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4997 | } |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 4998 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4999 | } |
| 5000 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5001 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 5002 | // Browser, In-progress download termination handling (private): |
| 5003 | |
[email protected] | b6a4ac2b | 2011-10-17 20:05:48 | [diff] [blame] | 5004 | bool Browser::CanCloseWithInProgressDownloads() { |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 5005 | // If we've prompted, we need to hear from the user before we |
| 5006 | // can close. |
| 5007 | if (cancel_download_confirmation_state_ != NOT_PROMPTED) |
| 5008 | return cancel_download_confirmation_state_ != WAITING_FOR_RESPONSE; |
| 5009 | |
| 5010 | int num_downloads_blocking; |
| 5011 | if (DOWNLOAD_CLOSE_OK == |
| 5012 | OkToCloseWithInProgressDownloads(&num_downloads_blocking)) |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 5013 | return true; |
| 5014 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 5015 | // Closing this window will kill some downloads; prompt to make sure |
| 5016 | // that's ok. |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 5017 | cancel_download_confirmation_state_ = WAITING_FOR_RESPONSE; |
| 5018 | window_->ConfirmBrowserCloseWithPendingDownloads(); |
| 5019 | |
| 5020 | // Return false so the browser does not close. We'll close if the user |
| 5021 | // confirms in the dialog. |
| 5022 | return false; |
| 5023 | } |
| 5024 | |
| 5025 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5026 | // Browser, Assorted utility functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5027 | |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 5028 | // static |
[email protected] | de4e763 | 2010-09-01 06:24:04 | [diff] [blame] | 5029 | Browser* Browser::GetTabbedBrowser(Profile* profile, bool match_incognito) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 5030 | return BrowserList::FindTabbedBrowser(profile, match_incognito); |
[email protected] | de4e763 | 2010-09-01 06:24:04 | [diff] [blame] | 5031 | } |
| 5032 | |
| 5033 | // static |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 5034 | Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) { |
[email protected] | de4e763 | 2010-09-01 06:24:04 | [diff] [blame] | 5035 | Browser* browser = GetTabbedBrowser(profile, false); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 5036 | if (!browser) |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 5037 | browser = Browser::Create(profile); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5038 | return browser; |
| 5039 | } |
| 5040 | |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 5041 | void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 5042 | // TabContents... |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 5043 | tab->tab_contents()->SetDelegate(delegate); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 5044 | |
| 5045 | // ...and all the helpers. |
| 5046 | tab->blocked_content_tab_helper()->set_delegate(delegate); |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 5047 | tab->bookmark_tab_helper()->set_delegate(delegate); |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 5048 | tab->constrained_window_tab_helper()->set_delegate(delegate); |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 5049 | tab->core_tab_helper()->set_delegate(delegate); |
[email protected] | 1739e57d | 2011-11-30 21:18:25 | [diff] [blame] | 5050 | tab->extension_tab_helper()->set_delegate(delegate); |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 5051 | tab->search_engine_tab_helper()->set_delegate(delegate); |
| 5052 | } |
| 5053 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 5054 | void Browser::FindInPage(bool find_next, bool forward_direction) { |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 5055 | ShowFindBar(); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 5056 | if (find_next) { |
[email protected] | 6a4f5af2 | 2009-09-23 22:43:00 | [diff] [blame] | 5057 | string16 find_text; |
| 5058 | #if defined(OS_MACOSX) |
| 5059 | // We always want to search for the contents of the find pasteboard on OS X. |
| 5060 | find_text = GetFindPboardText(); |
| 5061 | #endif |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 5062 | GetSelectedTabContentsWrapper()-> |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 5063 | find_tab_helper()->StartFinding(find_text, |
| 5064 | forward_direction, |
| 5065 | false); // Not case sensitive. |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 5066 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 5067 | } |
[email protected] | cb17f7f | 2009-02-06 18:14:48 | [diff] [blame] | 5068 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 5069 | void Browser::CloseFrame() { |
| 5070 | window_->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5071 | } |
| 5072 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 5073 | void Browser::TabDetachedAtImpl(TabContentsWrapper* contents, int index, |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5074 | DetachType type) { |
| 5075 | if (type == DETACH_TYPE_DETACH) { |
[email protected] | 5658085 | 2010-11-17 16:09:15 | [diff] [blame] | 5076 | // Save the current location bar state, but only if the tab being detached |
| 5077 | // is the selected tab. Because saving state can conditionally revert the |
| 5078 | // location bar, saving the current tab's location bar state to a |
| 5079 | // non-selected tab can corrupt both tabs. |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 5080 | if (contents == GetSelectedTabContentsWrapper()) { |
| 5081 | LocationBar* location_bar = window()->GetLocationBar(); |
| 5082 | if (location_bar) |
| 5083 | location_bar->SaveStateToContents(contents->tab_contents()); |
| 5084 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5085 | |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 5086 | if (!tab_handler_->GetTabStripModel()->closing_all()) |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5087 | SyncHistoryWithTabs(0); |
| 5088 | } |
| 5089 | |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 5090 | SetAsDelegate(contents, NULL); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 5091 | RemoveScheduledUpdatesFor(contents->tab_contents()); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5092 | |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 5093 | if (find_bar_controller_.get() && |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 5094 | index == tab_handler_->GetTabStripModel()->active_index()) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5095 | find_bar_controller_->ChangeTabContents(NULL); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 5096 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5097 | |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 5098 | if (is_attempting_to_close_browser_) { |
| 5099 | // If this is the last tab with unload handlers, then ProcessPendingTabs |
| 5100 | // would call back into the TabStripModel (which is invoking this method on |
| 5101 | // us). Avoid that by passing in false so that the call to |
| 5102 | // ProcessPendingTabs is delayed. |
| 5103 | ClearUnloadState(contents->tab_contents(), false); |
| 5104 | } |
| 5105 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 5106 | registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5107 | content::Source<TabContents>(contents->tab_contents())); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame^] | 5108 | registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
| 5109 | content::Source<TabContents>(contents->tab_contents())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 5110 | registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5111 | content::Source<TabContents>(contents->tab_contents())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 5112 | } |
| 5113 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5114 | // static |
[email protected] | f87919d7 | 2011-02-02 18:46:16 | [diff] [blame] | 5115 | void Browser::RegisterAppPrefs(const std::string& app_name, Profile* profile) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5116 | // We need to register the window position pref. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 5117 | std::string window_pref(prefs::kBrowserWindowPlacement); |
| 5118 | window_pref.append("_"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5119 | window_pref.append(app_name); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 5120 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 5121 | if (!prefs->FindPreference(window_pref.c_str())) { |
| 5122 | prefs->RegisterDictionaryPref(window_pref.c_str(), |
| 5123 | PrefService::UNSYNCABLE_PREF); |
| 5124 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5125 | } |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 5126 | |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 5127 | void Browser::TabRestoreServiceChanged(TabRestoreService* service) { |
| 5128 | command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, |
| 5129 | !service->entries().empty()); |
| 5130 | } |
| 5131 | |
| 5132 | void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) { |
| 5133 | if (!tab_restore_service_) |
| 5134 | return; |
| 5135 | |
| 5136 | DCHECK_EQ(tab_restore_service_, service); |
| 5137 | tab_restore_service_->RemoveObserver(this); |
| 5138 | tab_restore_service_ = NULL; |
| 5139 | } |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5140 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 5141 | // Centralized method for creating a TabContents, configuring and installing |
| 5142 | // all its supporting objects and observers. |
| 5143 | TabContentsWrapper* Browser::TabContentsFactory( |
| 5144 | Profile* profile, |
| 5145 | SiteInstance* site_instance, |
| 5146 | int routing_id, |
| 5147 | const TabContents* base_tab_contents, |
| 5148 | SessionStorageNamespace* session_storage_namespace) { |
| 5149 | TabContents* new_contents = new TabContents(profile, site_instance, |
| 5150 | routing_id, base_tab_contents, |
| 5151 | session_storage_namespace); |
| 5152 | TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); |
| 5153 | return wrapper; |
| 5154 | } |
| 5155 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 5156 | bool Browser::OpenInstant(WindowOpenDisposition disposition) { |
[email protected] | 3e48128 | 2011-10-15 15:39:50 | [diff] [blame] | 5157 | if (!instant() || !instant()->PrepareForCommit() || |
[email protected] | 3524260 | 2011-01-06 16:38:53 | [diff] [blame] | 5158 | disposition == NEW_BACKGROUND_TAB) { |
| 5159 | // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't |
| 5160 | // attempt to use the instant preview. |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5161 | return false; |
[email protected] | 3524260 | 2011-01-06 16:38:53 | [diff] [blame] | 5162 | } |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5163 | |
| 5164 | if (disposition == CURRENT_TAB) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 5165 | content::NotificationService::current()->Notify( |
[email protected] | 094b052 | 2011-10-06 00:55:27 | [diff] [blame] | 5166 | chrome::NOTIFICATION_INSTANT_COMMITTED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5167 | content::Source<TabContentsWrapper>(instant()->CommitCurrentPreview( |
[email protected] | 094b052 | 2011-10-06 00:55:27 | [diff] [blame] | 5168 | INSTANT_COMMIT_PRESSED_ENTER)), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 5169 | content::NotificationService::NoDetails()); |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5170 | return true; |
| 5171 | } |
[email protected] | 3524260 | 2011-01-06 16:38:53 | [diff] [blame] | 5172 | if (disposition == NEW_FOREGROUND_TAB) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 5173 | TabContentsWrapper* preview_contents = instant()->ReleasePreviewContents( |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 5174 | INSTANT_COMMIT_PRESSED_ENTER); |
[email protected] | a0df03c12 | 2011-01-05 00:22:55 | [diff] [blame] | 5175 | // HideInstant is invoked after release so that InstantController is not |
| 5176 | // active when HideInstant asks it for its state. |
| 5177 | HideInstant(); |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 5178 | preview_contents->tab_contents()->controller().PruneAllButActive(); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 5179 | tab_handler_->GetTabStripModel()->AddTabContents( |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5180 | preview_contents, |
| 5181 | -1, |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 5182 | instant()->last_transition_type(), |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 5183 | TabStripModel::ADD_ACTIVE); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 5184 | instant()->CompleteRelease(preview_contents); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 5185 | content::NotificationService::current()->Notify( |
[email protected] | 094b052 | 2011-10-06 00:55:27 | [diff] [blame] | 5186 | chrome::NOTIFICATION_INSTANT_COMMITTED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5187 | content::Source<TabContentsWrapper>(preview_contents), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 5188 | content::NotificationService::NoDetails()); |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 5189 | return true; |
| 5190 | } |
| 5191 | // The omnibox currently doesn't use other dispositions, so we don't attempt |
| 5192 | // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add |
| 5193 | // support for the new disposition. |
| 5194 | NOTREACHED(); |
| 5195 | return false; |
| 5196 | } |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 5197 | |
| 5198 | void Browser::CreateInstantIfNecessary() { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 5199 | if (is_type_tabbed() && InstantController::IsEnabled(profile()) && |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 5200 | !profile()->IsOffTheRecord()) { |
[email protected] | fdf773c5 | 2010-11-01 20:58:19 | [diff] [blame] | 5201 | instant_.reset(new InstantController(profile_, this)); |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 5202 | instant_unload_handler_.reset(new InstantUnloadHandler(this)); |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 5203 | } |
| 5204 | } |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5205 | |
| 5206 | void Browser::ViewSource(TabContentsWrapper* contents) { |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 5207 | DCHECK(contents); |
| 5208 | |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 5209 | NavigationEntry* active_entry = |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 5210 | contents->tab_contents()->controller().GetActiveEntry(); |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 5211 | if (!active_entry) |
| 5212 | return; |
| 5213 | |
| 5214 | ViewSource(contents, active_entry->url(), active_entry->content_state()); |
| 5215 | } |
| 5216 | |
| 5217 | void Browser::ViewSource(TabContentsWrapper* contents, |
| 5218 | const GURL& url, |
| 5219 | const std::string& content_state) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 5220 | content::RecordAction(UserMetricsAction("ViewSource")); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5221 | DCHECK(contents); |
| 5222 | |
| 5223 | TabContentsWrapper* view_source_contents = contents->Clone(); |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 5224 | view_source_contents->tab_contents()->controller().PruneAllButActive(); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5225 | NavigationEntry* active_entry = |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 5226 | view_source_contents->tab_contents()->controller().GetActiveEntry(); |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 5227 | if (!active_entry) |
| 5228 | return; |
| 5229 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 5230 | GURL view_source_url = GURL(chrome::kViewSourceScheme + std::string(":") + |
| 5231 | url.spec()); |
| 5232 | active_entry->set_virtual_url(view_source_url); |
[email protected] | 1436beff | 2010-12-16 19:47:04 | [diff] [blame] | 5233 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 5234 | // Do not restore scroller position. |
| 5235 | active_entry->set_content_state( |
| 5236 | webkit_glue::RemoveScrollOffsetFromHistoryState(content_state)); |
| 5237 | |
[email protected] | cd3d50d | 2010-12-18 21:03:29 | [diff] [blame] | 5238 | // Do not restore title, derive it from the url. |
[email protected] | 6b2f7a8 | 2011-04-25 19:30:51 | [diff] [blame] | 5239 | active_entry->set_title(string16()); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5240 | |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 5241 | // Now show view-source entry. |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5242 | if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
| 5243 | // If this is a tabbed browser, just create a duplicate tab inside the same |
| 5244 | // window next to the tab being duplicated. |
| 5245 | int index = tab_handler_->GetTabStripModel()-> |
| 5246 | GetIndexOfTabContents(contents); |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 5247 | int add_types = TabStripModel::ADD_ACTIVE | |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 5248 | TabStripModel::ADD_INHERIT_GROUP; |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5249 | tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 5250 | view_source_contents, |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5251 | add_types); |
| 5252 | } else { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 5253 | Browser* browser = Browser::CreateForType(TYPE_TABBED, profile_); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5254 | |
| 5255 | // Preserve the size of the original window. The new window has already |
| 5256 | // been given an offset by the OS, so we shouldn't copy the old bounds. |
| 5257 | BrowserWindow* new_window = browser->window(); |
| 5258 | new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 5259 | window()->GetRestoredBounds().size())); |
| 5260 | |
| 5261 | // We need to show the browser now. Otherwise ContainerWin assumes the |
| 5262 | // TabContents is invisible and won't size it. |
| 5263 | browser->window()->Show(); |
| 5264 | |
| 5265 | // The page transition below is only for the purpose of inserting the tab. |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 5266 | browser->AddTab(view_source_contents, content::PAGE_TRANSITION_LINK); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5267 | } |
| 5268 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 5269 | SessionService* session_service = |
| 5270 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 5271 | if (session_service) |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 5272 | session_service->TabRestored(view_source_contents, false); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 5273 | } |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 5274 | |
| 5275 | int Browser::GetContentRestrictionsForSelectedTab() { |
| 5276 | int content_restrictions = 0; |
| 5277 | TabContents* current_tab = GetSelectedTabContents(); |
| 5278 | if (current_tab) { |
| 5279 | content_restrictions = current_tab->content_restrictions(); |
[email protected] | 10b833e | 2011-12-21 17:36:30 | [diff] [blame] | 5280 | NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 5281 | // See comment in UpdateCommandsForTabState about why we call url(). |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame^] | 5282 | if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL()) |
| 5283 | || current_tab->showing_interstitial_page()) |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 5284 | content_restrictions |= content::CONTENT_RESTRICTION_SAVE; |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame^] | 5285 | if (current_tab->showing_interstitial_page()) |
| 5286 | content_restrictions |= content::CONTENT_RESTRICTION_PRINT; |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 5287 | } |
| 5288 | return content_restrictions; |
| 5289 | } |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 5290 | |
| 5291 | void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { |
| 5292 | BookmarkBar::State state; |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 5293 | // 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] | 5294 | if (browser_defaults::bookmarks_enabled && |
| 5295 | profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) && |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 5296 | (!window_ || !window_->IsFullscreen())) { |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 5297 | state = BookmarkBar::SHOW; |
| 5298 | } else { |
| 5299 | TabContentsWrapper* tab = GetSelectedTabContentsWrapper(); |
| 5300 | if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar()) |
| 5301 | state = BookmarkBar::DETACHED; |
| 5302 | else |
| 5303 | state = BookmarkBar::HIDDEN; |
| 5304 | } |
| 5305 | if (state == bookmark_bar_state_) |
| 5306 | return; |
| 5307 | |
| 5308 | bookmark_bar_state_ = state; |
| 5309 | |
| 5310 | if (!window_) |
| 5311 | return; // This is called from the constructor when window_ is NULL. |
| 5312 | |
| 5313 | if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) { |
| 5314 | // Don't notify BrowserWindow on a tab switch as at the time this is invoked |
| 5315 | // BrowserWindow hasn't yet switched tabs. The BrowserWindow implementations |
| 5316 | // end up querying state once they process the tab switch. |
| 5317 | return; |
| 5318 | } |
| 5319 | |
| 5320 | BookmarkBar::AnimateChangeType animate_type = |
| 5321 | (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE) ? |
| 5322 | BookmarkBar::ANIMATE_STATE_CHANGE : |
| 5323 | BookmarkBar::DONT_ANIMATE_STATE_CHANGE; |
| 5324 | window_->BookmarkBarStateChanged(animate_type); |
| 5325 | } |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 5326 | |
| 5327 | void Browser::ShowSyncSetup() { |
[email protected] | e0dc2cb | 2011-08-04 03:22:57 | [diff] [blame] | 5328 | ProfileSyncService* service = |
| 5329 | profile()->GetOriginalProfile()->GetProfileSyncService(); |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 5330 | if (service->HasSyncSetupCompleted()) |
[email protected] | a981fd6 | 2011-10-08 03:09:04 | [diff] [blame] | 5331 | ShowOptionsTab(chrome::kPersonalOptionsSubPage); |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 5332 | else |
[email protected] | e0dc2cb | 2011-08-04 03:22:57 | [diff] [blame] | 5333 | service->ShowLoginDialog(); |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 5334 | } |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 5335 | |
| 5336 | void Browser::ToggleSpeechInput() { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 5337 | GetSelectedTabContentsWrapper()->tab_contents()->GetRenderViewHost()-> |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 5338 | ToggleSpeechInput(); |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 5339 | } |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 5340 | |
| 5341 | void Browser::OnWindowDidShow() { |
| 5342 | if (window_has_shown_) |
| 5343 | return; |
| 5344 | window_has_shown_ = true; |
| 5345 | |
[email protected] | 7ffe7e1 | 2011-11-22 03:05:56 | [diff] [blame] | 5346 | // Nothing to do for non-tabbed windows. |
| 5347 | if (!is_type_tabbed()) |
| 5348 | return; |
| 5349 | |
[email protected] | 4e72ebb | 2011-10-18 05:02:18 | [diff] [blame] | 5350 | // Suppress the first run bubble if we're showing the sync promo. |
| 5351 | TabContents* contents = GetSelectedTabContents(); |
[email protected] | bba4ec5d | 2011-10-31 20:35:39 | [diff] [blame] | 5352 | bool is_showing_promo = contents && |
| 5353 | contents->GetURL().SchemeIs(chrome::kChromeUIScheme) && |
| 5354 | contents->GetURL().host() == chrome::kChromeUISyncPromoHost; |
[email protected] | 4e72ebb | 2011-10-18 05:02:18 | [diff] [blame] | 5355 | |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 5356 | // Show the First Run information bubble if we've been told to. |
| 5357 | PrefService* local_state = g_browser_process->local_state(); |
[email protected] | 4e72ebb | 2011-10-18 05:02:18 | [diff] [blame] | 5358 | if (!is_showing_promo && local_state && |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 5359 | local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) { |
[email protected] | 327f0da | 2011-11-08 22:52:43 | [diff] [blame] | 5360 | FirstRun::BubbleType bubble_type = FirstRun::MINIMAL_BUBBLE; |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 5361 | if (local_state-> |
| 5362 | FindPreference(prefs::kShouldUseOEMFirstRunBubble) && |
| 5363 | local_state->GetBoolean(prefs::kShouldUseOEMFirstRunBubble)) { |
| 5364 | bubble_type = FirstRun::OEM_BUBBLE; |
| 5365 | } else if (local_state-> |
| 5366 | FindPreference(prefs::kShouldUseMinimalFirstRunBubble) && |
| 5367 | local_state->GetBoolean(prefs::kShouldUseMinimalFirstRunBubble)) { |
| 5368 | bubble_type = FirstRun::MINIMAL_BUBBLE; |
| 5369 | } |
[email protected] | 4e72ebb | 2011-10-18 05:02:18 | [diff] [blame] | 5370 | // Reset the preference so we don't show the bubble for subsequent |
| 5371 | // windows. |
| 5372 | local_state->SetBoolean(prefs::kShouldShowFirstRunBubble, false); |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 5373 | window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
[email protected] | 7ffe7e1 | 2011-11-22 03:05:56 | [diff] [blame] | 5374 | } else { |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 5375 | GlobalErrorService* service = |
| 5376 | GlobalErrorServiceFactory::GetForProfile(profile()); |
| 5377 | GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
| 5378 | if (error) { |
| 5379 | error->ShowBubbleView(this); |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 5380 | } |
| 5381 | } |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 5382 | } |