diff options
author | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-18 16:37:04 +0000 |
---|---|---|
committer | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-18 16:37:04 +0000 |
commit | 61334a489141172f4ac76d12395e62fa3a3e20e4 (patch) | |
tree | 153d0759271bd4e712b5092b9e746f6fbc3bd2ba /chrome | |
parent | 92b533a37663e7f11b8150b70f8c70814a3ef402 (diff) | |
download | chromium_src-61334a489141172f4ac76d12395e62fa3a3e20e4.zip chromium_src-61334a489141172f4ac76d12395e62fa3a3e20e4.tar.gz chromium_src-61334a489141172f4ac76d12395e62fa3a3e20e4.tar.bz2 |
Show the current logged-in username on the NTP.
BUG=58024
TEST=included, for manual test sign into sync then go to NTP
Review URL: http://codereview.chromium.org/3784004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62933 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui_uitest.cc | 32 | ||||
-rw-r--r-- | chrome/browser/dom_ui/ntp_login_handler.cc | 55 | ||||
-rw-r--r-- | chrome/browser/dom_ui/ntp_login_handler.h | 42 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.css | 9 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.html | 8 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.js | 13 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 |
8 files changed, 163 insertions, 0 deletions
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index e5b5a12..b7471b7 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -24,6 +24,7 @@ #include "chrome/browser/dom_ui/foreign_session_handler.h" #include "chrome/browser/dom_ui/most_visited_handler.h" #include "chrome/browser/dom_ui/new_tab_page_sync_handler.h" +#include "chrome/browser/dom_ui/ntp_login_handler.h" #include "chrome/browser/dom_ui/ntp_resource_cache.h" #include "chrome/browser/dom_ui/shown_sections_handler.h" #include "chrome/browser/dom_ui/tips_handler.h" @@ -433,6 +434,7 @@ NewTabUI::NewTabUI(TabContents* contents) if (!GetProfile()->IsOffTheRecord()) { PrefService* pref_service = GetProfile()->GetPrefs(); + AddMessageHandler((new NTPLoginHandler())->Attach(this)); AddMessageHandler((new ShownSectionsHandler(pref_service))->Attach(this)); AddMessageHandler((new browser_sync::ForeignSessionHandler())-> Attach(this)); diff --git a/chrome/browser/dom_ui/new_tab_ui_uitest.cc b/chrome/browser/dom_ui/new_tab_ui_uitest.cc index cfa5644..7222405 100644 --- a/chrome/browser/dom_ui/new_tab_ui_uitest.cc +++ b/chrome/browser/dom_ui/new_tab_ui_uitest.cc @@ -8,6 +8,7 @@ #include "chrome/browser/browser_thread.h" #include "chrome/browser/dom_ui/new_tab_ui.h" #include "chrome/browser/prefs/pref_value_store.h" +#include "chrome/browser/sync/signin_manager.h" #include "chrome/common/json_pref_store.h" #include "chrome/common/pref_names.h" #include "chrome/test/automation/browser_proxy.h" @@ -51,6 +52,37 @@ TEST_F(NewTabUITest, NTPHasThumbnails) { action_max_timeout_ms())); } +TEST_F(NewTabUITest, NTPHasLoginName) { + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(window.get()); + + ASSERT_TRUE(window->SetStringPreference(prefs::kGoogleServicesUsername, + "user@gmail.com")); + // Bring up a new tab page. + ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB)); + int load_time; + ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time)); + + scoped_refptr<TabProxy> tab = window->GetActiveTab(); + ASSERT_TRUE(tab.get()); + + std::wstring displayed_username; + // The login span should be eventually populated and have the + // correct value. + ASSERT_TRUE(WaitUntilJavaScriptCondition(tab, L"", + L"window.domAutomationController.send(" + L"document.getElementById('login-username').innerText.length > 0)", + action_max_timeout_ms())); + + ASSERT_TRUE(tab->ExecuteAndExtractString( + L"", + L"window.domAutomationController.send(" + L"document.getElementById('login-username').innerText)", + &displayed_username)); + + EXPECT_EQ(L"user@gmail.com", displayed_username); +} + // Fails about ~5% of the time on all platforms. http://crbug.com/45001 TEST_F(NewTabUITest, FLAKY_ChromeInternalLoadsNTP) { scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); diff --git a/chrome/browser/dom_ui/ntp_login_handler.cc b/chrome/browser/dom_ui/ntp_login_handler.cc new file mode 100644 index 0000000..b250dd9 --- /dev/null +++ b/chrome/browser/dom_ui/ntp_login_handler.cc @@ -0,0 +1,55 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/dom_ui/ntp_login_handler.h" + +#include <string> + +#include "base/values.h" +#include "chrome/browser/dom_ui/dom_ui_util.h" +#include "chrome/browser/prefs/pref_notifier.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/browser/sync/sync_setup_flow.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/notification_details.h" + +NTPLoginHandler::NTPLoginHandler() { +} + +NTPLoginHandler::~NTPLoginHandler() { +} + +DOMMessageHandler* NTPLoginHandler::Attach(DOMUI* dom_ui) { + PrefService* pref_service = dom_ui->GetProfile()->GetPrefs(); + username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); + + return DOMMessageHandler::Attach(dom_ui); +} + +void NTPLoginHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("initializeLogin", + NewCallback(this, &NTPLoginHandler::HandleInitializeLogin)); +} + +void NTPLoginHandler::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::PREF_CHANGED); + std::string* name = Details<std::string>(details).ptr(); + if (prefs::kGoogleServicesUsername == *name) + UpdateLogin(); +} + +void NTPLoginHandler::HandleInitializeLogin(const ListValue* args) { + UpdateLogin(); +} + +void NTPLoginHandler::UpdateLogin() { + std::string username = dom_ui_->GetProfile()->GetPrefs()->GetString( + prefs::kGoogleServicesUsername); + StringValue string_value(username); + dom_ui_->CallJavascriptFunction(L"updateLogin", string_value); +} diff --git a/chrome/browser/dom_ui/ntp_login_handler.h b/chrome/browser/dom_ui/ntp_login_handler.h new file mode 100644 index 0000000..d6eabfe --- /dev/null +++ b/chrome/browser/dom_ui/ntp_login_handler.h @@ -0,0 +1,42 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_DOM_UI_NTP_LOGIN_HANDLER_H_ +#define CHROME_BROWSER_DOM_UI_NTP_LOGIN_HANDLER_H_ +#pragma once + +#include "chrome/browser/dom_ui/dom_ui.h" +#include "chrome/browser/prefs/pref_member.h" +#include "chrome/common/notification_observer.h" + +// The NTP login handler currently simply displays the current logged in +// username at the top of the NTP (and update itself when that changes). +// In the future it may expand to allow users to login from the NTP. +class NTPLoginHandler : public DOMMessageHandler, + public NotificationObserver { + public: + NTPLoginHandler(); + ~NTPLoginHandler(); + + virtual DOMMessageHandler* Attach(DOMUI* dom_ui); + + // DOMMessageHandler interface + virtual void RegisterMessages(); + + // NotificationObserver interface + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + private: + // Called from JS when the NTP is loaded. + void HandleInitializeLogin(const ListValue* args); + + // Internal helper method + void UpdateLogin(); + + StringPrefMember username_pref_; +}; + +#endif // CHROME_BROWSER_DOM_UI_NTP_LOGIN_HANDLER_H_ diff --git a/chrome/browser/resources/new_new_tab.css b/chrome/browser/resources/new_new_tab.css index 96a742b..9d271ec 100644 --- a/chrome/browser/resources/new_new_tab.css +++ b/chrome/browser/resources/new_new_tab.css @@ -29,6 +29,7 @@ body.loading #main { } #main, +#login-container, .section, .maxiview { width: 920px; @@ -279,6 +280,14 @@ html[anim=true][enable-section-animations=true] .section { -webkit-transition: top .15s; } +#login-container { + position: relative; +} +#login { + position: absolute; + right: 0; +} + .section.disabled, #closed-sections-bar .disabled { display: none !important; diff --git a/chrome/browser/resources/new_new_tab.html b/chrome/browser/resources/new_new_tab.html index e0f799e..fa4b320 100644 --- a/chrome/browser/resources/new_new_tab.html +++ b/chrome/browser/resources/new_new_tab.html @@ -131,6 +131,12 @@ if ('mode' in hashParams) { <span class="link"><span class="link-color"></span></span> </div> + <div class="login-container" id="login-container"> + <div id="login"> + <span id="login-username"></span> + </div> + </div> + <div class="maxiview" id="apps-maxiview"> <div id="apps-promo"> <button id="apps-promo-hide" i18n-content="appspromohide"></button> @@ -267,6 +273,8 @@ cr.ui.decorate('button[menu]', cr.ui.MenuButton); </script> <script> + initializeLogin(); + initializeSection('apps', MINIMIZED_APPS, Section.APPS); initializeSection('most-visited', MINIMIZED_THUMB, Section.THUMB); initializeSection('recently-closed', MINIMIZED_RECENT); diff --git a/chrome/browser/resources/new_new_tab.js b/chrome/browser/resources/new_new_tab.js index 0a577d4..3a3efc5 100644 --- a/chrome/browser/resources/new_new_tab.js +++ b/chrome/browser/resources/new_new_tab.js @@ -1059,6 +1059,19 @@ function fixLinkUnderline(el) { updateAttribution(); +function initializeLogin() { + chrome.send('initializeLogin', []); +} + +function updateLogin(login) { + if (login) { + document.getElementById("login-username").innerText = login; + document.getElementById("login").style.display = 'block'; + } else { + document.getElementById("login").style.display = 'none'; + } +} + var mostVisited = new MostVisited( $('most-visited-maxiview'), document.querySelector('#most-visited .miniview'), diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 9001013..3f5875ca 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1313,6 +1313,8 @@ 'browser/dom_ui/new_tab_page_sync_handler.h', 'browser/dom_ui/new_tab_ui.cc', 'browser/dom_ui/new_tab_ui.h', + 'browser/dom_ui/ntp_login_handler.cc', + 'browser/dom_ui/ntp_login_handler.h', 'browser/dom_ui/ntp_resource_cache.cc', 'browser/dom_ui/ntp_resource_cache.h', 'browser/dom_ui/plugins_ui.cc', |