[Extensions] Make extension message bubble factory platform-abstract
[chromium-blink-merge.git] / chrome / browser / ui / tab_helpers.cc
blobdf974a92d01639e03ee7a7e17d3d48a851ac8d15
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/favicon/favicon_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/net/predictor_tab_helper.h"
16 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
17 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h"
18 #include "chrome/browser/predictors/resource_prefetch_predictor_tab_helper.h"
19 #include "chrome/browser/prerender/prerender_tab_helper.h"
20 #include "chrome/browser/sessions/session_tab_helper.h"
21 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h"
22 #include "chrome/browser/translate/chrome_translate_client.h"
23 #include "chrome/browser/ui/autofill/chrome_autofill_client.h"
24 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
25 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
26 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
27 #include "chrome/browser/ui/navigation_correction_tab_observer.h"
28 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
29 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
30 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
31 #include "chrome/browser/ui/search/search_tab_helper.h"
32 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
33 #include "chrome/browser/ui/tab_dialogs.h"
34 #include "chrome/common/chrome_switches.h"
35 #include "components/autofill/content/browser/content_autofill_driver_factory.h"
36 #include "components/autofill/core/browser/autofill_manager.h"
37 #include "components/dom_distiller/content/web_contents_main_frame_observer.h"
38 #include "components/password_manager/core/browser/password_manager.h"
39 #include "content/public/browser/web_contents.h"
41 #if defined(OS_ANDROID)
42 #include "chrome/browser/android/voice_search_tab_helper.h"
43 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
44 #include "chrome/browser/enhanced_bookmarks/android/enhanced_bookmark_tab_helper.h"
45 #include "chrome/browser/ui/android/context_menu_helper.h"
46 #include "chrome/browser/ui/android/window_android_helper.h"
47 #else
48 #include "chrome/browser/external_protocol/external_protocol_observer.h"
49 #include "chrome/browser/plugins/plugin_observer.h"
50 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
51 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h"
52 #include "chrome/browser/ui/hung_plugin_tab_helper.h"
53 #include "chrome/browser/ui/sad_tab_helper.h"
54 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
55 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
56 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
57 #include "components/pdf/browser/pdf_web_contents_helper.h"
58 #include "components/ui/zoom/zoom_controller.h"
59 #include "components/web_modal/web_contents_modal_dialog_manager.h"
60 #endif // defined(OS_ANDROID)
62 #if defined(OS_WIN)
63 #include "chrome/browser/ui/metro_pin_tab_helper_win.h"
64 #endif
66 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
67 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
68 #endif
70 #if defined(ENABLE_EXTENSIONS)
71 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
72 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
73 #include "chrome/browser/extensions/tab_helper.h"
74 #include "extensions/browser/view_type_utils.h"
75 #endif
77 #if defined(ENABLE_SUPERVISED_USERS)
78 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
79 #endif
81 #if defined(ENABLE_PRINTING)
82 #if defined(ENABLE_PRINT_PREVIEW)
83 #include "chrome/browser/printing/print_preview_message_handler.h"
84 #include "chrome/browser/printing/print_view_manager.h"
85 #else
86 #include "chrome/browser/printing/print_view_manager_basic.h"
87 #endif // defined(ENABLE_PRINT_PREVIEW)
88 #endif // defined(ENABLE_PRINTING)
90 using content::WebContents;
92 namespace {
94 const char kTabContentsAttachedTabHelpersUserDataKey[] =
95 "TabContentsAttachedTabHelpers";
97 } // namespace
99 // static
100 void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
101 // If already adopted, nothing to be done.
102 base::SupportsUserData::Data* adoption_tag =
103 web_contents->GetUserData(&kTabContentsAttachedTabHelpersUserDataKey);
104 if (adoption_tag)
105 return;
107 // Mark as adopted.
108 web_contents->SetUserData(&kTabContentsAttachedTabHelpersUserDataKey,
109 new base::SupportsUserData::Data());
111 #if defined(ENABLE_EXTENSIONS)
112 // Set the view type.
113 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_TAB_CONTENTS);
114 #endif
116 // Create all the tab helpers.
118 // SessionTabHelper comes first because it sets up the tab ID, and other
119 // helpers may rely on that.
120 SessionTabHelper::CreateForWebContents(web_contents);
121 #if !defined(OS_ANDROID)
122 // ZoomController comes before common tab helpers since ChromeAutofillClient
123 // may want to register as a ZoomObserver with it.
124 ui_zoom::ZoomController::CreateForWebContents(web_contents);
125 #endif
127 // --- Common tab helpers ---
129 autofill::ChromeAutofillClient::CreateForWebContents(web_contents);
130 autofill::ContentAutofillDriverFactory::CreateForWebContentsAndDelegate(
131 web_contents,
132 autofill::ChromeAutofillClient::FromWebContents(web_contents),
133 g_browser_process->GetApplicationLocale(),
134 autofill::AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER);
135 BookmarkTabHelper::CreateForWebContents(web_contents);
136 chrome_browser_net::NetErrorTabHelper::CreateForWebContents(web_contents);
137 chrome_browser_net::PredictorTabHelper::CreateForWebContents(web_contents);
138 ChromeContentSettingsClient::CreateForWebContents(web_contents);
139 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient(
140 web_contents,
141 autofill::ChromeAutofillClient::FromWebContents(web_contents));
142 ChromeTranslateClient::CreateForWebContents(web_contents);
143 CoreTabHelper::CreateForWebContents(web_contents);
144 favicon::CreateContentFaviconDriverForWebContents(web_contents);
145 FindTabHelper::CreateForWebContents(web_contents);
146 HistoryTabHelper::CreateForWebContents(web_contents);
147 InfoBarService::CreateForWebContents(web_contents);
148 ManagePasswordsUIController::CreateForWebContents(web_contents);
149 NavigationCorrectionTabObserver::CreateForWebContents(web_contents);
150 NavigationMetricsRecorder::CreateForWebContents(web_contents);
151 PopupBlockerTabHelper::CreateForWebContents(web_contents);
152 PrefsTabHelper::CreateForWebContents(web_contents);
153 prerender::PrerenderTabHelper::CreateForWebContents(web_contents);
154 SearchTabHelper::CreateForWebContents(web_contents);
155 // TODO(vabr): Remove TabSpecificContentSettings from here once their function
156 // is taken over by ChromeContentSettingsClient. http://crbug.com/387075
157 TabSpecificContentSettings::CreateForWebContents(web_contents);
159 // --- Platform-specific tab helpers ---
161 #if defined(OS_ANDROID)
162 ContextMenuHelper::CreateForWebContents(web_contents);
163 EnhancedBookmarkTabHelper::CreateForWebContents(web_contents);
164 SingleTabModeTabHelper::CreateForWebContents(web_contents);
165 VoiceSearchTabHelper::CreateForWebContents(web_contents);
166 WindowAndroidHelper::CreateForWebContents(web_contents);
167 #else
168 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
169 web_contents);
170 extensions::WebNavigationTabObserver::CreateForWebContents(web_contents);
171 ExternalProtocolObserver::CreateForWebContents(web_contents);
172 HungPluginTabHelper::CreateForWebContents(web_contents);
173 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
174 web_contents,
175 scoped_ptr<pdf::PDFWebContentsHelperClient>(
176 new ChromePDFWebContentsHelperClient()));
177 PermissionBubbleManager::CreateForWebContents(web_contents);
178 PluginObserver::CreateForWebContents(web_contents);
179 SadTabHelper::CreateForWebContents(web_contents);
180 safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(web_contents);
181 SearchEngineTabHelper::CreateForWebContents(web_contents);
182 TabContentsSyncedTabDelegate::CreateForWebContents(web_contents);
183 TabDialogs::CreateForWebContents(web_contents);
184 ThumbnailTabHelper::CreateForWebContents(web_contents);
185 web_modal::WebContentsModalDialogManager::CreateForWebContents(web_contents);
186 #endif
188 #if defined(OS_WIN)
189 MetroPinTabHelper::CreateForWebContents(web_contents);
190 #endif
192 // --- Feature tab helpers behind flags ---
194 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
195 CaptivePortalTabHelper::CreateForWebContents(web_contents);
196 #endif
198 #if defined(ENABLE_EXTENSIONS)
199 extensions::TabHelper::CreateForWebContents(web_contents);
200 #endif
202 #if defined(ENABLE_SUPERVISED_USERS)
203 SupervisedUserNavigationObserver::CreateForWebContents(web_contents);
204 #endif
206 #if defined(ENABLE_PRINTING) && !defined(OS_ANDROID)
207 #if defined(ENABLE_PRINT_PREVIEW)
208 printing::PrintViewManager::CreateForWebContents(web_contents);
209 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
210 #else
211 printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
212 #endif // defined(ENABLE_PRINT_PREVIEW)
213 #endif // defined(ENABLE_PRINTING) && !defined(OS_ANDROID)
215 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
216 switches::kEnableDomDistiller)) {
217 dom_distiller::WebContentsMainFrameObserver::CreateForWebContents(
218 web_contents);
221 if (predictors::ResourcePrefetchPredictorFactory::GetForProfile(
222 web_contents->GetBrowserContext())) {
223 predictors::ResourcePrefetchPredictorTabHelper::CreateForWebContents(
224 web_contents);