Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 if (!username.empty()) { | 179 if (!username.empty()) { |
| 180 ProfileInfoCache& cache = | 180 ProfileInfoCache& cache = |
| 181 g_browser_process->profile_manager()->GetProfileInfoCache(); | 181 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 182 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 182 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 183 if (profile_index != std::string::npos) { | 183 if (profile_index != std::string::npos) { |
| 184 // Only show the profile picture and full name for the single profile | 184 // Only show the profile picture and full name for the single profile |
| 185 // case. In the multi-profile case the profile picture is visible in the | 185 // case. In the multi-profile case the profile picture is visible in the |
| 186 // title bar and the full name can be ambiguous. | 186 // title bar and the full name can be ambiguous. |
| 187 if (cache.GetNumberOfProfiles() == 1) { | 187 if (cache.GetNumberOfProfiles() == 1) { |
| 188 string16 name = cache.GetGAIANameOfProfileAtIndex(profile_index); | 188 string16 name = cache.GetGAIANameOfProfileAtIndex(profile_index); |
| 189 header = ASCIIToUTF16("<span class='profile-name'>") + | 189 header = AddCSSClass(name, "profile-name"); |
| 190 net::EscapeForHTML(name) + | |
| 191 ASCIIToUTF16("</span>"); | |
| 192 const gfx::Image* image = | 190 const gfx::Image* image = |
| 193 cache.GetGAIAPictureOfProfileAtIndex(profile_index); | 191 cache.GetGAIAPictureOfProfileAtIndex(profile_index); |
| 194 if (image) | 192 if (image) |
| 195 icon_url = web_ui_util::GetImageDataUrl(GetGAIAPictureForNTP(*image)); | 193 icon_url = web_ui_util::GetImageDataUrl(GetGAIAPictureForNTP(*image)); |
| 196 } | 194 } |
| 197 if (header.empty()) { | 195 if (header.empty()) { |
| 198 header = UTF8ToUTF16("<span class='profile-name'>" + | 196 header = AddCSSClass(username, "profile-name"); |
| 199 net::EscapeForHTML(username) + "</span>"); | |
| 200 } | 197 } |
| 201 } | 198 } |
| 202 } else if (SyncPromoUI::ShouldShowSyncPromo(profile) && | 199 } else if (SyncPromoUI::ShouldShowSyncPromo(profile) && |
| 203 (SyncPromoUI::UserHasSeenSyncPromoAtStartup(profile) || | 200 (SyncPromoUI::UserHasSeenSyncPromoAtStartup(profile) || |
| 204 PromoResourceService::CanShowNTPSignInPromo(profile))) { | 201 PromoResourceService::CanShowNTPSignInPromo(profile))) { |
| 205 string16 signed_in_link = l10n_util::GetStringUTF16( | 202 string16 signed_in_link = l10n_util::GetStringUTF16( |
| 206 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_LINK); | 203 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_LINK); |
| 207 signed_in_link = ASCIIToUTF16("<span class='link-span'>") + | 204 signed_in_link = AddCSSClass(signed_in_link, "link-span"); |
| 208 net::EscapeForHTML(signed_in_link) + | |
| 209 ASCIIToUTF16("</span>"); | |
| 210 header = l10n_util::GetStringFUTF16( | 205 header = l10n_util::GetStringFUTF16( |
| 211 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_HEADER, | 206 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_HEADER, |
| 212 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | 207 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); |
| 213 sub_header = l10n_util::GetStringFUTF16( | 208 sub_header = l10n_util::GetStringFUTF16( |
| 214 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_SUB_HEADER, signed_in_link); | 209 IDS_SYNC_PROMO_NOT_SIGNED_IN_STATUS_SUB_HEADER, signed_in_link); |
| 215 // Record that the user was shown the promo. | 210 // Record that the user was shown the promo. |
| 216 RecordInHistogram(NTP_SIGN_IN_PROMO_VIEWED); | 211 RecordInHistogram(NTP_SIGN_IN_PROMO_VIEWED); |
| 217 } | 212 } |
| 218 | 213 |
| 219 StringValue header_value(header); | 214 StringValue header_value(header); |
| 220 StringValue sub_header_value(sub_header); | 215 StringValue sub_header_value(sub_header); |
| 221 StringValue icon_url_value(icon_url); | 216 StringValue icon_url_value(icon_url); |
| 222 web_ui_->CallJavascriptFunction( | 217 web_ui_->CallJavascriptFunction( |
| 223 "updateLogin", header_value, sub_header_value, icon_url_value); | 218 "updateLogin", header_value, sub_header_value, icon_url_value); |
| 224 } | 219 } |
| 225 | 220 |
| 221 string16 NTPLoginHandler::AddCSSClass(std::string display_string, | |
|
James Hawkins
2011/12/12 19:09:18
This does not need to be on the NTPLoginHandler cl
James Hawkins
2011/12/12 19:09:18
Need a more descriptive (non-generic) name for the
Tyler Breisacher (Chromium)
2011/12/12 19:15:02
What would be a better class to put this in? Or sh
Tyler Breisacher (Chromium)
2011/12/12 19:15:02
I made two separate functions because "username" a
James Hawkins
2011/12/12 19:18:26
Not all functions need to live on an object, and i
James Hawkins
2011/12/12 19:18:26
UTF8ToUTF16
| |
| 222 std::string css_class) { | |
| 223 return UTF8ToUTF16("<span class='" + css_class + "'>" + | |
| 224 net::EscapeForHTML(display_string) + "</span>"); | |
| 225 } | |
| 226 | |
| 227 string16 NTPLoginHandler::AddCSSClass(string16 display_string, | |
| 228 std::string css_class) { | |
| 229 return UTF8ToUTF16("<span class='" + css_class + "'>") + | |
| 230 net::EscapeForHTML(display_string) + UTF8ToUTF16("</span>"); | |
| 231 } | |
| 232 | |
| 226 // static | 233 // static |
| 227 bool NTPLoginHandler::ShouldShow(Profile* profile) { | 234 bool NTPLoginHandler::ShouldShow(Profile* profile) { |
| 228 #if defined(OS_CHROMEOS) | 235 #if defined(OS_CHROMEOS) |
| 229 // For now we don't care about showing sync status on Chrome OS. The promo | 236 // For now we don't care about showing sync status on Chrome OS. The promo |
| 230 // UI and the avatar menu don't exist on that platform. | 237 // UI and the avatar menu don't exist on that platform. |
| 231 return false; | 238 return false; |
| 232 #else | 239 #else |
| 233 if (profile->IsOffTheRecord()) | 240 if (profile->IsOffTheRecord()) |
| 234 return false; | 241 return false; |
| 235 | 242 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 251 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); | 258 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| 252 values->SetString("login_status_url", | 259 values->SetString("login_status_url", |
| 253 google_util::StringAppendGoogleLocaleParam(chrome::kSyncLearnMoreURL)); | 260 google_util::StringAppendGoogleLocaleParam(chrome::kSyncLearnMoreURL)); |
| 254 values->SetString("login_status_learn_more", | 261 values->SetString("login_status_learn_more", |
| 255 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 262 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 256 values->SetString("login_status_advanced", | 263 values->SetString("login_status_advanced", |
| 257 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); | 264 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); |
| 258 values->SetString("login_status_dismiss", | 265 values->SetString("login_status_dismiss", |
| 259 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); | 266 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); |
| 260 } | 267 } |
| OLD | NEW |