Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: chrome/browser/ui/webui/app_launcher_login_handler.cc

Issue 1143963002: Split NTPLoginHandler across chrome://apps and chrome://history. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gyp fixes Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" 5 #include "chrome/browser/ui/webui/app_launcher_login_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/prefs/pref_notifier.h"
13 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 14 #include "base/values.h"
16 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_info_cache.h" 17 #include "chrome/browser/profiles/profile_info_cache.h"
19 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/profiles/profile_metrics.h" 19 #include "chrome/browser/profiles/profile_metrics.h"
21 #include "chrome/browser/signin/signin_manager_factory.h" 20 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chrome/browser/signin/signin_promo.h" 21 #include "chrome/browser/signin/signin_promo.h"
23 #include "chrome/browser/sync/profile_sync_service.h" 22 #include "chrome/browser/sync/profile_sync_service.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 23 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_finder.h" 25 #include "chrome/browser/ui/browser_finder.h"
27 #include "chrome/browser/ui/browser_window.h" 26 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/chrome_pages.h" 27 #include "chrome/browser/ui/chrome_pages.h"
29 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 28 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
29 #include "chrome/browser/ui/webui/profile_info_watcher.h"
30 #include "chrome/browser/web_resource/promo_resource_service.h" 30 #include "chrome/browser/web_resource/promo_resource_service.h"
31 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
32 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
33 #include "chrome/grit/chromium_strings.h" 33 #include "chrome/grit/chromium_strings.h"
34 #include "chrome/grit/generated_resources.h" 34 #include "chrome/grit/generated_resources.h"
35 #include "components/signin/core/browser/signin_manager.h" 35 #include "components/signin/core/browser/signin_manager.h"
36 #include "content/public/browser/host_zoom_map.h" 36 #include "content/public/browser/host_zoom_map.h"
37 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
38 #include "content/public/browser/web_ui.h" 38 #include "content/public/browser/web_ui.h"
39 #include "content/public/common/page_zoom.h" 39 #include "content/public/common/page_zoom.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 const std::string& css_class, 72 const std::string& css_class,
73 const std::string& extends_tag) { 73 const std::string& extends_tag) {
74 base::string16 start_tag = base::ASCIIToUTF16("<" + tag_name + 74 base::string16 start_tag = base::ASCIIToUTF16("<" + tag_name +
75 " class='" + css_class + "' is='" + extends_tag + "'>"); 75 " class='" + css_class + "' is='" + extends_tag + "'>");
76 base::string16 end_tag = base::ASCIIToUTF16("</" + tag_name + ">"); 76 base::string16 end_tag = base::ASCIIToUTF16("</" + tag_name + ">");
77 return start_tag + net::EscapeForHTML(content) + end_tag; 77 return start_tag + net::EscapeForHTML(content) + end_tag;
78 } 78 }
79 79
80 } // namespace 80 } // namespace
81 81
82 NTPLoginHandler::NTPLoginHandler() { 82 AppLauncherLoginHandler::AppLauncherLoginHandler() {}
83 }
84 83
85 NTPLoginHandler::~NTPLoginHandler() { 84 AppLauncherLoginHandler::~AppLauncherLoginHandler() {}
86 ProfileManager* profile_manager = g_browser_process->profile_manager();
87 // The profile_manager might be NULL in testing environments.
88 if (profile_manager)
89 profile_manager->GetProfileInfoCache().RemoveObserver(this);
90 }
91 85
92 void NTPLoginHandler::RegisterMessages() { 86 void AppLauncherLoginHandler::RegisterMessages() {
93 ProfileManager* profile_manager = g_browser_process->profile_manager(); 87 profile_info_watcher_.reset(new ProfileInfoWatcher(
94 // The profile_manager might be NULL in testing environments. 88 Profile::FromWebUI(web_ui()),
95 if (profile_manager) 89 base::Bind(&AppLauncherLoginHandler::UpdateLogin,
96 profile_manager->GetProfileInfoCache().AddObserver(this); 90 base::Unretained(this))));
97
98 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
99 signin_allowed_pref_.Init(prefs::kSigninAllowed,
100 pref_service,
101 base::Bind(&NTPLoginHandler::UpdateLogin,
102 base::Unretained(this)));
103 91
104 web_ui()->RegisterMessageCallback("initializeSyncLogin", 92 web_ui()->RegisterMessageCallback("initializeSyncLogin",
105 base::Bind(&NTPLoginHandler::HandleInitializeSyncLogin, 93 base::Bind(&AppLauncherLoginHandler::HandleInitializeSyncLogin,
106 base::Unretained(this))); 94 base::Unretained(this)));
107 web_ui()->RegisterMessageCallback("showSyncLoginUI", 95 web_ui()->RegisterMessageCallback("showSyncLoginUI",
108 base::Bind(&NTPLoginHandler::HandleShowSyncLoginUI, 96 base::Bind(&AppLauncherLoginHandler::HandleShowSyncLoginUI,
109 base::Unretained(this))); 97 base::Unretained(this)));
110 web_ui()->RegisterMessageCallback("loginMessageSeen", 98 web_ui()->RegisterMessageCallback("loginMessageSeen",
111 base::Bind(&NTPLoginHandler::HandleLoginMessageSeen, 99 base::Bind(&AppLauncherLoginHandler::HandleLoginMessageSeen,
112 base::Unretained(this))); 100 base::Unretained(this)));
113 web_ui()->RegisterMessageCallback("showAdvancedLoginUI", 101 web_ui()->RegisterMessageCallback("showAdvancedLoginUI",
114 base::Bind(&NTPLoginHandler::HandleShowAdvancedLoginUI, 102 base::Bind(&AppLauncherLoginHandler::HandleShowAdvancedLoginUI,
115 base::Unretained(this))); 103 base::Unretained(this)));
116 } 104 }
117 105
118 void NTPLoginHandler::OnProfileAuthInfoChanged( 106 void AppLauncherLoginHandler::HandleInitializeSyncLogin(
119 const base::FilePath& profile_path) { 107 const base::ListValue* args) {
120 UpdateLogin(); 108 UpdateLogin();
121 } 109 }
122 110
123 void NTPLoginHandler::HandleInitializeSyncLogin(const base::ListValue* args) { 111 void AppLauncherLoginHandler::HandleShowSyncLoginUI(
124 UpdateLogin(); 112 const base::ListValue* args) {
125 }
126
127 void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) {
128 Profile* profile = Profile::FromWebUI(web_ui()); 113 Profile* profile = Profile::FromWebUI(web_ui());
129 if (!signin::ShouldShowPromo(profile)) 114 if (!signin::ShouldShowPromo(profile))
130 return; 115 return;
131 116
132 std::string username = 117 std::string username =
133 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); 118 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername();
134 if (!username.empty()) 119 if (!username.empty())
135 return; 120 return;
136 121
137 content::WebContents* web_contents = web_ui()->GetWebContents(); 122 content::WebContents* web_contents = web_ui()->GetWebContents();
138 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 123 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
139 if (!browser) 124 if (!browser)
140 return; 125 return;
141 126
142 // The user isn't signed in, show the sign in promo. 127 // The user isn't signed in, show the sign in promo.
143 signin_metrics::Source source = 128 signin_metrics::Source source =
144 web_contents->GetURL().spec() == chrome::kChromeUIAppsURL ? 129 web_contents->GetURL().spec() == chrome::kChromeUIAppsURL ?
145 signin_metrics::SOURCE_APPS_PAGE_LINK : 130 signin_metrics::SOURCE_APPS_PAGE_LINK :
146 signin_metrics::SOURCE_NTP_LINK; 131 signin_metrics::SOURCE_NTP_LINK;
147 chrome::ShowBrowserSignin(browser, source); 132 chrome::ShowBrowserSignin(browser, source);
148 RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED); 133 RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED);
149 } 134 }
150 135
151 void NTPLoginHandler::RecordInHistogram(int type) { 136 void AppLauncherLoginHandler::RecordInHistogram(int type) {
152 // Invalid type to record. 137 // Invalid type to record.
153 if (type < NTP_SIGN_IN_PROMO_VIEWED || 138 if (type < NTP_SIGN_IN_PROMO_VIEWED ||
154 type > NTP_SIGN_IN_PROMO_CLICKED) { 139 type > NTP_SIGN_IN_PROMO_CLICKED) {
155 NOTREACHED(); 140 NOTREACHED();
156 } else { 141 } else {
157 UMA_HISTOGRAM_ENUMERATION("SyncPromo.NTPPromo", type, 142 UMA_HISTOGRAM_ENUMERATION("SyncPromo.NTPPromo", type,
158 NTP_SIGN_IN_PROMO_BUCKET_BOUNDARY); 143 NTP_SIGN_IN_PROMO_BUCKET_BOUNDARY);
159 } 144 }
160 } 145 }
161 146
162 void NTPLoginHandler::HandleLoginMessageSeen(const base::ListValue* args) { 147 void AppLauncherLoginHandler::HandleLoginMessageSeen(
148 const base::ListValue* args) {
163 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( 149 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean(
164 prefs::kSignInPromoShowNTPBubble, false); 150 prefs::kSignInPromoShowNTPBubble, false);
165 NewTabUI* ntp_ui = NewTabUI::FromWebUIController(web_ui()->GetController()); 151 NewTabUI* ntp_ui = NewTabUI::FromWebUIController(web_ui()->GetController());
166 // When instant extended is enabled, there may not be a NewTabUI object. 152 // When instant extended is enabled, there may not be a NewTabUI object.
167 if (ntp_ui) 153 if (ntp_ui)
168 ntp_ui->set_showing_sync_bubble(true); 154 ntp_ui->set_showing_sync_bubble(true);
169 } 155 }
170 156
171 void NTPLoginHandler::HandleShowAdvancedLoginUI(const base::ListValue* args) { 157 void AppLauncherLoginHandler::HandleShowAdvancedLoginUI(
158 const base::ListValue* args) {
172 Browser* browser = 159 Browser* browser =
173 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); 160 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
174 if (browser) 161 if (browser)
175 chrome::ShowBrowserSignin(browser, signin_metrics::SOURCE_NTP_LINK); 162 chrome::ShowBrowserSignin(browser, signin_metrics::SOURCE_NTP_LINK);
176 } 163 }
177 164
178 void NTPLoginHandler::UpdateLogin() { 165 void AppLauncherLoginHandler::UpdateLogin() {
179 Profile* profile = Profile::FromWebUI(web_ui()); 166 std::string username = profile_info_watcher_->GetAuthenticatedUsername();
180 SigninManagerBase* signin_manager =
181 SigninManagerFactory::GetForProfile(profile);
182 if (!signin_manager) {
183 // Guests on desktop do not have a signin manager.
184 return;
185 }
186
187 std::string username = signin_manager->GetAuthenticatedUsername();
188
189 base::string16 header, sub_header; 167 base::string16 header, sub_header;
190 std::string icon_url; 168 std::string icon_url;
169 Profile* profile = Profile::FromWebUI(web_ui());
191 if (!username.empty()) { 170 if (!username.empty()) {
192 ProfileInfoCache& cache = 171 ProfileInfoCache& cache =
193 g_browser_process->profile_manager()->GetProfileInfoCache(); 172 g_browser_process->profile_manager()->GetProfileInfoCache();
194 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 173 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
195 if (profile_index != std::string::npos) { 174 if (profile_index != std::string::npos) {
196 // Only show the profile picture and full name for the single profile 175 // Only show the profile picture and full name for the single profile
197 // case. In the multi-profile case the profile picture is visible in the 176 // case. In the multi-profile case the profile picture is visible in the
198 // title bar and the full name can be ambiguous. 177 // title bar and the full name can be ambiguous.
199 if (cache.GetNumberOfProfiles() == 1) { 178 if (cache.GetNumberOfProfiles() == 1) {
200 base::string16 name = cache.GetGAIANameOfProfileAtIndex(profile_index); 179 base::string16 name = cache.GetGAIANameOfProfileAtIndex(profile_index);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 212
234 base::StringValue header_value(header); 213 base::StringValue header_value(header);
235 base::StringValue sub_header_value(sub_header); 214 base::StringValue sub_header_value(sub_header);
236 base::StringValue icon_url_value(icon_url); 215 base::StringValue icon_url_value(icon_url);
237 base::FundamentalValue is_user_signed_in(!username.empty()); 216 base::FundamentalValue is_user_signed_in(!username.empty());
238 web_ui()->CallJavascriptFunction("ntp.updateLogin", 217 web_ui()->CallJavascriptFunction("ntp.updateLogin",
239 header_value, sub_header_value, icon_url_value, is_user_signed_in); 218 header_value, sub_header_value, icon_url_value, is_user_signed_in);
240 } 219 }
241 220
242 // static 221 // static
243 bool NTPLoginHandler::ShouldShow(Profile* profile) { 222 bool AppLauncherLoginHandler::ShouldShow(Profile* profile) {
244 #if defined(OS_CHROMEOS) 223 #if defined(OS_CHROMEOS)
245 // For now we don't care about showing sync status on Chrome OS. The promo 224 // For now we don't care about showing sync status on Chrome OS. The promo
246 // UI and the avatar menu don't exist on that platform. 225 // UI and the avatar menu don't exist on that platform.
247 return false; 226 return false;
248 #else 227 #else
249 SigninManager* signin = SigninManagerFactory::GetForProfile(profile); 228 SigninManager* signin = SigninManagerFactory::GetForProfile(profile);
250 return !profile->IsOffTheRecord() && signin && signin->IsSigninAllowed(); 229 return !profile->IsOffTheRecord() && signin && signin->IsSigninAllowed();
251 #endif 230 #endif
252 } 231 }
253 232
254 // static 233 // static
255 void NTPLoginHandler::GetLocalizedValues(Profile* profile, 234 void AppLauncherLoginHandler::GetLocalizedValues(
256 base::DictionaryValue* values) { 235 Profile* profile, base::DictionaryValue* values) {
257 PrefService* prefs = profile->GetPrefs(); 236 PrefService* prefs = profile->GetPrefs();
258 bool hide_sync = !prefs->GetBoolean(prefs::kSignInPromoShowNTPBubble); 237 bool hide_sync = !prefs->GetBoolean(prefs::kSignInPromoShowNTPBubble);
259 238
260 base::string16 message = hide_sync ? base::string16() : 239 base::string16 message = hide_sync ? base::string16() :
261 l10n_util::GetStringFUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE, 240 l10n_util::GetStringFUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE,
262 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); 241 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
263 242
264 values->SetString("login_status_message", message); 243 values->SetString("login_status_message", message);
265 values->SetString("login_status_url", 244 values->SetString("login_status_url",
266 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); 245 hide_sync ? std::string() : chrome::kSyncLearnMoreURL);
267 values->SetString("login_status_advanced", 246 values->SetString("login_status_advanced",
268 hide_sync ? base::string16() : 247 hide_sync ? base::string16() :
269 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); 248 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED));
270 values->SetString("login_status_dismiss", 249 values->SetString("login_status_dismiss",
271 hide_sync ? base::string16() : 250 hide_sync ? base::string16() :
272 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); 251 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK));
273 } 252 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/app_launcher_login_handler.h ('k') | chrome/browser/ui/webui/app_launcher_page_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698