NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / tab_helpers.cc
blob347d594ec73ae2df15ae54a51fa05bdc6f692c21
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/password_manager/password_manager.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 "chrome/common/profile_management_switches.h"
32 #include "components/autofill/content/browser/autofill_driver_impl.h"
33 #include "components/autofill/core/browser/autofill_manager.h"
34 #include "content/public/browser/web_contents.h"
35 #include "extensions/browser/view_type_utils.h"
37 #if defined(OS_ANDROID)
38 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
39 #include "chrome/browser/ui/android/context_menu_helper.h"
40 #include "chrome/browser/ui/android/window_android_helper.h"
41 #else
42 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
43 #include "chrome/browser/extensions/extension_web_contents_observer.h"
44 #include "chrome/browser/external_protocol/external_protocol_observer.h"
45 #include "chrome/browser/net/predictor_tab_helper.h"
46 #include "chrome/browser/network_time/navigation_time_helper.h"
47 #include "chrome/browser/password_manager/password_generation_manager.h"
48 #include "chrome/browser/plugins/plugin_observer.h"
49 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
50 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h"
51 #include "chrome/browser/ui/hung_plugin_tab_helper.h"
52 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
53 #include "chrome/browser/ui/pdf/pdf_tab_helper.h"
54 #include "chrome/browser/ui/sad_tab_helper.h"
55 #include "chrome/browser/ui/search/search_tab_helper.h"
56 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
57 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
58 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
59 #include "chrome/browser/ui/zoom/zoom_controller.h"
60 #include "components/web_modal/web_contents_modal_dialog_manager.h"
61 #endif // defined(OS_ANDROID)
63 #if defined(OS_WIN)
64 #include "chrome/browser/ui/metro_pin_tab_helper_win.h"
65 #endif
67 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
68 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
69 #endif
71 #if defined(ENABLE_MANAGED_USERS)
72 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
73 #endif
75 #if defined(ENABLE_PRINTING)
76 #if defined(ENABLE_FULL_PRINTING)
77 #include "chrome/browser/printing/print_preview_message_handler.h"
78 #include "chrome/browser/printing/print_view_manager.h"
79 #else
80 #include "chrome/browser/printing/print_view_manager_basic.h"
81 #endif // defined(ENABLE_FULL_PRINTING)
82 #endif // defined(ENABLE_PRINTING)
84 #if defined(ENABLE_ONE_CLICK_SIGNIN)
85 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
86 #endif
88 using content::WebContents;
90 namespace {
92 const char kTabContentsAttachedTabHelpersUserDataKey[] =
93 "TabContentsAttachedTabHelpers";
95 } // namespace
97 // static
98 void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
99 // If already adopted, nothing to be done.
100 base::SupportsUserData::Data* adoption_tag =
101 web_contents->GetUserData(&kTabContentsAttachedTabHelpersUserDataKey);
102 if (adoption_tag)
103 return;
105 // Mark as adopted.
106 web_contents->SetUserData(&kTabContentsAttachedTabHelpersUserDataKey,
107 new base::SupportsUserData::Data());
109 // Set the view type.
110 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_TAB_CONTENTS);
112 // Create all the tab helpers.
114 Profile* profile =
115 Profile::FromBrowserContext(web_contents->GetBrowserContext());
117 // SessionTabHelper comes first because it sets up the tab ID, and other
118 // helpers may rely on that.
119 SessionTabHelper::CreateForWebContents(web_contents);
121 // --- Common tab helpers ---
123 AlternateErrorPageTabObserver::CreateForWebContents(web_contents);
124 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents);
125 autofill::AutofillDriverImpl::CreateForWebContentsAndDelegate(
126 web_contents,
127 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents),
128 g_browser_process->GetApplicationLocale(),
129 autofill::AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER);
130 BookmarkTabHelper::CreateForWebContents(web_contents);
131 chrome_browser_net::NetErrorTabHelper::CreateForWebContents(web_contents);
132 CoreTabHelper::CreateForWebContents(web_contents);
133 extensions::TabHelper::CreateForWebContents(web_contents);
134 FaviconTabHelper::CreateForWebContents(web_contents);
135 FindTabHelper::CreateForWebContents(web_contents);
136 HistoryTabHelper::CreateForWebContents(web_contents);
137 InfoBarService::CreateForWebContents(web_contents);
138 NavigationMetricsRecorder::CreateForWebContents(web_contents);
139 ChromePasswordManagerClient::CreateForWebContents(web_contents);
140 PopupBlockerTabHelper::CreateForWebContents(web_contents);
141 PrefsTabHelper::CreateForWebContents(web_contents);
142 prerender::PrerenderTabHelper::CreateForWebContentsWithPasswordManager(
143 web_contents,
144 ChromePasswordManagerClient::GetManagerFromWebContents(web_contents));
145 SSLTabHelper::CreateForWebContents(web_contents);
146 TabSpecificContentSettings::CreateForWebContents(web_contents);
147 TranslateTabHelper::CreateForWebContents(web_contents);
149 // --- Platform-specific tab helpers ---
151 #if defined(OS_ANDROID)
152 ContextMenuHelper::CreateForWebContents(web_contents);
153 SingleTabModeTabHelper::CreateForWebContents(web_contents);
154 WindowAndroidHelper::CreateForWebContents(web_contents);
155 #else
156 chrome_browser_net::PredictorTabHelper::CreateForWebContents(web_contents);
157 extensions::ExtensionWebContentsObserver::CreateForWebContents(web_contents);
158 extensions::WebNavigationTabObserver::CreateForWebContents(web_contents);
159 ExternalProtocolObserver::CreateForWebContents(web_contents);
160 HungPluginTabHelper::CreateForWebContents(web_contents);
161 ManagePasswordsBubbleUIController::CreateForWebContents(web_contents);
162 NavigationTimeHelper::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
176 #if defined(OS_WIN)
177 MetroPinTabHelper::CreateForWebContents(web_contents);
178 #endif
180 // --- Feature tab helpers behind flags ---
182 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
183 captive_portal::CaptivePortalTabHelper::CreateForWebContents(web_contents);
184 #endif
186 #if defined(ENABLE_MANAGED_USERS)
187 if (profile->IsManaged()) {
188 ManagedModeNavigationObserver::CreateForWebContents(web_contents);
190 #endif
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)
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 // TODO(vabr): The check IsEnableWebBasedSignin is a hack for the time when
208 // OneClickSignin is disabled. http://crbug.com/339804
209 if (switches::IsEnableWebBasedSignin() &&
210 OneClickSigninHelper::CanOffer(web_contents,
211 OneClickSigninHelper::CAN_OFFER_FOR_ALL,
212 std::string(),
213 NULL)) {
214 OneClickSigninHelper::CreateForWebContentsWithPasswordManager(
215 web_contents,
216 ChromePasswordManagerClient::GetManagerFromWebContents(web_contents));
218 #endif