No longer register app window placement preference keys on
[chromium-blink-merge.git] / chrome / browser / ui / tab_helpers.cc
blob797bb3af6cc18848227beabf3ff625276421d288
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/favicon/favicon_tab_helper.h"
11 #include "chrome/browser/history/history_tab_helper.h"
12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/net/net_error_tab_helper.h"
14 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
15 #include "chrome/browser/prerender/prerender_tab_helper.h"
16 #include "chrome/browser/sessions/session_tab_helper.h"
17 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h"
18 #include "chrome/browser/translate/chrome_translate_client.h"
19 #include "chrome/browser/ui/autofill/chrome_autofill_client.h"
20 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
21 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
22 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
23 #include "chrome/browser/ui/navigation_correction_tab_observer.h"
24 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
25 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
26 #include "chrome/browser/ui/search/search_tab_helper.h"
27 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
28 #include "chrome/common/chrome_switches.h"
29 #include "components/autofill/content/browser/content_autofill_driver.h"
30 #include "components/autofill/core/browser/autofill_manager.h"
31 #include "components/dom_distiller/content/web_contents_main_frame_observer.h"
32 #include "components/password_manager/core/browser/password_manager.h"
33 #include "content/public/browser/web_contents.h"
35 #if defined(OS_ANDROID)
36 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
37 #include "chrome/browser/ui/android/context_menu_helper.h"
38 #include "chrome/browser/ui/android/window_android_helper.h"
39 #else
40 #include "chrome/browser/external_protocol/external_protocol_observer.h"
41 #include "chrome/browser/net/predictor_tab_helper.h"
42 #include "chrome/browser/plugins/plugin_observer.h"
43 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
44 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h"
45 #include "chrome/browser/ui/hung_plugin_tab_helper.h"
46 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
47 #include "chrome/browser/ui/sad_tab_helper.h"
48 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
49 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
50 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
51 #include "chrome/browser/ui/zoom/zoom_controller.h"
52 #include "components/pdf/browser/pdf_web_contents_helper.h"
53 #include "components/web_modal/web_contents_modal_dialog_manager.h"
54 #endif // defined(OS_ANDROID)
56 #if defined(OS_WIN)
57 #include "chrome/browser/ui/metro_pin_tab_helper_win.h"
58 #endif
60 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
61 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
62 #endif
64 #if defined(ENABLE_EXTENSIONS)
65 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
66 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
67 #include "chrome/browser/extensions/tab_helper.h"
68 #include "extensions/browser/view_type_utils.h"
69 #endif
71 #if defined(ENABLE_MANAGED_USERS)
72 #include "chrome/browser/supervised_user/supervised_user_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 #if defined(ENABLE_EXTENSIONS)
110 // Set the view type.
111 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_TAB_CONTENTS);
112 #endif
114 // Create all the tab helpers.
116 // SessionTabHelper comes first because it sets up the tab ID, and other
117 // helpers may rely on that.
118 SessionTabHelper::CreateForWebContents(web_contents);
119 #if !defined(OS_ANDROID)
120 // ZoomController comes before common tab helpers since ChromeAutofillClient
121 // may want to register as a ZoomObserver with it.
122 ZoomController::CreateForWebContents(web_contents);
123 #endif
125 // --- Common tab helpers ---
127 autofill::ChromeAutofillClient::CreateForWebContents(web_contents);
128 autofill::ContentAutofillDriver::CreateForWebContentsAndDelegate(
129 web_contents,
130 autofill::ChromeAutofillClient::FromWebContents(web_contents),
131 g_browser_process->GetApplicationLocale(),
132 autofill::AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER);
133 BookmarkTabHelper::CreateForWebContents(web_contents);
134 chrome_browser_net::NetErrorTabHelper::CreateForWebContents(web_contents);
135 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient(
136 web_contents,
137 autofill::ChromeAutofillClient::FromWebContents(web_contents));
138 CoreTabHelper::CreateForWebContents(web_contents);
139 FaviconTabHelper::CreateForWebContents(web_contents);
140 FindTabHelper::CreateForWebContents(web_contents);
141 HistoryTabHelper::CreateForWebContents(web_contents);
142 InfoBarService::CreateForWebContents(web_contents);
143 NavigationCorrectionTabObserver::CreateForWebContents(web_contents);
144 NavigationMetricsRecorder::CreateForWebContents(web_contents);
145 PopupBlockerTabHelper::CreateForWebContents(web_contents);
146 PrefsTabHelper::CreateForWebContents(web_contents);
147 prerender::PrerenderTabHelper::CreateForWebContentsWithPasswordManager(
148 web_contents,
149 ChromePasswordManagerClient::GetManagerFromWebContents(web_contents));
150 SearchTabHelper::CreateForWebContents(web_contents);
151 TabSpecificContentSettings::CreateForWebContents(web_contents);
152 ChromeTranslateClient::CreateForWebContents(web_contents);
154 // --- Platform-specific tab helpers ---
156 #if defined(OS_ANDROID)
157 ContextMenuHelper::CreateForWebContents(web_contents);
158 SingleTabModeTabHelper::CreateForWebContents(web_contents);
159 WindowAndroidHelper::CreateForWebContents(web_contents);
160 #else
161 chrome_browser_net::PredictorTabHelper::CreateForWebContents(web_contents);
162 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
163 web_contents);
164 extensions::WebNavigationTabObserver::CreateForWebContents(web_contents);
165 ExternalProtocolObserver::CreateForWebContents(web_contents);
166 HungPluginTabHelper::CreateForWebContents(web_contents);
167 ManagePasswordsUIController::CreateForWebContents(web_contents);
168 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
169 web_contents,
170 scoped_ptr<pdf::PDFWebContentsHelperClient>(
171 new ChromePDFWebContentsHelperClient()));
172 PermissionBubbleManager::CreateForWebContents(web_contents);
173 PluginObserver::CreateForWebContents(web_contents);
174 SadTabHelper::CreateForWebContents(web_contents);
175 safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(web_contents);
176 SearchEngineTabHelper::CreateForWebContents(web_contents);
177 TabContentsSyncedTabDelegate::CreateForWebContents(web_contents);
178 ThumbnailTabHelper::CreateForWebContents(web_contents);
179 web_modal::WebContentsModalDialogManager::CreateForWebContents(web_contents);
180 #endif
182 #if defined(OS_WIN)
183 MetroPinTabHelper::CreateForWebContents(web_contents);
184 #endif
186 // --- Feature tab helpers behind flags ---
188 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
189 CaptivePortalTabHelper::CreateForWebContents(web_contents);
190 #endif
192 #if defined(ENABLE_EXTENSIONS)
193 extensions::TabHelper::CreateForWebContents(web_contents);
194 #endif
196 #if defined(ENABLE_MANAGED_USERS)
197 SupervisedUserNavigationObserver::CreateForWebContents(web_contents);
198 #endif
200 #if defined(ENABLE_PRINTING) && !defined(OS_ANDROID)
201 #if defined(ENABLE_FULL_PRINTING)
202 printing::PrintViewManager::CreateForWebContents(web_contents);
203 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
204 #else
205 printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
206 #endif // defined(ENABLE_FULL_PRINTING)
207 #endif // defined(ENABLE_PRINTING) && !defined(OS_ANDROID)
209 if (CommandLine::ForCurrentProcess()->HasSwitch(
210 switches::kEnableDomDistiller)) {
211 dom_distiller::WebContentsMainFrameObserver::CreateForWebContents(
212 web_contents);
215 #if defined(ENABLE_ONE_CLICK_SIGNIN)
216 // If this is not an incognito window, setup to handle one-click login.
217 // We don't want to check that the profile is already connected at this time
218 // because the connected state may change while this tab is open. Having a
219 // one-click signin helper attached does not cause problems if the profile
220 // happens to be already connected.
221 if (OneClickSigninHelper::CanOffer(web_contents,
222 OneClickSigninHelper::CAN_OFFER_FOR_ALL,
223 std::string(),
224 NULL)) {
225 OneClickSigninHelper::CreateForWebContentsWithPasswordManager(
226 web_contents,
227 ChromePasswordManagerClient::GetManagerFromWebContents(web_contents));
229 #endif