[Extensions Toolbar Mac] Fix actions bar min size, spacing
[chromium-blink-merge.git] / chrome / browser / ui / tab_helpers.cc
blobfd8a661b76ae8951af04ef53e7578196392237d6
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_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/predictors/resource_prefetch_predictor_factory.h"
17 #include "chrome/browser/predictors/resource_prefetch_predictor_tab_helper.h"
18 #include "chrome/browser/prerender/prerender_tab_helper.h"
19 #include "chrome/browser/sessions/session_tab_helper.h"
20 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h"
21 #include "chrome/browser/translate/chrome_translate_client.h"
22 #include "chrome/browser/ui/autofill/chrome_autofill_client.h"
23 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
24 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
25 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
26 #include "chrome/browser/ui/navigation_correction_tab_observer.h"
27 #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
28 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
29 #include "chrome/browser/ui/search/search_tab_helper.h"
30 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
31 #include "chrome/browser/ui/tab_dialogs.h"
32 #include "chrome/common/chrome_switches.h"
33 #include "components/autofill/content/browser/content_autofill_driver_factory.h"
34 #include "components/autofill/core/browser/autofill_manager.h"
35 #include "components/dom_distiller/content/web_contents_main_frame_observer.h"
36 #include "components/password_manager/core/browser/password_manager.h"
37 #include "components/signin/core/common/profile_management_switches.h"
38 #include "content/public/browser/web_contents.h"
40 #if defined(OS_ANDROID)
41 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
42 #include "chrome/browser/ui/android/context_menu_helper.h"
43 #include "chrome/browser/ui/android/window_android_helper.h"
44 #else
45 #include "chrome/browser/external_protocol/external_protocol_observer.h"
46 #include "chrome/browser/net/predictor_tab_helper.h"
47 #include "chrome/browser/plugins/plugin_observer.h"
48 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
49 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h"
50 #include "chrome/browser/ui/hung_plugin_tab_helper.h"
51 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
52 #include "chrome/browser/ui/sad_tab_helper.h"
53 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
54 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
55 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
56 #include "components/pdf/browser/pdf_web_contents_helper.h"
57 #include "components/ui/zoom/zoom_controller.h"
58 #include "components/web_modal/web_contents_modal_dialog_manager.h"
59 #endif // defined(OS_ANDROID)
61 #if defined(OS_WIN)
62 #include "chrome/browser/ui/metro_pin_tab_helper_win.h"
63 #endif
65 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
66 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
67 #endif
69 #if defined(ENABLE_EXTENSIONS)
70 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
71 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
72 #include "chrome/browser/extensions/tab_helper.h"
73 #include "extensions/browser/view_type_utils.h"
74 #endif
76 #if defined(ENABLE_SUPERVISED_USERS)
77 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
78 #endif
80 #if defined(ENABLE_PRINTING)
81 #if defined(ENABLE_PRINT_PREVIEW)
82 #include "chrome/browser/printing/print_preview_message_handler.h"
83 #include "chrome/browser/printing/print_view_manager.h"
84 #else
85 #include "chrome/browser/printing/print_view_manager_basic.h"
86 #endif // defined(ENABLE_PRINT_PREVIEW)
87 #endif // defined(ENABLE_PRINTING)
89 #if defined(ENABLE_ONE_CLICK_SIGNIN)
90 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
91 #endif
93 using content::WebContents;
95 namespace {
97 const char kTabContentsAttachedTabHelpersUserDataKey[] =
98 "TabContentsAttachedTabHelpers";
100 } // namespace
102 // static
103 void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
104 // If already adopted, nothing to be done.
105 base::SupportsUserData::Data* adoption_tag =
106 web_contents->GetUserData(&kTabContentsAttachedTabHelpersUserDataKey);
107 if (adoption_tag)
108 return;
110 // Mark as adopted.
111 web_contents->SetUserData(&kTabContentsAttachedTabHelpersUserDataKey,
112 new base::SupportsUserData::Data());
114 #if defined(ENABLE_EXTENSIONS)
115 // Set the view type.
116 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_TAB_CONTENTS);
117 #endif
119 // Create all the tab helpers.
121 // SessionTabHelper comes first because it sets up the tab ID, and other
122 // helpers may rely on that.
123 SessionTabHelper::CreateForWebContents(web_contents);
124 #if !defined(OS_ANDROID)
125 // ZoomController comes before common tab helpers since ChromeAutofillClient
126 // may want to register as a ZoomObserver with it.
127 ui_zoom::ZoomController::CreateForWebContents(web_contents);
128 #endif
130 // --- Common tab helpers ---
132 autofill::ChromeAutofillClient::CreateForWebContents(web_contents);
133 autofill::ContentAutofillDriverFactory::CreateForWebContentsAndDelegate(
134 web_contents,
135 autofill::ChromeAutofillClient::FromWebContents(web_contents),
136 g_browser_process->GetApplicationLocale(),
137 autofill::AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER);
138 BookmarkTabHelper::CreateForWebContents(web_contents);
139 chrome_browser_net::NetErrorTabHelper::CreateForWebContents(web_contents);
140 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient(
141 web_contents,
142 autofill::ChromeAutofillClient::FromWebContents(web_contents));
143 CoreTabHelper::CreateForWebContents(web_contents);
144 FaviconTabHelper::CreateForWebContents(web_contents);
145 FindTabHelper::CreateForWebContents(web_contents);
146 HistoryTabHelper::CreateForWebContents(web_contents);
147 InfoBarService::CreateForWebContents(web_contents);
148 NavigationCorrectionTabObserver::CreateForWebContents(web_contents);
149 NavigationMetricsRecorder::CreateForWebContents(web_contents);
150 PopupBlockerTabHelper::CreateForWebContents(web_contents);
151 PrefsTabHelper::CreateForWebContents(web_contents);
152 prerender::PrerenderTabHelper::CreateForWebContents(web_contents);
153 SearchTabHelper::CreateForWebContents(web_contents);
154 // TODO(vabr): Remove TabSpecificContentSettings from here once their function
155 // is taken over by ChromeContentSettingsClient. http://crbug.com/387075
156 TabSpecificContentSettings::CreateForWebContents(web_contents);
157 ChromeContentSettingsClient::CreateForWebContents(web_contents);
158 ChromeTranslateClient::CreateForWebContents(web_contents);
160 // --- Platform-specific tab helpers ---
162 #if defined(OS_ANDROID)
163 ContextMenuHelper::CreateForWebContents(web_contents);
164 SingleTabModeTabHelper::CreateForWebContents(web_contents);
165 WindowAndroidHelper::CreateForWebContents(web_contents);
166 #else
167 chrome_browser_net::PredictorTabHelper::CreateForWebContents(web_contents);
168 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
169 web_contents);
170 extensions::WebNavigationTabObserver::CreateForWebContents(web_contents);
171 ExternalProtocolObserver::CreateForWebContents(web_contents);
172 HungPluginTabHelper::CreateForWebContents(web_contents);
173 ManagePasswordsUIController::CreateForWebContents(web_contents);
174 pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
175 web_contents,
176 scoped_ptr<pdf::PDFWebContentsHelperClient>(
177 new ChromePDFWebContentsHelperClient()));
178 PermissionBubbleManager::CreateForWebContents(web_contents);
179 PluginObserver::CreateForWebContents(web_contents);
180 SadTabHelper::CreateForWebContents(web_contents);
181 safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(web_contents);
182 SearchEngineTabHelper::CreateForWebContents(web_contents);
183 TabContentsSyncedTabDelegate::CreateForWebContents(web_contents);
184 TabDialogs::CreateForWebContents(web_contents);
185 ThumbnailTabHelper::CreateForWebContents(web_contents);
186 web_modal::WebContentsModalDialogManager::CreateForWebContents(web_contents);
187 #endif
189 #if defined(OS_WIN)
190 MetroPinTabHelper::CreateForWebContents(web_contents);
191 #endif
193 // --- Feature tab helpers behind flags ---
195 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
196 CaptivePortalTabHelper::CreateForWebContents(web_contents);
197 #endif
199 #if defined(ENABLE_EXTENSIONS)
200 extensions::TabHelper::CreateForWebContents(web_contents);
201 #endif
203 #if defined(ENABLE_SUPERVISED_USERS)
204 SupervisedUserNavigationObserver::CreateForWebContents(web_contents);
205 #endif
207 #if defined(ENABLE_PRINTING) && !defined(OS_ANDROID)
208 #if defined(ENABLE_PRINT_PREVIEW)
209 printing::PrintViewManager::CreateForWebContents(web_contents);
210 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
211 #else
212 printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
213 #endif // defined(ENABLE_PRINT_PREVIEW)
214 #endif // defined(ENABLE_PRINTING) && !defined(OS_ANDROID)
216 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
217 switches::kEnableDomDistiller)) {
218 dom_distiller::WebContentsMainFrameObserver::CreateForWebContents(
219 web_contents);
222 #if defined(ENABLE_ONE_CLICK_SIGNIN)
223 // If this is not an incognito window, setup to handle one-click login.
224 // We don't want to check that the profile is already connected at this time
225 // because the connected state may change while this tab is open. Having a
226 // one-click signin helper attached does not cause problems if the profile
227 // happens to be already connected.
228 if (switches::IsEnableWebBasedSignin() &&
229 OneClickSigninHelper::CanOffer(web_contents,
230 OneClickSigninHelper::CAN_OFFER_FOR_ALL,
231 std::string(),
232 NULL)) {
233 OneClickSigninHelper::CreateForWebContents(web_contents);
235 #endif
237 if (predictors::ResourcePrefetchPredictorFactory::GetForProfile(
238 web_contents->GetBrowserContext())) {
239 predictors::ResourcePrefetchPredictorTabHelper::CreateForWebContents(
240 web_contents);