OLD | NEW |
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/ntp/ntp_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" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 prefs::kGoogleServicesUsername); | 129 prefs::kGoogleServicesUsername); |
130 content::WebContents* web_contents = web_ui()->GetWebContents(); | 130 content::WebContents* web_contents = web_ui()->GetWebContents(); |
131 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 131 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
132 if (!browser) | 132 if (!browser) |
133 return; | 133 return; |
134 | 134 |
135 if (username.empty()) { | 135 if (username.empty()) { |
136 #if !defined(OS_ANDROID) | 136 #if !defined(OS_ANDROID) |
137 // The user isn't signed in, show the sync promo. | 137 // The user isn't signed in, show the sync promo. |
138 if (SyncPromoUI::ShouldShowSyncPromo(profile)) { | 138 if (SyncPromoUI::ShouldShowSyncPromo(profile)) { |
139 chrome::ShowSyncSetup(browser, SyncPromoUI::SOURCE_NTP_LINK); | 139 chrome::ShowBrowserSignin(browser, SyncPromoUI::SOURCE_NTP_LINK); |
140 RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED); | 140 RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED); |
141 } | 141 } |
142 #endif | 142 #endif |
143 } else if (args->GetSize() == 4 && | 143 } else if (args->GetSize() == 4 && |
144 chrome::IsCommandEnabled(browser, IDC_SHOW_AVATAR_MENU)) { | 144 chrome::IsCommandEnabled(browser, IDC_SHOW_AVATAR_MENU)) { |
145 // The user is signed in, show the profiles menu. | 145 // The user is signed in, show the profiles menu. |
146 double x = 0; | 146 double x = 0; |
147 double y = 0; | 147 double y = 0; |
148 double width = 0; | 148 double width = 0; |
149 double height = 0; | 149 double height = 0; |
(...skipping 30 matching lines...) Expand all Loading... |
180 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( | 180 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( |
181 prefs::kSyncPromoShowNTPBubble, false); | 181 prefs::kSyncPromoShowNTPBubble, false); |
182 NewTabUI* ntp_ui = NewTabUI::FromWebUIController(web_ui()->GetController()); | 182 NewTabUI* ntp_ui = NewTabUI::FromWebUIController(web_ui()->GetController()); |
183 ntp_ui->set_showing_sync_bubble(true); | 183 ntp_ui->set_showing_sync_bubble(true); |
184 } | 184 } |
185 | 185 |
186 void NTPLoginHandler::HandleShowAdvancedLoginUI(const ListValue* args) { | 186 void NTPLoginHandler::HandleShowAdvancedLoginUI(const ListValue* args) { |
187 Browser* browser = | 187 Browser* browser = |
188 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 188 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
189 if (browser) | 189 if (browser) |
190 chrome::ShowSyncSetup(browser, SyncPromoUI::SOURCE_NTP_LINK); | 190 chrome::ShowBrowserSignin(browser, SyncPromoUI::SOURCE_NTP_LINK); |
191 } | 191 } |
192 | 192 |
193 void NTPLoginHandler::UpdateLogin() { | 193 void NTPLoginHandler::UpdateLogin() { |
194 Profile* profile = Profile::FromWebUI(web_ui()); | 194 Profile* profile = Profile::FromWebUI(web_ui()); |
195 std::string username = profile->GetPrefs()->GetString( | 195 std::string username = profile->GetPrefs()->GetString( |
196 prefs::kGoogleServicesUsername); | 196 prefs::kGoogleServicesUsername); |
197 | 197 |
198 string16 header, sub_header; | 198 string16 header, sub_header; |
199 std::string icon_url; | 199 std::string icon_url; |
200 if (!username.empty()) { | 200 if (!username.empty()) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 header_value, sub_header_value, icon_url_value, is_user_signed_in); | 243 header_value, sub_header_value, icon_url_value, is_user_signed_in); |
244 } | 244 } |
245 | 245 |
246 // static | 246 // static |
247 bool NTPLoginHandler::ShouldShow(Profile* profile) { | 247 bool NTPLoginHandler::ShouldShow(Profile* profile) { |
248 #if defined(OS_CHROMEOS) | 248 #if defined(OS_CHROMEOS) |
249 // For now we don't care about showing sync status on Chrome OS. The promo | 249 // For now we don't care about showing sync status on Chrome OS. The promo |
250 // UI and the avatar menu don't exist on that platform. | 250 // UI and the avatar menu don't exist on that platform. |
251 return false; | 251 return false; |
252 #else | 252 #else |
253 if (profile->IsOffTheRecord()) | 253 return !profile->IsOffTheRecord(); |
254 return false; | |
255 | |
256 return profile->GetOriginalProfile()->IsSyncAccessible(); | |
257 #endif | 254 #endif |
258 } | 255 } |
259 | 256 |
260 // static | 257 // static |
261 void NTPLoginHandler::GetLocalizedValues(Profile* profile, | 258 void NTPLoginHandler::GetLocalizedValues(Profile* profile, |
262 DictionaryValue* values) { | 259 DictionaryValue* values) { |
263 PrefService* prefs = profile->GetPrefs(); | 260 PrefService* prefs = profile->GetPrefs(); |
264 std::string error_message = prefs->GetString(prefs::kSyncPromoErrorMessage); | 261 std::string error_message = prefs->GetString(prefs::kSyncPromoErrorMessage); |
265 bool hide_sync = !prefs->GetBoolean(prefs::kSyncPromoShowNTPBubble); | 262 bool hide_sync = !prefs->GetBoolean(prefs::kSyncPromoShowNTPBubble); |
266 | 263 |
267 string16 message = | 264 string16 message = |
268 hide_sync ? string16() : | 265 hide_sync ? string16() : |
269 !error_message.empty() ? UTF8ToUTF16(error_message) : | 266 !error_message.empty() ? UTF8ToUTF16(error_message) : |
270 l10n_util::GetStringFUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE, | 267 l10n_util::GetStringFUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE, |
271 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | 268 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); |
272 | 269 |
273 values->SetString("login_status_message", message); | 270 values->SetString("login_status_message", message); |
274 values->SetString("login_status_url", | 271 values->SetString("login_status_url", |
275 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); | 272 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); |
276 values->SetString("login_status_advanced", | 273 values->SetString("login_status_advanced", |
277 hide_sync || !error_message.empty() ? string16() : | 274 hide_sync || !error_message.empty() ? string16() : |
278 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); | 275 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); |
279 values->SetString("login_status_dismiss", | 276 values->SetString("login_status_dismiss", |
280 hide_sync ? string16() : | 277 hide_sync ? string16() : |
281 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); | 278 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); |
282 } | 279 } |
OLD | NEW |