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