Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / browser_tab_contents.cc
blobca9eeb7c505602e0e02c710c148f5f24440d8376
1 // Copyright (c) 2012 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/browser_tab_contents.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/api/web_navigation/web_navigation_api.h"
11 #include "chrome/browser/extensions/extension_web_contents_observer.h"
12 #include "chrome/browser/extensions/tab_helper.h"
13 #include "chrome/browser/external_protocol/external_protocol_observer.h"
14 #include "chrome/browser/favicon/favicon_tab_helper.h"
15 #include "chrome/browser/history/history_tab_helper.h"
16 #include "chrome/browser/infobars/infobar_service.h"
17 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
18 #include "chrome/browser/net/net_error_tab_helper.h"
19 #include "chrome/browser/net/predictor_tab_helper.h"
20 #include "chrome/browser/network_time/navigation_time_helper.h"
21 #include "chrome/browser/password_manager/password_generation_manager.h"
22 #include "chrome/browser/password_manager/password_manager.h"
23 #include "chrome/browser/password_manager/password_manager_delegate_impl.h"
24 #include "chrome/browser/plugins/plugin_observer.h"
25 #include "chrome/browser/prerender/prerender_tab_helper.h"
26 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
28 #include "chrome/browser/sessions/session_tab_helper.h"
29 #include "chrome/browser/ssl/ssl_tab_helper.h"
30 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h"
31 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h"
32 #include "chrome/browser/translate/translate_tab_helper.h"
33 #include "chrome/browser/ui/alternate_error_tab_observer.h"
34 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
35 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
36 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
37 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
38 #include "chrome/browser/ui/hung_plugin_tab_helper.h"
39 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
40 #include "chrome/browser/ui/pdf/pdf_tab_helper.h"
41 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
42 #include "chrome/browser/ui/sad_tab_helper.h"
43 #include "chrome/browser/ui/search/search_tab_helper.h"
44 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
45 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
46 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
47 #include "chrome/browser/ui/zoom/zoom_controller.h"
48 #include "chrome/common/chrome_switches.h"
49 #include "components/autofill/content/browser/autofill_driver_impl.h"
50 #include "components/autofill/core/browser/autofill_manager.h"
51 #include "components/web_modal/web_contents_modal_dialog_manager.h"
52 #include "content/public/browser/web_contents.h"
53 #include "extensions/browser/view_type_utils.h"
55 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
56 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
57 #endif
59 #if defined(ENABLE_PRINTING)
60 #if defined(ENABLE_FULL_PRINTING)
61 #include "chrome/browser/printing/print_preview_message_handler.h"
62 #include "chrome/browser/printing/print_view_manager.h"
63 #else
64 #include "chrome/browser/printing/print_view_manager_basic.h"
65 #endif // defined(ENABLE_FULL_PRINTING)
66 #endif // defined(ENABLE_PRINTING)
68 #if defined(ENABLE_ONE_CLICK_SIGNIN)
69 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
70 #endif
72 #if defined(OS_WIN)
73 #include "chrome/browser/ui/metro_pin_tab_helper_win.h"
74 #endif
76 using autofill::AutofillDriverImpl;
77 using autofill::AutofillManager;
78 using autofill::TabAutofillManagerDelegate;
79 using content::WebContents;
80 using web_modal::WebContentsModalDialogManager;
82 namespace {
84 const char kTabContentsAttachedTabHelpersUserDataKey[] =
85 "TabContentsAttachedTabHelpers";
87 } // namespace
89 // static
90 void BrowserTabContents::AttachTabHelpers(WebContents* web_contents) {
91 // If already adopted, nothing to be done.
92 base::SupportsUserData::Data* adoption_tag =
93 web_contents->GetUserData(&kTabContentsAttachedTabHelpersUserDataKey);
94 if (adoption_tag)
95 return;
97 // Mark as adopted.
98 web_contents->SetUserData(&kTabContentsAttachedTabHelpersUserDataKey,
99 new base::SupportsUserData::Data());
101 // Set the view type.
102 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_TAB_CONTENTS);
104 // Create all the tab helpers.
106 // ** Warning: This file is not used on Android. On Android, tab helpers are
107 // ** instantiated in chrome/browser/android/tab_android.cc. Please make sure
108 // ** to add the tab helper there too if appropriate.
110 Profile* profile =
111 Profile::FromBrowserContext(web_contents->GetBrowserContext());
113 // SessionTabHelper comes first because it sets up the tab ID, and other
114 // helpers may rely on that.
115 SessionTabHelper::CreateForWebContents(web_contents);
117 AlternateErrorPageTabObserver::CreateForWebContents(web_contents);
118 TabAutofillManagerDelegate::CreateForWebContents(web_contents);
119 AutofillDriverImpl::CreateForWebContentsAndDelegate(
120 web_contents,
121 TabAutofillManagerDelegate::FromWebContents(web_contents),
122 g_browser_process->GetApplicationLocale(),
123 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER);
124 BookmarkTabHelper::CreateForWebContents(web_contents);
125 chrome_browser_net::NetErrorTabHelper::CreateForWebContents(web_contents);
126 chrome_browser_net::PredictorTabHelper::CreateForWebContents(web_contents);
127 WebContentsModalDialogManager::CreateForWebContents(web_contents);
128 CoreTabHelper::CreateForWebContents(web_contents);
129 extensions::ExtensionWebContentsObserver::CreateForWebContents(web_contents);
130 extensions::TabHelper::CreateForWebContents(web_contents);
131 extensions::WebNavigationTabObserver::CreateForWebContents(web_contents);
132 ExternalProtocolObserver::CreateForWebContents(web_contents);
133 FaviconTabHelper::CreateForWebContents(web_contents);
134 FindTabHelper::CreateForWebContents(web_contents);
135 HistoryTabHelper::CreateForWebContents(web_contents);
136 HungPluginTabHelper::CreateForWebContents(web_contents);
137 InfoBarService::CreateForWebContents(web_contents);
138 NavigationMetricsRecorder::CreateForWebContents(web_contents);
139 NavigationTimeHelper::CreateForWebContents(web_contents);
140 PasswordGenerationManager::CreateForWebContents(web_contents);
141 PasswordManagerDelegateImpl::CreateForWebContents(web_contents);
142 PasswordManager::CreateForWebContentsAndDelegate(
143 web_contents, PasswordManagerDelegateImpl::FromWebContents(web_contents));
144 PDFTabHelper::CreateForWebContents(web_contents);
145 PluginObserver::CreateForWebContents(web_contents);
146 PopupBlockerTabHelper::CreateForWebContents(web_contents);
147 PrefsTabHelper::CreateForWebContents(web_contents);
148 prerender::PrerenderTabHelper::CreateForWebContentsWithPasswordManager(
149 web_contents, PasswordManager::FromWebContents(web_contents));
150 SadTabHelper::CreateForWebContents(web_contents);
151 safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(web_contents);
152 SearchEngineTabHelper::CreateForWebContents(web_contents);
153 SearchTabHelper::CreateForWebContents(web_contents);
154 SSLTabHelper::CreateForWebContents(web_contents);
155 TabContentsSyncedTabDelegate::CreateForWebContents(web_contents);
156 TabSpecificContentSettings::CreateForWebContents(web_contents);
157 ThumbnailTabHelper::CreateForWebContents(web_contents);
158 TranslateTabHelper::CreateForWebContents(web_contents);
159 ManagePasswordsBubbleUIController::CreateForWebContents(web_contents);
160 ZoomController::CreateForWebContents(web_contents);
162 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
163 captive_portal::CaptivePortalTabHelper::CreateForWebContents(web_contents);
164 #endif
166 if (profile->IsManaged()) {
167 ManagedModeNavigationObserver::CreateForWebContents(web_contents);
170 #if defined(ENABLE_PRINTING)
171 #if defined(ENABLE_FULL_PRINTING)
172 printing::PrintViewManager::CreateForWebContents(web_contents);
173 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
174 #else
175 printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
176 #endif // defined(ENABLE_FULL_PRINTING)
177 #endif // defined(ENABLE_PRINTING)
179 #if defined(ENABLE_ONE_CLICK_SIGNIN)
180 // If this is not an incognito window, setup to handle one-click login.
181 // We don't want to check that the profile is already connected at this time
182 // because the connected state may change while this tab is open. Having a
183 // one-click signin helper attached does not cause problems if the profile
184 // happens to be already connected.
185 if (OneClickSigninHelper::CanOffer(web_contents,
186 OneClickSigninHelper::CAN_OFFER_FOR_ALL,
187 std::string(),
188 NULL)) {
189 OneClickSigninHelper::CreateForWebContentsWithPasswordManager(
190 web_contents, PasswordManager::FromWebContents(web_contents));
192 #endif
194 #if defined(OS_WIN)
195 MetroPinTabHelper::CreateForWebContents(web_contents);
196 #endif