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.
5 #include "chrome/browser/ui/tab_helpers.h"
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/chrome_password_manager_client.h"
16 #include "chrome/browser/prerender/prerender_tab_helper.h"
17 #include "chrome/browser/sessions/session_tab_helper.h"
18 #include "chrome/browser/ssl/ssl_tab_helper.h"
19 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h"
20 #include "chrome/browser/translate/translate_tab_helper.h"
21 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
22 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
23 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
24 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
25 #include "chrome/browser/ui/navigation_correction_tab_observer.h"
26 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
27 #include "chrome/browser/ui/search/search_tab_helper.h"
28 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
29 #include "chrome/common/chrome_switches.h"
30 #include "components/autofill/content/browser/content_autofill_driver.h"
31 #include "components/autofill/core/browser/autofill_manager.h"
32 #include "components/password_manager/core/browser/password_manager.h"
33 #include "content/public/browser/web_contents.h"
34 #include "extensions/browser/view_type_utils.h"
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"
41 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
42 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
43 #include "chrome/browser/net/predictor_tab_helper.h"
44 #include "chrome/browser/network_time/navigation_time_helper.h"
45 #include "chrome/browser/plugins/plugin_observer.h"
46 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
47 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h"
48 #include "chrome/browser/ui/hung_plugin_tab_helper.h"
49 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
50 #include "chrome/browser/ui/pdf/pdf_tab_helper.h"
51 #include "chrome/browser/ui/sad_tab_helper.h"
52 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
53 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
54 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
55 #include "chrome/browser/ui/zoom/zoom_controller.h"
56 #include "components/web_modal/web_contents_modal_dialog_manager.h"
57 #endif // defined(OS_ANDROID)
60 #include "chrome/browser/ui/metro_pin_tab_helper_win.h"
63 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
64 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
67 #if defined(ENABLE_MANAGED_USERS)
68 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
71 #if defined(ENABLE_PRINTING)
72 #if defined(ENABLE_FULL_PRINTING)
73 #include "chrome/browser/printing/print_preview_message_handler.h"
74 #include "chrome/browser/printing/print_view_manager.h"
76 #include "chrome/browser/printing/print_view_manager_basic.h"
77 #endif // defined(ENABLE_FULL_PRINTING)
78 #endif // defined(ENABLE_PRINTING)
80 #if defined(ENABLE_ONE_CLICK_SIGNIN)
81 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
84 using content::WebContents
;
88 const char kTabContentsAttachedTabHelpersUserDataKey
[] =
89 "TabContentsAttachedTabHelpers";
94 void TabHelpers::AttachTabHelpers(WebContents
* web_contents
) {
95 // If already adopted, nothing to be done.
96 base::SupportsUserData::Data
* adoption_tag
=
97 web_contents
->GetUserData(&kTabContentsAttachedTabHelpersUserDataKey
);
102 web_contents
->SetUserData(&kTabContentsAttachedTabHelpersUserDataKey
,
103 new base::SupportsUserData::Data());
105 // Set the view type.
106 extensions::SetViewType(web_contents
, extensions::VIEW_TYPE_TAB_CONTENTS
);
108 // Create all the tab helpers.
110 // SessionTabHelper comes first because it sets up the tab ID, and other
111 // helpers may rely on that.
112 SessionTabHelper::CreateForWebContents(web_contents
);
114 // --- Common tab helpers ---
116 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents
);
117 autofill::ContentAutofillDriver::CreateForWebContentsAndDelegate(
119 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents
),
120 g_browser_process
->GetApplicationLocale(),
121 autofill::AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER
);
122 BookmarkTabHelper::CreateForWebContents(web_contents
);
123 chrome_browser_net::NetErrorTabHelper::CreateForWebContents(web_contents
);
124 ChromePasswordManagerClient::CreateForWebContentsWithAutofillManagerDelegate(
126 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents
));
127 CoreTabHelper::CreateForWebContents(web_contents
);
128 extensions::TabHelper::CreateForWebContents(web_contents
);
129 FaviconTabHelper::CreateForWebContents(web_contents
);
130 FindTabHelper::CreateForWebContents(web_contents
);
131 HistoryTabHelper::CreateForWebContents(web_contents
);
132 InfoBarService::CreateForWebContents(web_contents
);
133 NavigationCorrectionTabObserver::CreateForWebContents(web_contents
);
134 NavigationMetricsRecorder::CreateForWebContents(web_contents
);
135 PopupBlockerTabHelper::CreateForWebContents(web_contents
);
136 PrefsTabHelper::CreateForWebContents(web_contents
);
137 prerender::PrerenderTabHelper::CreateForWebContentsWithPasswordManager(
139 ChromePasswordManagerClient::GetManagerFromWebContents(web_contents
));
140 SearchTabHelper::CreateForWebContents(web_contents
);
141 SSLTabHelper::CreateForWebContents(web_contents
);
142 TabSpecificContentSettings::CreateForWebContents(web_contents
);
143 TranslateTabHelper::CreateForWebContents(web_contents
);
145 // --- Platform-specific tab helpers ---
147 #if defined(OS_ANDROID)
148 ContextMenuHelper::CreateForWebContents(web_contents
);
149 SingleTabModeTabHelper::CreateForWebContents(web_contents
);
150 WindowAndroidHelper::CreateForWebContents(web_contents
);
152 chrome_browser_net::PredictorTabHelper::CreateForWebContents(web_contents
);
153 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
155 extensions::WebNavigationTabObserver::CreateForWebContents(web_contents
);
156 HungPluginTabHelper::CreateForWebContents(web_contents
);
157 ManagePasswordsUIController::CreateForWebContents(web_contents
);
158 NavigationTimeHelper::CreateForWebContents(web_contents
);
159 PDFTabHelper::CreateForWebContents(web_contents
);
160 PermissionBubbleManager::CreateForWebContents(web_contents
);
161 PluginObserver::CreateForWebContents(web_contents
);
162 SadTabHelper::CreateForWebContents(web_contents
);
163 safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(web_contents
);
164 SearchEngineTabHelper::CreateForWebContents(web_contents
);
165 TabContentsSyncedTabDelegate::CreateForWebContents(web_contents
);
166 ThumbnailTabHelper::CreateForWebContents(web_contents
);
167 web_modal::WebContentsModalDialogManager::CreateForWebContents(web_contents
);
168 ZoomController::CreateForWebContents(web_contents
);
172 MetroPinTabHelper::CreateForWebContents(web_contents
);
175 // --- Feature tab helpers behind flags ---
177 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
178 CaptivePortalTabHelper::CreateForWebContents(web_contents
);
181 #if defined(ENABLE_MANAGED_USERS)
182 ManagedModeNavigationObserver::CreateForWebContents(web_contents
);
185 #if defined(ENABLE_PRINTING) && !defined(OS_ANDROID)
186 #if defined(ENABLE_FULL_PRINTING)
187 printing::PrintViewManager::CreateForWebContents(web_contents
);
188 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents
);
190 printing::PrintViewManagerBasic::CreateForWebContents(web_contents
);
191 #endif // defined(ENABLE_FULL_PRINTING)
192 #endif // defined(ENABLE_PRINTING) && !defined(OS_ANDROID)
194 #if defined(ENABLE_ONE_CLICK_SIGNIN)
195 // If this is not an incognito window, setup to handle one-click login.
196 // We don't want to check that the profile is already connected at this time
197 // because the connected state may change while this tab is open. Having a
198 // one-click signin helper attached does not cause problems if the profile
199 // happens to be already connected.
200 if (OneClickSigninHelper::CanOffer(web_contents
,
201 OneClickSigninHelper::CAN_OFFER_FOR_ALL
,
204 OneClickSigninHelper::CreateForWebContentsWithPasswordManager(
206 ChromePasswordManagerClient::GetManagerFromWebContents(web_contents
));