Commit ac198a50 authored by sail@chromium.org's avatar sail@chromium.org

Show GAIA profile info in NTP

Screenshots: http://imgur.com/6owxK

BUG=91241
TEST=

Review URL: http://codereview.chromium.org/8680033

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112876 0039d316-1c4b-4281-b951-d872f2087c98
parent 3e9ef527
...@@ -195,6 +195,17 @@ html[dir='rtl'] #login-container { ...@@ -195,6 +195,17 @@ html[dir='rtl'] #login-container {
right: auto; right: auto;
} }
.login-status-icon {
background-position: right center;
background-repeat: no-repeat;
min-height: 27px;
-webkit-padding-end: 37px;
}
html[dir='rtl'] .login-status-icon {
background-position-x: left;
}
.link-span { .link-span {
text-decoration: underline; text-decoration: underline;
} }
...@@ -211,11 +222,11 @@ html[dir='rtl'] #login-container { ...@@ -211,11 +222,11 @@ html[dir='rtl'] #login-container {
display: inline-block; display: inline-block;
} }
#login-status-action-area { .login-status-row {
display: -webkit-box;
-webkit-box-align: center; -webkit-box-align: center;
-webkit-box-orient: horizontal; -webkit-box-orient: horizontal;
-webkit-box-pack: end; -webkit-box-pack: end;
display: -webkit-box;
} }
#login-status-advanced-container { #login-status-advanced-container {
......
...@@ -65,7 +65,9 @@ ...@@ -65,7 +65,9 @@
<body> <body>
<button id="login-container" class="custom-appearance" hidden> <button id="login-container" class="custom-appearance" hidden>
<div id="login-status-header-container" class="login-status-row">
<div id="login-status-header"></div> <div id="login-status-header"></div>
</div>
<div id="login-status-sub-header"></div> <div id="login-status-sub-header"></div>
</button> </button>
...@@ -125,7 +127,7 @@ ...@@ -125,7 +127,7 @@
<a id="login-status-learn-more" i18n-content="login_status_learn_more" <a id="login-status-learn-more" i18n-content="login_status_learn_more"
target="_blank"></a> target="_blank"></a>
</div> </div>
<div id="login-status-action-area"> <div class="login-status-row">
<div id="login-status-advanced-container"> <div id="login-status-advanced-container">
<a id="login-status-advanced" <a id="login-status-advanced"
i18n-content="login_status_advanced" href="#"></a> i18n-content="login_status_advanced" href="#"></a>
......
...@@ -303,13 +303,24 @@ cr.define('ntp4', function() { ...@@ -303,13 +303,24 @@ cr.define('ntp4', function() {
* the login container is hidden. * the login container is hidden.
* @param {string} loginHeader The first line of text. * @param {string} loginHeader The first line of text.
* @param {string} loginSubHeader The second line of text. * @param {string} loginSubHeader The second line of text.
* @param {string} iconURL The url for the login status icon. If this is null
then the login status icon is hidden.
*/ */
function updateLogin(loginHeader, loginSubHeader) { function updateLogin(loginHeader, loginSubHeader, iconURL) {
if (loginHeader || loginSubHeader) { if (loginHeader || loginSubHeader) {
$('login-container').hidden = false; $('login-container').hidden = false;
$('login-status-header').innerHTML = loginHeader; $('login-status-header').innerHTML = loginHeader;
$('login-status-sub-header').innerHTML = loginSubHeader; $('login-status-sub-header').innerHTML = loginSubHeader;
$('card-slider-frame').classList.add('showing-login-area'); $('card-slider-frame').classList.add('showing-login-area');
if (iconURL) {
$('login-status-header-container').style.backgroundImage = url(iconURL);
$('login-status-header-container').classList.add('login-status-icon');
} else {
$('login-status-header-container').style.backgroundImage = 'none';
$('login-status-header-container').classList.remove(
'login-status-icon');
}
} else { } else {
$('login-container').hidden = true; $('login-container').hidden = true;
$('card-slider-frame').classList.remove('showing-login-area'); $('card-slider-frame').classList.remove('showing-login-area');
...@@ -318,6 +329,8 @@ cr.define('ntp4', function() { ...@@ -318,6 +329,8 @@ cr.define('ntp4', function() {
window.setTimeout(loginBubble.show.bind(loginBubble), 0); window.setTimeout(loginBubble.show.bind(loginBubble), 0);
chrome.send('loginMessageSeen'); chrome.send('loginMessageSeen');
shouldShowLoginBubble = false; shouldShowLoginBubble = false;
} else if (loginBubble) {
loginBubble.reposition();
} }
} }
......
...@@ -11,10 +11,13 @@ ...@@ -11,10 +11,13 @@
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/google/google_util.h" #include "chrome/browser/google/google_util.h"
#include "chrome/browser/prefs/pref_notifier.h" #include "chrome/browser/prefs/pref_notifier.h"
#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.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/profiles/profile_metrics.h"
#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/sync_setup_flow.h" #include "chrome/browser/sync/sync_setup_flow.h"
...@@ -23,15 +26,41 @@ ...@@ -23,15 +26,41 @@
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.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/sync_promo_ui.h"
#include "chrome/browser/ui/webui/web_ui_util.h"
#include "chrome/browser/web_resource/promo_resource_service.h" #include "chrome/browser/web_resource/promo_resource_service.h"
#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "grit/chromium_strings.h" #include "grit/chromium_strings.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "skia/ext/image_operations.h"
#include "ui/base/l10n/l10n_util.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() { NTPLoginHandler::NTPLoginHandler() {
} }
...@@ -43,6 +72,9 @@ WebUIMessageHandler* NTPLoginHandler::Attach(WebUI* web_ui) { ...@@ -43,6 +72,9 @@ WebUIMessageHandler* NTPLoginHandler::Attach(WebUI* web_ui) {
PrefService* pref_service = Profile::FromWebUI(web_ui)->GetPrefs(); PrefService* pref_service = Profile::FromWebUI(web_ui)->GetPrefs();
username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); 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); return WebUIMessageHandler::Attach(web_ui);
} }
...@@ -64,10 +96,15 @@ void NTPLoginHandler::RegisterMessages() { ...@@ -64,10 +96,15 @@ void NTPLoginHandler::RegisterMessages() {
void NTPLoginHandler::Observe(int type, void NTPLoginHandler::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); 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(); std::string* name = content::Details<std::string>(details).ptr();
if (prefs::kGoogleServicesUsername == *name) if (prefs::kGoogleServicesUsername == *name)
UpdateLogin(); UpdateLogin();
} else {
NOTREACHED();
}
} }
void NTPLoginHandler::HandleInitializeSyncLogin(const ListValue* args) { void NTPLoginHandler::HandleInitializeSyncLogin(const ListValue* args) {
...@@ -137,8 +174,25 @@ void NTPLoginHandler::UpdateLogin() { ...@@ -137,8 +174,25 @@ void NTPLoginHandler::UpdateLogin() {
prefs::kGoogleServicesUsername); prefs::kGoogleServicesUsername);
string16 header, sub_header; string16 header, sub_header;
std::string icon_url;
if (!username.empty()) { if (!username.empty()) {
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); header = UTF8ToUTF16(username);
}
} else if (SyncPromoUI::ShouldShowSyncPromo(profile) && } else if (SyncPromoUI::ShouldShowSyncPromo(profile) &&
(SyncPromoUI::UserHasSeenSyncPromoAtStartup(profile) || (SyncPromoUI::UserHasSeenSyncPromoAtStartup(profile) ||
PromoResourceService::CanShowNTPSignInPromo(profile))) { PromoResourceService::CanShowNTPSignInPromo(profile))) {
...@@ -157,8 +211,9 @@ void NTPLoginHandler::UpdateLogin() { ...@@ -157,8 +211,9 @@ void NTPLoginHandler::UpdateLogin() {
StringValue header_value(header); StringValue header_value(header);
StringValue sub_header_value(sub_header); StringValue sub_header_value(sub_header);
StringValue icon_url_value(icon_url);
web_ui_->CallJavascriptFunction( web_ui_->CallJavascriptFunction(
"updateLogin", header_value, sub_header_value); "updateLogin", header_value, sub_header_value, icon_url_value);
} }
// static // static
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/prefs/pref_member.h"
#include "content/browser/webui/web_ui.h" #include "content/browser/webui/web_ui.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class Profile; class Profile;
...@@ -71,6 +72,7 @@ class NTPLoginHandler : public WebUIMessageHandler, ...@@ -71,6 +72,7 @@ class NTPLoginHandler : public WebUIMessageHandler,
void UpdateLogin(); void UpdateLogin();
StringPrefMember username_pref_; StringPrefMember username_pref_;
content::NotificationRegistrar registrar_;
}; };
#endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_LOGIN_HANDLER_H_ #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_LOGIN_HANDLER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment