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

Unified Diff: chrome/browser/ui/webui/ntp/ntp_login_handler.cc

Issue 8680033: Show GAIA profile info in NTP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove logging Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_login_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/ntp/ntp_login_handler.cc
diff --git a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc
index c1a007f96bd88c352c32a60631d396d6e684ff00..dc7f087bd1a15199124028eac77cb0486d5d65d5 100644
--- a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc
+++ b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc
@@ -11,10 +11,13 @@
#include "base/metrics/histogram.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/prefs/pref_notifier.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_info_cache.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/sync_setup_flow.h"
@@ -23,15 +26,41 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/webui/sync_promo_ui.h"
+#include "chrome/browser/ui/webui/web_ui_util.h"
#include "chrome/browser/web_resource/promo_resource_service.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
+#include "skia/ext/image_operations.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/gfx/canvas_skia.h"
+#include "ui/gfx/image/image.h"
+
+namespace {
+
+SkBitmap GetGAIAPictureForNTP(const gfx::Image& image) {
+ // This value must match the width and height value of login-status-icon
+ // in new_tab.css.
+ const int length = 27;
+ SkBitmap bmp = skia::ImageOperations::Resize(
+ image, skia::ImageOperations::RESIZE_BEST, length, length);
+
+ gfx::CanvasSkia canvas(length, length, false);
+ canvas.DrawBitmapInt(bmp, 0, 0);
+
+ // Draw a gray border on the inside of the icon.
+ SkColor color = SkColorSetARGB(83, 0, 0, 0);
+ canvas.DrawRectInt(color, 0, 0, length - 1, length - 1);
+
+ return canvas.ExtractBitmap();
+}
+
+} // namespace
NTPLoginHandler::NTPLoginHandler() {
}
@@ -43,6 +72,9 @@ WebUIMessageHandler* NTPLoginHandler::Attach(WebUI* web_ui) {
PrefService* pref_service = Profile::FromWebUI(web_ui)->GetPrefs();
username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this);
+ registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
+ content::NotificationService::AllSources());
+
return WebUIMessageHandler::Attach(web_ui);
}
@@ -64,10 +96,15 @@ void NTPLoginHandler::RegisterMessages() {
void NTPLoginHandler::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED);
- std::string* name = content::Details<std::string>(details).ptr();
- if (prefs::kGoogleServicesUsername == *name)
+ if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) {
UpdateLogin();
+ } else if (type == chrome::NOTIFICATION_PREF_CHANGED) {
+ std::string* name = content::Details<std::string>(details).ptr();
+ if (prefs::kGoogleServicesUsername == *name)
+ UpdateLogin();
+ } else {
+ NOTREACHED();
+ }
}
void NTPLoginHandler::HandleInitializeSyncLogin(const ListValue* args) {
@@ -137,8 +174,25 @@ void NTPLoginHandler::UpdateLogin() {
prefs::kGoogleServicesUsername);
string16 header, sub_header;
+ std::string icon_url;
if (!username.empty()) {
- header = UTF8ToUTF16(username);
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
+ if (profile_index != std::string::npos) {
+ // Only show the profile picture and full name for the single profile
+ // case. In the multi-profile case the profile picture is visible in the
+ // title bar and the full name can be ambiguous.
+ if (cache.GetNumberOfProfiles() == 1) {
+ header = cache.GetGAIANameOfProfileAtIndex(profile_index);
+ const gfx::Image* image =
+ cache.GetGAIAPictureOfProfileAtIndex(profile_index);
+ if (image)
+ icon_url = web_ui_util::GetImageDataUrl(GetGAIAPictureForNTP(*image));
+ }
+ if (header.empty())
+ header = UTF8ToUTF16(username);
+ }
} else if (SyncPromoUI::ShouldShowSyncPromo(profile) &&
(SyncPromoUI::UserHasSeenSyncPromoAtStartup(profile) ||
PromoResourceService::CanShowNTPSignInPromo(profile))) {
@@ -157,8 +211,9 @@ void NTPLoginHandler::UpdateLogin() {
StringValue header_value(header);
StringValue sub_header_value(sub_header);
+ StringValue icon_url_value(icon_url);
web_ui_->CallJavascriptFunction(
- "updateLogin", header_value, sub_header_value);
+ "updateLogin", header_value, sub_header_value, icon_url_value);
}
// static
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_login_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698