Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / tab_helpers.cc
blob0f9ff1a5f483d83635ca3fe9354ffe54f2c1b500
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/chrome_content_settings_client.h"
10 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
11 #include "chrome/browser/engagement/site_engagement_helper.h"
12 #include "chrome/browser/engagement/site_engagement_service.h"
13 #include "chrome/browser/external_protocol/external_protocol_observer.h"
14 #include "chrome/browser/favicon/favicon_utils.h"
15 #include "chrome/browser/history/history_tab_helper.h"
16 #include "chrome/browser/history/top_sites_factory.h"
17 #include "chrome/browser/infobars/infobar_service.h"
18 #include "chrome/browser/net/net_error_tab_helper.h"
19 #include "chrome/browser/net/predictor_tab_helper.h"
20 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
21 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h"
22 #include "chrome/browser/predictors/resource_prefetch_predictor_tab_helper.h"
23 #include "chrome/browser/prerender/prerender_tab_helper.h"
24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/sessions/session_tab_helper.h"
26 #include "chrome/browser/ssl/security_state_model.h"
27 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h"
28 #include "chrome/browser/tracing/navigation_tracing.h"
29 #include "chrome/browser/translate/chrome_translate_client.h"
30 #include "chrome/browser/ui/autofill/chrome_autofill_client.h"
31 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
32 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
33 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
34 #include "chrome/browser/ui/navigation_correction_tab_observer.h"
35 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
36 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
37 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
38 #include "chrome/browser/ui/search/search_tab_helper.h"
39 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
40 #include "chrome/browser/ui/tab_dialogs.h"
41 #include "chrome/common/chrome_switches.h"
42 #include "components/autofill/content/browser/content_autofill_driver_factory.h"
43 #include "components/autofill/core/browser/autofill_manager.h"
44 #include "components/dom_distiller/content/browser/web_contents_main_frame_observer.h"
45 #include "components/dom_distiller/core/dom_distiller_switches.h"
46 #include "components/history/content/browser/web_contents_top_sites_observer.h"
47 #include "components/history/core/browser/top_sites.h"
48 #include "components/password_manager/core/browser/password_manager.h"
49 #include "components/tracing/tracing_switches.h"
50 #include "content/public/browser/web_contents.h"
52 #if defined(OS_ANDROID)
53 #include "chrome/browser/android/offline_pages/offline_page_web_contents_observer.h"
54 #include "chrome/browser/android/voice_search_tab_helper.h"
55 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
56 #include "chrome/browser/ui/android/context_menu_helper.h"
57 #include "chrome/browser/ui/android/window_android_helper.h"
58 #else
59 #include "chrome/browser/banners/app_banner_manager_desktop.h"
60 #include "chrome/browser/plugins/plugin_observer.h"
61 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
62 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h"
63 #include "chrome/browser/ui/hung_plugin_tab_helper.h"
64 #include "chrome/browser/ui/sad_tab_helper.h"
65 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
66 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
67 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
68 #include "components/pdf/browser/pdf_web_contents_helper.h"
69 #include "components/ui/zoom/zoom_controller.h"
70 #include "components/web_modal/web_contents_modal_dialog_manager.h"
71 #endif // defined(OS_ANDROID)
73 #if defined(OS_WIN)
74 #include "chrome/browser/ui/metro_pin_tab_helper_win.h"
75 #endif
77 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
78 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
79 #endif
81 #if defined(ENABLE_EXTENSIONS)
82 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
83 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
84 #include "chrome/browser/extensions/tab_helper.h"
85 #include "extensions/browser/view_type_utils.h"
86 #endif
88 #if defined(ENABLE_SUPERVISED_USERS)
89 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
90 #endif
92 #if defined(ENABLE_PRINTING)
93 #if defined(ENABLE_PRINT_PREVIEW)
94 #include "chrome/browser/printing/print_preview_message_handler.h"
95 #include "chrome/browser/printing/print_view_manager.h"
96 #else
97 #include "chrome/browser/printing/print_view_manager_basic.h"
98 #endif // defined(ENABLE_PRINT_PREVIEW)
99 #endif // defined(ENABLE_PRINTING)
101 using content::WebContents;
103 namespace {
105 const char kTabContentsAttachedTabHelpersUserDataKey[] =
106 "TabContentsAttachedTabHelpers";
108 } // namespace
110 // static
111 void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
112 // If already adopted, nothing to be done.
113 base::SupportsUserData::Data* adoption_tag =
114 web_contents->GetUserData(&kTabContentsAttachedTabHelpersUserDataKey);
115 if (adoption_tag)
116 return;
118 // Mark as adopted.
119 web_contents->SetUserData(&kTabContentsAttachedTabHelpersUserDataKey,
120 new base::SupportsUserData::Data());
122 #if defined(ENABLE_EXTENSIONS)
123 // Set the view type.
124 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_TAB_CONTENTS);
125 #endif
127 // Create all the tab helpers.
129 // SessionTabHelper comes first because it sets up the tab ID, and other
130 // helpers may rely on that.
131 SessionTabHelper::CreateForWebContents(web_contents);
132 #if !defined(OS_ANDROID)
133 // ZoomController comes before common tab helpers since ChromeAutofillClient
134 // may want to register as a ZoomObserver with it.
135 ui_zoom::ZoomController::CreateForWebContents(web_contents);
136 #endif
138 // --- Common tab helpers ---
140 autofill::ChromeAutofillClient::CreateForWebContents(web_contents);
141 autofill::ContentAutofillDriverFactory::CreateForWebContentsAndDelegate(
142 web_contents,
143 autofill::ChromeAutofillClient::FromWebContents(web_contents),
144 g_browser_process->GetApplicationLocale(),
145 autofill::AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER);
146 BookmarkTabHelper::CreateForWebContents(web_contents);
147 chrome_browser_net::NetErrorTabHelper::CreateForWebContents(web_contents);
148 chrome_browser_net::PredictorTabHelper::CreateForWebContents(web_contents);
149 ChromeContentSettingsClient::CreateForWebContents(web_contents);
150 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient(
151 web_contents,
152 autofill::ChromeAutofillClient::FromWebContents(web_contents));
153 ChromeTranslateClient::CreateForWebContents(web_contents);
154 CoreTabHelper::CreateForWebContents(web_contents);
155 ExternalProtocolObserver::CreateForWebContents(web_contents);
156 favicon::CreateContentFaviconDriverForWebContents(web_contents);
157 FindTabHelper::CreateForWebContents(web_contents);
158 history::WebContentsTopSitesObserver::CreateForWebContents(
159 web_contents, TopSitesFactory::GetForProfile(
160 Profile::FromBrowserContext(
161 web_contents->GetBrowserContext())).get());
162 HistoryTabHelper::CreateForWebContents(web_contents);
163 InfoBarService::CreateForWebContents(web_contents);
164 ManagePasswordsUIController::CreateForWebContents(web_contents);
165 NavigationCorrectionTabObserver::CreateForWebContents(web_contents);
166 NavigationMetricsRecorder::CreateForWebContents(web_contents);
167 PopupBlockerTabHelper::CreateForWebContents(web_contents);
168 PrefsTabHelper::CreateForWebContents(web_contents);
169 prerender::PrerenderTabHelper::CreateForWebContents(web_contents);
170 SearchTabHelper::CreateForWebContents(web_contents);
171 SecurityStateModel::CreateForWebContents(web_contents);
172 if (SiteEngagementService::IsEnabled())
173 SiteEngagementHelper::CreateForWebContents(web_contents);
174 // TODO(vabr): Remove TabSpecificContentSettings from here once their function
175 // is taken over by ChromeContentSettingsClient. http://crbug.com/387075
176 TabSpecificContentSettings::CreateForWebContents(web_contents);
178 // --- Platform-specific tab helpers ---
180 #if defined(OS_ANDROID)
181 ContextMenuHelper::CreateForWebContents(web_contents);
182 offline_pages::OfflinePageWebContentsObserver::CreateForWebContents(
183 web_contents);
184 SingleTabModeTabHelper::CreateForWebContents(web_contents);
185 VoiceSearchTabHelper::CreateForWebContents(web_contents);
186 WindowAndroidHelper::CreateForWebContents(web_contents);
187 #else
188 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
189 web_contents);
190 extensions::WebNavigationTabObserver::CreateForWebContents(web_contents);
191 HungPluginTabHelper::CreateForWebContents(web_contents);
192 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
193 web_contents,
194 scoped_ptr<pdf::PDFWebContentsHelperClient>(
195 new ChromePDFWebContentsHelperClient()));
196 PermissionBubbleManager::CreateForWebContents(web_contents);
197 PluginObserver::CreateForWebContents(web_contents);
198 SadTabHelper::CreateForWebContents(web_contents);
199 safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(web_contents);
200 SearchEngineTabHelper::CreateForWebContents(web_contents);
201 TabContentsSyncedTabDelegate::CreateForWebContents(web_contents);
202 TabDialogs::CreateForWebContents(web_contents);
203 ThumbnailTabHelper::CreateForWebContents(web_contents);
204 web_modal::WebContentsModalDialogManager::CreateForWebContents(web_contents);
206 if (banners::AppBannerManagerDesktop::IsEnabled()) {
207 banners::AppBannerManagerDesktop::CreateForWebContents(web_contents);
209 #endif
211 #if defined(OS_WIN)
212 MetroPinTabHelper::CreateForWebContents(web_contents);
213 #endif
215 // --- Feature tab helpers behind flags ---
217 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
218 CaptivePortalTabHelper::CreateForWebContents(web_contents);
219 #endif
221 #if defined(ENABLE_EXTENSIONS)
222 extensions::TabHelper::CreateForWebContents(web_contents);
223 #endif
225 #if defined(ENABLE_SUPERVISED_USERS)
226 SupervisedUserNavigationObserver::CreateForWebContents(web_contents);
227 #endif
229 #if defined(ENABLE_PRINTING) && !defined(OS_ANDROID)
230 #if defined(ENABLE_PRINT_PREVIEW)
231 printing::PrintViewManager::CreateForWebContents(web_contents);
232 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
233 #else
234 printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
235 #endif // defined(ENABLE_PRINT_PREVIEW)
236 #endif // defined(ENABLE_PRINTING) && !defined(OS_ANDROID)
238 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
239 switches::kEnableDomDistiller)) {
240 dom_distiller::WebContentsMainFrameObserver::CreateForWebContents(
241 web_contents);
244 if (predictors::ResourcePrefetchPredictorFactory::GetForProfile(
245 web_contents->GetBrowserContext())) {
246 predictors::ResourcePrefetchPredictorTabHelper::CreateForWebContents(
247 web_contents);
250 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
251 switches::kEnableNavigationTracing) &&
252 base::CommandLine::ForCurrentProcess()->HasSwitch(
253 switches::kTraceUploadURL)) {
254 tracing::NavigationTracingObserver::CreateForWebContents(web_contents);