| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/tab_helpers.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "chrome/browser/browser_process.h" | |
| 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | |
| 10 #include "chrome/browser/extensions/tab_helper.h" | |
| 11 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
| 12 #include "chrome/browser/history/history_tab_helper.h" | |
| 13 #include "chrome/browser/infobars/infobar_service.h" | |
| 14 #include "chrome/browser/net/net_error_tab_helper.h" | |
| 15 #include "chrome/browser/password_manager/password_manager.h" | |
| 16 #include "chrome/browser/password_manager/password_manager_delegate_impl.h" | |
| 17 #include "chrome/browser/prerender/prerender_tab_helper.h" | |
| 18 #include "chrome/browser/profiles/profile.h" | |
| 19 #include "chrome/browser/sessions/session_tab_helper.h" | |
| 20 #include "chrome/browser/ssl/ssl_tab_helper.h" | |
| 21 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h" | |
| 22 #include "chrome/browser/translate/translate_tab_helper.h" | |
| 23 #include "chrome/browser/ui/alternate_error_tab_observer.h" | |
| 24 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | |
| 25 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | |
| 26 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | |
| 27 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | |
| 28 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" | |
| 29 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | |
| 30 #include "chrome/common/chrome_switches.h" | |
| 31 #include "components/autofill/content/browser/autofill_driver_impl.h" | |
| 32 #include "components/autofill/core/browser/autofill_manager.h" | |
| 33 #include "content/public/browser/web_contents.h" | |
| 34 #include "extensions/browser/view_type_utils.h" | |
| 35 | |
| 36 #if defined(OS_ANDROID) | |
| 37 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h" | |
| 38 #include "chrome/browser/ui/android/context_menu_helper.h" | |
| 39 #include "chrome/browser/ui/android/window_android_helper.h" | |
| 40 #else | |
| 41 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" | |
| 42 #include "chrome/browser/extensions/extension_web_contents_observer.h" | |
| 43 #include "chrome/browser/external_protocol/external_protocol_observer.h" | |
| 44 #include "chrome/browser/net/predictor_tab_helper.h" | |
| 45 #include "chrome/browser/network_time/navigation_time_helper.h" | |
| 46 #include "chrome/browser/password_manager/password_generation_manager.h" | |
| 47 #include "chrome/browser/plugins/plugin_observer.h" | |
| 48 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" | |
| 49 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h" | |
| 50 #include "chrome/browser/ui/hung_plugin_tab_helper.h" | |
| 51 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" | |
| 52 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" | |
| 53 #include "chrome/browser/ui/sad_tab_helper.h" | |
| 54 #include "chrome/browser/ui/search/search_tab_helper.h" | |
| 55 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" | |
| 56 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" | |
| 57 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
| 58 #include "chrome/browser/ui/zoom/zoom_controller.h" | |
| 59 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
| 60 #endif // defined(OS_ANDROID) | |
| 61 | |
| 62 #if defined(OS_WIN) | |
| 63 #include "chrome/browser/ui/metro_pin_tab_helper_win.h" | |
| 64 #endif | |
| 65 | |
| 66 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 67 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | |
| 68 #endif | |
| 69 | |
| 70 #if defined(ENABLE_MANAGED_USERS) | |
| 71 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" | |
| 72 #endif | |
| 73 | |
| 74 #if defined(ENABLE_PRINTING) | |
| 75 #if defined(ENABLE_FULL_PRINTING) | |
| 76 #include "chrome/browser/printing/print_preview_message_handler.h" | |
| 77 #include "chrome/browser/printing/print_view_manager.h" | |
| 78 #else | |
| 79 #include "chrome/browser/printing/print_view_manager_basic.h" | |
| 80 #endif // defined(ENABLE_FULL_PRINTING) | |
| 81 #endif // defined(ENABLE_PRINTING) | |
| 82 | |
| 83 #if defined(ENABLE_ONE_CLICK_SIGNIN) | |
| 84 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | |
| 85 #endif | |
| 86 | |
| 87 using content::WebContents; | |
| 88 | |
| 89 namespace { | |
| 90 | |
| 91 const char kTabContentsAttachedTabHelpersUserDataKey[] = | |
| 92 "TabContentsAttachedTabHelpers"; | |
| 93 | |
| 94 } // namespace | |
| 95 | |
| 96 // static | |
| 97 void TabHelpers::AttachTabHelpers(WebContents* web_contents) { | |
| 98 // If already adopted, nothing to be done. | |
| 99 base::SupportsUserData::Data* adoption_tag = | |
| 100 web_contents->GetUserData(&kTabContentsAttachedTabHelpersUserDataKey); | |
| 101 if (adoption_tag) | |
| 102 return; | |
| 103 | |
| 104 // Mark as adopted. | |
| 105 web_contents->SetUserData(&kTabContentsAttachedTabHelpersUserDataKey, | |
| 106 new base::SupportsUserData::Data()); | |
| 107 | |
| 108 // Set the view type. | |
| 109 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_TAB_CONTENTS); | |
| 110 | |
| 111 // Create all the tab helpers. | |
| 112 | |
| 113 Profile* profile = | |
| 114 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 115 | |
| 116 // SessionTabHelper comes first because it sets up the tab ID, and other | |
| 117 // helpers may rely on that. | |
| 118 SessionTabHelper::CreateForWebContents(web_contents); | |
| 119 | |
| 120 // --- Common tab helpers --- | |
| 121 | |
| 122 AlternateErrorPageTabObserver::CreateForWebContents(web_contents); | |
| 123 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents); | |
| 124 autofill::AutofillDriverImpl::CreateForWebContentsAndDelegate( | |
| 125 web_contents, | |
| 126 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents), | |
| 127 g_browser_process->GetApplicationLocale(), | |
| 128 autofill::AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); | |
| 129 BookmarkTabHelper::CreateForWebContents(web_contents); | |
| 130 chrome_browser_net::NetErrorTabHelper::CreateForWebContents(web_contents); | |
| 131 CoreTabHelper::CreateForWebContents(web_contents); | |
| 132 extensions::TabHelper::CreateForWebContents(web_contents); | |
| 133 FaviconTabHelper::CreateForWebContents(web_contents); | |
| 134 FindTabHelper::CreateForWebContents(web_contents); | |
| 135 HistoryTabHelper::CreateForWebContents(web_contents); | |
| 136 InfoBarService::CreateForWebContents(web_contents); | |
| 137 NavigationMetricsRecorder::CreateForWebContents(web_contents); | |
| 138 PasswordManagerDelegateImpl::CreateForWebContents(web_contents); | |
| 139 PasswordManager::CreateForWebContentsAndDelegate( | |
| 140 web_contents, PasswordManagerDelegateImpl::FromWebContents(web_contents)); | |
| 141 PopupBlockerTabHelper::CreateForWebContents(web_contents); | |
| 142 PrefsTabHelper::CreateForWebContents(web_contents); | |
| 143 prerender::PrerenderTabHelper::CreateForWebContentsWithPasswordManager( | |
| 144 web_contents, PasswordManager::FromWebContents(web_contents)); | |
| 145 SSLTabHelper::CreateForWebContents(web_contents); | |
| 146 TabSpecificContentSettings::CreateForWebContents(web_contents); | |
| 147 TranslateTabHelper::CreateForWebContents(web_contents); | |
| 148 | |
| 149 // --- Platform-specific tab helpers --- | |
| 150 | |
| 151 #if defined(OS_ANDROID) | |
| 152 ContextMenuHelper::CreateForWebContents(web_contents); | |
| 153 SingleTabModeTabHelper::CreateForWebContents(web_contents); | |
| 154 #else | |
| 155 chrome_browser_net::PredictorTabHelper::CreateForWebContents(web_contents); | |
| 156 extensions::ExtensionWebContentsObserver::CreateForWebContents(web_contents); | |
| 157 extensions::WebNavigationTabObserver::CreateForWebContents(web_contents); | |
| 158 ExternalProtocolObserver::CreateForWebContents(web_contents); | |
| 159 HungPluginTabHelper::CreateForWebContents(web_contents); | |
| 160 ManagePasswordsBubbleUIController::CreateForWebContents(web_contents); | |
| 161 NavigationTimeHelper::CreateForWebContents(web_contents); | |
| 162 PasswordGenerationManager::CreateForWebContents(web_contents); | |
| 163 PDFTabHelper::CreateForWebContents(web_contents); | |
| 164 PermissionBubbleManager::CreateForWebContents(web_contents); | |
| 165 PluginObserver::CreateForWebContents(web_contents); | |
| 166 SadTabHelper::CreateForWebContents(web_contents); | |
| 167 safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(web_contents); | |
| 168 SearchEngineTabHelper::CreateForWebContents(web_contents); | |
| 169 SearchTabHelper::CreateForWebContents(web_contents); | |
| 170 TabContentsSyncedTabDelegate::CreateForWebContents(web_contents); | |
| 171 ThumbnailTabHelper::CreateForWebContents(web_contents); | |
| 172 web_modal::WebContentsModalDialogManager::CreateForWebContents(web_contents); | |
| 173 ZoomController::CreateForWebContents(web_contents); | |
| 174 #endif | |
| 175 | |
| 176 #if defined(OS_WIN) | |
| 177 MetroPinTabHelper::CreateForWebContents(web_contents); | |
| 178 #endif | |
| 179 | |
| 180 // --- Feature tab helpers behind flags --- | |
| 181 | |
| 182 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 183 captive_portal::CaptivePortalTabHelper::CreateForWebContents(web_contents); | |
| 184 #endif | |
| 185 | |
| 186 #if defined(ENABLE_MANAGED_USERS) | |
| 187 if (profile->IsManaged()) { | |
| 188 ManagedModeNavigationObserver::CreateForWebContents(web_contents); | |
| 189 } | |
| 190 #endif | |
| 191 | |
| 192 #if defined(ENABLE_PRINTING) && !defined(OS_ANDROID) | |
| 193 #if defined(ENABLE_FULL_PRINTING) | |
| 194 printing::PrintViewManager::CreateForWebContents(web_contents); | |
| 195 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents); | |
| 196 #else | |
| 197 printing::PrintViewManagerBasic::CreateForWebContents(web_contents); | |
| 198 #endif // defined(ENABLE_FULL_PRINTING) | |
| 199 #endif // defined(ENABLE_PRINTING) && !defined(OS_ANDROID) | |
| 200 | |
| 201 #if defined(ENABLE_ONE_CLICK_SIGNIN) | |
| 202 // If this is not an incognito window, setup to handle one-click login. | |
| 203 // We don't want to check that the profile is already connected at this time | |
| 204 // because the connected state may change while this tab is open. Having a | |
| 205 // one-click signin helper attached does not cause problems if the profile | |
| 206 // happens to be already connected. | |
| 207 if (OneClickSigninHelper::CanOffer(web_contents, | |
| 208 OneClickSigninHelper::CAN_OFFER_FOR_ALL, | |
| 209 std::string(), | |
| 210 NULL)) { | |
| 211 OneClickSigninHelper::CreateForWebContentsWithPasswordManager( | |
| 212 web_contents, PasswordManager::FromWebContents(web_contents)); | |
| 213 } | |
| 214 #endif | |
| 215 } | |
| OLD | NEW |