[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) |
| 8 | #include <shellapi.h> |
| 9 | #include <windows.h> |
| 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] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 16 | #include "base/command_line.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 17 | #include "base/logging.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 18 | #include "base/metrics/histogram.h" |
[email protected] | b02d038 | 2009-11-30 21:19:50 | [diff] [blame] | 19 | #include "base/path_service.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 20 | #include "base/string_util.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 21 | #include "base/threading/thread.h" |
| 22 | #include "base/threading/thread_restrictions.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 23 | #include "base/time.h" |
[email protected] | 6524385ef | 2010-08-18 06:34:13 | [diff] [blame] | 24 | #include "base/utf_string_conversions.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 25 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | cf28ec5 | 2010-04-09 22:56:34 | [diff] [blame] | 26 | #include "chrome/browser/autofill/autofill_manager.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 27 | #include "chrome/browser/background_contents_service.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 28 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 29 | #include "chrome/browser/bookmarks/bookmark_utils.h" |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 30 | #include "chrome/browser/browser_process.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 31 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | 1518b0d | 2010-04-02 18:38:53 | [diff] [blame] | 32 | #include "chrome/browser/browser_url_handler.h" |
[email protected] | 40d59ce5 | 2009-03-06 23:20:14 | [diff] [blame] | 33 | #include "chrome/browser/character_encoding.h" |
[email protected] | 40ecc90 | 2009-03-16 13:42:47 | [diff] [blame] | 34 | #include "chrome/browser/debugger/devtools_manager.h" |
[email protected] | 2a8a9812 | 2010-07-16 11:58:48 | [diff] [blame] | 35 | #include "chrome/browser/debugger/devtools_toggle_action.h" |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 36 | #include "chrome/browser/debugger/devtools_window.h" |
[email protected] | 6c69796d | 2010-07-16 21:41:16 | [diff] [blame] | 37 | #include "chrome/browser/download/download_item.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 38 | #include "chrome/browser/download/download_item_model.h" |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 39 | #include "chrome/browser/download/download_manager.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 40 | #include "chrome/browser/download/download_shelf.h" |
| 41 | #include "chrome/browser/download/download_started_animation.h" |
[email protected] | 3ea6063 | 2011-04-08 18:25:42 | [diff] [blame] | 42 | #include "chrome/browser/download/save_package.h" |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 43 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | 9fd542df | 2009-09-30 07:32:01 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_browser_event_router.h" |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
[email protected] | 6d7a604 | 2010-08-12 20:12:42 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 47 | #include "chrome/browser/extensions/extension_prefs.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 48 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 49 | #include "chrome/browser/extensions/extension_tab_helper.h" |
[email protected] | b17d41c | 2011-02-17 22:09:59 | [diff] [blame] | 50 | #include "chrome/browser/extensions/extension_tabs_module.h" |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 51 | #include "chrome/browser/favicon/favicon_tab_helper.h" |
[email protected] | 82073579 | 2010-07-29 23:40:01 | [diff] [blame] | 52 | #include "chrome/browser/first_run/first_run.h" |
[email protected] | f7578f5 | 2010-08-30 22:22:49 | [diff] [blame] | 53 | #include "chrome/browser/google/google_url_tracker.h" |
| 54 | #include "chrome/browser/google/google_util.h" |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 55 | #include "chrome/browser/instant/instant_controller.h" |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 56 | #include "chrome/browser/instant/instant_unload_handler.h" |
[email protected] | 90f3990 | 2009-10-03 04:25:37 | [diff] [blame] | 57 | #include "chrome/browser/net/browser_url_util.h" |
[email protected] | a239c3f | 2009-02-17 22:13:19 | [diff] [blame] | 58 | #include "chrome/browser/net/url_fixer_upper.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 59 | #include "chrome/browser/notifications/notification_ui_manager.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 60 | #include "chrome/browser/platform_util.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 61 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 0233759 | 2010-09-27 18:38:25 | [diff] [blame] | 62 | #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 63 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 85e921fb8 | 2009-02-11 23:19:44 | [diff] [blame] | 64 | #include "chrome/browser/sessions/session_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 65 | #include "chrome/browser/sessions/session_service_factory.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 66 | #include "chrome/browser/sessions/session_types.h" |
[email protected] | 92926d9 | 2010-09-02 18:35:06 | [diff] [blame] | 67 | #include "chrome/browser/sessions/tab_restore_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 68 | #include "chrome/browser/sessions/tab_restore_service_factory.h" |
[email protected] | 066629f | 2009-10-17 00:28:13 | [diff] [blame] | 69 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | 40f04797 | 2009-11-25 03:54:40 | [diff] [blame] | 70 | #include "chrome/browser/sync/sync_ui_util.h" |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 71 | #include "chrome/browser/tab_closeable_state_watcher.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 72 | #include "chrome/browser/tab_contents/background_contents.h" |
[email protected] | 7cceebac | 2011-03-03 00:32:21 | [diff] [blame] | 73 | #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 74 | #include "chrome/browser/tabs/tab_finder.h" |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 75 | #include "chrome/browser/tabs/tab_strip_model.h" |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame^] | 76 | #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 77 | #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 78 | #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 79 | #include "chrome/browser/ui/browser_dialogs.h" |
[email protected] | 6768ac0 | 2011-04-06 17:41:04 | [diff] [blame] | 80 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 81 | #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 82 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 3ea6063 | 2011-04-08 18:25:42 | [diff] [blame] | 83 | #include "chrome/browser/ui/download/download_tab_helper.h" |
[email protected] | 45300ad4 | 2010-12-02 15:51:14 | [diff] [blame] | 84 | #include "chrome/browser/ui/find_bar/find_bar.h" |
| 85 | #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 86 | #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 87 | #include "chrome/browser/ui/omnibox/location_bar.h" |
[email protected] | fe90ca8e | 2011-04-08 20:40:43 | [diff] [blame] | 88 | #include "chrome/browser/ui/panels/panel.h" |
| 89 | #include "chrome/browser/ui/panels/panel_manager.h" |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 90 | #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 91 | #include "chrome/browser/ui/status_bubble.h" |
| 92 | #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
[email protected] | 9a80065 | 2010-12-02 17:08:44 | [diff] [blame] | 93 | #include "chrome/browser/ui/tabs/dock_info.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 94 | #include "chrome/browser/ui/tabs/tab_menu_model.h" |
[email protected] | f847e608 | 2011-03-24 00:08:26 | [diff] [blame] | 95 | #include "chrome/browser/ui/web_applications/web_app_ui.h" |
[email protected] | edc37b4 | 2011-04-18 20:43:39 | [diff] [blame] | 96 | #include "chrome/browser/ui/webui/active_downloads_ui.h" |
[email protected] | 265a149 | 2011-02-27 05:58:07 | [diff] [blame] | 97 | #include "chrome/browser/ui/webui/bug_report_ui.h" |
[email protected] | 5c557f37 | 2011-02-26 15:09:20 | [diff] [blame] | 98 | #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
[email protected] | 692c534 | 2011-05-25 19:16:21 | [diff] [blame] | 99 | #include "chrome/browser/ui/webui/web_ui_util.h" |
[email protected] | 9a80065 | 2010-12-02 17:08:44 | [diff] [blame] | 100 | #include "chrome/browser/ui/window_sizer.h" |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 101 | #include "chrome/browser/upgrade_detector.h" |
[email protected] | 86b5401 | 2009-11-19 09:18:50 | [diff] [blame] | 102 | #include "chrome/browser/web_applications/web_app.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 103 | #include "chrome/common/chrome_constants.h" |
| 104 | #include "chrome/common/chrome_switches.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 105 | #include "chrome/common/extensions/extension.h" |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 106 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 15b2c6a | 2011-05-16 23:54:40 | [diff] [blame] | 107 | #include "chrome/common/extensions/extension_messages.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 108 | #include "chrome/common/pref_names.h" |
[email protected] | 7664ab3 | 2011-02-01 23:35:25 | [diff] [blame] | 109 | #include "chrome/common/profiling.h" |
[email protected] | b689fce7 | 2009-03-17 22:45:34 | [diff] [blame] | 110 | #include "chrome/common/url_constants.h" |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 111 | #include "chrome/common/web_apps.h" |
[email protected] | b6021d3 | 2011-02-26 01:25:54 | [diff] [blame] | 112 | #include "content/browser/host_zoom_map.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 113 | #include "content/browser/renderer_host/render_view_host.h" |
| 114 | #include "content/browser/site_instance.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 115 | #include "content/browser/tab_contents/interstitial_page.h" |
| 116 | #include "content/browser/tab_contents/navigation_controller.h" |
| 117 | #include "content/browser/tab_contents/navigation_entry.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 118 | #include "content/browser/tab_contents/tab_contents_view.h" |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 119 | #include "content/browser/user_metrics.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 120 | #include "content/common/content_restriction.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 121 | #include "content/common/notification_service.h" |
[email protected] | 4dd5793 | 2011-03-17 06:06:12 | [diff] [blame] | 122 | #include "content/common/page_transition_types.h" |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 123 | #include "content/common/page_zoom.h" |
| 124 | #include "content/common/view_messages.h" |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 125 | #include "grit/chromium_strings.h" |
| 126 | #include "grit/generated_resources.h" |
| 127 | #include "grit/locale_settings.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 128 | #include "net/base/cookie_monster.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 129 | #include "net/base/net_util.h" |
| 130 | #include "net/base/registry_controlled_domain.h" |
| 131 | #include "net/url_request/url_request_context.h" |
[email protected] | f6767806 | 2011-01-07 17:33:39 | [diff] [blame] | 132 | #include "ui/base/animation/animation.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 133 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 134 | #include "ui/gfx/point.h" |
[email protected] | 1436beff | 2010-12-16 19:47:04 | [diff] [blame] | 135 | #include "webkit/glue/webkit_glue.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 136 | #include "webkit/glue/window_open_disposition.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 137 | |
| 138 | #if defined(OS_WIN) |
[email protected] | b99603c | 2010-12-30 22:13:32 | [diff] [blame] | 139 | #include "app/win/shell.h" |
[email protected] | 36d5e559 | 2010-11-15 20:45:59 | [diff] [blame] | 140 | #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 141 | #include "chrome/browser/shell_integration.h" |
[email protected] | b17d41c | 2011-02-17 22:09:59 | [diff] [blame] | 142 | #include "chrome/browser/ssl/ssl_error_info.h" |
[email protected] | a5d1e1e | 2010-09-23 19:34:12 | [diff] [blame] | 143 | #include "chrome/browser/task_manager/task_manager.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 144 | #include "chrome/browser/ui/view_ids.h" |
| 145 | #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 146 | #endif // OS_WIN |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 147 | |
[email protected] | 6a4f5af2 | 2009-09-23 22:43:00 | [diff] [blame] | 148 | #if defined(OS_MACOSX) |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 149 | #include "chrome/browser/ui/cocoa/find_pasteboard.h" |
[email protected] | 6a4f5af2 | 2009-09-23 22:43:00 | [diff] [blame] | 150 | #endif |
| 151 | |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 152 | #if defined(OS_CHROMEOS) |
[email protected] | 6a2a61d | 2010-11-22 03:25:35 | [diff] [blame] | 153 | #include "chrome/browser/chromeos/boot_times_loader.h" |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 154 | #include "chrome/browser/extensions/file_manager_util.h" |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 155 | #endif |
| 156 | |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 157 | using base::TimeDelta; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 158 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 159 | /////////////////////////////////////////////////////////////////////////////// |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 160 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 161 | namespace { |
| 162 | |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 163 | // The URL to be loaded to display Help. |
[email protected] | 8332c16 | 2011-01-26 12:01:54 | [diff] [blame] | 164 | const char kHelpContentUrl[] = |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 165 | #if defined(OS_CHROMEOS) |
[email protected] | 8332c16 | 2011-01-26 12:01:54 | [diff] [blame] | 166 | #if defined(OFFICIAL_BUILD) |
| 167 | "chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"; |
| 168 | #else |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 169 | "https://www.google.com/support/chromeos/"; |
[email protected] | 8332c16 | 2011-01-26 12:01:54 | [diff] [blame] | 170 | #endif |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 171 | #else |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 172 | "https://www.google.com/support/chrome/"; |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 173 | #endif |
| 174 | |
| 175 | // The URL to be opened when the Help link on the Autofill dialog is clicked. |
| 176 | const char kAutofillHelpUrl[] = |
| 177 | #if defined(OS_CHROMEOS) |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 178 | "https://www.google.com/support/chromeos/bin/answer.py?answer=142893"; |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 179 | #else |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 180 | "https://www.google.com/support/chrome/bin/answer.py?answer=142893"; |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 181 | #endif |
| 182 | |
| 183 | // The URL to be loaded to display the "Report a broken page" form. |
| 184 | const char kBrokenPageUrl[] = |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 185 | "https://www.google.com/support/chrome/bin/request.py?contact_type=" |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 186 | "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; |
| 187 | |
| 188 | // The URL for the privacy dashboard. |
| 189 | const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; |
| 190 | |
| 191 | // How long we wait before updating the browser chrome while loading a page. |
| 192 | const int kUIUpdateCoalescingTimeMS = 200; |
| 193 | |
| 194 | const char kHashMark[] = "#"; |
| 195 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 196 | } // namespace |
| 197 | |
[email protected] | e838eaf | 2010-10-13 18:53:33 | [diff] [blame] | 198 | extern bool g_log_bug53991; |
| 199 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 200 | //////////////////////////////////////////////////////////////////////////////// |
| 201 | // Browser, CreateParams: |
| 202 | |
| 203 | Browser::CreateParams::CreateParams(Type type, Profile* profile) |
| 204 | : type(type), |
| 205 | profile(profile) { |
| 206 | } |
| 207 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 208 | /////////////////////////////////////////////////////////////////////////////// |
| 209 | // Browser, Constructors, Creation, Showing: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 210 | |
[email protected] | 299dabd | 2008-11-19 02:27:16 | [diff] [blame] | 211 | Browser::Browser(Type type, Profile* profile) |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 212 | : type_(type), |
| 213 | profile_(profile), |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 214 | window_(NULL), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 215 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 216 | tab_handler_(TabHandler::CreateTabHandler(this))), |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 217 | command_updater_(this), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 218 | toolbar_model_(this), |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 219 | chrome_updater_factory_(this), |
| 220 | is_attempting_to_close_browser_(false), |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 221 | cancel_download_confirmation_state_(NOT_PROMPTED), |
[email protected] | 2e71662 | 2009-03-09 21:11:01 | [diff] [blame] | 222 | maximized_state_(MAXIMIZED_STATE_DEFAULT), |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 223 | method_factory_(this), |
| 224 | block_command_execution_(false), |
| 225 | last_blocked_command_id_(-1), |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 226 | last_blocked_command_disposition_(CURRENT_TAB), |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 227 | pending_web_app_action_(NONE), |
| 228 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 229 | tab_restore_service_delegate_( |
| 230 | new BrowserTabRestoreServiceDelegate(this))) { |
[email protected] | 0cb9410 | 2009-05-22 19:51:21 | [diff] [blame] | 231 | registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, |
| 232 | NotificationService::AllSources()); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 233 | registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, |
| 234 | NotificationService::AllSources()); |
[email protected] | ad0c2e1b | 2010-01-30 00:00:10 | [diff] [blame] | 235 | registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
| 236 | NotificationService::AllSources()); |
[email protected] | 0cb9410 | 2009-05-22 19:51:21 | [diff] [blame] | 237 | registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 238 | NotificationService::AllSources()); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 239 | registrar_.Add(this, NotificationType::EXTENSION_UNINSTALLED, |
| 240 | NotificationService::AllSources()); |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 241 | registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED, |
[email protected] | 371ed7a | 2009-08-25 15:22:46 | [diff] [blame] | 242 | NotificationService::AllSources()); |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 243 | registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 244 | NotificationService::AllSources()); |
[email protected] | 9a9a9e2 | 2011-05-13 22:20:35 | [diff] [blame] | 245 | registrar_.Add(this, NotificationType::TAB_CONTENT_SETTINGS_CHANGED, |
| 246 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 247 | |
[email protected] | 91e1bd8 | 2009-09-03 22:04:40 | [diff] [blame] | 248 | // Need to know when to alert the user of theme install delay. |
| 249 | registrar_.Add(this, NotificationType::EXTENSION_READY_FOR_INSTALL, |
| 250 | NotificationService::AllSources()); |
| 251 | |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 252 | PrefService* local_state = g_browser_process->local_state(); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 253 | if (local_state) { |
| 254 | local_pref_registrar_.Init(local_state); |
| 255 | local_pref_registrar_.Add(prefs::kPrintingEnabled, this); |
| 256 | local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); |
| 257 | } |
| 258 | |
| 259 | profile_pref_registrar_.Init(profile_->GetPrefs()); |
| 260 | profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); |
| 261 | profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); |
| 262 | profile_pref_registrar_.Add(prefs::kInstantEnabled, this); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 263 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 264 | InitCommandState(); |
| 265 | BrowserList::AddBrowser(this); |
| 266 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 267 | // NOTE: These prefs all need to be explicitly destroyed in the destructor |
| 268 | // or you'll get a nasty surprise when you run the incognito tests. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 269 | encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, |
| 270 | profile_->GetPrefs(), NULL); |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 271 | use_vertical_tabs_.Init(prefs::kUseVerticalTabs, profile_->GetPrefs(), this); |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 272 | use_compact_navigation_bar_.Init(prefs::kUseCompactNavigationBar, |
| 273 | profile_->GetPrefs(), |
| 274 | this); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 275 | |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 276 | if (!TabMenuModel::AreVerticalTabsEnabled()) { |
| 277 | // If vertical tabs aren't enabled, explicitly turn them off. Otherwise we |
| 278 | // might show vertical tabs but not show an option to turn them off. |
| 279 | use_vertical_tabs_.SetValue(false); |
| 280 | } |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 281 | if (!TabMenuModel::IsCompactNavigationModeEnabled()) { |
| 282 | // If the compact navigation bar isn't enabled, explicitly turn it off. |
| 283 | // Otherwise we might show the compact navigation bar but not show an option |
| 284 | // to turn it off. |
| 285 | use_compact_navigation_bar_.SetValue(false); |
| 286 | } |
| 287 | |
[email protected] | b334487 | 2010-05-03 15:52:29 | [diff] [blame] | 288 | UpdateTabStripModelInsertionPolicy(); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 289 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 290 | tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 291 | if (tab_restore_service_) { |
| 292 | tab_restore_service_->AddObserver(this); |
| 293 | TabRestoreServiceChanged(tab_restore_service_); |
| 294 | } |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 295 | |
| 296 | if (profile_->GetProfileSyncService()) |
| 297 | profile_->GetProfileSyncService()->AddObserver(this); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 298 | |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 299 | CreateInstantIfNecessary(); |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 300 | |
| 301 | // Make sure TabFinder has been created. This does nothing if TabFinder is |
| 302 | // not enabled. |
| 303 | TabFinder::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | Browser::~Browser() { |
[email protected] | 5044da8 | 2010-10-27 01:09:16 | [diff] [blame] | 307 | VLOG_IF(1, g_log_bug53991) << "~Browser: " << profile_->IsOffTheRecord() |
| 308 | << "; stillActive=" |
| 309 | << BrowserList::IsOffTheRecordSessionActive(); |
[email protected] | e838eaf | 2010-10-13 18:53:33 | [diff] [blame] | 310 | |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 311 | if (profile_->GetProfileSyncService()) |
| 312 | profile_->GetProfileSyncService()->RemoveObserver(this); |
| 313 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 314 | BrowserList::RemoveBrowser(this); |
| 315 | |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 316 | #if !defined(OS_MACOSX) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 317 | if (!BrowserList::HasBrowserWithProfile(profile_)) { |
| 318 | // We're the last browser window with this profile. We need to nuke the |
| 319 | // TabRestoreService, which will start the shutdown of the |
| 320 | // NavigationControllers and allow for proper shutdown. If we don't do this |
| 321 | // chrome won't shutdown cleanly, and may end up crashing when some |
| 322 | // thread tries to use the IO thread (or another thread) that is no longer |
| 323 | // valid. |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 324 | // This isn't a valid assumption for Mac OS, as it stays running after |
| 325 | // the last browser has closed. The Mac equivalent is in its app |
| 326 | // controller. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 327 | TabRestoreServiceFactory::ResetForProfile(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 328 | } |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 329 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 330 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 331 | SessionService* session_service = |
| 332 | SessionServiceFactory::GetForProfile(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 333 | if (session_service) |
| 334 | session_service->WindowClosed(session_id_); |
| 335 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 336 | TabRestoreService* tab_restore_service = |
| 337 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 338 | if (tab_restore_service) |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 339 | tab_restore_service->BrowserClosed(tab_restore_service_delegate()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 340 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 341 | profile_pref_registrar_.RemoveAll(); |
| 342 | local_pref_registrar_.RemoveAll(); |
| 343 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 344 | encoding_auto_detect_.Destroy(); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 345 | use_vertical_tabs_.Destroy(); |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 346 | use_compact_navigation_bar_.Destroy(); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 347 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 348 | if (profile_->IsOffTheRecord() && |
| 349 | !BrowserList::IsOffTheRecordSessionActive()) { |
[email protected] | 0d1add3 | 2011-04-07 00:06:50 | [diff] [blame] | 350 | // An incognito profile is no longer needed, this indirectly |
[email protected] | 860f5549 | 2009-03-27 19:50:59 | [diff] [blame] | 351 | // frees its cache and cookies. |
| 352 | profile_->GetOriginalProfile()->DestroyOffTheRecordProfile(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | // There may be pending file dialogs, we need to tell them that we've gone |
| 356 | // away so they don't try and call back to us. |
| 357 | if (select_file_dialog_.get()) |
| 358 | select_file_dialog_->ListenerDestroyed(); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 359 | |
| 360 | TabRestoreServiceDestroyed(tab_restore_service_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 361 | } |
| 362 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 363 | // static |
| 364 | Browser* Browser::Create(Profile* profile) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 365 | Browser* browser = new Browser(TYPE_TABBED, profile); |
| 366 | browser->InitBrowserWindow(); |
| 367 | return browser; |
| 368 | } |
| 369 | |
| 370 | // static |
| 371 | Browser* Browser::CreateWithParams(const CreateParams& params) { |
| 372 | Browser* browser = new Browser(params.type, params.profile); |
| 373 | browser->app_name_ = params.app_name; |
| 374 | if (!params.initial_bounds.IsEmpty()) |
| 375 | browser->set_override_bounds(params.initial_bounds); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 376 | browser->InitBrowserWindow(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 377 | return browser; |
| 378 | } |
[email protected] | 6104acf | 2008-11-11 22:27:34 | [diff] [blame] | 379 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 380 | // static |
[email protected] | 9ee17e8c | 2010-08-10 19:17:31 | [diff] [blame] | 381 | Browser* Browser::CreateForType(Type type, Profile* profile) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 382 | CreateParams params(type, profile); |
| 383 | return CreateWithParams(params); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | // static |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 387 | Browser* Browser::CreateForApp(Type type, |
| 388 | const std::string& app_name, |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 389 | const gfx::Size& window_size, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 390 | Profile* profile) { |
| 391 | DCHECK(type != TYPE_TABBED); |
| 392 | DCHECK(!app_name.empty()); |
[email protected] | f075fe0a2 | 2010-04-26 04:06:43 | [diff] [blame] | 393 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 394 | RegisterAppPrefs(app_name, profile); |
| 395 | |
| 396 | #if !defined(OS_CHROMEOS) |
| 397 | if (type == TYPE_PANEL && |
| 398 | !CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) { |
| 399 | // The panel UI is not fully implemented, so we default to TYPE_POPUP when |
| 400 | // the panel switch is not enabled. See crbug/55943. |
| 401 | type = TYPE_POPUP; |
[email protected] | 5530ac65 | 2010-09-25 05:35:49 | [diff] [blame] | 402 | } |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 403 | #endif |
[email protected] | f075fe0a2 | 2010-04-26 04:06:43 | [diff] [blame] | 404 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 405 | CreateParams params(type, profile); |
| 406 | params.app_name = app_name; |
| 407 | if (!window_size.IsEmpty()) |
| 408 | params.initial_bounds.set_size(window_size); |
[email protected] | 605cfad | 2010-06-22 20:49:35 | [diff] [blame] | 409 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 410 | return CreateWithParams(params); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 411 | } |
| 412 | |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 413 | // static |
| 414 | Browser* Browser::CreateForDevTools(Profile* profile) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 415 | CreateParams params(TYPE_POPUP, profile); |
| 416 | params.app_name = DevToolsWindow::kDevToolsApp; |
| 417 | return CreateWithParams(params); |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 418 | } |
| 419 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 420 | void Browser::InitBrowserWindow() { |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 421 | DCHECK(!window_); |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 422 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 423 | window_ = CreateBrowserWindow(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 424 | |
[email protected] | 80cf356 | 2009-11-17 08:17:24 | [diff] [blame] | 425 | #if defined(OS_WIN) |
[email protected] | 45446a5 | 2010-11-04 17:41:00 | [diff] [blame] | 426 | { |
| 427 | // TODO: This might hit the disk |
| 428 | // http://code.google.com/p/chromium/issues/detail?id=61638 |
| 429 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 430 | |
| 431 | // Set the app user model id for this application to that of the application |
| 432 | // name. See http://crbug.com/7028. |
[email protected] | b99603c | 2010-12-30 22:13:32 | [diff] [blame] | 433 | app::win::SetAppIdForWindow( |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 434 | is_app() ? |
[email protected] | 45446a5 | 2010-11-04 17:41:00 | [diff] [blame] | 435 | ShellIntegration::GetAppId(UTF8ToWide(app_name_), profile_->GetPath()) : |
| 436 | ShellIntegration::GetChromiumAppId(profile_->GetPath()), |
| 437 | window()->GetNativeHandle()); |
| 438 | } |
[email protected] | 80cf356 | 2009-11-17 08:17:24 | [diff] [blame] | 439 | #endif |
| 440 | |
[email protected] | 14d8c66e | 2009-09-22 00:32:52 | [diff] [blame] | 441 | NotificationService::current()->Notify( |
| 442 | NotificationType::BROWSER_WINDOW_READY, |
| 443 | Source<Browser>(this), |
| 444 | NotificationService::NoDetails()); |
| 445 | |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 446 | if (use_compact_navigation_bar_.GetValue()) { |
| 447 | // This enables the compact navigation bar host. |
| 448 | UseCompactNavigationBarChanged(); |
| 449 | } |
| 450 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 451 | // Show the First Run information bubble if we've been told to. |
| 452 | PrefService* local_state = g_browser_process->local_state(); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 453 | if (!local_state) |
| 454 | return; |
[email protected] | da6ce560 | 2009-12-07 23:09:32 | [diff] [blame] | 455 | if (local_state->FindPreference(prefs::kShouldShowFirstRunBubble) && |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 456 | local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) { |
[email protected] | 450028dd | 2010-08-28 00:24:50 | [diff] [blame] | 457 | FirstRun::BubbleType bubble_type = FirstRun::LARGE_BUBBLE; |
[email protected] | adfe188 | 2010-04-13 23:01:07 | [diff] [blame] | 458 | if (local_state-> |
[email protected] | da6ce560 | 2009-12-07 23:09:32 | [diff] [blame] | 459 | FindPreference(prefs::kShouldUseOEMFirstRunBubble) && |
[email protected] | adfe188 | 2010-04-13 23:01:07 | [diff] [blame] | 460 | local_state->GetBoolean(prefs::kShouldUseOEMFirstRunBubble)) { |
[email protected] | 450028dd | 2010-08-28 00:24:50 | [diff] [blame] | 461 | bubble_type = FirstRun::OEM_BUBBLE; |
[email protected] | adfe188 | 2010-04-13 23:01:07 | [diff] [blame] | 462 | } else if (local_state-> |
| 463 | FindPreference(prefs::kShouldUseMinimalFirstRunBubble) && |
| 464 | local_state->GetBoolean(prefs::kShouldUseMinimalFirstRunBubble)) { |
[email protected] | 450028dd | 2010-08-28 00:24:50 | [diff] [blame] | 465 | bubble_type = FirstRun::MINIMAL_BUBBLE; |
[email protected] | adfe188 | 2010-04-13 23:01:07 | [diff] [blame] | 466 | } |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 467 | // Reset the preference so we don't show the bubble for subsequent windows. |
| 468 | local_state->ClearPref(prefs::kShouldShowFirstRunBubble); |
[email protected] | adfe188 | 2010-04-13 23:01:07 | [diff] [blame] | 469 | window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 470 | } |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 471 | if (local_state->FindPreference( |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 472 | prefs::kAutofillPersonalDataManagerFirstRun) && |
| 473 | local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) { |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 474 | // Notify PDM that this is a first run. |
| 475 | #if defined(OS_WIN) |
| 476 | ImportAutofillDataWin(profile_->GetPersonalDataManager()); |
| 477 | #endif // defined(OS_WIN) |
| 478 | // Reset the preference so we don't call it again for subsequent windows. |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 479 | local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun); |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 480 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 481 | } |
| 482 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 483 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 484 | // Getters & Setters |
| 485 | |
| 486 | const std::vector<std::wstring>& Browser::user_data_dir_profiles() const { |
| 487 | return g_browser_process->user_data_dir_profiles(); |
| 488 | } |
| 489 | |
| 490 | void Browser::set_user_data_dir_profiles( |
| 491 | const std::vector<std::wstring>& profiles) { |
| 492 | g_browser_process->user_data_dir_profiles() = profiles; |
| 493 | } |
| 494 | |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 495 | FindBarController* Browser::GetFindBarController() { |
| 496 | if (!find_bar_controller_.get()) { |
| 497 | FindBar* find_bar = BrowserWindow::CreateFindBar(this); |
| 498 | find_bar_controller_.reset(new FindBarController(find_bar)); |
| 499 | find_bar->SetFindBarController(find_bar_controller_.get()); |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 500 | find_bar_controller_->ChangeTabContents(GetSelectedTabContentsWrapper()); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 501 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
| 502 | } |
| 503 | return find_bar_controller_.get(); |
| 504 | } |
| 505 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 506 | bool Browser::HasFindBarController() const { |
| 507 | return find_bar_controller_.get() != NULL; |
| 508 | } |
| 509 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 510 | bool Browser::is_app() const { |
| 511 | return !app_name_.empty(); |
| 512 | } |
| 513 | |
| 514 | bool Browser::is_devtools() const { |
| 515 | return app_name_ == DevToolsWindow::kDevToolsApp; |
| 516 | } |
| 517 | |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 518 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 519 | // Browser, Creation Helpers: |
| 520 | |
| 521 | // static |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 522 | void Browser::OpenEmptyWindow(Profile* profile) { |
| 523 | Browser* browser = Browser::Create(profile); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 524 | browser->AddBlankTab(true); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 525 | browser->window()->Show(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 526 | } |
| 527 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 528 | // static |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 529 | void Browser::OpenWindowWithRestoredTabs(Profile* profile) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 530 | TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile); |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 531 | if (service) |
| 532 | service->RestoreMostRecentEntry(NULL); |
| 533 | } |
| 534 | |
| 535 | // static |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 536 | void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 537 | Browser* browser = GetOrCreateTabbedBrowser( |
| 538 | profile->GetOffTheRecordProfile()); |
| 539 | browser->AddSelectedTabWithURL(url, PageTransition::LINK); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 540 | browser->window()->Show(); |
[email protected] | 2baf83d | 2008-07-30 05:58:17 | [diff] [blame] | 541 | } |
| 542 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 543 | // static |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 544 | TabContents* Browser::OpenApplication( |
| 545 | Profile* profile, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 546 | const Extension* extension, |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 547 | extension_misc::LaunchContainer container, |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 548 | WindowOpenDisposition disposition) { |
[email protected] | 5686938 | 2010-05-11 21:45:46 | [diff] [blame] | 549 | TabContents* tab = NULL; |
[email protected] | 4033bd9 | 2011-03-08 19:27:04 | [diff] [blame] | 550 | ExtensionPrefs* prefs = profile->GetExtensionService()->extension_prefs(); |
| 551 | prefs->SetActiveBit(extension->id(), true); |
[email protected] | e3acb7c | 2010-05-11 19:23:37 | [diff] [blame] | 552 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 553 | UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchContainer", container, 100); |
| 554 | |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 555 | switch (container) { |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 556 | case extension_misc::LAUNCH_WINDOW: |
| 557 | case extension_misc::LAUNCH_PANEL: |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 558 | tab = Browser::OpenApplicationWindow(profile, extension, container, |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 559 | GURL(), NULL); |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 560 | break; |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 561 | case extension_misc::LAUNCH_TAB: { |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 562 | tab = Browser::OpenApplicationTab(profile, extension, disposition); |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 563 | break; |
| 564 | } |
| 565 | default: |
| 566 | NOTREACHED(); |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 567 | break; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 568 | } |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 569 | return tab; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | // static |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 573 | TabContents* Browser::OpenApplicationWindow( |
| 574 | Profile* profile, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 575 | const Extension* extension, |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 576 | extension_misc::LaunchContainer container, |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 577 | const GURL& url_input, |
| 578 | Browser** app_browser) { |
[email protected] | f381dfa | 2010-04-29 04:41:37 | [diff] [blame] | 579 | GURL url; |
| 580 | if (!url_input.is_empty()) { |
| 581 | if (extension) |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 582 | DCHECK(extension->web_extent().MatchesURL(url_input)); |
[email protected] | f381dfa | 2010-04-29 04:41:37 | [diff] [blame] | 583 | url = url_input; |
| 584 | } else { |
[email protected] | ae5909e | 2011-02-23 14:34:18 | [diff] [blame] | 585 | DCHECK(extension); // Empty url and no extension. Nothing to open. |
[email protected] | f381dfa | 2010-04-29 04:41:37 | [diff] [blame] | 586 | url = extension->GetFullLaunchURL(); |
| 587 | } |
| 588 | |
[email protected] | 2f1c09d | 2011-01-14 14:58:14 | [diff] [blame] | 589 | std::string app_name; |
| 590 | if (extension) |
| 591 | app_name = |
| 592 | web_app::GenerateApplicationNameFromExtensionId(extension->id()); |
| 593 | else |
| 594 | app_name = web_app::GenerateApplicationNameFromURL(url); |
| 595 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 596 | Type type = extension && (container == extension_misc::LAUNCH_PANEL) ? |
| 597 | TYPE_PANEL : TYPE_POPUP; |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 598 | |
| 599 | gfx::Size window_size; |
| 600 | if (extension) |
| 601 | window_size.SetSize(extension->launch_width(), |
| 602 | extension->launch_height()); |
| 603 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 604 | Browser* browser = Browser::CreateForApp(type, app_name, window_size, |
| 605 | profile); |
[email protected] | 011396a | 2011-04-13 23:35:28 | [diff] [blame] | 606 | |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 607 | if (app_browser) |
| 608 | *app_browser = browser; |
| 609 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 610 | TabContentsWrapper* wrapper = |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 611 | browser->AddSelectedTabWithURL(url, PageTransition::START_PAGE); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 612 | TabContents* contents = wrapper->tab_contents(); |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 613 | contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 614 | contents->render_view_host()->SyncRendererPrefs(); |
| 615 | browser->window()->Show(); |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 616 | |
[email protected] | 68f009f | 2009-02-26 19:43:35 | [diff] [blame] | 617 | // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
| 618 | // focus explicitly. |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 619 | contents->view()->SetInitialFocus(); |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 620 | return contents; |
| 621 | } |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 622 | |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 623 | TabContents* Browser::OpenAppShortcutWindow(Profile* profile, |
| 624 | const GURL& url, |
| 625 | bool update_shortcut) { |
| 626 | Browser* app_browser; |
| 627 | TabContents* tab = OpenApplicationWindow( |
| 628 | profile, |
| 629 | NULL, // this is a URL app. No extension. |
| 630 | extension_misc::LAUNCH_WINDOW, |
| 631 | url, |
| 632 | &app_browser); |
| 633 | |
| 634 | if (!tab) |
| 635 | return NULL; |
| 636 | |
| 637 | if (update_shortcut) { |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 638 | // Set UPDATE_SHORTCUT as the pending web app action. This action is picked |
| 639 | // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
| 640 | // the web app info is available, TabContents notifies Browser via |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 641 | // OnDidGetApplicationInfo, which calls |
| 642 | // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
| 643 | // pending web app action. |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 644 | app_browser->pending_web_app_action_ = UPDATE_SHORTCUT; |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 645 | } |
[email protected] | 0e71e415 | 2010-12-07 04:16:26 | [diff] [blame] | 646 | return tab; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | // static |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 650 | TabContents* Browser::OpenApplicationTab(Profile* profile, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 651 | const Extension* extension, |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 652 | WindowOpenDisposition disposition) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 653 | Browser* browser = BrowserList::FindTabbedBrowser(profile, false); |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 654 | TabContents* contents = NULL; |
[email protected] | ea86bfb | 2011-02-08 18:15:44 | [diff] [blame] | 655 | if (!browser) |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 656 | return contents; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 657 | |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 658 | // Check the prefs for overridden mode. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 659 | ExtensionService* extension_service = profile->GetExtensionService(); |
| 660 | DCHECK(extension_service); |
[email protected] | b283a753 | 2010-08-12 21:24:59 | [diff] [blame] | 661 | |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 662 | ExtensionPrefs::LaunchType launch_type = |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 663 | extension_service->extension_prefs()->GetLaunchType( |
[email protected] | 4e59568 | 2011-02-09 17:07:02 | [diff] [blame] | 664 | extension->id(), ExtensionPrefs::LAUNCH_DEFAULT); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 665 | UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 666 | int add_type = TabStripModel::ADD_ACTIVE; |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 667 | if (launch_type == ExtensionPrefs::LAUNCH_PINNED) |
| 668 | add_type |= TabStripModel::ADD_PINNED; |
| 669 | |
[email protected] | 37fcf26 | 2011-01-26 19:39:15 | [diff] [blame] | 670 | // For extensions lacking launch urls, determine a reasonable fallback. |
| 671 | GURL extension_url = extension->GetFullLaunchURL(); |
| 672 | if (!extension_url.is_valid()) { |
| 673 | extension_url = extension->options_url(); |
| 674 | if (!extension_url.is_valid()) |
| 675 | extension_url = GURL(chrome::kChromeUIExtensionsURL); |
| 676 | } |
| 677 | |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 678 | // TODO(erikkay): START_PAGE doesn't seem like the right transition in all |
| 679 | // cases. |
[email protected] | 37fcf26 | 2011-01-26 19:39:15 | [diff] [blame] | 680 | browser::NavigateParams params(browser, extension_url, |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 681 | PageTransition::START_PAGE); |
| 682 | params.tabstrip_add_types = add_type; |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 683 | params.disposition = disposition; |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 684 | |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 685 | if (disposition == CURRENT_TAB) { |
| 686 | TabContents* existing_tab = browser->GetSelectedTabContents(); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 687 | TabStripModel* model = browser->tabstrip_model(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 688 | int tab_index = model->GetWrapperIndex(existing_tab); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 689 | |
| 690 | existing_tab->OpenURL(extension->GetFullLaunchURL(), existing_tab->GetURL(), |
[email protected] | 7e41c2b | 2011-05-06 10:31:16 | [diff] [blame] | 691 | disposition, PageTransition::LINK); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 692 | if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) { |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 693 | model->SetTabPinned(tab_index, true); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 694 | tab_index = model->GetWrapperIndex(existing_tab); |
[email protected] | 7dfec421 | 2010-11-01 22:12:26 | [diff] [blame] | 695 | } |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 696 | if (params.tabstrip_add_types & TabStripModel::ADD_ACTIVE) |
| 697 | model->ActivateTabAt(tab_index, true); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 698 | |
| 699 | contents = existing_tab; |
| 700 | } else { |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 701 | browser::Navigate(¶ms); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 702 | contents = params.target_contents->tab_contents(); |
[email protected] | 24bf202 | 2010-10-14 16:34:39 | [diff] [blame] | 703 | } |
| 704 | |
[email protected] | 7bd42fc | 2011-02-09 17:32:42 | [diff] [blame] | 705 | // TODO(skerner): If we are already in full screen mode, and the user |
| 706 | // set the app to open as a regular or pinned tab, what should happen? |
| 707 | // Today we open the tab, but stay in full screen mode. Should we leave |
| 708 | // full screen mode in this case? |
| 709 | if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && |
| 710 | !browser->window()->IsFullscreen()) |
| 711 | browser->ToggleFullscreenMode(); |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 712 | |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 713 | return contents; |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | // static |
[email protected] | 90a8bf25 | 2010-03-12 00:09:47 | [diff] [blame] | 717 | void Browser::OpenBookmarkManagerWindow(Profile* profile) { |
| 718 | Browser* browser = Browser::Create(profile); |
| 719 | browser->ShowBookmarkManagerTab(); |
| 720 | browser->window()->Show(); |
| 721 | } |
| 722 | |
[email protected] | 057d959a | 2010-03-12 02:56:20 | [diff] [blame] | 723 | #if defined(OS_MACOSX) |
[email protected] | 90a8bf25 | 2010-03-12 00:09:47 | [diff] [blame] | 724 | // static |
[email protected] | 91a5b3e | 2009-10-30 19:32:22 | [diff] [blame] | 725 | void Browser::OpenHistoryWindow(Profile* profile) { |
| 726 | Browser* browser = Browser::Create(profile); |
| 727 | browser->ShowHistoryTab(); |
| 728 | browser->window()->Show(); |
| 729 | } |
| 730 | |
| 731 | // static |
| 732 | void Browser::OpenDownloadsWindow(Profile* profile) { |
| 733 | Browser* browser = Browser::Create(profile); |
| 734 | browser->ShowDownloadsTab(); |
| 735 | browser->window()->Show(); |
| 736 | } |
| 737 | |
| 738 | // static |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 739 | void Browser::OpenHelpWindow(Profile* profile) { |
| 740 | Browser* browser = Browser::Create(profile); |
| 741 | browser->OpenHelpTab(); |
| 742 | browser->window()->Show(); |
| 743 | } |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 744 | |
[email protected] | eca25813 | 2010-11-15 23:33:08 | [diff] [blame] | 745 | // static |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 746 | void Browser::OpenOptionsWindow(Profile* profile) { |
| 747 | Browser* browser = Browser::Create(profile); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 748 | browser->OpenOptionsDialog(); |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 749 | browser->window()->Show(); |
| 750 | } |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 751 | |
| 752 | // static |
| 753 | void Browser::OpenClearBrowingDataDialogWindow(Profile* profile) { |
| 754 | Browser* browser = Browser::Create(profile); |
| 755 | browser->OpenClearBrowsingDataDialog(); |
| 756 | browser->window()->Show(); |
| 757 | } |
| 758 | |
| 759 | // static |
| 760 | void Browser::OpenImportSettingsDialogWindow(Profile* profile) { |
| 761 | Browser* browser = Browser::Create(profile); |
| 762 | browser->OpenImportSettingsDialog(); |
| 763 | browser->window()->Show(); |
| 764 | } |
[email protected] | b99081b | 2011-03-10 17:43:47 | [diff] [blame] | 765 | |
| 766 | // static |
| 767 | void Browser::OpenInstantConfirmDialogWindow(Profile* profile) { |
| 768 | Browser* browser = Browser::Create(profile); |
| 769 | browser->OpenInstantConfirmDialog(); |
| 770 | browser->window()->Show(); |
| 771 | } |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 772 | #endif |
| 773 | |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 774 | // static |
| 775 | void Browser::OpenExtensionsWindow(Profile* profile) { |
| 776 | Browser* browser = Browser::Create(profile); |
| 777 | browser->ShowExtensionsTab(); |
| 778 | browser->window()->Show(); |
| 779 | } |
| 780 | |
[email protected] | 29d7025 | 2011-04-28 02:16:58 | [diff] [blame] | 781 | // static |
| 782 | void Browser::NewWindowWithProfile(Profile* profile) { |
| 783 | UserMetrics::RecordAction(UserMetricsAction("NewWindow")); |
| 784 | SessionService* session_service = |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 785 | SessionServiceFactory::GetForProfile(profile->GetOriginalProfile()); |
[email protected] | 29d7025 | 2011-04-28 02:16:58 | [diff] [blame] | 786 | if (!session_service || |
| 787 | !session_service->RestoreIfNecessary(std::vector<GURL>())) { |
| 788 | Browser::OpenEmptyWindow(profile->GetOriginalProfile()); |
| 789 | } |
| 790 | } |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 791 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 792 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 793 | // Browser, State Storage and Retrieval for UI: |
| 794 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 795 | std::string Browser::GetWindowPlacementKey() const { |
| 796 | std::string name(prefs::kBrowserWindowPlacement); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 797 | if (!app_name_.empty()) { |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 798 | name.append("_"); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 799 | name.append(app_name_); |
| 800 | } |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 801 | return name; |
| 802 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 803 | |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 804 | bool Browser::ShouldSaveWindowPlacement() const { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 805 | switch (type_) { |
| 806 | case TYPE_TABBED: |
| 807 | return true; |
| 808 | case TYPE_POPUP: |
| 809 | // Only save the window placement of popups if they are restored. |
| 810 | return browser_defaults::kRestorePopups; |
| 811 | case TYPE_PANEL: |
| 812 | // Do not save the window placement of panels. |
| 813 | return false; |
| 814 | default: |
| 815 | return false; |
| 816 | } |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 817 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 818 | |
[email protected] | bc9a515 | 2008-11-15 00:32:04 | [diff] [blame] | 819 | void Browser::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized) { |
| 820 | // Save to the session storage service, used when reloading a past session. |
| 821 | // Note that we don't want to be the ones who cause lazy initialization of |
| 822 | // the session service. This function gets called during initial window |
| 823 | // 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] | 824 | SessionService* session_service = |
| 825 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
| 826 | if (session_service) |
| 827 | session_service->SetWindowBounds(session_id_, bounds, maximized); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 828 | } |
| 829 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 830 | gfx::Rect Browser::GetSavedWindowBounds() const { |
[email protected] | bb97536 | 2009-01-21 01:00:22 | [diff] [blame] | 831 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 832 | bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode); |
| 833 | bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode); |
| 834 | if (record_mode || playback_mode) { |
| 835 | // In playback/record mode we always fix the size of the browser and |
| 836 | // move it to (0,0). The reason for this is two reasons: First we want |
| 837 | // resize/moves in the playback to still work, and Second we want |
| 838 | // playbacks to work (as much as possible) on machines w/ different |
| 839 | // screen sizes. |
| 840 | return gfx::Rect(0, 0, 800, 600); |
| 841 | } |
| 842 | |
| 843 | gfx::Rect restored_bounds = override_bounds_; |
| 844 | bool maximized; |
[email protected] | f87919d7 | 2011-02-02 18:46:16 | [diff] [blame] | 845 | WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 846 | &restored_bounds, &maximized); |
| 847 | return restored_bounds; |
| 848 | } |
| 849 | |
| 850 | // TODO(beng): obtain maximized state some other way so we don't need to go |
| 851 | // through all this hassle. |
| 852 | bool Browser::GetSavedMaximizedState() const { |
[email protected] | bb97536 | 2009-01-21 01:00:22 | [diff] [blame] | 853 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 854 | return true; |
| 855 | |
[email protected] | 2e71662 | 2009-03-09 21:11:01 | [diff] [blame] | 856 | if (maximized_state_ == MAXIMIZED_STATE_MAXIMIZED) |
| 857 | return true; |
| 858 | if (maximized_state_ == MAXIMIZED_STATE_UNMAXIMIZED) |
| 859 | return false; |
| 860 | |
| 861 | // An explicit maximized state was not set. Query the window sizer. |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 862 | gfx::Rect restored_bounds; |
[email protected] | 2e71662 | 2009-03-09 21:11:01 | [diff] [blame] | 863 | bool maximized = false; |
[email protected] | f87919d7 | 2011-02-02 18:46:16 | [diff] [blame] | 864 | WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 865 | &restored_bounds, &maximized); |
| 866 | return maximized; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | SkBitmap Browser::GetCurrentPageIcon() const { |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 870 | TabContentsWrapper* contents = GetSelectedTabContentsWrapper(); |
[email protected] | ce5348a8 | 2008-12-18 18:36:23 | [diff] [blame] | 871 | // |contents| can be NULL since GetCurrentPageIcon() is called by the window |
| 872 | // during the window's creation (before tabs have been added). |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 873 | return contents ? contents->favicon_tab_helper()->GetFavicon() : SkBitmap(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 874 | } |
| 875 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 876 | string16 Browser::GetWindowTitleForCurrentTab() const { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 877 | TabContents* contents = GetSelectedTabContents(); |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 878 | string16 title; |
[email protected] | c7c4233 | 2008-11-15 01:10:54 | [diff] [blame] | 879 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 880 | // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the |
| 881 | // window during the window's creation (before tabs have been added). |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 882 | if (contents) { |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 883 | title = contents->GetTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 884 | FormatTitleForDisplay(&title); |
| 885 | } |
| 886 | if (title.empty()) |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 887 | title = TabContentsWrapper::GetDefaultTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 888 | |
[email protected] | 1677984 | 2009-07-08 23:45:29 | [diff] [blame] | 889 | #if defined(OS_MACOSX) || defined(OS_CHROMEOS) |
[email protected] | 22a3daa | 2009-11-09 22:03:33 | [diff] [blame] | 890 | // On Mac or ChromeOS, we don't want to suffix the page title with |
| 891 | // the application name. |
[email protected] | d904bc8 | 2009-07-07 00:41:04 | [diff] [blame] | 892 | return title; |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 893 | #else |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 894 | int string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT; |
[email protected] | dff52973 | 2010-04-01 23:50:55 | [diff] [blame] | 895 | // 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] | 896 | if (is_app()) |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 897 | string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT_NO_LOGO; |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 898 | return l10n_util::GetStringFUTF16(string_id, title); |
[email protected] | 57e68dba | 2009-05-15 21:30:50 | [diff] [blame] | 899 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | // static |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 903 | void Browser::FormatTitleForDisplay(string16* title) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 904 | size_t current_index = 0; |
| 905 | size_t match_index; |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 906 | while ((match_index = title->find(L'\n', current_index)) != string16::npos) { |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 907 | title->replace(match_index, 1, string16()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 908 | current_index = match_index; |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | /////////////////////////////////////////////////////////////////////////////// |
| 913 | // Browser, OnBeforeUnload handling: |
| 914 | |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 915 | bool Browser::TabsNeedBeforeUnloadFired() { |
| 916 | if (tabs_needing_before_unload_fired_.empty()) { |
| 917 | for (int i = 0; i < tab_count(); ++i) { |
| 918 | TabContents* contents = GetTabContentsAt(i); |
| 919 | if (contents->NeedToFireBeforeUnload()) |
| 920 | tabs_needing_before_unload_fired_.insert(contents); |
| 921 | } |
| 922 | } |
| 923 | return !tabs_needing_before_unload_fired_.empty(); |
| 924 | } |
| 925 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 926 | bool Browser::ShouldCloseWindow() { |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 927 | if (!CanCloseWithInProgressDownloads()) |
| 928 | return false; |
| 929 | |
| 930 | if (HasCompletedUnloadProcessing()) |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 931 | return IsClosingPermitted(); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 932 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 933 | is_attempting_to_close_browser_ = true; |
| 934 | |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 935 | if (!TabsNeedBeforeUnloadFired()) |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 936 | return IsClosingPermitted(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 937 | |
| 938 | ProcessPendingTabs(); |
| 939 | return false; |
| 940 | } |
| 941 | |
| 942 | void Browser::OnWindowClosing() { |
| 943 | if (!ShouldCloseWindow()) |
| 944 | return; |
| 945 | |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 946 | bool exiting = false; |
| 947 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 948 | // Application should shutdown on last window close if the user is explicitly |
| 949 | // trying to quit, or if there is nothing keeping the browser alive (such as |
| 950 | // AppController on the Mac, or BackgroundContentsService for background |
| 951 | // pages). |
| 952 | bool should_quit_if_last_browser = |
| 953 | browser_shutdown::IsTryingToQuit() || !BrowserList::WillKeepAlive(); |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 954 | |
| 955 | if (should_quit_if_last_browser && BrowserList::size() == 1) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 956 | browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 957 | exiting = true; |
| 958 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 959 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 960 | // Don't use GetForProfileIfExisting here, we want to force creation of the |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 961 | // session service so that user can restore what was open. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 962 | SessionService* session_service = |
| 963 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 964 | if (session_service) |
| 965 | session_service->WindowClosing(session_id()); |
| 966 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 967 | TabRestoreService* tab_restore_service = |
| 968 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 969 | if (tab_restore_service && is_type_tabbed() && tab_count()) |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 970 | tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 971 | |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 972 | // TODO(sky): convert session/tab restore to use notification. |
| 973 | NotificationService::current()->Notify( |
| 974 | NotificationType::BROWSER_CLOSING, |
| 975 | Source<Browser>(this), |
| 976 | Details<bool>(&exiting)); |
| 977 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 978 | CloseAllTabs(); |
| 979 | } |
| 980 | |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 981 | void Browser::OnWindowActivated() { |
| 982 | // On some platforms we want to automatically reload tabs that are |
| 983 | // killed when the user selects them. |
| 984 | TabContents* contents = GetSelectedTabContents(); |
| 985 | if (contents && contents->crashed_status() == |
| 986 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 987 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 988 | switches::kReloadKilledTabs)) { |
| 989 | Reload(CURRENT_TAB); |
| 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 994 | //////////////////////////////////////////////////////////////////////////////// |
| 995 | // In-progress download termination handling: |
| 996 | |
| 997 | void Browser::InProgressDownloadResponse(bool cancel_downloads) { |
| 998 | if (cancel_downloads) { |
| 999 | cancel_download_confirmation_state_ = RESPONSE_RECEIVED; |
| 1000 | CloseWindow(); |
| 1001 | return; |
| 1002 | } |
| 1003 | |
| 1004 | // Sets the confirmation state to NOT_PROMPTED so that if the user tries to |
| 1005 | // close again we'll show the warning again. |
| 1006 | cancel_download_confirmation_state_ = NOT_PROMPTED; |
| 1007 | |
| 1008 | // Show the download page so the user can figure-out what downloads are still |
| 1009 | // in-progress. |
| 1010 | ShowDownloadsTab(); |
| 1011 | } |
| 1012 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 1013 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1014 | // Browser, TabStripModel pass-thrus: |
| 1015 | |
| 1016 | int Browser::tab_count() const { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1017 | return tab_handler_->GetTabStripModel()->count(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1018 | } |
| 1019 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 1020 | int Browser::active_index() const { |
| 1021 | return tab_handler_->GetTabStripModel()->active_index(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | int Browser::GetIndexOfController( |
| 1025 | const NavigationController* controller) const { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1026 | return tab_handler_->GetTabStripModel()->GetIndexOfController(controller); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1027 | } |
| 1028 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1029 | TabContentsWrapper* Browser::GetSelectedTabContentsWrapper() const { |
| 1030 | return tabstrip_model()->GetSelectedTabContents(); |
| 1031 | } |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1032 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1033 | TabContentsWrapper* Browser::GetTabContentsWrapperAt(int index) const { |
| 1034 | return tabstrip_model()->GetTabContentsAt(index); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | TabContents* Browser::GetSelectedTabContents() const { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1038 | TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); |
| 1039 | if (wrapper) |
| 1040 | return wrapper->tab_contents(); |
| 1041 | return NULL; |
| 1042 | } |
| 1043 | |
| 1044 | TabContents* Browser::GetTabContentsAt(int index) const { |
| 1045 | TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
| 1046 | if (wrapper) |
| 1047 | return wrapper->tab_contents(); |
| 1048 | return NULL; |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1049 | } |
| 1050 | |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1051 | void Browser::ActivateTabAt(int index, bool user_gesture) { |
| 1052 | tab_handler_->GetTabStripModel()->ActivateTabAt(index, user_gesture); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1053 | } |
| 1054 | |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 1055 | bool Browser::IsTabPinned(int index) const { |
| 1056 | return tabstrip_model()->IsTabPinned(index); |
| 1057 | } |
| 1058 | |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1059 | void Browser::CloseAllTabs() { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1060 | tab_handler_->GetTabStripModel()->CloseAllTabs(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1064 | // Browser, Tab adding/showing functions: |
| 1065 | |
[email protected] | 95bf8a5b | 2010-12-22 16:04:07 | [diff] [blame] | 1066 | bool Browser::IsTabStripEditable() const { |
| 1067 | return window()->IsTabStripEditable(); |
| 1068 | } |
| 1069 | |
[email protected] | b334487 | 2010-05-03 15:52:29 | [diff] [blame] | 1070 | int Browser::GetIndexForInsertionDuringRestore(int relative_index) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1071 | return (tab_handler_->GetTabStripModel()->insertion_policy() == |
| 1072 | TabStripModel::INSERT_AFTER) ? tab_count() : relative_index; |
[email protected] | b334487 | 2010-05-03 15:52:29 | [diff] [blame] | 1073 | } |
| 1074 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1075 | TabContentsWrapper* Browser::AddSelectedTabWithURL(const GURL& url, |
[email protected] | cecc93a | 2010-10-05 15:58:55 | [diff] [blame] | 1076 | PageTransition::Type transition) { |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1077 | browser::NavigateParams params(this, url, transition); |
| 1078 | params.disposition = NEW_FOREGROUND_TAB; |
| 1079 | browser::Navigate(¶ms); |
| 1080 | return params.target_contents; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1081 | } |
| 1082 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1083 | TabContents* Browser::AddTab(TabContentsWrapper* tab_contents, |
[email protected] | d99cdfd | 2009-10-08 18:58:11 | [diff] [blame] | 1084 | PageTransition::Type type) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1085 | tab_handler_->GetTabStripModel()->AddTabContents( |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1086 | tab_contents, -1, type, TabStripModel::ADD_ACTIVE); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1087 | return tab_contents->tab_contents(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1088 | } |
| 1089 | |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 1090 | void Browser::AddTabContents(TabContents* new_contents, |
| 1091 | WindowOpenDisposition disposition, |
| 1092 | const gfx::Rect& initial_pos, |
| 1093 | bool user_gesture) { |
| 1094 | AddNewContents(NULL, new_contents, disposition, initial_pos, user_gesture); |
| 1095 | } |
| 1096 | |
| 1097 | void Browser::CloseTabContents(TabContents* contents) { |
| 1098 | CloseContents(contents); |
| 1099 | } |
| 1100 | |
| 1101 | void Browser::BrowserShowHtmlDialog(HtmlDialogUIDelegate* delegate, |
[email protected] | 322f3ff | 2009-05-22 16:19:54 | [diff] [blame] | 1102 | gfx::NativeWindow parent_window) { |
[email protected] | 66b0967e | 2011-05-10 17:55:56 | [diff] [blame] | 1103 | window_->ShowHTMLDialog(delegate, parent_window); |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | void Browser::BrowserRenderWidgetShowing() { |
| 1107 | RenderWidgetShowing(); |
| 1108 | } |
| 1109 | |
[email protected] | c9bd2e8 | 2011-04-15 23:28:19 | [diff] [blame] | 1110 | void Browser::BookmarkBarSizeChanged(bool is_animating) { |
| 1111 | window_->ToolbarSizeChanged(is_animating); |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 1112 | } |
| 1113 | |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1114 | TabContents* Browser::AddRestoredTab( |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1115 | const std::vector<TabNavigation>& navigations, |
| 1116 | int tab_index, |
| 1117 | int selected_navigation, |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 1118 | const std::string& extension_app_id, |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1119 | bool select, |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1120 | bool pin, |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 1121 | bool from_last_session, |
| 1122 | SessionStorageNamespace* session_storage_namespace) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1123 | TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL, |
| 1124 | MSG_ROUTING_NONE, |
| 1125 | GetSelectedTabContents(), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1126 | session_storage_namespace); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1127 | TabContents* new_tab = wrapper->tab_contents(); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1128 | wrapper->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1129 | new_tab->controller().RestoreFromState(navigations, selected_navigation, |
| 1130 | from_last_session); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1131 | |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1132 | int add_types = select ? TabStripModel::ADD_ACTIVE : |
[email protected] | 981b992e | 2011-03-28 21:05:21 | [diff] [blame] | 1133 | TabStripModel::ADD_NONE; |
| 1134 | if (pin) { |
| 1135 | tab_index = std::min(tab_index, tabstrip_model()->IndexOfFirstNonMiniTab()); |
| 1136 | add_types |= TabStripModel::ADD_PINNED; |
| 1137 | } |
| 1138 | tab_handler_->GetTabStripModel()->InsertTabContentsAt(tab_index, wrapper, |
| 1139 | add_types); |
[email protected] | c93a9dd | 2010-04-22 20:25:18 | [diff] [blame] | 1140 | if (select) { |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 1141 | window_->Activate(); |
[email protected] | c93a9dd | 2010-04-22 20:25:18 | [diff] [blame] | 1142 | } else { |
| 1143 | // We set the size of the view here, before WebKit does its initial |
| 1144 | // layout. If we don't, the initial layout of background tabs will be |
| 1145 | // performed with a view width of 0, which may cause script outputs and |
| 1146 | // anchor link location calculations to be incorrect even after a new |
| 1147 | // layout with proper view dimensions. TabStripModel::AddTabContents() |
| 1148 | // contains similar logic. |
| 1149 | new_tab->view()->SizeContents(window_->GetRestoredBounds().size()); |
| 1150 | new_tab->HideContents(); |
| 1151 | } |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1152 | SessionService* session_service = |
| 1153 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 1154 | if (session_service) |
| 1155 | session_service->TabRestored(&new_tab->controller(), pin); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1156 | return new_tab; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | void Browser::ReplaceRestoredTab( |
| 1160 | const std::vector<TabNavigation>& navigations, |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1161 | int selected_navigation, |
[email protected] | fca656c | 2010-02-10 20:30:10 | [diff] [blame] | 1162 | bool from_last_session, |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 1163 | const std::string& extension_app_id, |
| 1164 | SessionStorageNamespace* session_storage_namespace) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1165 | TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL, |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1166 | MSG_ROUTING_NONE, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1167 | GetSelectedTabContents(), |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 1168 | session_storage_namespace); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1169 | wrapper->extension_tab_helper()->SetExtensionAppById(extension_app_id); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1170 | TabContents* replacement = wrapper->tab_contents(); |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1171 | replacement->controller().RestoreFromState(navigations, selected_navigation, |
| 1172 | from_last_session); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1173 | |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1174 | tab_handler_->GetTabStripModel()->ReplaceNavigationControllerAt( |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 1175 | tab_handler_->GetTabStripModel()->active_index(), |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1176 | wrapper); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1177 | } |
| 1178 | |
[email protected] | a8eff10 | 2009-04-14 15:23:43 | [diff] [blame] | 1179 | bool Browser::CanRestoreTab() { |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 1180 | return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB); |
[email protected] | a8eff10 | 2009-04-14 15:23:43 | [diff] [blame] | 1181 | } |
| 1182 | |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1183 | bool Browser::NavigateToIndexWithDisposition(int index, |
| 1184 | WindowOpenDisposition disp) { |
| 1185 | NavigationController& controller = |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1186 | GetOrCloneTabForDisposition(disp)->controller(); |
| 1187 | if (index < 0 || index >= controller.entry_count()) |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1188 | return false; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1189 | controller.GoToIndex(index); |
| 1190 | return true; |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1191 | } |
| 1192 | |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1193 | browser::NavigateParams Browser::GetSingletonTabNavigateParams( |
| 1194 | const GURL& url) { |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1195 | browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK); |
| 1196 | params.disposition = SINGLETON_TAB; |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 1197 | params.window_action = browser::NavigateParams::SHOW_WINDOW; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 1198 | params.user_gesture = true; |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1199 | return params; |
| 1200 | } |
| 1201 | |
| 1202 | void Browser::ShowSingletonTab(const GURL& url) { |
| 1203 | browser::NavigateParams params(GetSingletonTabNavigateParams(url)); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1204 | browser::Navigate(¶ms); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1205 | } |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 1206 | |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1207 | void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { |
[email protected] | 326464d | 2010-02-16 22:21:10 | [diff] [blame] | 1208 | #if !defined(OS_MACOSX) |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1209 | const bool show_main_ui = is_type_tabbed() && !is_fullscreen; |
[email protected] | 326464d | 2010-02-16 22:21:10 | [diff] [blame] | 1210 | #else |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1211 | const bool show_main_ui = is_type_tabbed(); |
[email protected] | 326464d | 2010-02-16 22:21:10 | [diff] [blame] | 1212 | #endif |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1213 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1214 | bool main_not_fullscreen = show_main_ui && !is_fullscreen; |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 1215 | |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1216 | // Navigation commands |
| 1217 | command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); |
| 1218 | |
| 1219 | // Window management commands |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1220 | command_updater_.UpdateCommandEnabled(IDC_SHOW_AS_TAB, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1221 | type_ != TYPE_TABBED && !is_fullscreen); |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1222 | |
| 1223 | // Focus various bits of UI |
| 1224 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); |
| 1225 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui); |
| 1226 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); |
[email protected] | cc82437 | 2010-03-31 15:33:01 | [diff] [blame] | 1227 | command_updater_.UpdateCommandEnabled( |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1228 | IDC_FOCUS_MENU_BAR, main_not_fullscreen); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 1229 | command_updater_.UpdateCommandEnabled( |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1230 | IDC_FOCUS_NEXT_PANE, main_not_fullscreen); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 1231 | command_updater_.UpdateCommandEnabled( |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1232 | IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 1233 | command_updater_.UpdateCommandEnabled( |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1234 | IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 1235 | command_updater_.UpdateCommandEnabled( |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1236 | IDC_FOCUS_CHROMEOS_STATUS, main_not_fullscreen); |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1237 | |
| 1238 | // Show various bits of UI |
| 1239 | command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
[email protected] | 1c41a93 | 2010-11-22 23:41:23 | [diff] [blame] | 1240 | command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
[email protected] | 4a4180a5 | 2010-08-23 06:39:48 | [diff] [blame] | 1241 | command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, |
| 1242 | browser_defaults::bookmarks_enabled && show_main_ui); |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1243 | command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, show_main_ui); |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 1244 | command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, |
| 1245 | show_main_ui && profile_->IsSyncAccessible()); |
[email protected] | da96e54c | 2010-08-12 00:18:32 | [diff] [blame] | 1246 | |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1247 | command_updater_.UpdateCommandEnabled(IDC_OPTIONS, show_main_ui); |
| 1248 | command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 1249 | command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 1250 | command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
[email protected] | fdb9851 | 2009-08-26 01:37:10 | [diff] [blame] | 1251 | command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
[email protected] | c8b59f9 | 2010-05-28 21:45:47 | [diff] [blame] | 1252 | command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 1253 | command_updater_.UpdateCommandEnabled(IDC_COMPACT_NAVBAR, show_main_ui); |
[email protected] | 7664ab3 | 2011-02-01 23:35:25 | [diff] [blame] | 1254 | #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
| 1255 | command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| 1256 | #endif |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1257 | } |
| 1258 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1259 | /////////////////////////////////////////////////////////////////////////////// |
| 1260 | // Browser, Assorted browser commands: |
| 1261 | |
[email protected] | d497b078 | 2010-03-29 19:19:06 | [diff] [blame] | 1262 | bool Browser::ShouldOpenNewTabForWindowDisposition( |
| 1263 | WindowOpenDisposition disposition) { |
| 1264 | return (disposition == NEW_FOREGROUND_TAB || |
| 1265 | disposition == NEW_BACKGROUND_TAB); |
| 1266 | } |
| 1267 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1268 | TabContents* Browser::GetOrCloneTabForDisposition( |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1269 | WindowOpenDisposition disposition) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1270 | TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
[email protected] | d497b078 | 2010-03-29 19:19:06 | [diff] [blame] | 1271 | if (ShouldOpenNewTabForWindowDisposition(disposition)) { |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1272 | current_tab = current_tab->Clone(); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1273 | tab_handler_->GetTabStripModel()->AddTabContents( |
[email protected] | 4a166544 | 2010-06-28 16:09:39 | [diff] [blame] | 1274 | current_tab, -1, PageTransition::LINK, |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1275 | disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE : |
[email protected] | 4a166544 | 2010-06-28 16:09:39 | [diff] [blame] | 1276 | TabStripModel::ADD_NONE); |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1277 | } |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1278 | return current_tab->tab_contents(); |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1279 | } |
| 1280 | |
[email protected] | b334487 | 2010-05-03 15:52:29 | [diff] [blame] | 1281 | void Browser::UpdateTabStripModelInsertionPolicy() { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1282 | tab_handler_->GetTabStripModel()->SetInsertionPolicy(UseVerticalTabs() ? |
[email protected] | b334487 | 2010-05-03 15:52:29 | [diff] [blame] | 1283 | TabStripModel::INSERT_BEFORE : TabStripModel::INSERT_AFTER); |
| 1284 | } |
| 1285 | |
| 1286 | void Browser::UseVerticalTabsChanged() { |
| 1287 | UpdateTabStripModelInsertionPolicy(); |
| 1288 | window()->ToggleTabStripMode(); |
| 1289 | } |
| 1290 | |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 1291 | void Browser::UseCompactNavigationBarChanged() { |
| 1292 | window_->ToggleUseCompactNavigationBar(); |
| 1293 | } |
| 1294 | |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1295 | bool Browser::SupportsWindowFeatureImpl(WindowFeature feature, |
| 1296 | bool check_fullscreen) const { |
| 1297 | // On Mac, fullscreen mode has most normal things (in a slide-down panel). On |
| 1298 | // other platforms, we hide some controls when in fullscreen mode. |
| 1299 | bool hide_ui_for_fullscreen = false; |
| 1300 | #if !defined(OS_MACOSX) |
| 1301 | hide_ui_for_fullscreen = check_fullscreen && window_ && |
| 1302 | window_->IsFullscreen(); |
| 1303 | #endif |
| 1304 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 1305 | unsigned int features = FEATURE_INFOBAR | FEATURE_SIDEBAR; |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1306 | |
| 1307 | #if !defined(OS_CHROMEOS) |
| 1308 | // Chrome OS opens a FileBrowse pop up instead of using download shelf. |
| 1309 | // So FEATURE_DOWNLOADSHELF is only added for non-chromeos platforms. |
| 1310 | features |= FEATURE_DOWNLOADSHELF; |
| 1311 | #endif // !defined(OS_CHROMEOS) |
| 1312 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1313 | if (is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1314 | features |= FEATURE_BOOKMARKBAR; |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1315 | |
| 1316 | if (!hide_ui_for_fullscreen) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1317 | if (!is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1318 | features |= FEATURE_TITLEBAR; |
| 1319 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1320 | if (is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1321 | features |= FEATURE_TABSTRIP; |
| 1322 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1323 | if (is_type_tabbed()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1324 | features |= FEATURE_TOOLBAR; |
| 1325 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1326 | if (!is_app()) |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1327 | features |= FEATURE_LOCATIONBAR; |
| 1328 | } |
| 1329 | return !!(features & feature); |
| 1330 | } |
| 1331 | |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 1332 | bool Browser::IsClosingPermitted() { |
| 1333 | TabCloseableStateWatcher* watcher = |
| 1334 | g_browser_process->tab_closeable_state_watcher(); |
| 1335 | bool can_close = !watcher || watcher->CanCloseBrowser(this); |
| 1336 | if (!can_close && is_attempting_to_close_browser_) |
| 1337 | CancelWindowClose(); |
| 1338 | return can_close; |
| 1339 | } |
| 1340 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1341 | void Browser::GoBack(WindowOpenDisposition disposition) { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1342 | UserMetrics::RecordAction(UserMetricsAction("Back")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1343 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1344 | TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1345 | if (current_tab->controller().CanGoBack()) { |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1346 | TabContents* new_tab = GetOrCloneTabForDisposition(disposition); |
[email protected] | d497b078 | 2010-03-29 19:19:06 | [diff] [blame] | 1347 | // If we are on an interstitial page and clone the tab, it won't be copied |
| 1348 | // to the new tab, so we don't need to go back. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1349 | if (current_tab->tab_contents()->showing_interstitial_page() && |
| 1350 | (new_tab != current_tab->tab_contents())) |
[email protected] | d497b078 | 2010-03-29 19:19:06 | [diff] [blame] | 1351 | return; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1352 | new_tab->controller().GoBack(); |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1353 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1354 | } |
| 1355 | |
[email protected] | 3698f17 | 2010-03-17 20:50:29 | [diff] [blame] | 1356 | void Browser::GoForward(WindowOpenDisposition disposition) { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1357 | UserMetrics::RecordAction(UserMetricsAction("Forward")); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1358 | if (GetSelectedTabContentsWrapper()->controller().CanGoForward()) |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1359 | GetOrCloneTabForDisposition(disposition)->controller().GoForward(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1360 | } |
| 1361 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1362 | void Browser::Reload(WindowOpenDisposition disposition) { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1363 | UserMetrics::RecordAction(UserMetricsAction("Reload")); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1364 | ReloadInternal(disposition, false); |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 1365 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1366 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1367 | void Browser::ReloadIgnoringCache(WindowOpenDisposition disposition) { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1368 | UserMetrics::RecordAction(UserMetricsAction("ReloadIgnoringCache")); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1369 | ReloadInternal(disposition, true); |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 1370 | } |
| 1371 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1372 | void Browser::ReloadInternal(WindowOpenDisposition disposition, |
| 1373 | bool ignore_cache) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1374 | // If we are showing an interstitial, treat this as an OpenURL. |
| 1375 | TabContents* current_tab = GetSelectedTabContents(); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1376 | if (current_tab && current_tab->showing_interstitial_page()) { |
| 1377 | NavigationEntry* entry = current_tab->controller().GetActiveEntry(); |
| 1378 | DCHECK(entry); // Should exist if interstitial is showing. |
| 1379 | OpenURL(entry->url(), GURL(), disposition, PageTransition::RELOAD); |
| 1380 | return; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1381 | } |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1382 | |
| 1383 | // 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] | 1384 | TabContents* tab = GetOrCloneTabForDisposition(disposition); |
| 1385 | if (!tab->FocusLocationBarByDefault()) |
| 1386 | tab->Focus(); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1387 | if (ignore_cache) |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1388 | tab->controller().ReloadIgnoringCache(true); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 1389 | else |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1390 | tab->controller().Reload(true); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1391 | } |
| 1392 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1393 | void Browser::Home(WindowOpenDisposition disposition) { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1394 | UserMetrics::RecordAction(UserMetricsAction("Home")); |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1395 | OpenURL(GetHomePage(), GURL(), disposition, PageTransition::AUTO_BOOKMARK); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1396 | } |
| 1397 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1398 | void Browser::OpenCurrentURL() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1399 | UserMetrics::RecordAction(UserMetricsAction("LoadURL")); |
[email protected] | 7745b82 | 2009-01-27 20:15:35 | [diff] [blame] | 1400 | LocationBar* location_bar = window_->GetLocationBar(); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 1401 | if (!location_bar) |
| 1402 | return; |
| 1403 | |
[email protected] | 9d0306ea | 2009-09-02 19:38:39 | [diff] [blame] | 1404 | WindowOpenDisposition open_disposition = |
| 1405 | location_bar->GetWindowOpenDisposition(); |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 1406 | if (OpenInstant(open_disposition)) |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 1407 | return; |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 1408 | |
[email protected] | 83bf2d14 | 2009-11-06 18:19:30 | [diff] [blame] | 1409 | GURL url(WideToUTF8(location_bar->GetInputString())); |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 1410 | |
| 1411 | if (open_disposition == CURRENT_TAB && TabFinder::IsEnabled()) { |
| 1412 | Browser* existing_browser = NULL; |
| 1413 | TabContents* existing_tab = TabFinder::GetInstance()->FindTab( |
| 1414 | this, url, &existing_browser); |
| 1415 | if (existing_tab) { |
| 1416 | existing_browser->ActivateContents(existing_tab); |
| 1417 | return; |
| 1418 | } |
| 1419 | } |
| 1420 | |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1421 | browser::NavigateParams params(this, url, location_bar->GetPageTransition()); |
| 1422 | params.disposition = open_disposition; |
[email protected] | 514576a | 2010-07-01 22:51:25 | [diff] [blame] | 1423 | // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least |
| 1424 | // inherit the opener. In some cases the tabstrip will determine the group |
| 1425 | // should be inherited, in which case the group is inherited instead of the |
| 1426 | // opener. |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1427 | params.tabstrip_add_types = |
| 1428 | TabStripModel::ADD_FORCE_INDEX | TabStripModel::ADD_INHERIT_OPENER; |
| 1429 | browser::Navigate(¶ms); |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 1430 | |
[email protected] | 6e37fe3 | 2011-03-02 09:06:52 | [diff] [blame] | 1431 | DCHECK(profile_->GetExtensionService()); |
| 1432 | if (profile_->GetExtensionService()->IsInstalledApp(url)) { |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 1433 | UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, |
| 1434 | extension_misc::APP_LAUNCH_OMNIBOX_LOCATION, |
| 1435 | extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 1436 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1437 | } |
| 1438 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1439 | void Browser::Stop() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1440 | UserMetrics::RecordAction(UserMetricsAction("Stop")); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1441 | GetSelectedTabContentsWrapper()->tab_contents()->Stop(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | void Browser::NewWindow() { |
[email protected] | 047e727 | 2010-06-03 19:53:35 | [diff] [blame] | 1445 | if (browser_defaults::kAlwaysOpenIncognitoWindow && |
[email protected] | 6e6f6cb | 2011-01-27 13:26:55 | [diff] [blame] | 1446 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) && |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 1447 | profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { |
[email protected] | 047e727 | 2010-06-03 19:53:35 | [diff] [blame] | 1448 | NewIncognitoWindow(); |
| 1449 | return; |
| 1450 | } |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1451 | UserMetrics::RecordAction(UserMetricsAction("NewWindow")); |
[email protected] | c9b1994 | 2010-03-26 15:58:08 | [diff] [blame] | 1452 | SessionService* session_service = |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1453 | SessionServiceFactory::GetForProfile(profile_->GetOriginalProfile()); |
[email protected] | c9b1994 | 2010-03-26 15:58:08 | [diff] [blame] | 1454 | if (!session_service || |
| 1455 | !session_service->RestoreIfNecessary(std::vector<GURL>())) { |
| 1456 | Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); |
| 1457 | } |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | void Browser::NewIncognitoWindow() { |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 1461 | if (!profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { |
[email protected] | 6e6f6cb | 2011-01-27 13:26:55 | [diff] [blame] | 1462 | NewWindow(); |
| 1463 | return; |
| 1464 | } |
| 1465 | |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1466 | UserMetrics::RecordAction(UserMetricsAction("NewIncognitoWindow")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1467 | Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); |
| 1468 | } |
| 1469 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1470 | void Browser::CloseWindow() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1471 | UserMetrics::RecordAction(UserMetricsAction("CloseWindow")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1472 | window_->Close(); |
| 1473 | } |
| 1474 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1475 | void Browser::NewTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1476 | UserMetrics::RecordAction(UserMetricsAction("NewTab")); |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 1477 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1478 | if (is_type_tabbed()) { |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1479 | AddBlankTab(true); |
[email protected] | 49bb7ea3 | 2011-02-02 17:58:06 | [diff] [blame] | 1480 | GetSelectedTabContentsWrapper()->view()->RestoreFocus(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1481 | } else { |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 1482 | Browser* b = GetOrCreateTabbedBrowser(profile_); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1483 | b->AddBlankTab(true); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1484 | b->window()->Show(); |
[email protected] | e54f30d | 2009-01-14 21:17:11 | [diff] [blame] | 1485 | // The call to AddBlankTab above did not set the focus to the tab as its |
| 1486 | // window was not active, so we have to do it explicitly. |
| 1487 | // See http://crbug.com/6380. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1488 | b->GetSelectedTabContentsWrapper()->view()->RestoreFocus(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | void Browser::CloseTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1493 | UserMetrics::RecordAction(UserMetricsAction("CloseTab_Accelerator")); |
[email protected] | 90b1a7a | 2011-03-17 21:28:21 | [diff] [blame] | 1494 | if (CanCloseTab()) |
| 1495 | tab_handler_->GetTabStripModel()->CloseSelectedTabs(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1496 | } |
| 1497 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1498 | void Browser::SelectNextTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1499 | UserMetrics::RecordAction(UserMetricsAction("SelectNextTab")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1500 | tab_handler_->GetTabStripModel()->SelectNextTab(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | void Browser::SelectPreviousTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1504 | UserMetrics::RecordAction(UserMetricsAction("SelectPrevTab")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1505 | tab_handler_->GetTabStripModel()->SelectPreviousTab(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1506 | } |
| 1507 | |
[email protected] | 91ac920 | 2010-07-30 18:32:35 | [diff] [blame] | 1508 | void Browser::OpenTabpose() { |
| 1509 | #if defined(OS_MACOSX) |
[email protected] | aac169d | 2011-03-18 19:53:03 | [diff] [blame] | 1510 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 1511 | switches::kEnableExposeForTabs)) { |
| 1512 | return; |
| 1513 | } |
| 1514 | |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1515 | UserMetrics::RecordAction(UserMetricsAction("OpenTabpose")); |
[email protected] | 91ac920 | 2010-07-30 18:32:35 | [diff] [blame] | 1516 | window()->OpenTabpose(); |
| 1517 | #else |
| 1518 | NOTREACHED(); |
| 1519 | #endif |
| 1520 | } |
| 1521 | |
[email protected] | 9ac7fcb | 2009-09-14 18:22:52 | [diff] [blame] | 1522 | void Browser::MoveTabNext() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1523 | UserMetrics::RecordAction(UserMetricsAction("MoveTabNext")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1524 | tab_handler_->GetTabStripModel()->MoveTabNext(); |
[email protected] | 9ac7fcb | 2009-09-14 18:22:52 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | void Browser::MoveTabPrevious() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1528 | UserMetrics::RecordAction(UserMetricsAction("MoveTabPrevious")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1529 | tab_handler_->GetTabStripModel()->MoveTabPrevious(); |
[email protected] | 9ac7fcb | 2009-09-14 18:22:52 | [diff] [blame] | 1530 | } |
| 1531 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1532 | void Browser::SelectNumberedTab(int index) { |
| 1533 | if (index < tab_count()) { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1534 | UserMetrics::RecordAction(UserMetricsAction("SelectNumberedTab")); |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1535 | tab_handler_->GetTabStripModel()->ActivateTabAt(index, true); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | void Browser::SelectLastTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1540 | UserMetrics::RecordAction(UserMetricsAction("SelectLastTab")); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1541 | tab_handler_->GetTabStripModel()->SelectLastTab(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | void Browser::DuplicateTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1545 | UserMetrics::RecordAction(UserMetricsAction("Duplicate")); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 1546 | DuplicateContentsAt(active_index()); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | void Browser::RestoreTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1550 | UserMetrics::RecordAction(UserMetricsAction("RestoreTab")); |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1551 | TabRestoreService* service = |
| 1552 | TabRestoreServiceFactory::GetForProfile(profile_); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1553 | if (!service) |
| 1554 | return; |
| 1555 | |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 1556 | service->RestoreMostRecentEntry(tab_restore_service_delegate()); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1557 | } |
| 1558 | |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1559 | void Browser::WriteCurrentURLToClipboard() { |
| 1560 | // TODO(ericu): There isn't currently a metric for this. Should there be? |
| 1561 | // We don't appear to track the action when it comes from the |
| 1562 | // RenderContextViewMenu. |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1563 | |
| 1564 | TabContents* contents = GetSelectedTabContents(); |
| 1565 | if (!contents->ShouldDisplayURL()) |
| 1566 | return; |
| 1567 | |
[email protected] | 90f3990 | 2009-10-03 04:25:37 | [diff] [blame] | 1568 | chrome_browser_net::WriteURLToClipboard( |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1569 | contents->GetURL(), |
[email protected] | 9f284f13 | 2010-08-31 06:14:17 | [diff] [blame] | 1570 | profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
[email protected] | 0c4c388 | 2009-10-01 21:42:14 | [diff] [blame] | 1571 | g_browser_process->clipboard()); |
| 1572 | } |
| 1573 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1574 | void Browser::ConvertPopupToTabbedBrowser() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1575 | UserMetrics::RecordAction(UserMetricsAction("ShowAsTab")); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 1576 | int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1577 | TabContentsWrapper* contents = |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1578 | tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1579 | Browser* browser = Browser::Create(profile_); |
| 1580 | browser->tabstrip_model()->AppendTabContents(contents, true); |
| 1581 | browser->window()->Show(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1582 | } |
| 1583 | |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 1584 | void Browser::ToggleFullscreenMode() { |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 1585 | #if !defined(OS_MACOSX) |
| 1586 | // In kiosk mode, we always want to be fullscreen. When the browser first |
| 1587 | // starts we're not yet fullscreen, so let the initial toggle go through. |
| 1588 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && |
| 1589 | window_->IsFullscreen()) |
| 1590 | return; |
| 1591 | #endif |
| 1592 | |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1593 | UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 1594 | window_->SetFullscreen(!window_->IsFullscreen()); |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 1595 | // On X11, setting fullscreen mode is an async call to the X server, which |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1596 | // may or may not support fullscreen mode. |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 1597 | #if !defined(USE_X11) |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 1598 | UpdateCommandsForFullscreenMode(window_->IsFullscreen()); |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 1599 | #endif |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 1600 | } |
| 1601 | |
[email protected] | da17b37 | 2010-01-22 23:37:22 | [diff] [blame] | 1602 | #if defined(OS_CHROMEOS) |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 1603 | void Browser::Search() { |
| 1604 | // If the NTP is showing, close it. |
[email protected] | 692c534 | 2011-05-25 19:16:21 | [diff] [blame] | 1605 | const GURL& url = GetSelectedTabContents()->GetURL(); |
| 1606 | if (web_ui_util::ChromeURLHostEquals(url, chrome::kChromeUINewTabHost)) { |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 1607 | CloseTab(); |
| 1608 | return; |
| 1609 | } |
[email protected] | 6455986 | 2010-09-23 19:00:16 | [diff] [blame] | 1610 | |
| 1611 | // Exit fullscreen to show omnibox. |
[email protected] | ebdda909 | 2010-10-22 17:59:10 | [diff] [blame] | 1612 | if (window_->IsFullscreen()) { |
[email protected] | 6455986 | 2010-09-23 19:00:16 | [diff] [blame] | 1613 | ToggleFullscreenMode(); |
[email protected] | ebdda909 | 2010-10-22 17:59:10 | [diff] [blame] | 1614 | // ToggleFullscreenMode is asynchronous, so we don't have omnibox |
| 1615 | // visible at this point. Wait for next event cycle which toggles |
| 1616 | // the visibility of omnibox before creating new tab. |
| 1617 | MessageLoop::current()->PostTask( |
| 1618 | FROM_HERE, method_factory_.NewRunnableMethod(&Browser::Search)); |
| 1619 | return; |
| 1620 | } |
[email protected] | 6455986 | 2010-09-23 19:00:16 | [diff] [blame] | 1621 | |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 1622 | // Otherwise just open it. |
| 1623 | NewTab(); |
| 1624 | } |
[email protected] | d14af52 | 2010-12-02 03:54:50 | [diff] [blame] | 1625 | |
| 1626 | void Browser::ShowKeyboardOverlay() { |
| 1627 | window_->ShowKeyboardOverlay(window_->GetNativeHandle()); |
| 1628 | } |
[email protected] | 20d1724 | 2009-10-26 20:21:05 | [diff] [blame] | 1629 | #endif |
| 1630 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1631 | void Browser::Exit() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1632 | UserMetrics::RecordAction(UserMetricsAction("Exit")); |
[email protected] | 965e4c4 | 2010-09-07 21:23:35 | [diff] [blame] | 1633 | #if defined(OS_CHROMEOS) |
[email protected] | 6a2a61d | 2010-11-22 03:25:35 | [diff] [blame] | 1634 | chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutStarted", false); |
| 1635 | // Write /tmp/uptime-logout-started as well. |
| 1636 | const char kLogoutStarted[] = "logout-started"; |
| 1637 | chromeos::BootTimesLoader::Get()->RecordCurrentStats(kLogoutStarted); |
[email protected] | db3abe6 | 2011-02-09 15:13:25 | [diff] [blame] | 1638 | |
| 1639 | // Login screen should show up in owner's locale. |
| 1640 | PrefService* state = g_browser_process->local_state(); |
| 1641 | if (state) { |
| 1642 | std::string owner_locale = state->GetString(prefs::kOwnerLocale); |
| 1643 | if (!owner_locale.empty() && |
| 1644 | state->GetString(prefs::kApplicationLocale) != owner_locale && |
| 1645 | !state->IsManagedPreference(prefs::kApplicationLocale)) { |
| 1646 | state->SetString(prefs::kApplicationLocale, owner_locale); |
| 1647 | state->ScheduleSavePersistentPrefs(); |
| 1648 | } |
| 1649 | } |
[email protected] | 965e4c4 | 2010-09-07 21:23:35 | [diff] [blame] | 1650 | #endif |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 1651 | BrowserList::Exit(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1652 | } |
| 1653 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1654 | void Browser::BookmarkCurrentPage() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1655 | UserMetrics::RecordAction(UserMetricsAction("Star")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1656 | |
[email protected] | 76624fde | 2009-10-09 18:13:23 | [diff] [blame] | 1657 | BookmarkModel* model = profile()->GetBookmarkModel(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1658 | if (!model || !model->IsLoaded()) |
| 1659 | return; // Ignore requests until bookmarks are loaded. |
| 1660 | |
[email protected] | 76624fde | 2009-10-09 18:13:23 | [diff] [blame] | 1661 | GURL url; |
[email protected] | 261cd76 | 2010-08-20 05:45:37 | [diff] [blame] | 1662 | string16 title; |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1663 | TabContentsWrapper* tab = GetSelectedTabContentsWrapper(); |
| 1664 | bookmark_utils::GetURLAndTitleToBookmark(tab->tab_contents(), &url, &title); |
[email protected] | c50d0d4 | 2009-03-03 17:37:44 | [diff] [blame] | 1665 | bool was_bookmarked = model->IsBookmarked(url); |
[email protected] | ef0d04c | 2010-12-15 23:34:21 | [diff] [blame] | 1666 | if (!was_bookmarked && profile_->IsOffTheRecord()) { |
[email protected] | 2c910b7 | 2011-03-08 21:16:32 | [diff] [blame] | 1667 | // 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] | 1668 | // so that bookmarks have an icon for the page. |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1669 | tab->favicon_tab_helper()->SaveFavicon(); |
[email protected] | ef0d04c | 2010-12-15 23:34:21 | [diff] [blame] | 1670 | } |
[email protected] | 261cd76 | 2010-08-20 05:45:37 | [diff] [blame] | 1671 | model->SetURLStarred(url, title, true); |
[email protected] | 11dbbd2 | 2009-11-06 18:55:04 | [diff] [blame] | 1672 | // Make sure the model actually added a bookmark before showing the star. A |
| 1673 | // bookmark isn't created if the url is invalid. |
| 1674 | if (window_->IsActive() && model->IsBookmarked(url)) { |
[email protected] | 5f2731c5 | 2009-02-28 00:41:27 | [diff] [blame] | 1675 | // Only show the bubble if the window is active, otherwise we may get into |
| 1676 | // weird situations were the bubble is deleted as soon as it is shown. |
[email protected] | c50d0d4 | 2009-03-03 17:37:44 | [diff] [blame] | 1677 | window_->ShowBookmarkBubble(url, was_bookmarked); |
[email protected] | 5f2731c5 | 2009-02-28 00:41:27 | [diff] [blame] | 1678 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1679 | } |
| 1680 | |
[email protected] | 40bdb6d9 | 2009-02-25 00:22:27 | [diff] [blame] | 1681 | void Browser::SavePage() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1682 | UserMetrics::RecordAction(UserMetricsAction("SavePage")); |
[email protected] | 15d04ae | 2010-10-30 01:04:50 | [diff] [blame] | 1683 | TabContents* current_tab = GetSelectedTabContents(); |
| 1684 | if (current_tab && current_tab->contents_mime_type() == "application/pdf") |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1685 | UserMetrics::RecordAction(UserMetricsAction("PDF.SavePage")); |
[email protected] | 3ea6063 | 2011-04-08 18:25:42 | [diff] [blame] | 1686 | GetSelectedTabContentsWrapper()->download_tab_helper()->OnSavePage(); |
[email protected] | 40bdb6d9 | 2009-02-25 00:22:27 | [diff] [blame] | 1687 | } |
| 1688 | |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 1689 | void Browser::ViewSelectedSource() { |
| 1690 | ViewSource(GetSelectedTabContentsWrapper()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1691 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1692 | |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1693 | void Browser::ShowFindBar() { |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 1694 | GetFindBarController()->Show(); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1695 | } |
| 1696 | |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 1697 | bool Browser::SupportsWindowFeature(WindowFeature feature) const { |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1698 | return SupportsWindowFeatureImpl(feature, true); |
| 1699 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1700 | |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1701 | bool Browser::CanSupportWindowFeature(WindowFeature feature) const { |
| 1702 | return SupportsWindowFeatureImpl(feature, false); |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 1703 | } |
| 1704 | |
[email protected] | 89d6e6e | 2009-12-03 23:06:51 | [diff] [blame] | 1705 | void Browser::EmailPageLocation() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1706 | UserMetrics::RecordAction(UserMetricsAction("EmailPageLocation")); |
[email protected] | d221a39 | 2011-05-24 14:34:24 | [diff] [blame] | 1707 | TabContents* tc = GetSelectedTabContents(); |
| 1708 | DCHECK(tc); |
| 1709 | |
| 1710 | std::string title = EscapeQueryParamValue(UTF16ToUTF8(tc->GetTitle()), false); |
| 1711 | std::string page_url = EscapeQueryParamValue(tc->GetURL().spec(), false); |
| 1712 | std::string mailto = std::string("mailto:?subject=Fwd:%20") + |
| 1713 | title + "&body=%0A%0A" + page_url; |
| 1714 | platform_util::OpenExternal(GURL(mailto)); |
[email protected] | 89d6e6e | 2009-12-03 23:06:51 | [diff] [blame] | 1715 | } |
| 1716 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1717 | void Browser::Print() { |
[email protected] | 8980e0d | 2011-05-27 19:16:23 | [diff] [blame] | 1718 | if (switches::IsPrintPreviewEnabled()) |
| 1719 | GetSelectedTabContentsWrapper()->print_view_manager()->PrintPreviewNow(); |
| 1720 | else |
[email protected] | 49fe226 | 2011-04-15 20:56:15 | [diff] [blame] | 1721 | GetSelectedTabContentsWrapper()->print_view_manager()->PrintNow(); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1722 | } |
| 1723 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1724 | void Browser::ToggleEncodingAutoDetect() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1725 | UserMetrics::RecordAction(UserMetricsAction("AutoDetectChange")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1726 | encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 1727 | // If "auto detect" is turned on, then any current override encoding |
| 1728 | // is cleared. This also implicitly performs a reload. |
| 1729 | // OTOH, if "auto detect" is turned off, we don't change the currently |
| 1730 | // active encoding. |
| 1731 | if (encoding_auto_detect_.GetValue()) { |
| 1732 | TabContents* contents = GetSelectedTabContents(); |
| 1733 | if (contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 1734 | contents->ResetOverrideEncoding(); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 1735 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | void Browser::OverrideEncoding(int encoding_id) { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1739 | UserMetrics::RecordAction(UserMetricsAction("OverrideEncoding")); |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1740 | const std::string selected_encoding = |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1741 | CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1742 | TabContents* contents = GetSelectedTabContents(); |
| 1743 | if (!selected_encoding.empty() && contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 1744 | contents->SetOverrideEncoding(selected_encoding); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1745 | // Update the list of recently selected encodings. |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1746 | std::string new_selected_encoding_list; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 1747 | if (CharacterEncoding::UpdateRecentlySelectedEncoding( |
| 1748 | profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding), |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1749 | encoding_id, |
| 1750 | &new_selected_encoding_list)) { |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1751 | profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 1752 | new_selected_encoding_list); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1753 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1754 | } |
| 1755 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1756 | void Browser::Cut() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1757 | UserMetrics::RecordAction(UserMetricsAction("Cut")); |
[email protected] | 20012dd4 | 2010-01-25 04:46:23 | [diff] [blame] | 1758 | window()->Cut(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1759 | } |
| 1760 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1761 | void Browser::Copy() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1762 | UserMetrics::RecordAction(UserMetricsAction("Copy")); |
[email protected] | 20012dd4 | 2010-01-25 04:46:23 | [diff] [blame] | 1763 | window()->Copy(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1764 | } |
| 1765 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1766 | void Browser::Paste() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1767 | UserMetrics::RecordAction(UserMetricsAction("Paste")); |
[email protected] | 20012dd4 | 2010-01-25 04:46:23 | [diff] [blame] | 1768 | window()->Paste(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | void Browser::Find() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1772 | UserMetrics::RecordAction(UserMetricsAction("Find")); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1773 | FindInPage(false, false); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | void Browser::FindNext() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1777 | UserMetrics::RecordAction(UserMetricsAction("FindNext")); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1778 | FindInPage(true, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | void Browser::FindPrevious() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1782 | UserMetrics::RecordAction(UserMetricsAction("FindPrevious")); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1783 | FindInPage(true, false); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1784 | } |
| 1785 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1786 | void Browser::Zoom(PageZoom::Function zoom_function) { |
[email protected] | 89622004 | 2010-03-23 18:14:28 | [diff] [blame] | 1787 | static const UserMetricsAction kActions[] = { |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1788 | UserMetricsAction("ZoomMinus"), |
| 1789 | UserMetricsAction("ZoomNormal"), |
| 1790 | UserMetricsAction("ZoomPlus") |
| 1791 | }; |
[email protected] | 89622004 | 2010-03-23 18:14:28 | [diff] [blame] | 1792 | |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1793 | UserMetrics::RecordAction(kActions[zoom_function - PageZoom::ZOOM_OUT]); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1794 | TabContentsWrapper* tab_contents = GetSelectedTabContentsWrapper(); |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1795 | RenderViewHost* host = tab_contents->render_view_host(); |
| 1796 | host->Send(new ViewMsg_Zoom(host->routing_id(), zoom_function)); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | void Browser::FocusToolbar() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1800 | UserMetrics::RecordAction(UserMetricsAction("FocusToolbar")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1801 | window_->FocusToolbar(); |
| 1802 | } |
| 1803 | |
[email protected] | bdb7ff6 | 2010-07-20 01:56:52 | [diff] [blame] | 1804 | void Browser::FocusAppMenu() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1805 | UserMetrics::RecordAction(UserMetricsAction("FocusAppMenu")); |
[email protected] | bdb7ff6 | 2010-07-20 01:56:52 | [diff] [blame] | 1806 | window_->FocusAppMenu(); |
[email protected] | cc82437 | 2010-03-31 15:33:01 | [diff] [blame] | 1807 | } |
| 1808 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1809 | void Browser::FocusLocationBar() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1810 | UserMetrics::RecordAction(UserMetricsAction("FocusLocation")); |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 1811 | window_->SetFocusToLocationBar(true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1812 | } |
| 1813 | |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 1814 | void Browser::FocusBookmarksToolbar() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1815 | UserMetrics::RecordAction(UserMetricsAction("FocusBookmarksToolbar")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 1816 | window_->FocusBookmarksToolbar(); |
| 1817 | } |
| 1818 | |
| 1819 | void Browser::FocusChromeOSStatus() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1820 | UserMetrics::RecordAction(UserMetricsAction("FocusChromeOSStatus")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 1821 | window_->FocusChromeOSStatus(); |
| 1822 | } |
| 1823 | |
| 1824 | void Browser::FocusNextPane() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1825 | UserMetrics::RecordAction(UserMetricsAction("FocusNextPane")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 1826 | window_->RotatePaneFocus(true); |
| 1827 | } |
| 1828 | |
| 1829 | void Browser::FocusPreviousPane() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1830 | UserMetrics::RecordAction(UserMetricsAction("FocusPreviousPane")); |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 1831 | window_->RotatePaneFocus(false); |
| 1832 | } |
| 1833 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1834 | void Browser::FocusSearch() { |
| 1835 | // TODO(beng): replace this with FocusLocationBar |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1836 | UserMetrics::RecordAction(UserMetricsAction("FocusSearch")); |
[email protected] | 7745b82 | 2009-01-27 20:15:35 | [diff] [blame] | 1837 | window_->GetLocationBar()->FocusSearch(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | void Browser::OpenFile() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1841 | UserMetrics::RecordAction(UserMetricsAction("OpenFile")); |
[email protected] | 9d1d8ad5 | 2011-03-11 22:58:17 | [diff] [blame] | 1842 | #if defined(OS_CHROMEOS) && !defined(FILE_MANAGER_EXTENSION) |
[email protected] | f59f116 | 2010-04-23 21:19:29 | [diff] [blame] | 1843 | FileBrowseUI::OpenPopup(profile_, |
| 1844 | "", |
| 1845 | FileBrowseUI::kPopupWidth, |
| 1846 | FileBrowseUI::kPopupHeight); |
| 1847 | #else |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1848 | if (!select_file_dialog_.get()) |
| 1849 | select_file_dialog_ = SelectFileDialog::Create(this); |
| 1850 | |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 1851 | const FilePath directory = profile_->last_selected_directory(); |
| 1852 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1853 | // TODO(beng): figure out how to juggle this. |
[email protected] | d56bcd2 | 2009-03-16 19:51:56 | [diff] [blame] | 1854 | gfx::NativeWindow parent_window = window_->GetNativeHandle(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1855 | select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 1856 | string16(), directory, |
[email protected] | b949f111 | 2009-04-12 20:03:08 | [diff] [blame] | 1857 | NULL, 0, FILE_PATH_LITERAL(""), |
[email protected] | d989891 | 2011-04-15 21:10:00 | [diff] [blame] | 1858 | GetSelectedTabContents(), |
[email protected] | d56bcd2 | 2009-03-16 19:51:56 | [diff] [blame] | 1859 | parent_window, NULL); |
[email protected] | f59f116 | 2010-04-23 21:19:29 | [diff] [blame] | 1860 | #endif |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | void Browser::OpenCreateShortcutsDialog() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1864 | UserMetrics::RecordAction(UserMetricsAction("CreateShortcut")); |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 1865 | #if !defined(OS_MACOSX) |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1866 | TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
| 1867 | DCHECK(current_tab && |
| 1868 | web_app::IsValidUrl(current_tab->tab_contents()->GetURL())) << |
| 1869 | "Menu item should be disabled."; |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 1870 | |
| 1871 | NavigationEntry* entry = current_tab->controller().GetLastCommittedEntry(); |
| 1872 | if (!entry) |
| 1873 | return; |
| 1874 | |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 1875 | // RVH's GetApplicationInfo should not be called before it returns. |
| 1876 | DCHECK(pending_web_app_action_ == NONE); |
| 1877 | pending_web_app_action_ = CREATE_SHORTCUT; |
| 1878 | |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 1879 | // Start fetching web app info for CreateApplicationShortcut dialog and show |
| 1880 | // the dialog when the data is available in OnDidGetApplicationInfo. |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 1881 | current_tab->extension_tab_helper()->GetApplicationInfo(entry->page_id()); |
[email protected] | 98f6e02 | 2009-06-05 22:49:53 | [diff] [blame] | 1882 | #else |
| 1883 | NOTIMPLEMENTED(); |
| 1884 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1885 | } |
| 1886 | |
[email protected] | 2a8a9812 | 2010-07-16 11:58:48 | [diff] [blame] | 1887 | void Browser::ToggleDevToolsWindow(DevToolsToggleAction action) { |
| 1888 | std::string uma_string; |
| 1889 | switch (action) { |
| 1890 | case DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE: |
| 1891 | uma_string = "DevTools_ToggleConsole"; |
| 1892 | break; |
| 1893 | case DEVTOOLS_TOGGLE_ACTION_NONE: |
| 1894 | case DEVTOOLS_TOGGLE_ACTION_INSPECT: |
| 1895 | default: |
| 1896 | uma_string = "DevTools_ToggleWindow"; |
| 1897 | break; |
| 1898 | } |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1899 | UserMetrics::RecordAction(UserMetricsAction(uma_string.c_str())); |
[email protected] | 3061ccf3 | 2009-07-13 14:17:49 | [diff] [blame] | 1900 | DevToolsManager::GetInstance()->ToggleDevToolsWindow( |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1901 | GetSelectedTabContentsWrapper()->render_view_host(), action); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1902 | } |
| 1903 | |
[email protected] | adb6a84d | 2011-02-07 16:58:40 | [diff] [blame] | 1904 | void Browser::OpenTaskManager(bool highlight_background_resources) { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1905 | UserMetrics::RecordAction(UserMetricsAction("TaskManager")); |
[email protected] | adb6a84d | 2011-02-07 16:58:40 | [diff] [blame] | 1906 | if (highlight_background_resources) |
| 1907 | window_->ShowBackgroundPages(); |
| 1908 | else |
| 1909 | window_->ShowTaskManager(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1910 | } |
| 1911 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1912 | void Browser::OpenBugReportDialog() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1913 | UserMetrics::RecordAction(UserMetricsAction("ReportBug")); |
[email protected] | 35d0615 | 2011-01-10 22:19:42 | [diff] [blame] | 1914 | browser::ShowHtmlBugReportView(this); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1915 | } |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 1916 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1917 | void Browser::ToggleBookmarkBar() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1918 | UserMetrics::RecordAction(UserMetricsAction("ShowBookmarksBar")); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1919 | window_->ToggleBookmarkBar(); |
| 1920 | } |
| 1921 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1922 | void Browser::OpenBookmarkManager() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1923 | UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager")); |
[email protected] | 47e532b | 2010-04-23 17:46:40 | [diff] [blame] | 1924 | ShowBookmarkManagerTab(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1925 | } |
[email protected] | 8bf80e92 | 2009-03-09 20:56:36 | [diff] [blame] | 1926 | |
[email protected] | fdb9851 | 2009-08-26 01:37:10 | [diff] [blame] | 1927 | void Browser::ShowAppMenu() { |
[email protected] | 366069f | 2011-01-11 09:36:12 | [diff] [blame] | 1928 | // We record the user metric for this event in WrenchMenu::RunMenu. |
[email protected] | fdb9851 | 2009-08-26 01:37:10 | [diff] [blame] | 1929 | window_->ShowAppMenu(); |
| 1930 | } |
| 1931 | |
[email protected] | 6404197b | 2010-03-03 00:40:40 | [diff] [blame] | 1932 | void Browser::ShowBookmarkManagerTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1933 | UserMetrics::RecordAction(UserMetricsAction("ShowBookmarks")); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1934 | ShowSingletonTab(GURL(chrome::kChromeUIBookmarksURL)); |
[email protected] | 6404197b | 2010-03-03 00:40:40 | [diff] [blame] | 1935 | } |
| 1936 | |
[email protected] | 8bf80e92 | 2009-03-09 20:56:36 | [diff] [blame] | 1937 | void Browser::ShowHistoryTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1938 | UserMetrics::RecordAction(UserMetricsAction("ShowHistory")); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1939 | ShowSingletonTab(GURL(chrome::kChromeUIHistoryURL)); |
[email protected] | 8bf80e92 | 2009-03-09 20:56:36 | [diff] [blame] | 1940 | } |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1941 | |
| 1942 | void Browser::ShowDownloadsTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1943 | UserMetrics::RecordAction(UserMetricsAction("ShowDownloads")); |
[email protected] | 3d037ce7 | 2011-04-04 17:43:45 | [diff] [blame] | 1944 | if (window()) { |
| 1945 | DownloadShelf* shelf = window()->GetDownloadShelf(); |
| 1946 | if (shelf->IsShowing()) |
| 1947 | shelf->Close(); |
| 1948 | } |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1949 | ShowSingletonTab(GURL(chrome::kChromeUIDownloadsURL)); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1950 | } |
| 1951 | |
[email protected] | 34085a3 | 2009-11-06 22:49:48 | [diff] [blame] | 1952 | void Browser::ShowExtensionsTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1953 | UserMetrics::RecordAction(UserMetricsAction("ShowExtensions")); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1954 | ShowSingletonTab(GURL(chrome::kChromeUIExtensionsURL)); |
[email protected] | 34085a3 | 2009-11-06 22:49:48 | [diff] [blame] | 1955 | } |
| 1956 | |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 1957 | void Browser::ShowAboutConflictsTab() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1958 | UserMetrics::RecordAction(UserMetricsAction("AboutConflicts")); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1959 | ShowSingletonTab(GURL(chrome::kChromeUIConflictsURL)); |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 1960 | } |
| 1961 | |
[email protected] | 10e457c | 2010-04-29 03:35:23 | [diff] [blame] | 1962 | void Browser::ShowBrokenPageTab(TabContents* contents) { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1963 | UserMetrics::RecordAction(UserMetricsAction("ReportBug")); |
[email protected] | 10e457c | 2010-04-29 03:35:23 | [diff] [blame] | 1964 | string16 page_title = contents->GetTitle(); |
| 1965 | NavigationEntry* entry = contents->controller().GetActiveEntry(); |
| 1966 | if (!entry) |
| 1967 | return; |
| 1968 | std::string page_url = entry->url().spec(); |
| 1969 | std::vector<std::string> subst; |
| 1970 | subst.push_back(UTF16ToASCII(page_title)); |
| 1971 | subst.push_back(page_url); |
| 1972 | std::string report_page_url = |
| 1973 | ReplaceStringPlaceholders(kBrokenPageUrl, subst, NULL); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1974 | ShowSingletonTab(GURL(report_page_url)); |
[email protected] | 10e457c | 2010-04-29 03:35:23 | [diff] [blame] | 1975 | } |
| 1976 | |
[email protected] | 12e816bde | 2010-09-14 19:59:29 | [diff] [blame] | 1977 | void Browser::ShowOptionsTab(const std::string& sub_page) { |
[email protected] | e50eeee | 2010-09-22 00:33:30 | [diff] [blame] | 1978 | GURL url(chrome::kChromeUISettingsURL + sub_page); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 1979 | browser::NavigateParams params(GetSingletonTabNavigateParams(url)); |
| 1980 | params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
| 1981 | browser::Navigate(¶ms); |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 1982 | } |
| 1983 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1984 | void Browser::OpenClearBrowsingDataDialog() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1985 | UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_ShowDlg")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 1986 | ShowOptionsTab(chrome::kClearBrowserDataSubPage); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1987 | } |
| 1988 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1989 | void Browser::OpenOptionsDialog() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1990 | UserMetrics::RecordAction(UserMetricsAction("ShowOptions")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 1991 | GURL url(chrome::kChromeUISettingsURL); |
| 1992 | browser::NavigateParams params(GetSingletonTabNavigateParams(url)); |
| 1993 | params.path_behavior = browser::NavigateParams::IGNORE_AND_STAY_PUT; |
| 1994 | browser::Navigate(¶ms); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | void Browser::OpenPasswordManager() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 1998 | UserMetrics::RecordAction(UserMetricsAction("Options_ShowPasswordManager")); |
[email protected] | e8ce8bb | 2011-03-10 03:10:04 | [diff] [blame] | 1999 | ShowOptionsTab(chrome::kPasswordManagerSubPage); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2000 | } |
| 2001 | |
[email protected] | 1bdf29e | 2009-05-11 23:45:25 | [diff] [blame] | 2002 | void Browser::OpenImportSettingsDialog() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 2003 | UserMetrics::RecordAction(UserMetricsAction("Import_ShowDlg")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2004 | ShowOptionsTab(chrome::kImportDataSubPage); |
[email protected] | 1bdf29e | 2009-05-11 23:45:25 | [diff] [blame] | 2005 | } |
[email protected] | 1bdf29e | 2009-05-11 23:45:25 | [diff] [blame] | 2006 | |
[email protected] | b99081b | 2011-03-10 17:43:47 | [diff] [blame] | 2007 | void Browser::OpenInstantConfirmDialog() { |
| 2008 | ShowOptionsTab(chrome::kInstantConfirmPage); |
| 2009 | } |
| 2010 | |
[email protected] | ca38d8e | 2009-08-20 18:08:16 | [diff] [blame] | 2011 | void Browser::OpenSyncMyBookmarksDialog() { |
[email protected] | 40f04797 | 2009-11-25 03:54:40 | [diff] [blame] | 2012 | sync_ui_util::OpenSyncMyBookmarksDialog( |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 2013 | profile_, this, ProfileSyncService::START_FROM_WRENCH); |
[email protected] | ca38d8e | 2009-08-20 18:08:16 | [diff] [blame] | 2014 | } |
[email protected] | ca38d8e | 2009-08-20 18:08:16 | [diff] [blame] | 2015 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2016 | void Browser::OpenAboutChromeDialog() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 2017 | UserMetrics::RecordAction(UserMetricsAction("AboutChrome")); |
[email protected] | 976e69f | 2010-08-13 18:28:17 | [diff] [blame] | 2018 | #if defined(OS_CHROMEOS) |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 2019 | ShowSingletonTab(GURL(chrome::kChromeUIAboutURL)); |
[email protected] | 976e69f | 2010-08-13 18:28:17 | [diff] [blame] | 2020 | #else |
[email protected] | 2d46c84 | 2008-11-14 19:24:31 | [diff] [blame] | 2021 | window_->ShowAboutChromeDialog(); |
[email protected] | 976e69f | 2010-08-13 18:28:17 | [diff] [blame] | 2022 | #endif |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2023 | } |
| 2024 | |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 2025 | void Browser::OpenUpdateChromeDialog() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 2026 | UserMetrics::RecordAction(UserMetricsAction("UpdateChrome")); |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 2027 | window_->ShowUpdateChromeDialog(); |
| 2028 | } |
| 2029 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2030 | void Browser::OpenHelpTab() { |
[email protected] | 0a4a0be | 2010-11-09 10:42:47 | [diff] [blame] | 2031 | GURL help_url(kHelpContentUrl); |
[email protected] | 0a4a0be | 2010-11-09 10:42:47 | [diff] [blame] | 2032 | GURL localized_help_url = google_util::AppendGoogleLocaleParam(help_url); |
| 2033 | AddSelectedTabWithURL(localized_help_url, PageTransition::AUTO_BOOKMARK); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2034 | } |
| 2035 | |
[email protected] | 403c1486 | 2009-10-28 00:00:49 | [diff] [blame] | 2036 | void Browser::OpenThemeGalleryTabAndActivate() { |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 2037 | AddSelectedTabWithURL(GURL(l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_URL)), |
| 2038 | PageTransition::LINK); |
[email protected] | 403c1486 | 2009-10-28 00:00:49 | [diff] [blame] | 2039 | } |
| 2040 | |
[email protected] | 31cc1c02 | 2010-10-15 20:03:47 | [diff] [blame] | 2041 | void Browser::OpenPrivacyDashboardTabAndActivate() { |
[email protected] | 3e050545 | 2010-11-02 21:45:24 | [diff] [blame] | 2042 | OpenURL(GURL(kPrivacyDashboardUrl), GURL(), |
| 2043 | NEW_FOREGROUND_TAB, PageTransition::LINK); |
[email protected] | 31cc1c02 | 2010-10-15 20:03:47 | [diff] [blame] | 2044 | window_->Activate(); |
| 2045 | } |
| 2046 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 2047 | void Browser::OpenAutofillHelpTabAndActivate() { |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 2048 | GURL help_url = google_util::AppendGoogleLocaleParam(GURL(kAutofillHelpUrl)); |
| 2049 | AddSelectedTabWithURL(help_url, PageTransition::LINK); |
[email protected] | bb8fe2d | 2010-06-28 20:04:22 | [diff] [blame] | 2050 | } |
| 2051 | |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 2052 | void Browser::OpenSearchEngineOptionsDialog() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 2053 | UserMetrics::RecordAction(UserMetricsAction("EditSearchEngines")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2054 | ShowOptionsTab(chrome::kSearchEnginesSubPage); |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 2055 | } |
| 2056 | |
[email protected] | 1677984 | 2009-07-08 23:45:29 | [diff] [blame] | 2057 | #if defined(OS_CHROMEOS) |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 2058 | void Browser::OpenFileManager() { |
| 2059 | UserMetrics::RecordAction(UserMetricsAction("OpenFileManager")); |
| 2060 | ShowSingletonTab(FileManagerUtil::GetFileBrowserUrl()); |
| 2061 | } |
| 2062 | |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 2063 | void Browser::OpenSystemOptionsDialog() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 2064 | UserMetrics::RecordAction(UserMetricsAction("OpenSystemOptionsDialog")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2065 | ShowOptionsTab(chrome::kSystemOptionsSubPage); |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | void Browser::OpenInternetOptionsDialog() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 2069 | UserMetrics::RecordAction(UserMetricsAction("OpenInternetOptionsDialog")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2070 | ShowOptionsTab(chrome::kInternetOptionsSubPage); |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | void Browser::OpenLanguageOptionsDialog() { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 2074 | UserMetrics::RecordAction(UserMetricsAction("OpenLanguageOptionsDialog")); |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2075 | ShowOptionsTab(chrome::kLanguageOptionsSubPage); |
[email protected] | be71507 | 2009-07-07 15:43:20 | [diff] [blame] | 2076 | } |
[email protected] | 46b92f85 | 2010-10-06 13:12:05 | [diff] [blame] | 2077 | |
| 2078 | void Browser::OpenSystemTabAndActivate() { |
| 2079 | OpenURL(GURL(chrome::kChromeUISystemInfoURL), GURL(), |
| 2080 | NEW_FOREGROUND_TAB, PageTransition::LINK); |
| 2081 | window_->Activate(); |
| 2082 | } |
| 2083 | |
[email protected] | 3801761 | 2010-10-13 18:46:00 | [diff] [blame] | 2084 | void Browser::OpenMobilePlanTabAndActivate() { |
| 2085 | OpenURL(GURL(chrome::kChromeUIMobileSetupURL), GURL(), |
| 2086 | NEW_FOREGROUND_TAB, PageTransition::LINK); |
| 2087 | window_->Activate(); |
| 2088 | } |
[email protected] | be71507 | 2009-07-07 15:43:20 | [diff] [blame] | 2089 | #endif |
| 2090 | |
[email protected] | a003d8e | 2010-10-02 21:03:35 | [diff] [blame] | 2091 | void Browser::OpenPluginsTabAndActivate() { |
| 2092 | OpenURL(GURL(chrome::kAboutPluginsURL), GURL(), |
| 2093 | NEW_FOREGROUND_TAB, PageTransition::LINK); |
| 2094 | window_->Activate(); |
| 2095 | } |
| 2096 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2097 | /////////////////////////////////////////////////////////////////////////////// |
| 2098 | |
| 2099 | // static |
[email protected] | 7911717 | 2009-08-28 16:11:44 | [diff] [blame] | 2100 | void Browser::SetNewHomePagePrefs(PrefService* prefs) { |
[email protected] | 8fe6e1c | 2010-05-27 08:21:54 | [diff] [blame] | 2101 | const PrefService::Preference* home_page_pref = |
| 2102 | prefs->FindPreference(prefs::kHomePage); |
| 2103 | if (home_page_pref && |
| 2104 | !home_page_pref->IsManaged() && |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2105 | !prefs->HasPrefPath(prefs::kHomePage)) { |
[email protected] | b41eb73 | 2009-09-30 16:49:33 | [diff] [blame] | 2106 | prefs->SetString(prefs::kHomePage, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2107 | GoogleURLTracker::kDefaultGoogleHomepage); |
| 2108 | } |
[email protected] | 8fe6e1c | 2010-05-27 08:21:54 | [diff] [blame] | 2109 | const PrefService::Preference* home_page_is_new_tab_page_pref = |
| 2110 | prefs->FindPreference(prefs::kHomePageIsNewTabPage); |
| 2111 | if (home_page_is_new_tab_page_pref && |
| 2112 | !home_page_is_new_tab_page_pref->IsManaged() && |
| 2113 | !prefs->HasPrefPath(prefs::kHomePageIsNewTabPage)) |
[email protected] | b41eb73 | 2009-09-30 16:49:33 | [diff] [blame] | 2114 | prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false); |
[email protected] | 7911717 | 2009-08-28 16:11:44 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | // static |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2118 | void Browser::RegisterPrefs(PrefService* prefs) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2119 | prefs->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 2120 | prefs->RegisterIntegerPref(prefs::kExtensionSidebarWidth, -1); |
[email protected] | f87919d7 | 2011-02-02 18:46:16 | [diff] [blame] | 2121 | prefs->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0); |
[email protected] | d989891 | 2011-04-15 21:10:00 | [diff] [blame] | 2122 | prefs->RegisterBooleanPref(prefs::kAllowFileSelectionDialogs, true); |
[email protected] | 09d81f8 | 2010-12-15 16:46:42 | [diff] [blame] | 2123 | // Educated guess: Chrome has a bundled Flash version supporting |
| 2124 | // clearing LSO data, Chromium hasn't. |
| 2125 | #if defined(GOOGLE_CHROME_BUILD) |
| 2126 | prefs->RegisterBooleanPref(prefs::kClearPluginLSODataEnabled, true); |
| 2127 | #else |
| 2128 | prefs->RegisterBooleanPref(prefs::kClearPluginLSODataEnabled, false); |
| 2129 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | // static |
| 2133 | void Browser::RegisterUserPrefs(PrefService* prefs) { |
[email protected] | 0d22083 | 2009-11-06 00:45:18 | [diff] [blame] | 2134 | prefs->RegisterStringPref(prefs::kHomePage, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2135 | chrome::kChromeUINewTabURL, |
| 2136 | PrefService::SYNCABLE_PREF); |
| 2137 | prefs->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, |
| 2138 | true, |
| 2139 | PrefService::SYNCABLE_PREF); |
| 2140 | prefs->RegisterBooleanPref(prefs::kShowHomeButton, |
| 2141 | false, |
| 2142 | PrefService::SYNCABLE_PREF); |
[email protected] | 93a2c724 | 2009-07-07 18:43:09 | [diff] [blame] | 2143 | #if defined(OS_MACOSX) |
| 2144 | // This really belongs in platform code, but there's no good place to |
| 2145 | // initialize it between the time when the AppController is created |
| 2146 | // (where there's no profile) and the time the controller gets another |
| 2147 | // crack at the start of the main event loop. By that time, BrowserInit |
| 2148 | // has already created the browser window, and it's too late: we need the |
| 2149 | // pref to be already initialized. Doing it here also saves us from having |
| 2150 | // to hard-code pref registration in the several unit tests that use |
| 2151 | // this preference. |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2152 | prefs->RegisterBooleanPref(prefs::kConfirmToQuitEnabled, |
| 2153 | false, |
| 2154 | PrefService::SYNCABLE_PREF); |
| 2155 | prefs->RegisterBooleanPref(prefs::kShowUpdatePromotionInfoBar, |
| 2156 | true, |
| 2157 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 93a2c724 | 2009-07-07 18:43:09 | [diff] [blame] | 2158 | #endif |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2159 | prefs->RegisterBooleanPref(prefs::kDeleteBrowsingHistory, |
| 2160 | true, |
| 2161 | PrefService::SYNCABLE_PREF); |
| 2162 | prefs->RegisterBooleanPref(prefs::kDeleteDownloadHistory, |
| 2163 | true, |
| 2164 | PrefService::SYNCABLE_PREF); |
| 2165 | prefs->RegisterBooleanPref(prefs::kDeleteCache, |
| 2166 | true, |
| 2167 | PrefService::SYNCABLE_PREF); |
| 2168 | prefs->RegisterBooleanPref(prefs::kDeleteCookies, |
| 2169 | true, |
| 2170 | PrefService::SYNCABLE_PREF); |
| 2171 | prefs->RegisterBooleanPref(prefs::kDeletePasswords, |
| 2172 | false, |
| 2173 | PrefService::SYNCABLE_PREF); |
| 2174 | prefs->RegisterBooleanPref(prefs::kDeleteFormData, |
| 2175 | false, |
| 2176 | PrefService::SYNCABLE_PREF); |
| 2177 | prefs->RegisterIntegerPref(prefs::kDeleteTimePeriod, |
| 2178 | 0, |
| 2179 | PrefService::SYNCABLE_PREF); |
| 2180 | prefs->RegisterBooleanPref(prefs::kCheckDefaultBrowser, |
| 2181 | true, |
| 2182 | PrefService::UNSYNCABLE_PREF); |
| 2183 | prefs->RegisterBooleanPref(prefs::kShowOmniboxSearchHint, |
| 2184 | true, |
| 2185 | PrefService::UNSYNCABLE_PREF); |
| 2186 | prefs->RegisterBooleanPref(prefs::kWebAppCreateOnDesktop, |
| 2187 | true, |
| 2188 | PrefService::UNSYNCABLE_PREF); |
| 2189 | prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, |
| 2190 | true, |
| 2191 | PrefService::UNSYNCABLE_PREF); |
| 2192 | prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, |
| 2193 | true, |
| 2194 | PrefService::UNSYNCABLE_PREF); |
| 2195 | prefs->RegisterBooleanPref(prefs::kUseVerticalTabs, |
| 2196 | false, |
| 2197 | PrefService::UNSYNCABLE_PREF); |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 2198 | prefs->RegisterBooleanPref(prefs::kUseCompactNavigationBar, |
| 2199 | false, |
| 2200 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2201 | prefs->RegisterBooleanPref(prefs::kEnableTranslate, |
| 2202 | true, |
| 2203 | PrefService::SYNCABLE_PREF); |
| 2204 | prefs->RegisterBooleanPref(prefs::kEnableBookmarkBar, |
| 2205 | true, |
| 2206 | PrefService::UNSYNCABLE_PREF); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2207 | prefs->RegisterStringPref(prefs::kCloudPrintEmail, |
| 2208 | std::string(), |
| 2209 | PrefService::UNSYNCABLE_PREF); |
| 2210 | prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, |
| 2211 | true, |
| 2212 | PrefService::UNSYNCABLE_PREF); |
| 2213 | prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, |
| 2214 | false, |
| 2215 | PrefService::UNSYNCABLE_PREF); |
| 2216 | prefs->RegisterBooleanPref(prefs::kIncognitoEnabled, |
| 2217 | true, |
| 2218 | PrefService::UNSYNCABLE_PREF); |
| 2219 | prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, |
| 2220 | -1, |
| 2221 | PrefService::UNSYNCABLE_PREF); |
| 2222 | prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement, |
| 2223 | PrefService::UNSYNCABLE_PREF); |
| 2224 | prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement, |
| 2225 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 2bf2bd9 | 2011-03-31 07:12:44 | [diff] [blame] | 2226 | // We need to register the type of these preferences in order to query |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2227 | // them even though they're only typically controlled via policy. |
| 2228 | prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, |
| 2229 | false, |
| 2230 | PrefService::UNSYNCABLE_PREF); |
| 2231 | prefs->RegisterBooleanPref(prefs::kPluginsAllowOutdated, |
| 2232 | false, |
| 2233 | PrefService::UNSYNCABLE_PREF); |
| 2234 | prefs->RegisterBooleanPref(prefs::kPluginsAlwaysAuthorize, |
| 2235 | false, |
| 2236 | PrefService::UNSYNCABLE_PREF); |
| 2237 | prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, |
| 2238 | true, |
| 2239 | PrefService::UNSYNCABLE_PREF); |
| 2240 | prefs->RegisterBooleanPref(prefs::kEnableReferrers, |
| 2241 | true, |
| 2242 | PrefService::UNSYNCABLE_PREF); |
| 2243 | prefs->RegisterBooleanPref(prefs::kWebKitAllowRunningInsecureContent, |
[email protected] | f43fd974d | 2011-06-01 18:53:19 | [diff] [blame] | 2244 | false, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2245 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 839fee77 | 2011-05-05 03:21:37 | [diff] [blame] | 2246 | prefs->RegisterBooleanPref(prefs::kWebKitAllowDisplayingInsecureContent, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 2247 | true, |
| 2248 | PrefService::UNSYNCABLE_PREF); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | // static |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2252 | bool Browser::RunUnloadEventsHelper(TabContents* contents) { |
| 2253 | // If the TabContents is not connected yet, then there's no unload |
| 2254 | // handler we can fire even if the TabContents has an unload listener. |
| 2255 | // One case where we hit this is in a tab that has an infinite loop |
| 2256 | // before load. |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 2257 | if (contents->NeedToFireBeforeUnload()) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2258 | // If the page has unload listeners, then we tell the renderer to fire |
| 2259 | // them. Once they have fired, we'll get a message back saying whether |
| 2260 | // 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] | 2261 | // with the NeedToFireBeforeUnload bit cleared. |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2262 | contents->render_view_host()->FirePageBeforeUnload(false); |
| 2263 | return true; |
| 2264 | } |
| 2265 | return false; |
| 2266 | } |
| 2267 | |
| 2268 | // static |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2269 | Browser* Browser::GetBrowserForController( |
| 2270 | const NavigationController* controller, int* index_result) { |
| 2271 | BrowserList::const_iterator it; |
| 2272 | for (it = BrowserList::begin(); it != BrowserList::end(); ++it) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2273 | int index = (*it)->tab_handler_->GetTabStripModel()->GetIndexOfController( |
| 2274 | controller); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2275 | if (index != TabStripModel::kNoTab) { |
| 2276 | if (index_result) |
| 2277 | *index_result = index; |
| 2278 | return *it; |
| 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | return NULL; |
| 2283 | } |
| 2284 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 2285 | void Browser::ExecuteCommandWithDisposition( |
| 2286 | int id, WindowOpenDisposition disposition) { |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2287 | // No commands are enabled if there is not yet any selected tab. |
| 2288 | // TODO(pkasting): It seems like we should not need this, because either |
| 2289 | // most/all commands should not have been enabled yet anyway or the ones that |
| 2290 | // are enabled should be global, or safe themselves against having no selected |
| 2291 | // tab. However, Ben says he tried removing this before and got lots of |
| 2292 | // crashes, e.g. from Windows sending WM_COMMANDs at random times during |
| 2293 | // window construction. This probably could use closer examination someday. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2294 | if (!GetSelectedTabContentsWrapper()) |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2295 | return; |
| 2296 | |
[email protected] | 59c9f00 | 2010-11-19 00:38:05 | [diff] [blame] | 2297 | DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command " |
| 2298 | << id; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2299 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 2300 | // If command execution is blocked then just record the command and return. |
| 2301 | if (block_command_execution_) { |
| 2302 | // We actually only allow no more than one blocked command, otherwise some |
| 2303 | // commands maybe lost. |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 2304 | DCHECK_EQ(last_blocked_command_id_, -1); |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 2305 | last_blocked_command_id_ = id; |
| 2306 | last_blocked_command_disposition_ = disposition; |
| 2307 | return; |
| 2308 | } |
| 2309 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2310 | // The order of commands in this switch statement must match the function |
| 2311 | // declaration order in browser.h! |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2312 | switch (id) { |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2313 | // Navigation commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2314 | case IDC_BACK: GoBack(disposition); break; |
| 2315 | case IDC_FORWARD: GoForward(disposition); break; |
| 2316 | case IDC_RELOAD: Reload(disposition); break; |
| 2317 | case IDC_RELOAD_IGNORING_CACHE: ReloadIgnoringCache(disposition); break; |
| 2318 | case IDC_HOME: Home(disposition); break; |
| 2319 | case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2320 | case IDC_STOP: Stop(); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2321 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2322 | // Window management commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2323 | case IDC_NEW_WINDOW: NewWindow(); break; |
| 2324 | case IDC_NEW_INCOGNITO_WINDOW: NewIncognitoWindow(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2325 | case IDC_CLOSE_WINDOW: CloseWindow(); break; |
| 2326 | case IDC_NEW_TAB: NewTab(); break; |
| 2327 | case IDC_CLOSE_TAB: CloseTab(); break; |
| 2328 | case IDC_SELECT_NEXT_TAB: SelectNextTab(); break; |
| 2329 | case IDC_SELECT_PREVIOUS_TAB: SelectPreviousTab(); break; |
[email protected] | 91ac920 | 2010-07-30 18:32:35 | [diff] [blame] | 2330 | case IDC_TABPOSE: OpenTabpose(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2331 | case IDC_MOVE_TAB_NEXT: MoveTabNext(); break; |
| 2332 | case IDC_MOVE_TAB_PREVIOUS: MoveTabPrevious(); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2333 | case IDC_SELECT_TAB_0: |
| 2334 | case IDC_SELECT_TAB_1: |
| 2335 | case IDC_SELECT_TAB_2: |
| 2336 | case IDC_SELECT_TAB_3: |
| 2337 | case IDC_SELECT_TAB_4: |
| 2338 | case IDC_SELECT_TAB_5: |
| 2339 | case IDC_SELECT_TAB_6: |
[email protected] | cb525c8 | 2008-12-08 23:04:54 | [diff] [blame] | 2340 | case IDC_SELECT_TAB_7: SelectNumberedTab(id - IDC_SELECT_TAB_0); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2341 | break; |
| 2342 | case IDC_SELECT_LAST_TAB: SelectLastTab(); break; |
| 2343 | case IDC_DUPLICATE_TAB: DuplicateTab(); break; |
| 2344 | case IDC_RESTORE_TAB: RestoreTab(); break; |
| 2345 | case IDC_COPY_URL: WriteCurrentURLToClipboard(); break; |
| 2346 | case IDC_SHOW_AS_TAB: ConvertPopupToTabbedBrowser(); break; |
| 2347 | case IDC_FULLSCREEN: ToggleFullscreenMode(); break; |
| 2348 | case IDC_EXIT: Exit(); break; |
| 2349 | case IDC_TOGGLE_VERTICAL_TABS: ToggleUseVerticalTabs(); break; |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 2350 | case IDC_COMPACT_NAVBAR: ToggleUseCompactNavigationBar(); break; |
[email protected] | da17b37 | 2010-01-22 23:37:22 | [diff] [blame] | 2351 | #if defined(OS_CHROMEOS) |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2352 | case IDC_SEARCH: Search(); break; |
[email protected] | d14af52 | 2010-12-02 03:54:50 | [diff] [blame] | 2353 | case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break; |
[email protected] | 20d1724 | 2009-10-26 20:21:05 | [diff] [blame] | 2354 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2355 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2356 | // Page-related commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2357 | case IDC_SAVE_PAGE: SavePage(); break; |
| 2358 | case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break; |
| 2359 | case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(); break; |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 2360 | case IDC_VIEW_SOURCE: ViewSelectedSource(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2361 | case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break; |
| 2362 | case IDC_PRINT: Print(); break; |
| 2363 | case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2364 | case IDC_ENCODING_UTF8: |
| 2365 | case IDC_ENCODING_UTF16LE: |
| 2366 | case IDC_ENCODING_ISO88591: |
| 2367 | case IDC_ENCODING_WINDOWS1252: |
[email protected] | 1c5bf63 | 2008-12-11 20:30:49 | [diff] [blame] | 2368 | case IDC_ENCODING_GBK: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2369 | case IDC_ENCODING_GB18030: |
| 2370 | case IDC_ENCODING_BIG5HKSCS: |
| 2371 | case IDC_ENCODING_BIG5: |
| 2372 | case IDC_ENCODING_KOREAN: |
| 2373 | case IDC_ENCODING_SHIFTJIS: |
| 2374 | case IDC_ENCODING_ISO2022JP: |
| 2375 | case IDC_ENCODING_EUCJP: |
| 2376 | case IDC_ENCODING_THAI: |
| 2377 | case IDC_ENCODING_ISO885915: |
| 2378 | case IDC_ENCODING_MACINTOSH: |
| 2379 | case IDC_ENCODING_ISO88592: |
| 2380 | case IDC_ENCODING_WINDOWS1250: |
| 2381 | case IDC_ENCODING_ISO88595: |
| 2382 | case IDC_ENCODING_WINDOWS1251: |
| 2383 | case IDC_ENCODING_KOI8R: |
| 2384 | case IDC_ENCODING_KOI8U: |
| 2385 | case IDC_ENCODING_ISO88597: |
| 2386 | case IDC_ENCODING_WINDOWS1253: |
| 2387 | case IDC_ENCODING_ISO88594: |
| 2388 | case IDC_ENCODING_ISO885913: |
| 2389 | case IDC_ENCODING_WINDOWS1257: |
| 2390 | case IDC_ENCODING_ISO88593: |
| 2391 | case IDC_ENCODING_ISO885910: |
| 2392 | case IDC_ENCODING_ISO885914: |
| 2393 | case IDC_ENCODING_ISO885916: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2394 | case IDC_ENCODING_WINDOWS1254: |
| 2395 | case IDC_ENCODING_ISO88596: |
| 2396 | case IDC_ENCODING_WINDOWS1256: |
| 2397 | case IDC_ENCODING_ISO88598: |
[email protected] | e13271f | 2009-03-07 00:26:00 | [diff] [blame] | 2398 | case IDC_ENCODING_ISO88598I: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2399 | case IDC_ENCODING_WINDOWS1255: |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2400 | case IDC_ENCODING_WINDOWS1258: OverrideEncoding(id); break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2401 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2402 | // Clipboard commands |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2403 | case IDC_CUT: Cut(); break; |
| 2404 | case IDC_COPY: Copy(); break; |
| 2405 | case IDC_PASTE: Paste(); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2406 | |
| 2407 | // Find-in-page |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2408 | case IDC_FIND: Find(); break; |
| 2409 | case IDC_FIND_NEXT: FindNext(); break; |
| 2410 | case IDC_FIND_PREVIOUS: FindPrevious(); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2411 | |
| 2412 | // Zoom |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2413 | case IDC_ZOOM_PLUS: Zoom(PageZoom::ZOOM_IN); break; |
| 2414 | case IDC_ZOOM_NORMAL: Zoom(PageZoom::RESET); break; |
| 2415 | case IDC_ZOOM_MINUS: Zoom(PageZoom::ZOOM_OUT); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2416 | |
| 2417 | // Focus various bits of UI |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2418 | case IDC_FOCUS_TOOLBAR: FocusToolbar(); break; |
| 2419 | case IDC_FOCUS_LOCATION: FocusLocationBar(); break; |
| 2420 | case IDC_FOCUS_SEARCH: FocusSearch(); break; |
[email protected] | bdb7ff6 | 2010-07-20 01:56:52 | [diff] [blame] | 2421 | case IDC_FOCUS_MENU_BAR: FocusAppMenu(); break; |
[email protected] | 83548a4 | 2010-06-18 13:53:37 | [diff] [blame] | 2422 | case IDC_FOCUS_BOOKMARKS: FocusBookmarksToolbar(); break; |
| 2423 | case IDC_FOCUS_CHROMEOS_STATUS: FocusChromeOSStatus(); break; |
| 2424 | case IDC_FOCUS_NEXT_PANE: FocusNextPane(); break; |
| 2425 | case IDC_FOCUS_PREVIOUS_PANE: FocusPreviousPane(); break; |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2426 | |
| 2427 | // Show various bits of UI |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2428 | case IDC_OPEN_FILE: OpenFile(); break; |
| 2429 | case IDC_CREATE_SHORTCUTS: OpenCreateShortcutsDialog(); break; |
[email protected] | 2a8a9812 | 2010-07-16 11:58:48 | [diff] [blame] | 2430 | case IDC_DEV_TOOLS: ToggleDevToolsWindow( |
| 2431 | DEVTOOLS_TOGGLE_ACTION_NONE); |
| 2432 | break; |
| 2433 | case IDC_DEV_TOOLS_CONSOLE: ToggleDevToolsWindow( |
| 2434 | DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); |
| 2435 | break; |
| 2436 | case IDC_DEV_TOOLS_INSPECT: ToggleDevToolsWindow( |
| 2437 | DEVTOOLS_TOGGLE_ACTION_INSPECT); |
| 2438 | break; |
[email protected] | adb6a84d | 2011-02-07 16:58:40 | [diff] [blame] | 2439 | case IDC_TASK_MANAGER: OpenTaskManager(false); break; |
| 2440 | case IDC_VIEW_BACKGROUND_PAGES: OpenTaskManager(true); break; |
[email protected] | 1c41a93 | 2010-11-22 23:41:23 | [diff] [blame] | 2441 | case IDC_FEEDBACK: OpenBugReportDialog(); break; |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 2442 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2443 | case IDC_SHOW_BOOKMARK_BAR: ToggleBookmarkBar(); break; |
[email protected] | 7664ab3 | 2011-02-01 23:35:25 | [diff] [blame] | 2444 | case IDC_PROFILING_ENABLED: Profiling::Toggle(); break; |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 2445 | |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2446 | case IDC_SHOW_BOOKMARK_MANAGER: OpenBookmarkManager(); break; |
| 2447 | case IDC_SHOW_APP_MENU: ShowAppMenu(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2448 | case IDC_SHOW_HISTORY: ShowHistoryTab(); break; |
| 2449 | case IDC_SHOW_DOWNLOADS: ShowDownloadsTab(); break; |
| 2450 | case IDC_MANAGE_EXTENSIONS: ShowExtensionsTab(); break; |
| 2451 | case IDC_SYNC_BOOKMARKS: OpenSyncMyBookmarksDialog(); break; |
| 2452 | case IDC_OPTIONS: OpenOptionsDialog(); break; |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 2453 | case IDC_EDIT_SEARCH_ENGINES: OpenSearchEngineOptionsDialog(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2454 | case IDC_VIEW_PASSWORDS: OpenPasswordManager(); break; |
| 2455 | case IDC_CLEAR_BROWSING_DATA: OpenClearBrowsingDataDialog(); break; |
| 2456 | case IDC_IMPORT_SETTINGS: OpenImportSettingsDialog(); break; |
[email protected] | b21d691 | 2010-08-31 19:22:41 | [diff] [blame] | 2457 | case IDC_ABOUT: OpenAboutChromeDialog(); break; |
| 2458 | case IDC_UPGRADE_DIALOG: OpenUpdateChromeDialog(); break; |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 2459 | case IDC_VIEW_INCOMPATIBILITIES: ShowAboutConflictsTab(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2460 | case IDC_HELP_PAGE: OpenHelpTab(); break; |
[email protected] | 1677984 | 2009-07-08 23:45:29 | [diff] [blame] | 2461 | #if defined(OS_CHROMEOS) |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 2462 | case IDC_FILE_MANAGER: OpenFileManager(); break; |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2463 | case IDC_SYSTEM_OPTIONS: OpenSystemOptionsDialog(); break; |
| 2464 | case IDC_INTERNET_OPTIONS: OpenInternetOptionsDialog(); break; |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 2465 | case IDC_LANGUAGE_OPTIONS: OpenLanguageOptionsDialog(); break; |
[email protected] | be71507 | 2009-07-07 15:43:20 | [diff] [blame] | 2466 | #endif |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 2467 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2468 | default: |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2469 | LOG(WARNING) << "Received Unimplemented Command: " << id; |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 2470 | break; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | |
[email protected] | 3ab6796d3 | 2010-12-21 23:56:07 | [diff] [blame] | 2474 | bool Browser::ExecuteCommandIfEnabled(int id) { |
| 2475 | if (command_updater_.SupportsCommand(id) && |
| 2476 | command_updater_.IsCommandEnabled(id)) { |
| 2477 | ExecuteCommand(id); |
| 2478 | return true; |
| 2479 | } |
| 2480 | return false; |
| 2481 | } |
| 2482 | |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 2483 | bool Browser::IsReservedCommandOrKey(int command_id, |
| 2484 | const NativeWebKeyboardEvent& event) { |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 2485 | #if defined(OS_CHROMEOS) |
| 2486 | // Chrome OS's top row of keys produces F1-10. Make sure that web pages |
| 2487 | // aren't able to block Chrome from performing the standard actions for F1-F4 |
| 2488 | // (F5-7 are grabbed by other X clients and hence don't need this protection, |
| 2489 | // and F8-10 are handled separately in Chrome via a GDK event filter, but |
| 2490 | // let's future-proof this). |
| 2491 | ui::KeyboardCode key_code = |
[email protected] | 6a1ae6cd | 2011-02-11 20:06:09 | [diff] [blame] | 2492 | static_cast<ui::KeyboardCode>(event.windowsKeyCode); |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 2493 | if (key_code == ui::VKEY_F1 || |
| 2494 | key_code == ui::VKEY_F2 || |
| 2495 | key_code == ui::VKEY_F3 || |
| 2496 | key_code == ui::VKEY_F4 || |
| 2497 | key_code == ui::VKEY_F5 || |
| 2498 | key_code == ui::VKEY_F6 || |
| 2499 | key_code == ui::VKEY_F7 || |
| 2500 | key_code == ui::VKEY_F8 || |
| 2501 | key_code == ui::VKEY_F9 || |
| 2502 | key_code == ui::VKEY_F10) { |
[email protected] | 6a1ae6cd | 2011-02-11 20:06:09 | [diff] [blame] | 2503 | return true; |
[email protected] | 0618142 | 2011-02-09 17:44:21 | [diff] [blame] | 2504 | } |
| 2505 | #endif |
| 2506 | |
[email protected] | 6a1ae6cd | 2011-02-11 20:06:09 | [diff] [blame] | 2507 | return command_id == IDC_CLOSE_TAB || |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 2508 | command_id == IDC_CLOSE_WINDOW || |
| 2509 | command_id == IDC_NEW_INCOGNITO_WINDOW || |
| 2510 | command_id == IDC_NEW_TAB || |
| 2511 | command_id == IDC_NEW_WINDOW || |
| 2512 | command_id == IDC_RESTORE_TAB || |
| 2513 | command_id == IDC_SELECT_NEXT_TAB || |
| 2514 | command_id == IDC_SELECT_PREVIOUS_TAB || |
[email protected] | c1d0d81 | 2010-07-27 20:21:55 | [diff] [blame] | 2515 | command_id == IDC_TABPOSE || |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 2516 | command_id == IDC_EXIT || |
| 2517 | command_id == IDC_SEARCH; |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | void Browser::SetBlockCommandExecution(bool block) { |
| 2521 | block_command_execution_ = block; |
| 2522 | if (block) { |
| 2523 | last_blocked_command_id_ = -1; |
| 2524 | last_blocked_command_disposition_ = CURRENT_TAB; |
| 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) { |
| 2529 | if (disposition) |
| 2530 | *disposition = last_blocked_command_disposition_; |
| 2531 | return last_blocked_command_id_; |
| 2532 | } |
| 2533 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2534 | void Browser::UpdateUIForNavigationInTab(TabContentsWrapper* contents, |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 2535 | PageTransition::Type transition, |
| 2536 | bool user_initiated) { |
| 2537 | tabstrip_model()->TabNavigating(contents, transition); |
| 2538 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2539 | bool contents_is_selected = contents == GetSelectedTabContentsWrapper(); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 2540 | if (user_initiated && contents_is_selected && window()->GetLocationBar()) { |
| 2541 | // Forcibly reset the location bar if the url is going to change in the |
| 2542 | // current tab, since otherwise it won't discard any ongoing user edits, |
| 2543 | // since it doesn't realize this is a user-initiated action. |
| 2544 | window()->GetLocationBar()->Revert(); |
| 2545 | } |
| 2546 | |
| 2547 | if (GetStatusBubble()) |
| 2548 | GetStatusBubble()->Hide(); |
| 2549 | |
| 2550 | // Update the location bar. This is synchronous. We specifically don't |
| 2551 | // update the load state since the load hasn't started yet and updating it |
| 2552 | // will put it out of sync with the actual state like whether we're |
| 2553 | // displaying a favicon, which controls the throbber. If we updated it here, |
| 2554 | // the throbber will show the default favicon for a split second when |
| 2555 | // navigating away from the new tab page. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2556 | ScheduleUIUpdate(contents->tab_contents(), TabContents::INVALIDATE_URL); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 2557 | |
| 2558 | if (contents_is_selected) |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2559 | contents->tab_contents()->Focus(); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | GURL Browser::GetHomePage() const { |
| 2563 | // --homepage overrides any preferences. |
| 2564 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 2565 | if (command_line.HasSwitch(switches::kHomePage)) { |
[email protected] | a8e4b5a8 | 2010-10-27 00:05:47 | [diff] [blame] | 2566 | // TODO(evanm): clean up usage of DIR_CURRENT. |
| 2567 | // http://code.google.com/p/chromium/issues/detail?id=60630 |
| 2568 | // For now, allow this code to call getcwd(). |
| 2569 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 2570 | |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 2571 | FilePath browser_directory; |
| 2572 | PathService::Get(base::DIR_CURRENT, &browser_directory); |
| 2573 | GURL home_page(URLFixerUpper::FixupRelativeFile(browser_directory, |
| 2574 | command_line.GetSwitchValuePath(switches::kHomePage))); |
| 2575 | if (home_page.is_valid()) |
| 2576 | return home_page; |
| 2577 | } |
| 2578 | |
| 2579 | if (profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) |
| 2580 | return GURL(chrome::kChromeUINewTabURL); |
| 2581 | GURL home_page(URLFixerUpper::FixupURL( |
| 2582 | profile_->GetPrefs()->GetString(prefs::kHomePage), |
| 2583 | std::string())); |
| 2584 | if (!home_page.is_valid()) |
| 2585 | return GURL(chrome::kChromeUINewTabURL); |
| 2586 | return home_page; |
| 2587 | } |
| 2588 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2589 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2590 | // Browser, PageNavigator implementation: |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 2591 | |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2592 | void Browser::OpenURL(const GURL& url, const GURL& referrer, |
| 2593 | WindowOpenDisposition disposition, |
| 2594 | PageTransition::Type transition) { |
| 2595 | OpenURLFromTab(NULL, url, referrer, disposition, transition); |
| 2596 | } |
| 2597 | |
| 2598 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 2599 | // Browser, CommandUpdater::CommandUpdaterDelegate implementation: |
| 2600 | |
| 2601 | void Browser::ExecuteCommand(int id) { |
| 2602 | ExecuteCommandWithDisposition(id, CURRENT_TAB); |
| 2603 | } |
| 2604 | |
| 2605 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2606 | // Browser, TabHandlerDelegate implementation: |
| 2607 | |
| 2608 | Profile* Browser::GetProfile() const { |
| 2609 | return profile(); |
| 2610 | } |
| 2611 | |
| 2612 | Browser* Browser::AsBrowser() { |
| 2613 | return this; |
| 2614 | } |
| 2615 | |
| 2616 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2617 | // Browser, TabStripModelDelegate implementation: |
| 2618 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2619 | TabContentsWrapper* Browser::AddBlankTab(bool foreground) { |
[email protected] | 22735af6 | 2009-04-07 21:09:58 | [diff] [blame] | 2620 | return AddBlankTabAt(-1, foreground); |
| 2621 | } |
| 2622 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2623 | TabContentsWrapper* Browser::AddBlankTabAt(int index, bool foreground) { |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 2624 | // Time new tab page creation time. We keep track of the timing data in |
| 2625 | // TabContents, but we want to include the time it takes to create the |
| 2626 | // TabContents object too. |
| 2627 | base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 2628 | browser::NavigateParams params(this, GURL(chrome::kChromeUINewTabURL), |
| 2629 | PageTransition::TYPED); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 2630 | params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
| 2631 | params.tabstrip_index = index; |
| 2632 | browser::Navigate(¶ms); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2633 | params.target_contents->tab_contents()->set_new_tab_start_time( |
| 2634 | new_tab_start_time); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 2635 | return params.target_contents; |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 2636 | } |
| 2637 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2638 | Browser* Browser::CreateNewStripWithContents( |
| 2639 | TabContentsWrapper* detached_contents, |
| 2640 | const gfx::Rect& window_bounds, |
| 2641 | const DockInfo& dock_info, |
| 2642 | bool maximize) { |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 2643 | DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); |
[email protected] | adf650f | 2008-12-09 16:10:06 | [diff] [blame] | 2644 | |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 2645 | gfx::Rect new_window_bounds = window_bounds; |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 2646 | if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize)) |
| 2647 | dock_info.AdjustOtherWindowBounds(); |
| 2648 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2649 | // Create an empty new browser window the same size as the old one. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 2650 | Browser* browser = new Browser(TYPE_TABBED, profile_); |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 2651 | browser->set_override_bounds(new_window_bounds); |
[email protected] | 2e71662 | 2009-03-09 21:11:01 | [diff] [blame] | 2652 | browser->set_maximized_state( |
| 2653 | maximize ? MAXIMIZED_STATE_MAXIMIZED : MAXIMIZED_STATE_UNMAXIMIZED); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2654 | browser->InitBrowserWindow(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 2655 | browser->tabstrip_model()->AppendTabContents(detached_contents, true); |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 2656 | // Make sure the loading state is updated correctly, otherwise the throbber |
| 2657 | // won't start if the page is loading. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2658 | browser->LoadingStateChanged(detached_contents->tab_contents()); |
[email protected] | 3d1104f | 2009-03-26 15:30:28 | [diff] [blame] | 2659 | return browser; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | int Browser::GetDragActions() const { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2663 | return TabStripModelDelegate::TAB_TEAROFF_ACTION | (tab_count() > 1 ? |
| 2664 | TabStripModelDelegate::TAB_MOVE_ACTION : 0); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2665 | } |
| 2666 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2667 | TabContentsWrapper* Browser::CreateTabContentsForURL( |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2668 | const GURL& url, const GURL& referrer, Profile* profile, |
| 2669 | PageTransition::Type transition, bool defer_load, |
| 2670 | SiteInstance* instance) const { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2671 | TabContentsWrapper* contents = TabContentsFactory(profile, instance, |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2672 | MSG_ROUTING_NONE, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2673 | GetSelectedTabContents(), NULL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2674 | if (!defer_load) { |
| 2675 | // Load the initial URL before adding the new tab contents to the tab strip |
| 2676 | // so that the tab contents has navigation state. |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2677 | contents->controller().LoadURL(url, referrer, transition); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | return contents; |
| 2681 | } |
| 2682 | |
| 2683 | bool Browser::CanDuplicateContentsAt(int index) { |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2684 | NavigationController& nc = GetTabContentsAt(index)->controller(); |
| 2685 | return nc.tab_contents() && nc.GetLastCommittedEntry(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | void Browser::DuplicateContentsAt(int index) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2689 | TabContentsWrapper* contents = GetTabContentsWrapperAt(index); |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 2690 | CHECK(contents); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 2691 | TabContentsWrapper* contents_dupe = contents->Clone(); |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 2692 | TabContents* new_contents = contents_dupe->tab_contents(); |
| 2693 | |
| 2694 | bool pinned = false; |
| 2695 | if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
| 2696 | // If this is a tabbed browser, just create a duplicate tab inside the same |
| 2697 | // window next to the tab being duplicated. |
| 2698 | int index = tab_handler_->GetTabStripModel()-> |
| 2699 | GetIndexOfTabContents(contents); |
| 2700 | pinned = tab_handler_->GetTabStripModel()->IsTabPinned(index); |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 2701 | int add_types = TabStripModel::ADD_ACTIVE | |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 2702 | TabStripModel::ADD_INHERIT_GROUP | |
| 2703 | (pinned ? TabStripModel::ADD_PINNED : 0); |
| 2704 | tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, |
| 2705 | contents_dupe, |
| 2706 | add_types); |
| 2707 | } else { |
| 2708 | Browser* browser = NULL; |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 2709 | if (is_app()) { |
| 2710 | CHECK(!is_type_popup()); |
| 2711 | CHECK(!is_type_panel()); |
| 2712 | browser = Browser::CreateForApp(TYPE_POPUP, app_name_, gfx::Size(), |
| 2713 | profile_); |
| 2714 | } else if (is_type_popup()) { |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 2715 | browser = Browser::CreateForType(TYPE_POPUP, profile_); |
| 2716 | } |
| 2717 | |
| 2718 | // Preserve the size of the original window. The new window has already |
| 2719 | // been given an offset by the OS, so we shouldn't copy the old bounds. |
| 2720 | BrowserWindow* new_window = browser->window(); |
| 2721 | new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 2722 | window()->GetRestoredBounds().size())); |
| 2723 | |
[email protected] | 4e59568 | 2011-02-09 17:07:02 | [diff] [blame] | 2724 | // We need to show the browser now. Otherwise ContainerWin assumes the |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 2725 | // TabContents is invisible and won't size it. |
| 2726 | browser->window()->Show(); |
| 2727 | |
| 2728 | // The page transition below is only for the purpose of inserting the tab. |
| 2729 | browser->AddTab(contents_dupe, PageTransition::LINK); |
| 2730 | } |
| 2731 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2732 | SessionService* session_service = |
| 2733 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 2734 | if (session_service) |
| 2735 | session_service->TabRestored(&new_contents->controller(), pinned); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2736 | } |
| 2737 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2738 | void Browser::CloseFrameAfterDragSession() { |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 2739 | #if !defined(OS_MACOSX) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2740 | // This is scheduled to run after we return to the message loop because |
| 2741 | // otherwise the frame will think the drag session is still active and ignore |
| 2742 | // the request. |
[email protected] | d6a3c77 | 2009-01-27 19:41:20 | [diff] [blame] | 2743 | // TODO(port): figure out what is required here in a cross-platform world |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 2744 | MessageLoop::current()->PostTask( |
| 2745 | FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame)); |
[email protected] | d6a3c77 | 2009-01-27 19:41:20 | [diff] [blame] | 2746 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2747 | } |
| 2748 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2749 | void Browser::CreateHistoricalTab(TabContentsWrapper* contents) { |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 2750 | // We don't create historical tabs for incognito windows or windows without |
| 2751 | // profiles. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2752 | if (!profile() || profile()->IsOffTheRecord()) |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 2753 | return; |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2754 | |
[email protected] | 0d4ef7f | 2011-05-12 22:38:57 | [diff] [blame] | 2755 | // We don't create historical tabs for print preview tabs. |
| 2756 | if (contents->tab_contents()->GetURL() == GURL(chrome::kChromeUIPrintURL)) |
| 2757 | return; |
| 2758 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2759 | TabRestoreService* service = |
| 2760 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 2761 | |
[email protected] | fb5ff42 | 2010-05-03 20:46:10 | [diff] [blame] | 2762 | // We only create historical tab entries for tabbed browser windows. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2763 | if (service && CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
| 2764 | service->CreateHistoricalTab(&contents->controller(), |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 2765 | tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents)); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 2766 | } |
| 2767 | } |
| 2768 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2769 | bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { |
| 2770 | return Browser::RunUnloadEventsHelper(contents->tab_contents()); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 2771 | } |
| 2772 | |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 2773 | bool Browser::CanReloadContents(TabContents* source) const { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 2774 | return !is_devtools(); |
[email protected] | 8e48e98 | 2009-12-25 11:22:46 | [diff] [blame] | 2775 | } |
| 2776 | |
[email protected] | 2db5a204 | 2011-04-26 17:13:47 | [diff] [blame] | 2777 | bool Browser::CanCloseContents(std::vector<int>* indices) { |
| 2778 | DCHECK(!indices->empty()); |
| 2779 | TabCloseableStateWatcher* watcher = |
| 2780 | g_browser_process->tab_closeable_state_watcher(); |
| 2781 | bool can_close_all = !watcher || watcher->CanCloseTabs(this, indices); |
| 2782 | if (indices->empty()) // Cannot close any tab. |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 2783 | return false; |
[email protected] | 2db5a204 | 2011-04-26 17:13:47 | [diff] [blame] | 2784 | // Now, handle cases where at least one tab can be closed. |
| 2785 | // 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] | 2786 | // in-progress downloads. |
| 2787 | // Note that the next call when it returns false will ask the user for |
| 2788 | // confirmation before closing the browser if the user decides so. |
[email protected] | 2db5a204 | 2011-04-26 17:13:47 | [diff] [blame] | 2789 | if (tab_handler_->GetTabStripModel()->count() == |
| 2790 | static_cast<int>(indices->size()) && |
| 2791 | !CanCloseWithInProgressDownloads()) { |
| 2792 | indices->clear(); |
| 2793 | can_close_all = false; |
| 2794 | } |
| 2795 | return can_close_all; |
[email protected] | 940ccb2 | 2009-04-30 17:11:10 | [diff] [blame] | 2796 | } |
[email protected] | d6a3c77 | 2009-01-27 19:41:20 | [diff] [blame] | 2797 | |
[email protected] | a206b44 | 2009-10-08 23:20:20 | [diff] [blame] | 2798 | bool Browser::CanBookmarkAllTabs() const { |
| 2799 | BookmarkModel* model = profile()->GetBookmarkModel(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 2800 | return (model && model->IsLoaded()) && |
| 2801 | tab_count() > 1 && |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 2802 | profile()->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled); |
[email protected] | a206b44 | 2009-10-08 23:20:20 | [diff] [blame] | 2803 | } |
| 2804 | |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 2805 | void Browser::BookmarkAllTabs() { |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 2806 | BookmarkModel* model = profile()->GetBookmarkModel(); |
| 2807 | DCHECK(model && model->IsLoaded()); |
| 2808 | |
| 2809 | BookmarkEditor::EditDetails details; |
| 2810 | details.type = BookmarkEditor::EditDetails::NEW_FOLDER; |
| 2811 | bookmark_utils::GetURLsForOpenTabs(this, &(details.urls)); |
| 2812 | DCHECK(!details.urls.empty()); |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 2813 | |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 2814 | BookmarkEditor::Show(window()->GetNativeHandle(), profile_, |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 2815 | model->GetParentForNewNodes(), details, |
[email protected] | 97a05646 | 2010-04-28 16:46:35 | [diff] [blame] | 2816 | BookmarkEditor::SHOW_TREE); |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 2817 | } |
| 2818 | |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 2819 | bool Browser::CanCloseTab() const { |
| 2820 | TabCloseableStateWatcher* watcher = |
| 2821 | g_browser_process->tab_closeable_state_watcher(); |
| 2822 | return !watcher || watcher->CanCloseTab(this); |
| 2823 | } |
| 2824 | |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 2825 | void Browser::ToggleUseVerticalTabs() { |
| 2826 | use_vertical_tabs_.SetValue(!UseVerticalTabs()); |
[email protected] | b334487 | 2010-05-03 15:52:29 | [diff] [blame] | 2827 | UseVerticalTabsChanged(); |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 2828 | } |
| 2829 | |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 2830 | void Browser::ToggleUseCompactNavigationBar() { |
| 2831 | use_compact_navigation_bar_.SetValue(!UseCompactNavigationBar()); |
| 2832 | UseCompactNavigationBarChanged(); |
| 2833 | } |
| 2834 | |
[email protected] | b283a753 | 2010-08-12 21:24:59 | [diff] [blame] | 2835 | bool Browser::LargeIconsPermitted() const { |
[email protected] | af801acd | 2010-08-20 20:27:44 | [diff] [blame] | 2836 | // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because |
| 2837 | // for those windows, we already have a big icon in the top-left outside any |
| 2838 | // tab. Having big tab icons too looks kinda redonk. |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 2839 | return true; |
[email protected] | b283a753 | 2010-08-12 21:24:59 | [diff] [blame] | 2840 | } |
| 2841 | |
[email protected] | 2d46c84 | 2008-11-14 19:24:31 | [diff] [blame] | 2842 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2843 | // Browser, TabStripModelObserver implementation: |
| 2844 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2845 | void Browser::TabInsertedAt(TabContentsWrapper* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2846 | int index, |
| 2847 | bool foreground) { |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 2848 | SetAsDelegate(contents, this); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2849 | contents->controller().SetWindowID(session_id()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2850 | |
[email protected] | 15b2c6a | 2011-05-16 23:54:40 | [diff] [blame] | 2851 | // Extension code in the renderer holds the ID of the window that hosts it. |
| 2852 | // Notify it that the window ID changed. |
| 2853 | contents->render_view_host()->Send(new ExtensionMsg_UpdateBrowserWindowId( |
| 2854 | contents->render_view_host()->routing_id(), |
| 2855 | contents->controller().window_id().id())); |
[email protected] | e524ff9 | 2011-03-30 13:26:58 | [diff] [blame] | 2856 | |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2857 | SyncHistoryWithTabs(index); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2858 | |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 2859 | // Make sure the loading state is updated correctly, otherwise the throbber |
| 2860 | // won't start if the page is loading. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2861 | LoadingStateChanged(contents->tab_contents()); |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 2862 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2863 | // If the tab crashes in the beforeunload or unload handler, it won't be |
| 2864 | // able to ack. But we know we can close it. |
[email protected] | 0cb9410 | 2009-05-22 19:51:21 | [diff] [blame] | 2865 | registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, |
[email protected] | 8d258e19 | 2011-05-05 21:21:05 | [diff] [blame] | 2866 | Source<TabContents>(contents->tab_contents())); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 2867 | |
| 2868 | registrar_.Add(this, NotificationType::INTERSTITIAL_ATTACHED, |
| 2869 | Source<TabContents>(contents->tab_contents())); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2870 | } |
| 2871 | |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 2872 | void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2873 | TabContentsWrapper* contents, |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 2874 | int index) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 2875 | NotificationService::current()->Notify( |
| 2876 | NotificationType::TAB_CLOSING, |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2877 | Source<NavigationController>(&contents->controller()), |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 2878 | NotificationService::NoDetails()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2879 | |
| 2880 | // Sever the TabContents' connection back to us. |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 2881 | SetAsDelegate(contents, NULL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2882 | } |
| 2883 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2884 | void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2885 | TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2886 | } |
| 2887 | |
[email protected] | 2ab3fa9 | 2011-02-27 21:46:51 | [diff] [blame] | 2888 | void Browser::TabDeselected(TabContentsWrapper* contents) { |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 2889 | if (instant()) |
| 2890 | instant()->DestroyPreviewContents(); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 2891 | |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 2892 | // Save what the user's currently typing, so it can be restored when we |
| 2893 | // switch back to this tab. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2894 | window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 2895 | } |
| 2896 | |
[email protected] | 3aca95d4 | 2011-05-24 22:06:54 | [diff] [blame] | 2897 | void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, |
| 2898 | TabContentsWrapper* new_contents, |
| 2899 | int index, |
| 2900 | bool user_gesture) { |
[email protected] | 02cd2bf | 2011-03-02 21:45:56 | [diff] [blame] | 2901 | if (old_contents == new_contents) |
| 2902 | return; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2903 | |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 2904 | // On some platforms we want to automatically reload tabs that are |
| 2905 | // killed when the user selects them. |
| 2906 | if (user_gesture && new_contents->tab_contents()->crashed_status() == |
| 2907 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 2908 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 2909 | if (parsed_command_line.HasSwitch(switches::kReloadKilledTabs)) { |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 2910 | Reload(CURRENT_TAB); |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 2911 | return; |
| 2912 | } |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 2913 | } |
| 2914 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2915 | // If we have any update pending, do it now. |
| 2916 | if (!chrome_updater_factory_.empty() && old_contents) |
| 2917 | ProcessPendingUIUpdates(); |
| 2918 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2919 | // Propagate the profile to the location bar. |
| 2920 | UpdateToolbar(true); |
| 2921 | |
[email protected] | 943d812 | 2010-06-11 02:13:45 | [diff] [blame] | 2922 | // Update reload/stop state. |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2923 | UpdateReloadStopState(new_contents->tab_contents()->is_loading(), true); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2924 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 2925 | // Update commands to reflect current state. |
| 2926 | UpdateCommandsForTabState(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2927 | |
| 2928 | // Reset the status bubble. |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 2929 | StatusBubble* status_bubble = GetStatusBubble(); |
| 2930 | if (status_bubble) { |
| 2931 | status_bubble->Hide(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2932 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 2933 | // Show the loading state (if any). |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 2934 | status_bubble->SetStatus(GetSelectedTabContentsWrapper()->GetStatusText()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 2935 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2936 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 2937 | if (HasFindBarController()) { |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 2938 | find_bar_controller_->ChangeTabContents(new_contents); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 2939 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 2940 | } |
| 2941 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2942 | // Update sessions. Don't force creation of sessions. If sessions doesn't |
| 2943 | // exist, the change will be picked up by sessions when created. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2944 | SessionService* session_service = |
| 2945 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 2946 | if (session_service && !tab_handler_->GetTabStripModel()->closing_all()) { |
| 2947 | session_service->SetSelectedTabInWindow( |
| 2948 | session_id(), tab_handler_->GetTabStripModel()->active_index()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2949 | } |
| 2950 | } |
| 2951 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2952 | void Browser::TabMoved(TabContentsWrapper* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2953 | int from_index, |
[email protected] | 1a242c3 | 2010-02-02 21:20:54 | [diff] [blame] | 2954 | int to_index) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2955 | DCHECK(from_index >= 0 && to_index >= 0); |
| 2956 | // Notify the history service. |
| 2957 | SyncHistoryWithTabs(std::min(from_index, to_index)); |
| 2958 | } |
| 2959 | |
[email protected] | da25dd5 | 2011-01-11 19:06:30 | [diff] [blame] | 2960 | void Browser::TabReplacedAt(TabStripModel* tab_strip_model, |
| 2961 | TabContentsWrapper* old_contents, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2962 | TabContentsWrapper* new_contents, |
[email protected] | 8a34e660 | 2010-10-02 17:29:43 | [diff] [blame] | 2963 | int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2964 | TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); |
| 2965 | TabInsertedAt(new_contents, index, |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 2966 | (index == tab_handler_->GetTabStripModel()->active_index())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2967 | |
| 2968 | int entry_count = new_contents->controller().entry_count(); |
| 2969 | if (entry_count > 0) { |
| 2970 | // Send out notification so that observers are updated appropriately. |
| 2971 | new_contents->controller().NotifyEntryChanged( |
| 2972 | new_contents->controller().GetEntryAtIndex(entry_count - 1), |
| 2973 | entry_count - 1); |
| 2974 | } |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 2975 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2976 | SessionService* session_service = |
| 2977 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 2978 | if (session_service) { |
| 2979 | // The new_contents may end up with a different navigation stack. Force |
| 2980 | // the session service to update itself. |
| 2981 | session_service->TabRestored( |
| 2982 | &new_contents->controller(), |
| 2983 | tab_handler_->GetTabStripModel()->IsTabPinned(index)); |
| 2984 | } |
[email protected] | 2914600d | 2011-01-31 23:25:14 | [diff] [blame] | 2985 | |
| 2986 | DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
| 2987 | if (devtools_manager) // NULL in unit tests. |
| 2988 | devtools_manager->TabReplaced(old_contents, new_contents); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2989 | } |
| 2990 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2991 | void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2992 | SessionService* session_service = |
| 2993 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 2994 | if (session_service) { |
| 2995 | session_service->SetPinnedState( |
| 2996 | session_id(), |
| 2997 | GetTabContentsAt(index)->controller().session_id(), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2998 | tab_handler_->GetTabStripModel()->IsTabPinned(index)); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 2999 | } |
| 3000 | } |
| 3001 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3002 | void Browser::TabStripEmpty() { |
| 3003 | // Close the frame after we return to the message loop (not immediately, |
| 3004 | // otherwise it will destroy this object before the stack has a chance to |
| 3005 | // cleanly unwind.) |
| 3006 | // Note: This will be called several times if TabStripEmpty is called several |
| 3007 | // times. This is because it does not close the window if tabs are |
| 3008 | // still present. |
| 3009 | // NOTE: If you change to be immediate (no invokeLater) then you'll need to |
| 3010 | // update BrowserList::CloseAllBrowsers. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 3011 | MessageLoop::current()->PostTask( |
| 3012 | FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | /////////////////////////////////////////////////////////////////////////////// |
| 3016 | // Browser, TabContentsDelegate implementation: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3017 | |
| 3018 | void Browser::OpenURLFromTab(TabContents* source, |
[email protected] | 1f7d7e9 | 2009-06-02 20:55:04 | [diff] [blame] | 3019 | const GURL& url, |
| 3020 | const GURL& referrer, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3021 | WindowOpenDisposition disposition, |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 3022 | PageTransition::Type transition) { |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3023 | browser::NavigateParams params(this, url, transition); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3024 | params.source_contents = |
| 3025 | tabstrip_model()->GetTabContentsAt( |
| 3026 | tabstrip_model()->GetWrapperIndex(source)); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3027 | params.referrer = referrer; |
| 3028 | params.disposition = disposition; |
| 3029 | params.tabstrip_add_types = TabStripModel::ADD_NONE; |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 3030 | params.window_action = browser::NavigateParams::SHOW_WINDOW; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 3031 | params.user_gesture = true; |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3032 | browser::Navigate(¶ms); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | void Browser::NavigationStateChanged(const TabContents* source, |
| 3036 | unsigned changed_flags) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3037 | // Only update the UI when something visible has changed. |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 3038 | if (changed_flags) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3039 | ScheduleUIUpdate(source, changed_flags); |
| 3040 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3041 | // We don't schedule updates to commands since they will only change once per |
| 3042 | // navigation, so we don't have to worry about flickering. |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 3043 | if (changed_flags & TabContents::INVALIDATE_URL) |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3044 | UpdateCommandsForTabState(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3045 | } |
| 3046 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3047 | void Browser::AddNewContents(TabContents* source, |
| 3048 | TabContents* new_contents, |
| 3049 | WindowOpenDisposition disposition, |
| 3050 | const gfx::Rect& initial_pos, |
| 3051 | bool user_gesture) { |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3052 | // No code for this yet. |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 3053 | DCHECK(disposition != SAVE_TO_DISK); |
| 3054 | // Can't create a new contents for the current tab - invalid case. |
| 3055 | DCHECK(disposition != CURRENT_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3056 | |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3057 | TabContentsWrapper* source_wrapper = NULL; |
| 3058 | BlockedContentTabHelper* source_blocked_content = NULL; |
[email protected] | ad1be159 | 2011-04-27 14:14:45 | [diff] [blame] | 3059 | TabContentsWrapper* new_wrapper = |
| 3060 | TabContentsWrapper::GetCurrentWrapperForContents(new_contents); |
| 3061 | if (!new_wrapper) |
| 3062 | new_wrapper = new TabContentsWrapper(new_contents); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3063 | if (source) { |
| 3064 | source_wrapper = TabContentsWrapper::GetCurrentWrapperForContents(source); |
| 3065 | source_blocked_content = source_wrapper->blocked_content_tab_helper(); |
| 3066 | } |
| 3067 | |
| 3068 | if (source_wrapper) { |
| 3069 | // Handle blocking of all contents. |
| 3070 | if (source_blocked_content->all_contents_blocked()) { |
| 3071 | source_blocked_content->AddTabContents(new_wrapper, |
| 3072 | disposition, |
| 3073 | initial_pos, |
| 3074 | user_gesture); |
| 3075 | return; |
| 3076 | } |
| 3077 | |
| 3078 | // Handle blocking of popups. |
| 3079 | if ((disposition == NEW_POPUP) && !user_gesture && |
| 3080 | !CommandLine::ForCurrentProcess()->HasSwitch( |
| 3081 | switches::kDisablePopupBlocking)) { |
| 3082 | // Unrequested popups from normal pages are constrained unless they're in |
| 3083 | // the whitelist. The popup owner will handle checking this. |
[email protected] | 393c0ed0 | 2011-04-22 14:55:36 | [diff] [blame] | 3084 | GetConstrainingContentsWrapper(source_wrapper)-> |
| 3085 | blocked_content_tab_helper()-> |
| 3086 | AddPopup(new_wrapper, initial_pos, user_gesture); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3087 | return; |
| 3088 | } |
| 3089 | |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 3090 | RenderViewHost* view = new_contents->render_view_host(); |
| 3091 | view->Send(new ViewMsg_DisassociateFromPopupCount(view->routing_id())); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3092 | } |
| 3093 | |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3094 | browser::NavigateParams params(this, new_wrapper); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3095 | params.source_contents = |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3096 | source ? tabstrip_model()->GetTabContentsAt( |
| 3097 | tabstrip_model()->GetWrapperIndex(source)) |
| 3098 | : NULL; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3099 | params.disposition = disposition; |
| 3100 | params.window_bounds = initial_pos; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 3101 | params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 3102 | params.user_gesture = user_gesture; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3103 | browser::Navigate(¶ms); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3104 | |
| 3105 | if (source) { |
| 3106 | NotificationService::current()->Notify( |
| 3107 | NotificationType::TAB_ADDED, |
| 3108 | Source<TabContentsDelegate>(source->delegate()), |
| 3109 | Details<TabContents>(source)); |
| 3110 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3111 | } |
| 3112 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3113 | void Browser::ActivateContents(TabContents* contents) { |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 3114 | tab_handler_->GetTabStripModel()->ActivateTabAt( |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3115 | tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), false); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 3116 | window_->Activate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3117 | } |
| 3118 | |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 3119 | void Browser::DeactivateContents(TabContents* contents) { |
| 3120 | window_->Deactivate(); |
| 3121 | } |
| 3122 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3123 | void Browser::LoadingStateChanged(TabContents* source) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3124 | window_->UpdateLoadingAnimations( |
| 3125 | tab_handler_->GetTabStripModel()->TabsAreLoading()); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 3126 | window_->UpdateTitleBar(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3127 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3128 | TabContents* selected_contents = GetSelectedTabContents(); |
| 3129 | if (source == selected_contents) { |
[email protected] | 943d812 | 2010-06-11 02:13:45 | [diff] [blame] | 3130 | UpdateReloadStopState(source->is_loading(), false); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 3131 | if (GetStatusBubble()) { |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 3132 | GetStatusBubble()->SetStatus( |
| 3133 | GetSelectedTabContentsWrapper()->GetStatusText()); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 3134 | } |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3135 | |
| 3136 | if (!source->is_loading() && |
| 3137 | pending_web_app_action_ == UPDATE_SHORTCUT) { |
[email protected] | 867dff8 | 2010-04-23 21:30:33 | [diff] [blame] | 3138 | // Schedule a shortcut update when web application info is available if |
| 3139 | // last committed entry is not NULL. Last committed entry could be NULL |
| 3140 | // when an interstitial page is injected (e.g. bad https certificate, |
| 3141 | // malware site etc). When this happens, we abort the shortcut update. |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3142 | NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
| 3143 | if (entry) { |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 3144 | TabContentsWrapper::GetCurrentWrapperForContents(source)-> |
| 3145 | extension_tab_helper()->GetApplicationInfo(entry->page_id()); |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3146 | } else { |
| 3147 | pending_web_app_action_ = NONE; |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 3148 | } |
| 3149 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | void Browser::CloseContents(TabContents* source) { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 3154 | if (is_attempting_to_close_browser_) { |
| 3155 | // 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] | 3156 | // 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] | 3157 | // will go down the slow shutdown path instead of the fast path of killing |
| 3158 | // all the renderer processes. |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 3159 | ClearUnloadState(source, true); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 3160 | return; |
| 3161 | } |
| 3162 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3163 | int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3164 | if (index == TabStripModel::kNoTab) { |
| 3165 | NOTREACHED() << "CloseContents called for tab not in our strip"; |
| 3166 | return; |
| 3167 | } |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3168 | tab_handler_->GetTabStripModel()->CloseTabContentsAt( |
[email protected] | 0cce15f | 2010-05-21 16:58:39 | [diff] [blame] | 3169 | index, |
| 3170 | TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3171 | } |
| 3172 | |
[email protected] | 15e8abe | 2008-08-20 22:40:40 | [diff] [blame] | 3173 | void Browser::MoveContents(TabContents* source, const gfx::Rect& pos) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3174 | if (!IsPopupOrPanel(source)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3175 | NOTREACHED() << "moving invalid browser type"; |
| 3176 | return; |
| 3177 | } |
[email protected] | e561e20 | 2010-03-24 17:57:12 | [diff] [blame] | 3178 | window_->SetBounds(pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3179 | } |
| 3180 | |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 3181 | void Browser::DetachContents(TabContents* source) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3182 | int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 3183 | if (index >= 0) |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3184 | tab_handler_->GetTabStripModel()->DetachTabContentsAt(index); |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 3185 | } |
| 3186 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3187 | bool Browser::IsPopupOrPanel(const TabContents* source) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3188 | // A non-tabbed BROWSER is an unconstrained popup. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3189 | return is_type_popup() || is_type_panel(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3190 | } |
| 3191 | |
[email protected] | b8595e9 | 2009-11-14 01:18:00 | [diff] [blame] | 3192 | void Browser::ContentsMouseEvent( |
| 3193 | TabContents* source, const gfx::Point& location, bool motion) { |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3194 | if (!GetStatusBubble()) |
| 3195 | return; |
| 3196 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3197 | if (source == GetSelectedTabContents()) { |
[email protected] | b8595e9 | 2009-11-14 01:18:00 | [diff] [blame] | 3198 | GetStatusBubble()->MouseMoved(location, !motion); |
| 3199 | if (!motion) |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 3200 | GetStatusBubble()->SetURL(GURL(), string16()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3201 | } |
| 3202 | } |
| 3203 | |
| 3204 | void Browser::UpdateTargetURL(TabContents* source, const GURL& url) { |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 3205 | if (!GetStatusBubble()) |
| 3206 | return; |
| 3207 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3208 | if (source == GetSelectedTabContents()) { |
| 3209 | PrefService* prefs = profile_->GetPrefs(); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 3210 | GetStatusBubble()->SetURL( |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 3211 | url, UTF8ToUTF16(prefs->GetString(prefs::kAcceptLanguages))); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3212 | } |
| 3213 | } |
| 3214 | |
[email protected] | 3a6a3b6 | 2009-05-27 21:36:20 | [diff] [blame] | 3215 | void Browser::UpdateDownloadShelfVisibility(bool visible) { |
[email protected] | 9b032bf | 2009-07-21 17:34:23 | [diff] [blame] | 3216 | if (GetStatusBubble()) |
| 3217 | GetStatusBubble()->UpdateDownloadShelfVisibility(visible); |
[email protected] | 3a6a3b6 | 2009-05-27 21:36:20 | [diff] [blame] | 3218 | } |
| 3219 | |
[email protected] | aa02fff1 | 2010-07-21 19:55:25 | [diff] [blame] | 3220 | bool Browser::UseVerticalTabs() const { |
| 3221 | return use_vertical_tabs_.GetValue(); |
| 3222 | } |
| 3223 | |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 3224 | bool Browser::UseCompactNavigationBar() const { |
| 3225 | return use_compact_navigation_bar_.GetValue(); |
| 3226 | } |
| 3227 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3228 | void Browser::ContentsZoomChange(bool zoom_in) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3229 | ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3230 | } |
| 3231 | |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 3232 | void Browser::SetTabContentBlocked(TabContents* contents, bool blocked) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3233 | int index = tabstrip_model()->GetWrapperIndex(contents); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 3234 | if (index == TabStripModel::kNoTab) { |
| 3235 | NOTREACHED(); |
| 3236 | return; |
| 3237 | } |
| 3238 | tabstrip_model()->SetTabBlocked(index, blocked); |
| 3239 | } |
| 3240 | |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 3241 | void Browser::TabContentsFocused(TabContents* tab_content) { |
| 3242 | window_->TabContentsFocused(tab_content); |
| 3243 | } |
| 3244 | |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 3245 | bool Browser::TakeFocus(bool reverse) { |
| 3246 | NotificationService::current()->Notify( |
| 3247 | NotificationType::FOCUS_RETURNED_TO_BROWSER, |
| 3248 | Source<Browser>(this), |
| 3249 | NotificationService::NoDetails()); |
| 3250 | return false; |
| 3251 | } |
| 3252 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3253 | bool Browser::IsApplication() const { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3254 | return is_app(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | void Browser::ConvertContentsToApplication(TabContents* contents) { |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 3258 | const GURL& url = contents->controller().GetActiveEntry()->url(); |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 3259 | std::string app_name = web_app::GenerateApplicationNameFromURL(url); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3260 | |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 3261 | DetachContents(contents); |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 3262 | Browser* app_browser = Browser::CreateForApp( |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3263 | TYPE_POPUP, app_name, gfx::Size(), profile_); |
[email protected] | ae2f2a77 | 2011-05-04 16:30:27 | [diff] [blame] | 3264 | TabContentsWrapper* wrapper = |
| 3265 | TabContentsWrapper::GetCurrentWrapperForContents(contents); |
| 3266 | if (!wrapper) |
| 3267 | wrapper = new TabContentsWrapper(contents); |
[email protected] | 75aef12 | 2010-12-06 21:48:32 | [diff] [blame] | 3268 | app_browser->tabstrip_model()->AppendTabContents(wrapper, true); |
| 3269 | |
| 3270 | contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 3271 | contents->render_view_host()->SyncRendererPrefs(); |
| 3272 | app_browser->window()->Show(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3273 | } |
| 3274 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3275 | bool Browser::ShouldDisplayURLField() { |
| 3276 | return !IsApplication(); |
| 3277 | } |
| 3278 | |
| 3279 | void Browser::BeforeUnloadFired(TabContents* tab, |
| 3280 | bool proceed, |
| 3281 | bool* proceed_to_fire_unload) { |
| 3282 | if (!is_attempting_to_close_browser_) { |
| 3283 | *proceed_to_fire_unload = proceed; |
[email protected] | 0cce15f | 2010-05-21 16:58:39 | [diff] [blame] | 3284 | if (!proceed) |
| 3285 | tab->set_closed_by_user_gesture(false); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3286 | return; |
| 3287 | } |
| 3288 | |
| 3289 | if (!proceed) { |
| 3290 | CancelWindowClose(); |
| 3291 | *proceed_to_fire_unload = false; |
[email protected] | 0cce15f | 2010-05-21 16:58:39 | [diff] [blame] | 3292 | tab->set_closed_by_user_gesture(false); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3293 | return; |
| 3294 | } |
| 3295 | |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 3296 | if (RemoveFromSet(&tabs_needing_before_unload_fired_, tab)) { |
[email protected] | 2d46c84 | 2008-11-14 19:24:31 | [diff] [blame] | 3297 | // Now that beforeunload has fired, put the tab on the queue to fire |
| 3298 | // unload. |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 3299 | tabs_needing_unload_fired_.insert(tab); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3300 | ProcessPendingTabs(); |
[email protected] | adf650f | 2008-12-09 16:10:06 | [diff] [blame] | 3301 | // We want to handle firing the unload event ourselves since we want to |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3302 | // fire all the beforeunload events before attempting to fire the unload |
| 3303 | // events should the user cancel closing the browser. |
| 3304 | *proceed_to_fire_unload = false; |
| 3305 | return; |
| 3306 | } |
| 3307 | |
| 3308 | *proceed_to_fire_unload = true; |
| 3309 | } |
| 3310 | |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 3311 | void Browser::SetFocusToLocationBar(bool select_all) { |
[email protected] | 1a38062 | 2009-02-17 17:33:13 | [diff] [blame] | 3312 | // Two differences between this and FocusLocationBar(): |
| 3313 | // (1) This doesn't get recorded in user metrics, since it's called |
| 3314 | // internally. |
| 3315 | // (2) This checks whether the location bar can be focused, and if not, clears |
| 3316 | // the focus. FocusLocationBar() is only reached when the location bar is |
| 3317 | // focusable, but this may be reached at other times, e.g. while in |
| 3318 | // fullscreen mode, where we need to leave focus in a consistent state. |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 3319 | window_->SetFocusToLocationBar(select_all); |
[email protected] | 4bcefee | 2009-01-29 15:57:57 | [diff] [blame] | 3320 | } |
| 3321 | |
[email protected] | 7d5925a | 2009-03-03 02:59:12 | [diff] [blame] | 3322 | void Browser::RenderWidgetShowing() { |
| 3323 | window_->DisableInactiveFrame(); |
| 3324 | } |
[email protected] | a239c3f | 2009-02-17 22:13:19 | [diff] [blame] | 3325 | |
[email protected] | 0a2aeb8 | 2009-05-15 21:52:48 | [diff] [blame] | 3326 | int Browser::GetExtraRenderViewHeight() const { |
| 3327 | return window_->GetExtraRenderViewHeight(); |
| 3328 | } |
| 3329 | |
[email protected] | bb67833 | 2009-07-21 00:15:50 | [diff] [blame] | 3330 | void Browser::ShowPageInfo(Profile* profile, |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 3331 | const GURL& url, |
| 3332 | const NavigationEntry::SSLStatus& ssl, |
| 3333 | bool show_history) { |
[email protected] | bb67833 | 2009-07-21 00:15:50 | [diff] [blame] | 3334 | window()->ShowPageInfo(profile, url, ssl, show_history); |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 3335 | } |
| 3336 | |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 3337 | void Browser::ViewSourceForTab(TabContents* source, const GURL& page_url) { |
| 3338 | DCHECK(source); |
| 3339 | int index = tabstrip_model()->GetWrapperIndex(source); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 3340 | TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
| 3341 | ViewSource(wrapper); |
| 3342 | } |
| 3343 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 3344 | void Browser::ViewSourceForFrame(TabContents* source, |
| 3345 | const GURL& frame_url, |
| 3346 | const std::string& frame_content_state) { |
| 3347 | DCHECK(source); |
| 3348 | int index = tabstrip_model()->GetWrapperIndex(source); |
| 3349 | TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
| 3350 | ViewSource(wrapper, frame_url, frame_content_state); |
| 3351 | } |
| 3352 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 3353 | bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 3354 | bool* is_keyboard_shortcut) { |
| 3355 | return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 3356 | } |
[email protected] | 97df4b33 | 2009-10-02 01:25:41 | [diff] [blame] | 3357 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 3358 | void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 3359 | window()->HandleKeyboardEvent(event); |
[email protected] | 97df4b33 | 2009-10-02 01:25:41 | [diff] [blame] | 3360 | } |
| 3361 | |
[email protected] | 14f3408a | 2009-08-31 20:53:53 | [diff] [blame] | 3362 | void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { |
| 3363 | window()->ShowRepostFormWarningDialog(tab_contents); |
| 3364 | } |
| 3365 | |
[email protected] | 579e319 | 2011-03-11 22:37:45 | [diff] [blame] | 3366 | void Browser::ShowContentSettingsPage(ContentSettingsType content_type) { |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 3367 | ShowOptionsTab( |
| 3368 | chrome::kContentSettingsExceptionsSubPage + std::string(kHashMark) + |
| 3369 | ContentSettingsHandler::ContentSettingsTypeToGroupName(content_type)); |
[email protected] | 6354314 | 2010-02-09 23:22:20 | [diff] [blame] | 3370 | } |
| 3371 | |
[email protected] | a503c97c | 2010-07-16 13:05:48 | [diff] [blame] | 3372 | void Browser::ShowCollectedCookiesDialog(TabContents *tab_contents) { |
| 3373 | window()->ShowCollectedCookiesDialog(tab_contents); |
| 3374 | } |
| 3375 | |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 3376 | bool Browser::ShouldAddNavigationToHistory( |
| 3377 | const history::HistoryAddPageArgs& add_page_args, |
| 3378 | NavigationType::Type navigation_type) { |
[email protected] | 2e29d92 | 2009-10-22 22:13:35 | [diff] [blame] | 3379 | // Don't update history if running as app. |
| 3380 | return !IsApplication(); |
| 3381 | } |
| 3382 | |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 3383 | void Browser::ContentRestrictionsChanged(TabContents* source) { |
| 3384 | UpdateCommandsForContentRestrictionState(); |
| 3385 | } |
| 3386 | |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 3387 | void Browser::RendererUnresponsive(TabContents* source) { |
| 3388 | browser::ShowHungRendererDialog(source); |
| 3389 | } |
| 3390 | |
| 3391 | void Browser::RendererResponsive(TabContents* source) { |
| 3392 | browser::HideHungRendererDialog(source); |
| 3393 | } |
| 3394 | |
| 3395 | void Browser::WorkerCrashed(TabContents* source) { |
| 3396 | TabContentsWrapper* wrapper = |
| 3397 | TabContentsWrapper::GetCurrentWrapperForContents(source); |
| 3398 | wrapper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 3399 | source, NULL, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), |
| 3400 | true)); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 3401 | } |
| 3402 | |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 3403 | TabContentsDelegate::MainFrameCommitDetails* |
| 3404 | Browser::CreateMainFrameCommitDetails(TabContents* tab) { |
| 3405 | if (tab != GetSelectedTabContents()) |
| 3406 | return NULL; |
| 3407 | |
| 3408 | BrowserMainFrameCommitDetails* details = new BrowserMainFrameCommitDetails; |
| 3409 | details->bookmark_bar_visible = GetSelectedTabContentsWrapper()-> |
| 3410 | bookmark_tab_helper()->ShouldShowBookmarkBar(); |
| 3411 | return details; // Caller takes ownership. |
| 3412 | } |
| 3413 | |
| 3414 | void Browser::DidNavigateMainFramePostCommit( |
| 3415 | TabContents* tab, |
| 3416 | const MainFrameCommitDetails& details) { |
| 3417 | bool visible = static_cast<const BrowserMainFrameCommitDetails&>(details). |
| 3418 | bookmark_bar_visible; |
| 3419 | if (tab == GetSelectedTabContents() && visible != |
| 3420 | GetSelectedTabContentsWrapper()->bookmark_tab_helper()-> |
| 3421 | ShouldShowBookmarkBar()) { |
| 3422 | window()->ShelfVisibilityChanged(); |
| 3423 | } |
| 3424 | } |
| 3425 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame^] | 3426 | content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { |
| 3427 | return GetJavaScriptDialogCreatorInstance(); |
| 3428 | } |
| 3429 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3430 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 3431 | // Browser, TabContentsWrapperDelegate implementation: |
| 3432 | |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 3433 | void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
| 3434 | int32 page_id) { |
| 3435 | if (GetSelectedTabContentsWrapper() != source) |
| 3436 | return; |
| 3437 | |
| 3438 | NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
| 3439 | if (!entry || (entry->page_id() != page_id)) |
| 3440 | return; |
| 3441 | |
| 3442 | switch (pending_web_app_action_) { |
| 3443 | case CREATE_SHORTCUT: { |
| 3444 | window()->ShowCreateWebAppShortcutsDialog(source); |
| 3445 | break; |
| 3446 | } |
| 3447 | case UPDATE_SHORTCUT: { |
| 3448 | web_app::UpdateShortcutForTabContents(source); |
| 3449 | break; |
| 3450 | } |
| 3451 | default: |
| 3452 | NOTREACHED(); |
| 3453 | break; |
| 3454 | } |
| 3455 | |
| 3456 | pending_web_app_action_ = NONE; |
| 3457 | } |
| 3458 | |
| 3459 | void Browser::OnInstallApplication(TabContentsWrapper* source, |
| 3460 | const WebApplicationInfo& web_app) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 3461 | ExtensionService* extension_service = profile()->GetExtensionService(); |
| 3462 | if (!extension_service) |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 3463 | return; |
| 3464 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 3465 | scoped_refptr<CrxInstaller> installer(extension_service->MakeCrxInstaller( |
| 3466 | extension_service->show_extensions_prompts() ? |
| 3467 | new ExtensionInstallUI(profile()) : NULL)); |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 3468 | installer->InstallWebApp(web_app); |
| 3469 | } |
| 3470 | |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 3471 | /////////////////////////////////////////////////////////////////////////////// |
| 3472 | // Browser, SearchEngineTabHelperDelegate implementation: |
| 3473 | |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 3474 | void Browser::ConfirmSetDefaultSearchProvider( |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 3475 | TabContents* tab_contents, |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 3476 | TemplateURL* template_url, |
| 3477 | TemplateURLModel* template_url_model) { |
| 3478 | window()->ConfirmSetDefaultSearchProvider(tab_contents, template_url, |
| 3479 | template_url_model); |
| 3480 | } |
| 3481 | |
| 3482 | void Browser::ConfirmAddSearchProvider(const TemplateURL* template_url, |
| 3483 | Profile* profile) { |
| 3484 | window()->ConfirmAddSearchProvider(template_url, profile); |
| 3485 | } |
| 3486 | |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 3487 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3488 | // Browser, BlockedContentTabHelperDelegate implementation: |
| 3489 | |
[email protected] | 393c0ed0 | 2011-04-22 14:55:36 | [diff] [blame] | 3490 | TabContentsWrapper* Browser::GetConstrainingContentsWrapper( |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 3491 | TabContentsWrapper* source) { |
| 3492 | return source; |
| 3493 | } |
| 3494 | |
| 3495 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 3496 | // Browser, BookmarkTabHelperDelegate implementation: |
[email protected] | 52cc59b | 2011-05-06 14:42:38 | [diff] [blame] | 3497 | |
| 3498 | void Browser::URLStarredChanged(TabContentsWrapper* source, bool starred) { |
| 3499 | if (source == GetSelectedTabContentsWrapper()) |
| 3500 | window_->SetStarredState(starred); |
| 3501 | } |
| 3502 | |
| 3503 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | ddb8505 | 2011-05-18 14:40:27 | [diff] [blame] | 3504 | // Browser, DownloadTabHelperDelegate implementation: |
| 3505 | |
| 3506 | bool Browser::CanDownload(int request_id) { |
| 3507 | return true; |
| 3508 | } |
| 3509 | |
| 3510 | void Browser::OnStartDownload(DownloadItem* download, TabContentsWrapper* tab) { |
| 3511 | if (!window()) |
| 3512 | return; |
| 3513 | |
| 3514 | #if defined(OS_CHROMEOS) |
| 3515 | // Don't show content browser for extension/theme downloads from gallery. |
| 3516 | if (download->is_extension_install()) { |
| 3517 | ExtensionService* service = profile_->GetExtensionService(); |
[email protected] | 4cd82f7 | 2011-05-23 19:15:01 | [diff] [blame] | 3518 | if (service && service->IsDownloadFromGallery(download->GetURL(), |
[email protected] | ddb8505 | 2011-05-18 14:40:27 | [diff] [blame] | 3519 | download->referrer_url())) { |
| 3520 | return; |
| 3521 | } |
| 3522 | } |
| 3523 | // Open the Active Downloads ui for chromeos. |
| 3524 | ActiveDownloadsUI::OpenPopup(profile_); |
| 3525 | #else |
| 3526 | // GetDownloadShelf creates the download shelf if it was not yet created. |
| 3527 | window()->GetDownloadShelf()->AddDownload(new DownloadItemModel(download)); |
| 3528 | |
| 3529 | // Don't show the animation for "Save file" downloads. |
| 3530 | if (download->total_bytes() <= 0) |
| 3531 | return; |
| 3532 | |
| 3533 | // For non-theme extensions, we don't show the download animation. |
| 3534 | if (download->is_extension_install() && |
[email protected] | 4cd82f7 | 2011-05-23 19:15:01 | [diff] [blame] | 3535 | !ExtensionService::IsDownloadFromMiniGallery(download->GetURL())) |
[email protected] | ddb8505 | 2011-05-18 14:40:27 | [diff] [blame] | 3536 | return; |
| 3537 | |
| 3538 | TabContents* current_tab = GetSelectedTabContents(); |
| 3539 | // We make this check for the case of minimized windows, unit tests, etc. |
| 3540 | if (platform_util::IsVisible(current_tab->GetNativeView()) && |
| 3541 | ui::Animation::ShouldRenderRichAnimation()) { |
| 3542 | DownloadStartedAnimation::Show(current_tab); |
| 3543 | } |
| 3544 | #endif |
| 3545 | |
| 3546 | // If the download occurs in a new tab, close it. |
| 3547 | if (tab->tab_contents()->controller().IsInitialNavigation() && |
| 3548 | GetConstrainingContentsWrapper(tab) == tab && tab_count() > 1) { |
| 3549 | CloseContents(tab->tab_contents()); |
| 3550 | } |
| 3551 | } |
| 3552 | |
| 3553 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3554 | // Browser, SelectFileDialog::Listener implementation: |
| 3555 | |
[email protected] | 561abe6 | 2009-04-06 18:08:34 | [diff] [blame] | 3556 | void Browser::FileSelected(const FilePath& path, int index, void* params) { |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 3557 | profile_->set_last_selected_directory(path.DirName()); |
[email protected] | 72cbd32 | 2009-04-07 10:17:12 | [diff] [blame] | 3558 | GURL file_url = net::FilePathToFileURL(path); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3559 | if (!file_url.is_empty()) |
| 3560 | OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
| 3561 | } |
| 3562 | |
| 3563 | /////////////////////////////////////////////////////////////////////////////// |
| 3564 | // Browser, NotificationObserver implementation: |
| 3565 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3566 | void Browser::Observe(NotificationType type, |
| 3567 | const NotificationSource& source, |
| 3568 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 3569 | switch (type.value) { |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3570 | case NotificationType::TAB_CONTENTS_DISCONNECTED: |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 3571 | if (is_attempting_to_close_browser_) { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 3572 | // Pass in false so that we delay processing. We need to delay the |
| 3573 | // processing as it may close the tab, which is currently on the call |
| 3574 | // stack above us. |
| 3575 | ClearUnloadState(Source<TabContents>(source).ptr(), false); |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 3576 | } |
| 3577 | break; |
| 3578 | |
[email protected] | b4a19ea | 2009-03-17 10:08:24 | [diff] [blame] | 3579 | case NotificationType::SSL_VISIBLE_STATE_CHANGED: |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 3580 | // 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] | 3581 | // bar to reflect the new state. Note that it's possible for the selected |
| 3582 | // tab contents to be NULL. This is because we listen for all sources |
| 3583 | // (NavigationControllers) for convenience, so the notification could |
| 3584 | // actually be for a different window while we're doing asynchronous |
| 3585 | // closing of this one. |
| 3586 | if (GetSelectedTabContents() && |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 3587 | &GetSelectedTabContents()->controller() == |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 3588 | Source<NavigationController>(source).ptr()) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3589 | UpdateToolbar(false); |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 3590 | break; |
| 3591 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 3592 | case NotificationType::EXTENSION_UPDATE_DISABLED: { |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 3593 | // Show the UI if the extension was disabled for escalated permissions. |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 3594 | Profile* profile = Source<Profile>(source).ptr(); |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 3595 | if (profile_->IsSameProfile(profile)) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3596 | ExtensionService* service = profile->GetExtensionService(); |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 3597 | DCHECK(service); |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 3598 | const Extension* extension = Details<const Extension>(details).ptr(); |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 3599 | if (service->extension_prefs()->DidExtensionEscalatePermissions( |
| 3600 | extension->id())) |
| 3601 | ShowExtensionDisabledUI(service, profile_, extension); |
| 3602 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 3603 | break; |
| 3604 | } |
| 3605 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 3606 | case NotificationType::EXTENSION_UNLOADED: { |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 3607 | if (window()->GetLocationBar()) |
| 3608 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 57f71b9 | 2009-09-11 19:31:38 | [diff] [blame] | 3609 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 3610 | // Close any tabs from the unloaded extension. |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 3611 | const Extension* extension = |
| 3612 | Details<UnloadedExtensionInfo>(details)->extension; |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 3613 | TabStripModel* model = tab_handler_->GetTabStripModel(); |
| 3614 | for (int i = model->count() - 1; i >= 0; --i) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3615 | TabContents* tc = model->GetTabContentsAt(i)->tab_contents(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 3616 | if (tc->GetURL().SchemeIs(chrome::kExtensionScheme) && |
| 3617 | tc->GetURL().host() == extension->id()) { |
| 3618 | CloseTabContents(tc); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 3619 | } |
| 3620 | } |
[email protected] | 9fd542df | 2009-09-30 07:32:01 | [diff] [blame] | 3621 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 3622 | break; |
| 3623 | } |
| 3624 | |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 3625 | case NotificationType::EXTENSION_PROCESS_TERMINATED: { |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 3626 | if (window()->GetLocationBar()) |
| 3627 | window()->GetLocationBar()->InvalidatePageActions(); |
[email protected] | 371ed7a | 2009-08-25 15:22:46 | [diff] [blame] | 3628 | break; |
| 3629 | } |
| 3630 | |
[email protected] | 7ec9b3d8 | 2011-04-13 17:19:21 | [diff] [blame] | 3631 | case NotificationType::EXTENSION_UNINSTALLED: |
| 3632 | case NotificationType::EXTENSION_LOADED: |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 3633 | if (window()->GetLocationBar()) |
| 3634 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 3635 | break; |
[email protected] | ad0c2e1b | 2010-01-30 00:00:10 | [diff] [blame] | 3636 | |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 3637 | case NotificationType::BROWSER_THEME_CHANGED: |
| 3638 | window()->UserChangedTheme(); |
| 3639 | break; |
| 3640 | |
[email protected] | 91e1bd8 | 2009-09-03 22:04:40 | [diff] [blame] | 3641 | case NotificationType::EXTENSION_READY_FOR_INSTALL: { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3642 | // Handle EXTENSION_READY_FOR_INSTALL for last active tabbed browser. |
| 3643 | if (BrowserList::FindTabbedBrowser(profile(), true) != this) |
[email protected] | 91e1bd8 | 2009-09-03 22:04:40 | [diff] [blame] | 3644 | break; |
[email protected] | ac02528 | 2009-12-16 19:16:38 | [diff] [blame] | 3645 | |
| 3646 | // We only want to show the loading dialog for themes, but we don't want |
| 3647 | // to wait until unpack to find out an extension is a theme, so we test |
| 3648 | // the download_url GURL instead. This means that themes in the extensions |
| 3649 | // gallery won't get the loading dialog. |
| 3650 | GURL download_url = *(Details<GURL>(details).ptr()); |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3651 | if (ExtensionService::IsDownloadFromMiniGallery(download_url)) |
[email protected] | ac02528 | 2009-12-16 19:16:38 | [diff] [blame] | 3652 | window()->ShowThemeInstallBubble(); |
[email protected] | 91e1bd8 | 2009-09-03 22:04:40 | [diff] [blame] | 3653 | break; |
| 3654 | } |
| 3655 | |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 3656 | case NotificationType::PREF_CHANGED: { |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 3657 | const std::string& pref_name = *Details<std::string>(details).ptr(); |
| 3658 | if (pref_name == prefs::kUseVerticalTabs) { |
[email protected] | b334487 | 2010-05-03 15:52:29 | [diff] [blame] | 3659 | UseVerticalTabsChanged(); |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 3660 | } else if (pref_name == prefs::kUseCompactNavigationBar) { |
| 3661 | UseCompactNavigationBarChanged(); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 3662 | } else if (pref_name == prefs::kPrintingEnabled) { |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 3663 | UpdatePrintingState(GetContentRestrictionsForSelectedTab()); |
[email protected] | 73de26a | 2010-10-17 03:23:25 | [diff] [blame] | 3664 | } else if (pref_name == prefs::kInstantEnabled) { |
| 3665 | if (!InstantController::IsEnabled(profile())) { |
| 3666 | if (instant()) { |
| 3667 | instant()->DestroyPreviewContents(); |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 3668 | instant_.reset(); |
| 3669 | instant_unload_handler_.reset(); |
[email protected] | 73de26a | 2010-10-17 03:23:25 | [diff] [blame] | 3670 | } |
| 3671 | } else { |
| 3672 | CreateInstantIfNecessary(); |
| 3673 | } |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 3674 | } else if (pref_name == prefs::kDevToolsDisabled) { |
| 3675 | UpdateCommandsForDevTools(); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 3676 | if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 3677 | g_browser_process->devtools_manager()->CloseAllClientHosts(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 3678 | } else if (pref_name == prefs::kEditBookmarksEnabled) { |
| 3679 | UpdateCommandsForBookmarkEditing(); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 3680 | } else if (pref_name == prefs::kAllowFileSelectionDialogs) { |
| 3681 | UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); |
| 3682 | UpdateOpenFileState(); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 3683 | } else { |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 3684 | NOTREACHED(); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 3685 | } |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 3686 | break; |
| 3687 | } |
| 3688 | |
[email protected] | 9a9a9e2 | 2011-05-13 22:20:35 | [diff] [blame] | 3689 | case NotificationType::TAB_CONTENT_SETTINGS_CHANGED: { |
| 3690 | TabContents* tab_contents = Source<TabContents>(source).ptr(); |
| 3691 | if (tab_contents == GetSelectedTabContents()) { |
| 3692 | LocationBar* location_bar = window()->GetLocationBar(); |
| 3693 | if (location_bar) |
| 3694 | location_bar->UpdateContentSettingsIcons(); |
| 3695 | } |
| 3696 | break; |
| 3697 | } |
| 3698 | |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 3699 | case NotificationType::INTERSTITIAL_ATTACHED: |
| 3700 | window()->ShelfVisibilityChanged(); |
| 3701 | break; |
| 3702 | |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 3703 | default: |
| 3704 | NOTREACHED() << "Got a notification we didn't register for."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3705 | } |
| 3706 | } |
| 3707 | |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 3708 | /////////////////////////////////////////////////////////////////////////////// |
| 3709 | // Browser, ProfileSyncServiceObserver implementation: |
| 3710 | |
| 3711 | void Browser::OnStateChanged() { |
| 3712 | DCHECK(profile_->GetProfileSyncService()); |
| 3713 | |
| 3714 | #if !defined(OS_MACOSX) |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3715 | const bool show_main_ui = is_type_tabbed() && !window_->IsFullscreen(); |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 3716 | #else |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3717 | const bool show_main_ui = is_type_tabbed(); |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 3718 | #endif |
| 3719 | |
| 3720 | command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, |
| 3721 | show_main_ui && profile_->IsSyncAccessible()); |
| 3722 | } |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 3723 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3724 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 3725 | // Browser, InstantDelegate implementation: |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 3726 | |
[email protected] | 36d5e559 | 2010-11-15 20:45:59 | [diff] [blame] | 3727 | void Browser::PrepareForInstant() { |
| 3728 | window_->PrepareForInstant(); |
| 3729 | } |
| 3730 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3731 | void Browser::ShowInstant(TabContentsWrapper* preview_contents) { |
| 3732 | DCHECK(instant_->tab_contents() == GetSelectedTabContentsWrapper()); |
[email protected] | e3690ed | 2011-03-25 20:25:14 | [diff] [blame] | 3733 | window_->ShowInstant(preview_contents); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 3734 | } |
| 3735 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 3736 | void Browser::HideInstant() { |
[email protected] | 1946c93 | 2010-12-15 00:07:38 | [diff] [blame] | 3737 | window_->HideInstant(instant_->is_active()); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 3738 | } |
| 3739 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 3740 | void Browser::CommitInstant(TabContentsWrapper* preview_contents) { |
| 3741 | TabContentsWrapper* tab_contents = instant_->tab_contents(); |
| 3742 | int index = |
| 3743 | tab_handler_->GetTabStripModel()->GetIndexOfTabContents(tab_contents); |
| 3744 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 3745 | // TabStripModel takes ownership of preview_contents. |
[email protected] | 4303234 | 2011-03-21 14:10:31 | [diff] [blame] | 3746 | tab_handler_->GetTabStripModel()->ReplaceTabContentsAt( |
| 3747 | index, preview_contents); |
| 3748 | // InstantUnloadHandler takes ownership of tab_contents. |
| 3749 | instant_unload_handler_->RunUnloadListenersOrDestroy(tab_contents, index); |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 3750 | |
| 3751 | GURL url = preview_contents->tab_contents()->GetURL(); |
[email protected] | 6e37fe3 | 2011-03-02 09:06:52 | [diff] [blame] | 3752 | DCHECK(profile_->GetExtensionService()); |
| 3753 | if (profile_->GetExtensionService()->IsInstalledApp(url)) { |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 3754 | UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, |
| 3755 | extension_misc::APP_LAUNCH_OMNIBOX_INSTANT, |
| 3756 | extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 3757 | } |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 3758 | } |
| 3759 | |
[email protected] | c98fd5d8 | 2011-05-04 15:20:09 | [diff] [blame] | 3760 | void Browser::SwapTabContents(TabContentsWrapper* old_tab_contents, |
| 3761 | TabContentsWrapper* new_tab_contents) { |
| 3762 | int index = |
| 3763 | tab_handler_->GetTabStripModel()->GetIndexOfTabContents(old_tab_contents); |
[email protected] | 71b5d24 | 2011-04-30 02:27:20 | [diff] [blame] | 3764 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | c98fd5d8 | 2011-05-04 15:20:09 | [diff] [blame] | 3765 | tab_handler_->GetTabStripModel()->ReplaceTabContentsAt(index, |
| 3766 | new_tab_contents); |
[email protected] | 71b5d24 | 2011-04-30 02:27:20 | [diff] [blame] | 3767 | // TODO(tburkard): Run unload handlers like Instant does in |
| 3768 | // InstantUnloadHandler::RunUnloadListenersOrDestroy |
[email protected] | 71b5d24 | 2011-04-30 02:27:20 | [diff] [blame] | 3769 | } |
| 3770 | |
[email protected] | 33b8b8e | 2011-03-15 14:51:55 | [diff] [blame] | 3771 | void Browser::SetSuggestedText(const string16& text, |
| 3772 | InstantCompleteBehavior behavior) { |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 3773 | if (window()->GetLocationBar()) |
| 3774 | window()->GetLocationBar()->SetSuggestedText(text, behavior); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 3775 | } |
| 3776 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 3777 | gfx::Rect Browser::GetInstantBounds() { |
| 3778 | return window()->GetInstantBounds(); |
[email protected] | 46fe8e9 | 2010-09-22 03:32:47 | [diff] [blame] | 3779 | } |
| 3780 | |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 3781 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 3782 | // Browser, protected: |
| 3783 | |
| 3784 | BrowserWindow* Browser::CreateBrowserWindow() { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3785 | if (type_ == TYPE_PANEL && |
[email protected] | 011396a | 2011-04-13 23:35:28 | [diff] [blame] | 3786 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) |
| 3787 | return PanelManager::GetInstance()->CreatePanel(this); |
| 3788 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 3789 | return BrowserWindow::CreateBrowserWindow(this); |
| 3790 | } |
| 3791 | |
| 3792 | |
| 3793 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3794 | // Browser, Command and state updating (private): |
| 3795 | |
| 3796 | void Browser::InitCommandState() { |
| 3797 | // All browser commands whose state isn't set automagically some other way |
| 3798 | // (like Back & Forward with initial page load) must have their state |
| 3799 | // initialized here, otherwise they will be forever disabled. |
| 3800 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3801 | // Navigation commands |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3802 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 3803 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3804 | |
| 3805 | // Window management commands |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3806 | command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 3807 | command_updater_.UpdateCommandEnabled( |
| 3808 | IDC_NEW_INCOGNITO_WINDOW, |
| 3809 | profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3810 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); |
| 3811 | command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); |
| 3812 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); |
| 3813 | command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 3814 | command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3815 | command_updater_.UpdateCommandEnabled(IDC_EXIT, true); |
[email protected] | c8b59f9 | 2010-05-28 21:45:47 | [diff] [blame] | 3816 | command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, true); |
[email protected] | cdc05ec | 2011-05-18 15:15:59 | [diff] [blame] | 3817 | command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3818 | |
| 3819 | // Page-related commands |
[email protected] | 89d6e6e | 2009-12-03 23:06:51 | [diff] [blame] | 3820 | command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3821 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true); |
| 3822 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true); |
| 3823 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true); |
| 3824 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88591, true); |
| 3825 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252, true); |
| 3826 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_GBK, true); |
| 3827 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_GB18030, true); |
| 3828 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5HKSCS, true); |
| 3829 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5, true); |
| 3830 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_THAI, true); |
| 3831 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOREAN, true); |
| 3832 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS, true); |
| 3833 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP, true); |
| 3834 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_EUCJP, true); |
| 3835 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885915, true); |
| 3836 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH, true); |
| 3837 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88592, true); |
| 3838 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250, true); |
| 3839 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88595, true); |
| 3840 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251, true); |
| 3841 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8R, true); |
| 3842 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8U, true); |
| 3843 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88597, true); |
| 3844 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253, true); |
| 3845 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88594, true); |
| 3846 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885913, true); |
| 3847 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257, true); |
| 3848 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88593, true); |
| 3849 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885910, true); |
| 3850 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885914, true); |
| 3851 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885916, true); |
| 3852 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254, true); |
| 3853 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88596, true); |
| 3854 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256, true); |
| 3855 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598, true); |
[email protected] | e13271f | 2009-03-07 00:26:00 | [diff] [blame] | 3856 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598I, true); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3857 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); |
| 3858 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3859 | |
[email protected] | 63b0293 | 2009-06-05 09:40:51 | [diff] [blame] | 3860 | // Zoom |
| 3861 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); |
| 3862 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); |
| 3863 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); |
| 3864 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); |
| 3865 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3866 | // Show various bits of UI |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 3867 | UpdateOpenFileState(); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3868 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 3869 | UpdateCommandsForDevTools(); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3870 | command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, true); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3871 | command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true); |
[email protected] | 4a4180a5 | 2010-08-23 06:39:48 | [diff] [blame] | 3872 | command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, |
| 3873 | browser_defaults::bookmarks_enabled); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3874 | command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
| 3875 | command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE, true); |
[email protected] | 4aee565 | 2009-11-19 18:59:21 | [diff] [blame] | 3876 | command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true); |
[email protected] | d6852fd | 2011-05-20 17:19:12 | [diff] [blame] | 3877 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, true); |
[email protected] | 9cd51a0 | 2009-10-23 22:30:29 | [diff] [blame] | 3878 | |
[email protected] | 96e3467 | 2010-02-09 21:40:29 | [diff] [blame] | 3879 | #if defined(OS_CHROMEOS) |
[email protected] | ec2fd5a | 2011-04-30 06:16:05 | [diff] [blame] | 3880 | command_updater_.UpdateCommandEnabled(IDC_FILE_MANAGER, true); |
[email protected] | f97d7f63 | 2010-06-01 21:08:33 | [diff] [blame] | 3881 | command_updater_.UpdateCommandEnabled(IDC_SEARCH, true); |
[email protected] | d14af52 | 2010-12-02 03:54:50 | [diff] [blame] | 3882 | command_updater_.UpdateCommandEnabled(IDC_SHOW_KEYBOARD_OVERLAY, true); |
[email protected] | c8b59f9 | 2010-05-28 21:45:47 | [diff] [blame] | 3883 | command_updater_.UpdateCommandEnabled(IDC_SYSTEM_OPTIONS, true); |
| 3884 | command_updater_.UpdateCommandEnabled(IDC_INTERNET_OPTIONS, true); |
[email protected] | 96e3467 | 2010-02-09 21:40:29 | [diff] [blame] | 3885 | #endif |
[email protected] | c8b59f9 | 2010-05-28 21:45:47 | [diff] [blame] | 3886 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 3887 | ExtensionService* extension_service = profile()->GetExtensionService(); |
[email protected] | 9cd51a0 | 2009-10-23 22:30:29 | [diff] [blame] | 3888 | bool enable_extensions = |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 3889 | extension_service && extension_service->extensions_enabled(); |
[email protected] | 9cd51a0 | 2009-10-23 22:30:29 | [diff] [blame] | 3890 | command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, |
| 3891 | enable_extensions); |
| 3892 | |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 3893 | // Initialize other commands based on the window type. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3894 | bool normal_window = is_type_tabbed(); |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 3895 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 3896 | // Navigation commands |
| 3897 | command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 3898 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 3899 | // Window management commands |
[email protected] | cf299bc | 2010-08-12 20:27:09 | [diff] [blame] | 3900 | command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3901 | !(is_type_panel() && is_app())); |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 3902 | command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| 3903 | command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| 3904 | normal_window); |
| 3905 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window); |
| 3906 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window); |
| 3907 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window); |
| 3908 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window); |
| 3909 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window); |
| 3910 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window); |
| 3911 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window); |
| 3912 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window); |
| 3913 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window); |
| 3914 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window); |
| 3915 | command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window); |
[email protected] | c1d0d81 | 2010-07-27 20:21:55 | [diff] [blame] | 3916 | #if defined(OS_MACOSX) |
| 3917 | command_updater_.UpdateCommandEnabled(IDC_TABPOSE, normal_window); |
| 3918 | #endif |
[email protected] | e662ade | 2009-06-08 18:20:14 | [diff] [blame] | 3919 | |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 3920 | // Clipboard commands |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3921 | command_updater_.UpdateCommandEnabled(IDC_COPY_URL, !is_devtools()); |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 3922 | |
| 3923 | // Find-in-page |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3924 | command_updater_.UpdateCommandEnabled(IDC_FIND, !is_devtools()); |
| 3925 | command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, !is_devtools()); |
| 3926 | command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, !is_devtools()); |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 3927 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 3928 | // Autofill |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3929 | command_updater_.UpdateCommandEnabled(IDC_AUTOFILL_DEFAULT, !is_devtools()); |
[email protected] | cf28ec5 | 2010-04-09 22:56:34 | [diff] [blame] | 3930 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 3931 | // Show various bits of UI |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 3932 | command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window); |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 3933 | |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 3934 | // The upgrade entry and the view incompatibility entry should always be |
| 3935 | // enabled. Whether they are visible is a separate matter determined on menu |
| 3936 | // show. |
[email protected] | b21d691 | 2010-08-31 19:22:41 | [diff] [blame] | 3937 | command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true); |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 3938 | command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true); |
[email protected] | b21d691 | 2010-08-31 19:22:41 | [diff] [blame] | 3939 | |
[email protected] | b569c11 | 2010-11-22 20:53:44 | [diff] [blame] | 3940 | // View Background Pages entry is always enabled, but is hidden if there are |
| 3941 | // no background pages. |
| 3942 | command_updater_.UpdateCommandEnabled(IDC_VIEW_BACKGROUND_PAGES, true); |
| 3943 | |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 3944 | // Initialize other commands whose state changes based on fullscreen mode. |
| 3945 | UpdateCommandsForFullscreenMode(false); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 3946 | |
| 3947 | UpdateCommandsForContentRestrictionState(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 3948 | |
| 3949 | UpdateCommandsForBookmarkEditing(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 3950 | } |
| 3951 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3952 | void Browser::UpdateCommandsForTabState() { |
[email protected] | c7c4233 | 2008-11-15 01:10:54 | [diff] [blame] | 3953 | TabContents* current_tab = GetSelectedTabContents(); |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 3954 | TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); |
| 3955 | if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore. |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 3956 | return; |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 3957 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3958 | // Navigation commands |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 3959 | NavigationController& nc = current_tab->controller(); |
| 3960 | command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack()); |
| 3961 | command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward()); |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 3962 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, |
| 3963 | CanReloadContents(current_tab)); |
| 3964 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, |
| 3965 | CanReloadContents(current_tab)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3966 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3967 | // Window management commands |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3968 | command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 3969 | !is_app() && CanDuplicateContentsAt(active_index())); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 3970 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3971 | // Page-related commands |
[email protected] | 52cc59b | 2011-05-06 14:42:38 | [diff] [blame] | 3972 | window_->SetStarredState( |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 3973 | current_tab_wrapper->bookmark_tab_helper()->is_starred()); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3974 | command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, |
[email protected] | 3168228 | 2010-01-15 18:05:16 | [diff] [blame] | 3975 | current_tab->controller().CanViewSource()); |
[email protected] | 151666e | 2010-10-21 17:05:25 | [diff] [blame] | 3976 | command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, |
| 3977 | current_tab->ShouldDisplayURL() && current_tab->GetURL().is_valid()); |
[email protected] | af664c7 | 2011-05-17 14:33:40 | [diff] [blame] | 3978 | if (is_devtools()) |
| 3979 | command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false); |
[email protected] | 151666e | 2010-10-21 17:05:25 | [diff] [blame] | 3980 | |
| 3981 | // Changing the encoding is not possible on Chrome-internal webpages. |
[email protected] | 4d07cdc | 2009-08-22 16:09:39 | [diff] [blame] | 3982 | // Instead of using GetURL here, we use url() (which is the "real" url of the |
| 3983 | // page) from the NavigationEntry because its reflects their origin rather |
| 3984 | // than the display one (returned by GetURL) which may be different (like |
| 3985 | // having "view-source:" on the front). |
[email protected] | fc33e999 | 2010-04-08 19:40:13 | [diff] [blame] | 3986 | NavigationEntry* active_entry = nc.GetActiveEntry(); |
[email protected] | c0f82ec5 | 2010-07-27 14:22:14 | [diff] [blame] | 3987 | bool is_chrome_internal = (active_entry ? |
| 3988 | active_entry->url().SchemeIs(chrome::kChromeUIScheme) : false); |
| 3989 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, |
| 3990 | !is_chrome_internal && SavePackage::IsSavableContents( |
| 3991 | current_tab->contents_mime_type())); |
| 3992 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3993 | // Show various bits of UI |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 3994 | // TODO(pinkerton): Disable app-mode in the model until we implement it |
| 3995 | // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 |
| 3996 | #if !defined(OS_MACOSX) |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3997 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, |
[email protected] | 12ea22a | 2009-11-19 07:17:23 | [diff] [blame] | 3998 | web_app::IsValidUrl(current_tab->GetURL())); |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 3999 | #endif |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4000 | |
| 4001 | UpdateCommandsForContentRestrictionState(); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4002 | UpdateCommandsForBookmarkEditing(); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | void Browser::UpdateCommandsForContentRestrictionState() { |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 4006 | int restrictions = GetContentRestrictionsForSelectedTab(); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4007 | |
| 4008 | command_updater_.UpdateCommandEnabled( |
| 4009 | IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY)); |
| 4010 | command_updater_.UpdateCommandEnabled( |
| 4011 | IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT)); |
| 4012 | command_updater_.UpdateCommandEnabled( |
| 4013 | IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE)); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4014 | UpdateSaveAsState(restrictions); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4015 | UpdatePrintingState(restrictions); |
| 4016 | } |
| 4017 | |
| 4018 | void Browser::UpdatePrintingState(int content_restrictions) { |
| 4019 | bool enabled = true; |
| 4020 | if (content_restrictions & CONTENT_RESTRICTION_PRINT) { |
| 4021 | enabled = false; |
| 4022 | } else if (g_browser_process->local_state()) { |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4023 | enabled = g_browser_process->local_state()-> |
| 4024 | GetBoolean(prefs::kPrintingEnabled); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 4025 | } |
| 4026 | command_updater_.UpdateCommandEnabled(IDC_PRINT, enabled); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4027 | } |
| 4028 | |
[email protected] | 943d812 | 2010-06-11 02:13:45 | [diff] [blame] | 4029 | void Browser::UpdateReloadStopState(bool is_loading, bool force) { |
| 4030 | window_->UpdateReloadStopState(is_loading, force); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 4031 | command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
[email protected] | 64ff794 | 2008-12-17 18:11:23 | [diff] [blame] | 4032 | } |
| 4033 | |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 4034 | void Browser::UpdateCommandsForDevTools() { |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4035 | bool dev_tools_enabled = |
[email protected] | 5073f49 | 2011-05-03 09:36:42 | [diff] [blame] | 4036 | !profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 4037 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, |
| 4038 | dev_tools_enabled); |
| 4039 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE, |
| 4040 | dev_tools_enabled); |
| 4041 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT, |
| 4042 | dev_tools_enabled); |
| 4043 | } |
| 4044 | |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4045 | void Browser::UpdateCommandsForBookmarkEditing() { |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4046 | bool enabled = |
| 4047 | profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled) && |
| 4048 | browser_defaults::bookmarks_enabled; |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4049 | |
| 4050 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE, |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4051 | enabled && is_type_tabbed()); |
[email protected] | a13f47d1 | 2011-04-14 11:41:58 | [diff] [blame] | 4052 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS, |
| 4053 | enabled && CanBookmarkAllTabs()); |
| 4054 | } |
| 4055 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 4056 | void Browser::UpdateSaveAsState(int content_restrictions) { |
| 4057 | bool enabled = !(content_restrictions & CONTENT_RESTRICTION_SAVE); |
| 4058 | PrefService* state = g_browser_process->local_state(); |
| 4059 | if (state) |
| 4060 | enabled = enabled && state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 4061 | |
| 4062 | command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, enabled); |
| 4063 | } |
| 4064 | |
| 4065 | void Browser::UpdateOpenFileState() { |
| 4066 | bool enabled = true; |
| 4067 | PrefService* local_state = g_browser_process->local_state(); |
| 4068 | if (local_state) |
| 4069 | enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 4070 | |
| 4071 | command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
| 4072 | } |
| 4073 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4074 | /////////////////////////////////////////////////////////////////////////////// |
| 4075 | // Browser, UI update coalescing and handling (private): |
| 4076 | |
| 4077 | void Browser::UpdateToolbar(bool should_restore_state) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4078 | window_->UpdateToolbar(GetSelectedTabContentsWrapper(), should_restore_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4079 | } |
| 4080 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4081 | void Browser::ScheduleUIUpdate(const TabContents* source, |
| 4082 | unsigned changed_flags) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4083 | if (!source) |
| 4084 | return; |
| 4085 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 4086 | // Do some synchronous updates. |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4087 | if (changed_flags & TabContents::INVALIDATE_URL && |
| 4088 | source == GetSelectedTabContents()) { |
| 4089 | // Only update the URL for the current tab. Note that we do not update |
| 4090 | // the navigation commands since those would have already been updated |
| 4091 | // synchronously by NavigationStateChanged. |
| 4092 | UpdateToolbar(false); |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 4093 | changed_flags &= ~TabContents::INVALIDATE_URL; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4094 | } |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4095 | if (changed_flags & TabContents::INVALIDATE_LOAD) { |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 4096 | // Update the loading state synchronously. This is so the throbber will |
| 4097 | // immediately start/stop, which gives a more snappy feel. We want to do |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4098 | // this for any tab so they start & stop quickly. |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4099 | tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( |
| 4100 | tab_handler_->GetTabStripModel()->GetIndexOfController( |
| 4101 | &source->controller()), |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 4102 | TabStripModelObserver::LOADING_ONLY); |
| 4103 | // The status bubble needs to be updated during INVALIDATE_LOAD too, but |
| 4104 | // we do that asynchronously by not stripping INVALIDATE_LOAD from |
| 4105 | // changed_flags. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 4106 | } |
| 4107 | |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 4108 | if (changed_flags & TabContents::INVALIDATE_TITLE && !source->is_loading()) { |
| 4109 | // To correctly calculate whether the title changed while not loading |
| 4110 | // we need to process the update synchronously. This state only matters for |
| 4111 | // the TabStripModel, so we notify the TabStripModel now and notify others |
| 4112 | // asynchronously. |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4113 | tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( |
| 4114 | tab_handler_->GetTabStripModel()->GetIndexOfController( |
| 4115 | &source->controller()), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 4116 | TabStripModelObserver::TITLE_NOT_LOADING); |
| 4117 | } |
| 4118 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 4119 | // If the only updates were synchronously handled above, we're done. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 4120 | if (changed_flags == 0) |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 4121 | return; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4122 | |
| 4123 | // Save the dirty bits. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 4124 | scheduled_updates_[source] |= changed_flags; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4125 | |
| 4126 | if (chrome_updater_factory_.empty()) { |
| 4127 | // No task currently scheduled, start another. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 4128 | MessageLoop::current()->PostDelayedTask( |
| 4129 | FROM_HERE, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4130 | chrome_updater_factory_.NewRunnableMethod( |
| 4131 | &Browser::ProcessPendingUIUpdates), |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 4132 | kUIUpdateCoalescingTimeMS); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4133 | } |
| 4134 | } |
| 4135 | |
| 4136 | void Browser::ProcessPendingUIUpdates() { |
| 4137 | #ifndef NDEBUG |
| 4138 | // Validate that all tabs we have pending updates for exist. This is scary |
| 4139 | // because the pending list must be kept in sync with any detached or |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4140 | // deleted tabs. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 4141 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 4142 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4143 | bool found = false; |
| 4144 | for (int tab = 0; tab < tab_count(); tab++) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4145 | if (GetTabContentsAt(tab) == i->first) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4146 | found = true; |
| 4147 | break; |
| 4148 | } |
| 4149 | } |
| 4150 | DCHECK(found); |
| 4151 | } |
| 4152 | #endif |
| 4153 | |
| 4154 | chrome_updater_factory_.RevokeAll(); |
| 4155 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 4156 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 4157 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4158 | // Do not dereference |contents|, it may be out-of-date! |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 4159 | const TabContents* contents = i->first; |
| 4160 | unsigned flags = i->second; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4161 | |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4162 | if (contents == GetSelectedTabContents()) { |
| 4163 | // Updates that only matter when the tab is selected go here. |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 4164 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 4165 | if (flags & TabContents::INVALIDATE_PAGE_ACTIONS) { |
| 4166 | LocationBar* location_bar = window()->GetLocationBar(); |
| 4167 | if (location_bar) |
| 4168 | location_bar->UpdatePageActions(); |
| 4169 | } |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 4170 | // Updating the URL happens synchronously in ScheduleUIUpdate. |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 4171 | if (flags & TabContents::INVALIDATE_LOAD && GetStatusBubble()) { |
| 4172 | GetStatusBubble()->SetStatus( |
| 4173 | GetSelectedTabContentsWrapper()->GetStatusText()); |
| 4174 | } |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4175 | |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 4176 | if (flags & (TabContents::INVALIDATE_TAB | |
| 4177 | TabContents::INVALIDATE_TITLE)) { |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 4178 | // TODO(pinkerton): Disable app-mode in the model until we implement it |
| 4179 | // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 |
| 4180 | #if !defined(OS_MACOSX) |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4181 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, |
[email protected] | 12ea22a | 2009-11-19 07:17:23 | [diff] [blame] | 4182 | web_app::IsValidUrl(contents->GetURL())); |
[email protected] | c065fa07 | 2010-01-20 23:12:25 | [diff] [blame] | 4183 | #endif |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4184 | window_->UpdateTitleBar(); |
| 4185 | } |
[email protected] | 4d34e2e | 2009-05-26 22:55:28 | [diff] [blame] | 4186 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4187 | |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 4188 | // Updates that don't depend upon the selected state go here. |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 4189 | if (flags & (TabContents::INVALIDATE_TAB | TabContents::INVALIDATE_TITLE)) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4190 | tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4191 | tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 4192 | TabStripModelObserver::ALL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4193 | } |
| 4194 | |
| 4195 | // We don't need to process INVALIDATE_STATE, since that's not visible. |
| 4196 | } |
| 4197 | |
| 4198 | scheduled_updates_.clear(); |
| 4199 | } |
| 4200 | |
| 4201 | void Browser::RemoveScheduledUpdatesFor(TabContents* contents) { |
| 4202 | if (!contents) |
| 4203 | return; |
| 4204 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 4205 | UpdateMap::iterator i = scheduled_updates_.find(contents); |
| 4206 | if (i != scheduled_updates_.end()) |
| 4207 | scheduled_updates_.erase(i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4208 | } |
| 4209 | |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 4210 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4211 | /////////////////////////////////////////////////////////////////////////////// |
| 4212 | // Browser, Getters for UI (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4213 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4214 | StatusBubble* Browser::GetStatusBubble() { |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 4215 | #if !defined(OS_MACOSX) |
| 4216 | // In kiosk mode, we want to always hide the status bubble. |
| 4217 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 4218 | return NULL; |
| 4219 | #endif |
[email protected] | 9b032bf | 2009-07-21 17:34:23 | [diff] [blame] | 4220 | return window_ ? window_->GetStatusBubble() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4221 | } |
| 4222 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4223 | /////////////////////////////////////////////////////////////////////////////// |
| 4224 | // Browser, Session restore functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4225 | |
| 4226 | void Browser::SyncHistoryWithTabs(int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 4227 | SessionService* session_service = |
| 4228 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4229 | if (session_service) { |
| 4230 | for (int i = index; i < tab_count(); ++i) { |
| 4231 | TabContents* contents = GetTabContentsAt(i); |
| 4232 | if (contents) { |
| 4233 | session_service->SetTabIndexInWindow( |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 4234 | session_id(), contents->controller().session_id(), i); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4235 | session_service->SetPinnedState( |
| 4236 | session_id(), |
| 4237 | contents->controller().session_id(), |
| 4238 | tab_handler_->GetTabStripModel()->IsTabPinned(i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4239 | } |
| 4240 | } |
| 4241 | } |
| 4242 | } |
| 4243 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4244 | /////////////////////////////////////////////////////////////////////////////// |
| 4245 | // Browser, OnBeforeUnload handling (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4246 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4247 | void Browser::ProcessPendingTabs() { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4248 | if (!is_attempting_to_close_browser_) { |
| 4249 | // Because we might invoke this after a delay it's possible for the value of |
| 4250 | // is_attempting_to_close_browser_ to have changed since we scheduled the |
| 4251 | // task. |
| 4252 | return; |
| 4253 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4254 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4255 | if (HasCompletedUnloadProcessing()) { |
| 4256 | // We've finished all the unload events and can proceed to close the |
| 4257 | // browser. |
| 4258 | OnWindowClosing(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4259 | return; |
| 4260 | } |
| 4261 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4262 | // Process beforeunload tabs first. When that queue is empty, process |
| 4263 | // unload tabs. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4264 | if (!tabs_needing_before_unload_fired_.empty()) { |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 4265 | TabContents* tab = *(tabs_needing_before_unload_fired_.begin()); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4266 | // Null check render_view_host here as this gets called on a PostTask and |
| 4267 | // the tab's render_view_host may have been nulled out. |
| 4268 | if (tab->render_view_host()) { |
[email protected] | ae23c27 | 2009-07-27 20:15:40 | [diff] [blame] | 4269 | tab->render_view_host()->FirePageBeforeUnload(false); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4270 | } else { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4271 | ClearUnloadState(tab, true); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4272 | } |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4273 | } else if (!tabs_needing_unload_fired_.empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4274 | // We've finished firing all beforeunload events and can proceed with unload |
| 4275 | // events. |
| 4276 | // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting |
| 4277 | // somewhere around here so that we have accurate measurements of shutdown |
| 4278 | // time. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4279 | // TODO(ojan): We can probably fire all the unload events in parallel and |
| 4280 | // get a perf benefit from that in the cases where the tab hangs in it's |
| 4281 | // unload handler or takes a long time to page in. |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 4282 | TabContents* tab = *(tabs_needing_unload_fired_.begin()); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4283 | // Null check render_view_host here as this gets called on a PostTask and |
| 4284 | // the tab's render_view_host may have been nulled out. |
| 4285 | if (tab->render_view_host()) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 4286 | tab->render_view_host()->ClosePage(); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4287 | } else { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4288 | ClearUnloadState(tab, true); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 4289 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4290 | } else { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4291 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4292 | } |
| 4293 | } |
| 4294 | |
[email protected] | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 4295 | bool Browser::HasCompletedUnloadProcessing() const { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4296 | return is_attempting_to_close_browser_ && |
| 4297 | tabs_needing_before_unload_fired_.empty() && |
| 4298 | tabs_needing_unload_fired_.empty(); |
| 4299 | } |
| 4300 | |
| 4301 | void Browser::CancelWindowClose() { |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 4302 | // Closing of window can be canceled from: |
| 4303 | // - canceling beforeunload |
| 4304 | // - disallowing closing from IsClosingPermitted. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4305 | DCHECK(is_attempting_to_close_browser_); |
[email protected] | 8f673f3a | 2008-08-05 22:34:28 | [diff] [blame] | 4306 | tabs_needing_before_unload_fired_.clear(); |
| 4307 | tabs_needing_unload_fired_.clear(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4308 | is_attempting_to_close_browser_ = false; |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 4309 | |
| 4310 | // Inform TabCloseableStateWatcher that closing of window has been canceled. |
| 4311 | TabCloseableStateWatcher* watcher = |
| 4312 | g_browser_process->tab_closeable_state_watcher(); |
| 4313 | if (watcher) |
| 4314 | watcher->OnWindowCloseCanceled(this); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4315 | } |
| 4316 | |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 4317 | bool Browser::RemoveFromSet(UnloadListenerSet* set, TabContents* tab) { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4318 | DCHECK(is_attempting_to_close_browser_); |
| 4319 | |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 4320 | UnloadListenerSet::iterator iter = std::find(set->begin(), set->end(), tab); |
| 4321 | if (iter != set->end()) { |
| 4322 | set->erase(iter); |
| 4323 | return true; |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4324 | } |
| 4325 | return false; |
| 4326 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4327 | |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4328 | void Browser::ClearUnloadState(TabContents* tab, bool process_now) { |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 4329 | // Closing of browser could be canceled (via IsClosingPermitted) between the |
| 4330 | // time when request was initiated and when this method is called, so check |
| 4331 | // for is_attempting_to_close_browser_ flag before proceeding. |
| 4332 | if (is_attempting_to_close_browser_) { |
| 4333 | RemoveFromSet(&tabs_needing_before_unload_fired_, tab); |
| 4334 | RemoveFromSet(&tabs_needing_unload_fired_, tab); |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4335 | if (process_now) { |
| 4336 | ProcessPendingTabs(); |
| 4337 | } else { |
| 4338 | MessageLoop::current()->PostTask( |
| 4339 | FROM_HERE, |
| 4340 | method_factory_.NewRunnableMethod(&Browser::ProcessPendingTabs)); |
| 4341 | } |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 4342 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4343 | } |
| 4344 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4345 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 4346 | // Browser, In-progress download termination handling (private): |
| 4347 | |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 4348 | void Browser::CheckDownloadsInProgress(bool* normal_downloads_are_present, |
| 4349 | bool* incognito_downloads_are_present) { |
| 4350 | *normal_downloads_are_present = false; |
| 4351 | *incognito_downloads_are_present = false; |
| 4352 | |
| 4353 | // If there are no download in-progress, our job is done. |
| 4354 | DownloadManager* download_manager = NULL; |
| 4355 | // But first we need to check for the existance of the download manager, as |
| 4356 | // GetDownloadManager() will unnecessarily try to create one if it does not |
| 4357 | // exist. |
| 4358 | if (profile()->HasCreatedDownloadManager()) |
| 4359 | download_manager = profile()->GetDownloadManager(); |
| 4360 | if (profile()->IsOffTheRecord()) { |
| 4361 | // Browser is incognito and so download_manager if present is for incognito |
| 4362 | // downloads. |
| 4363 | *incognito_downloads_are_present = |
| 4364 | (download_manager && download_manager->in_progress_count() != 0); |
| 4365 | // Check original profile. |
| 4366 | if (profile()->GetOriginalProfile()->HasCreatedDownloadManager()) |
| 4367 | download_manager = profile()->GetOriginalProfile()->GetDownloadManager(); |
| 4368 | } |
| 4369 | |
| 4370 | *normal_downloads_are_present = |
| 4371 | (download_manager && download_manager->in_progress_count() != 0); |
| 4372 | } |
| 4373 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 4374 | bool Browser::CanCloseWithInProgressDownloads() { |
| 4375 | if (cancel_download_confirmation_state_ != NOT_PROMPTED) { |
[email protected] | 7a22201c | 2009-10-16 16:50:37 | [diff] [blame] | 4376 | if (cancel_download_confirmation_state_ == WAITING_FOR_RESPONSE) { |
| 4377 | // We need to hear from the user before we can close. |
| 4378 | return false; |
| 4379 | } |
| 4380 | // RESPONSE_RECEIVED case, the user decided to go along with the closing. |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 4381 | return true; |
| 4382 | } |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 4383 | // Indicated that normal (non-incognito) downloads are pending. |
| 4384 | bool normal_downloads_are_present = false; |
| 4385 | bool incognito_downloads_are_present = false; |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 4386 | CheckDownloadsInProgress(&normal_downloads_are_present, |
| 4387 | &incognito_downloads_are_present); |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 4388 | if (!normal_downloads_are_present && !incognito_downloads_are_present) |
| 4389 | return true; |
| 4390 | |
| 4391 | if (is_attempting_to_close_browser_) |
| 4392 | return true; |
| 4393 | |
| 4394 | if ((!normal_downloads_are_present && !profile()->IsOffTheRecord()) || |
| 4395 | (!incognito_downloads_are_present && profile()->IsOffTheRecord())) |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 4396 | return true; |
| 4397 | |
| 4398 | // Let's figure out if we are the last window for our profile. |
| 4399 | // Note that we cannot just use BrowserList::GetBrowserCount as browser |
| 4400 | // windows closing is delayed and the returned count might include windows |
| 4401 | // that are being closed. |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 4402 | // The browser allowed to be closed only if: |
| 4403 | // 1. It is a regular browser and there are no regular downloads present or |
| 4404 | // this is not the last regular browser window. |
| 4405 | // 2. It is an incognito browser and there are no incognito downloads present |
| 4406 | // or this is not the last incognito browser window. |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 4407 | int count = 0; |
| 4408 | for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 4409 | iter != BrowserList::end(); ++iter) { |
| 4410 | // Don't count this browser window or any other in the process of closing. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4411 | // Only consider tabbed browser windows, not popups. |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 4412 | Browser* const browser = *iter; |
| 4413 | if (browser == this |
| 4414 | || browser->is_attempting_to_close_browser_ |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4415 | || !browser->is_type_tabbed()) |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 4416 | continue; |
| 4417 | |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 4418 | // Verify that this is not the last non-incognito or incognito browser, |
| 4419 | // depending on the pending downloads. |
| 4420 | if (normal_downloads_are_present && !profile()->IsOffTheRecord() && |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 4421 | browser->profile()->IsOffTheRecord()) |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 4422 | continue; |
| 4423 | if (incognito_downloads_are_present && profile()->IsOffTheRecord() && |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 4424 | !browser->profile()->IsOffTheRecord()) |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 4425 | continue; |
| 4426 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 4427 | // We test the original profile, because an incognito browser window keeps |
| 4428 | // the original profile alive (and its DownloadManager). |
| 4429 | // We also need to test explicitly the profile directly so that 2 incognito |
| 4430 | // profiles count as a match. |
| 4431 | if ((*iter)->profile() == profile() || |
| 4432 | (*iter)->profile()->GetOriginalProfile() == profile()) |
| 4433 | count++; |
| 4434 | } |
| 4435 | if (count > 0) |
| 4436 | return true; |
| 4437 | |
| 4438 | cancel_download_confirmation_state_ = WAITING_FOR_RESPONSE; |
| 4439 | window_->ConfirmBrowserCloseWithPendingDownloads(); |
| 4440 | |
| 4441 | // Return false so the browser does not close. We'll close if the user |
| 4442 | // confirms in the dialog. |
| 4443 | return false; |
| 4444 | } |
| 4445 | |
| 4446 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4447 | // Browser, Assorted utility functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4448 | |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 4449 | // static |
[email protected] | de4e763 | 2010-09-01 06:24:04 | [diff] [blame] | 4450 | Browser* Browser::GetTabbedBrowser(Profile* profile, bool match_incognito) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4451 | return BrowserList::FindTabbedBrowser(profile, match_incognito); |
[email protected] | de4e763 | 2010-09-01 06:24:04 | [diff] [blame] | 4452 | } |
| 4453 | |
| 4454 | // static |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 4455 | Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) { |
[email protected] | de4e763 | 2010-09-01 06:24:04 | [diff] [blame] | 4456 | Browser* browser = GetTabbedBrowser(profile, false); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 4457 | if (!browser) |
[email protected] | 1a6b30a | 2009-08-19 03:52:11 | [diff] [blame] | 4458 | browser = Browser::Create(profile); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4459 | return browser; |
| 4460 | } |
| 4461 | |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 4462 | void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 4463 | // TabContents... |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 4464 | tab->tab_contents()->set_delegate(delegate); |
| 4465 | tab->set_delegate(delegate); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 4466 | |
| 4467 | // ...and all the helpers. |
| 4468 | tab->blocked_content_tab_helper()->set_delegate(delegate); |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 4469 | tab->bookmark_tab_helper()->set_delegate(delegate); |
[email protected] | ddb8505 | 2011-05-18 14:40:27 | [diff] [blame] | 4470 | tab->download_tab_helper()->set_delegate(delegate); |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 4471 | tab->search_engine_tab_helper()->set_delegate(delegate); |
| 4472 | } |
| 4473 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4474 | void Browser::FindInPage(bool find_next, bool forward_direction) { |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 4475 | ShowFindBar(); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4476 | if (find_next) { |
[email protected] | 6a4f5af2 | 2009-09-23 22:43:00 | [diff] [blame] | 4477 | string16 find_text; |
| 4478 | #if defined(OS_MACOSX) |
| 4479 | // We always want to search for the contents of the find pasteboard on OS X. |
| 4480 | find_text = GetFindPboardText(); |
| 4481 | #endif |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 4482 | GetSelectedTabContentsWrapper()-> |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 4483 | find_tab_helper()->StartFinding(find_text, |
| 4484 | forward_direction, |
| 4485 | false); // Not case sensitive. |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4486 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 4487 | } |
[email protected] | cb17f7f | 2009-02-06 18:14:48 | [diff] [blame] | 4488 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 4489 | void Browser::CloseFrame() { |
| 4490 | window_->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4491 | } |
| 4492 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4493 | void Browser::TabDetachedAtImpl(TabContentsWrapper* contents, int index, |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 4494 | DetachType type) { |
| 4495 | if (type == DETACH_TYPE_DETACH) { |
[email protected] | 5658085 | 2010-11-17 16:09:15 | [diff] [blame] | 4496 | // Save the current location bar state, but only if the tab being detached |
| 4497 | // is the selected tab. Because saving state can conditionally revert the |
| 4498 | // location bar, saving the current tab's location bar state to a |
| 4499 | // non-selected tab can corrupt both tabs. |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 4500 | if (contents == GetSelectedTabContentsWrapper()) { |
| 4501 | LocationBar* location_bar = window()->GetLocationBar(); |
| 4502 | if (location_bar) |
| 4503 | location_bar->SaveStateToContents(contents->tab_contents()); |
| 4504 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 4505 | |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4506 | if (!tab_handler_->GetTabStripModel()->closing_all()) |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 4507 | SyncHistoryWithTabs(0); |
| 4508 | } |
| 4509 | |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 4510 | SetAsDelegate(contents, NULL); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4511 | RemoveScheduledUpdatesFor(contents->tab_contents()); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 4512 | |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4513 | if (find_bar_controller_.get() && |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 4514 | index == tab_handler_->GetTabStripModel()->active_index()) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 4515 | find_bar_controller_->ChangeTabContents(NULL); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4516 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 4517 | |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 4518 | if (is_attempting_to_close_browser_) { |
| 4519 | // If this is the last tab with unload handlers, then ProcessPendingTabs |
| 4520 | // would call back into the TabStripModel (which is invoking this method on |
| 4521 | // us). Avoid that by passing in false so that the call to |
| 4522 | // ProcessPendingTabs is delayed. |
| 4523 | ClearUnloadState(contents->tab_contents(), false); |
| 4524 | } |
| 4525 | |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 4526 | registrar_.Remove(this, NotificationType::INTERSTITIAL_ATTACHED, |
| 4527 | Source<TabContents>(contents->tab_contents())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 4528 | registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED, |
[email protected] | 8d258e19 | 2011-05-05 21:21:05 | [diff] [blame] | 4529 | Source<TabContents>(contents->tab_contents())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 4530 | } |
| 4531 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4532 | // static |
[email protected] | f87919d7 | 2011-02-02 18:46:16 | [diff] [blame] | 4533 | void Browser::RegisterAppPrefs(const std::string& app_name, Profile* profile) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4534 | // We need to register the window position pref. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 4535 | std::string window_pref(prefs::kBrowserWindowPlacement); |
| 4536 | window_pref.append("_"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4537 | window_pref.append(app_name); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4538 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 4539 | if (!prefs->FindPreference(window_pref.c_str())) { |
| 4540 | prefs->RegisterDictionaryPref(window_pref.c_str(), |
| 4541 | PrefService::UNSYNCABLE_PREF); |
| 4542 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4543 | } |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 4544 | |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 4545 | void Browser::TabRestoreServiceChanged(TabRestoreService* service) { |
| 4546 | command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, |
| 4547 | !service->entries().empty()); |
| 4548 | } |
| 4549 | |
| 4550 | void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) { |
| 4551 | if (!tab_restore_service_) |
| 4552 | return; |
| 4553 | |
| 4554 | DCHECK_EQ(tab_restore_service_, service); |
| 4555 | tab_restore_service_->RemoveObserver(this); |
| 4556 | tab_restore_service_ = NULL; |
| 4557 | } |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 4558 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4559 | // Centralized method for creating a TabContents, configuring and installing |
| 4560 | // all its supporting objects and observers. |
| 4561 | TabContentsWrapper* Browser::TabContentsFactory( |
| 4562 | Profile* profile, |
| 4563 | SiteInstance* site_instance, |
| 4564 | int routing_id, |
| 4565 | const TabContents* base_tab_contents, |
| 4566 | SessionStorageNamespace* session_storage_namespace) { |
| 4567 | TabContents* new_contents = new TabContents(profile, site_instance, |
| 4568 | routing_id, base_tab_contents, |
| 4569 | session_storage_namespace); |
| 4570 | TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); |
| 4571 | return wrapper; |
| 4572 | } |
| 4573 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 4574 | bool Browser::OpenInstant(WindowOpenDisposition disposition) { |
[email protected] | 3524260 | 2011-01-06 16:38:53 | [diff] [blame] | 4575 | if (!instant() || !instant()->is_active() || !instant()->IsCurrent() || |
| 4576 | disposition == NEW_BACKGROUND_TAB) { |
| 4577 | // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't |
| 4578 | // attempt to use the instant preview. |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 4579 | return false; |
[email protected] | 3524260 | 2011-01-06 16:38:53 | [diff] [blame] | 4580 | } |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 4581 | |
| 4582 | if (disposition == CURRENT_TAB) { |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 4583 | instant()->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER); |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 4584 | return true; |
| 4585 | } |
[email protected] | 3524260 | 2011-01-06 16:38:53 | [diff] [blame] | 4586 | if (disposition == NEW_FOREGROUND_TAB) { |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 4587 | TabContentsWrapper* preview_contents = instant()->ReleasePreviewContents( |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 4588 | INSTANT_COMMIT_PRESSED_ENTER); |
[email protected] | a0df03c12 | 2011-01-05 00:22:55 | [diff] [blame] | 4589 | // HideInstant is invoked after release so that InstantController is not |
| 4590 | // active when HideInstant asks it for its state. |
| 4591 | HideInstant(); |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 4592 | preview_contents->controller().PruneAllButActive(); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 4593 | tab_handler_->GetTabStripModel()->AddTabContents( |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 4594 | preview_contents, |
| 4595 | -1, |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 4596 | instant()->last_transition_type(), |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 4597 | TabStripModel::ADD_ACTIVE); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 4598 | instant()->CompleteRelease(preview_contents); |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 4599 | return true; |
| 4600 | } |
| 4601 | // The omnibox currently doesn't use other dispositions, so we don't attempt |
| 4602 | // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add |
| 4603 | // support for the new disposition. |
| 4604 | NOTREACHED(); |
| 4605 | return false; |
| 4606 | } |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 4607 | |
| 4608 | void Browser::CreateInstantIfNecessary() { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4609 | if (is_type_tabbed() && InstantController::IsEnabled(profile()) && |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 4610 | !profile()->IsOffTheRecord()) { |
[email protected] | fdf773c5 | 2010-11-01 20:58:19 | [diff] [blame] | 4611 | instant_.reset(new InstantController(profile_, this)); |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 4612 | instant_unload_handler_.reset(new InstantUnloadHandler(this)); |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 4613 | } |
| 4614 | } |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 4615 | |
| 4616 | void Browser::ViewSource(TabContentsWrapper* contents) { |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 4617 | DCHECK(contents); |
| 4618 | |
| 4619 | NavigationEntry* active_entry = contents->controller().GetActiveEntry(); |
| 4620 | if (!active_entry) |
| 4621 | return; |
| 4622 | |
| 4623 | ViewSource(contents, active_entry->url(), active_entry->content_state()); |
| 4624 | } |
| 4625 | |
| 4626 | void Browser::ViewSource(TabContentsWrapper* contents, |
| 4627 | const GURL& url, |
| 4628 | const std::string& content_state) { |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 4629 | UserMetrics::RecordAction(UserMetricsAction("ViewSource")); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 4630 | DCHECK(contents); |
| 4631 | |
| 4632 | TabContentsWrapper* view_source_contents = contents->Clone(); |
| 4633 | view_source_contents->controller().PruneAllButActive(); |
| 4634 | NavigationEntry* active_entry = |
| 4635 | view_source_contents->controller().GetActiveEntry(); |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 4636 | if (!active_entry) |
| 4637 | return; |
| 4638 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 4639 | GURL view_source_url = GURL(chrome::kViewSourceScheme + std::string(":") + |
| 4640 | url.spec()); |
| 4641 | active_entry->set_virtual_url(view_source_url); |
[email protected] | 1436beff | 2010-12-16 19:47:04 | [diff] [blame] | 4642 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 4643 | // Do not restore scroller position. |
| 4644 | active_entry->set_content_state( |
| 4645 | webkit_glue::RemoveScrollOffsetFromHistoryState(content_state)); |
| 4646 | |
[email protected] | cd3d50d | 2010-12-18 21:03:29 | [diff] [blame] | 4647 | // Do not restore title, derive it from the url. |
[email protected] | 6b2f7a8 | 2011-04-25 19:30:51 | [diff] [blame] | 4648 | active_entry->set_title(string16()); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 4649 | |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 4650 | // Now show view-source entry. |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 4651 | if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
| 4652 | // If this is a tabbed browser, just create a duplicate tab inside the same |
| 4653 | // window next to the tab being duplicated. |
| 4654 | int index = tab_handler_->GetTabStripModel()-> |
| 4655 | GetIndexOfTabContents(contents); |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 4656 | int add_types = TabStripModel::ADD_ACTIVE | |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 4657 | TabStripModel::ADD_INHERIT_GROUP; |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 4658 | tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 4659 | view_source_contents, |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 4660 | add_types); |
| 4661 | } else { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 4662 | Browser* browser = Browser::CreateForType(TYPE_TABBED, profile_); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 4663 | |
| 4664 | // Preserve the size of the original window. The new window has already |
| 4665 | // been given an offset by the OS, so we shouldn't copy the old bounds. |
| 4666 | BrowserWindow* new_window = browser->window(); |
| 4667 | new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 4668 | window()->GetRestoredBounds().size())); |
| 4669 | |
| 4670 | // We need to show the browser now. Otherwise ContainerWin assumes the |
| 4671 | // TabContents is invisible and won't size it. |
| 4672 | browser->window()->Show(); |
| 4673 | |
| 4674 | // The page transition below is only for the purpose of inserting the tab. |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 4675 | browser->AddTab(view_source_contents, PageTransition::LINK); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 4676 | } |
| 4677 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 4678 | SessionService* session_service = |
| 4679 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 4680 | if (session_service) |
| 4681 | session_service->TabRestored(&view_source_contents->controller(), false); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 4682 | } |
[email protected] | b9163e0 | 2011-04-20 16:03:37 | [diff] [blame] | 4683 | |
| 4684 | int Browser::GetContentRestrictionsForSelectedTab() { |
| 4685 | int content_restrictions = 0; |
| 4686 | TabContents* current_tab = GetSelectedTabContents(); |
| 4687 | if (current_tab) { |
| 4688 | content_restrictions = current_tab->content_restrictions(); |
| 4689 | NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); |
| 4690 | // See comment in UpdateCommandsForTabState about why we call url(). |
| 4691 | if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) |
| 4692 | content_restrictions |= CONTENT_RESTRICTION_SAVE; |
| 4693 | } |
| 4694 | return content_restrictions; |
| 4695 | } |