diff options
author | tengs@chromium.org <tengs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-13 13:57:16 +0000 |
---|---|---|
committer | tengs@chromium.org <tengs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-13 13:57:16 +0000 |
commit | c5dae7d2d9d70d023f06a7734033c11ba96dfcc8 (patch) | |
tree | 5d12486b7212e4ac851d07e60096dd2ec2836ef5 | |
parent | e659257b9e3665d2faeb73b261116c356a6f54ca (diff) | |
download | chromium_src-c5dae7d2d9d70d023f06a7734033c11ba96dfcc8.zip chromium_src-c5dae7d2d9d70d023f06a7734033c11ba96dfcc8.tar.gz chromium_src-c5dae7d2d9d70d023f06a7734033c11ba96dfcc8.tar.bz2 |
Add a custom button to user pods on the login/lock screen.
This button is beside the password field and is shown through the
chrome.screenlockPrivate API.
BUG=320156
TEST=manual
Review URL: https://codereview.chromium.org/111013004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240626 0039d316-1c4b-4281-b951-d872f2087c98
24 files changed, 406 insertions, 9 deletions
diff --git a/chrome/browser/chromeos/login/login_display.h b/chrome/browser/chromeos/login/login_display.h index dff5b4a..6958bf8 100644 --- a/chrome/browser/chromeos/login/login_display.h +++ b/chrome/browser/chromeos/login/login_display.h @@ -8,11 +8,13 @@ #include <string> #include <vector> +#include "base/callback.h" #include "base/strings/string16.h" #include "chrome/browser/chromeos/login/help_app_launcher.h" #include "chrome/browser/chromeos/login/remove_user_delegate.h" #include "chrome/browser/chromeos/login/user.h" #include "chrome/browser/chromeos/login/user_manager.h" +#include "ui/gfx/image/image.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" @@ -146,6 +148,11 @@ class LoginDisplay : public RemoveUserDelegate { // Displays a banner on the login screen containing |message|. virtual void ShowBannerMessage(const std::string& message) = 0; + // Shows a button with an icon inside the user pod of |username|. + virtual void ShowUserPodButton(const std::string& username, + const std::string& iconURL, + const base::Closure& click_callback) = 0; + // Displays simple error bubble with |error_msg_id| specified. // |login_attempts| shows number of login attempts made by current user. // |help_topic_id| is additional help topic that is presented as link. diff --git a/chrome/browser/chromeos/login/mock_login_display.h b/chrome/browser/chromeos/login/mock_login_display.h index 632d202..ee1cd966 100644 --- a/chrome/browser/chromeos/login/mock_login_display.h +++ b/chrome/browser/chromeos/login/mock_login_display.h @@ -25,6 +25,9 @@ class MockLoginDisplay : public LoginDisplay { MOCK_METHOD1(SetUIEnabled, void(bool)); MOCK_METHOD1(SelectPod, void(int)); MOCK_METHOD1(ShowBannerMessage, void(const std::string&)); + MOCK_METHOD3(ShowUserPodButton, void(const std::string&, + const std::string&, + const base::Closure&)); MOCK_METHOD3(ShowError, void(int, int, HelpAppLauncher::HelpTopic)); MOCK_METHOD1(ShowErrorScreen, void(LoginDisplay::SigninError)); MOCK_METHOD1(ShowGaiaPasswordChanged, void(const std::string&)); diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index 7e61d01..33a0ee3 100644 --- a/chrome/browser/chromeos/login/screen_locker.cc +++ b/chrome/browser/chromeos/login/screen_locker.cc @@ -36,18 +36,22 @@ #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" +#include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h" +#include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h" #include "chrome/common/chrome_switches.h" #include "chromeos/audio/chromeos_sounds.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/session_manager_client.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" +#include "content/public/browser/url_data_source.h" #include "content/public/browser/user_metrics.h" #include "grit/browser_resources.h" #include "grit/generated_resources.h" #include "media/audio/sounds/sounds_manager.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/image/image.h" #include "url/gurl.h" using content::BrowserThread; @@ -181,6 +185,14 @@ void ScreenLocker::Init() { authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); delegate_.reset(new WebUIScreenLocker(this)); delegate_->LockScreen(); + + // Ownership of |icon_image_source| is passed. + screenlock_icon_provider_.reset(new ScreenlockIconProvider); + ScreenlockIconSource* screenlock_icon_source = + new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); + content::URLDataSource::Add( + Profile::FromWebUI(GetAssociatedWebUI()), + screenlock_icon_source); } void ScreenLocker::OnLoginFailure(const LoginFailure& error) { @@ -302,6 +314,19 @@ void ScreenLocker::ShowBannerMessage(const std::string& message) { delegate_->ShowBannerMessage(message); } +void ScreenLocker::ShowUserPodButton(const std::string& username, + const gfx::Image& icon, + const base::Closure& click_callback) { + if (!locked_) + return; + + screenlock_icon_provider_->AddIcon(username, icon); + delegate_->ShowUserPodButton( + username, + ScreenlockIconSource::GetIconURLForUser(username), + click_callback); +} + void ScreenLocker::ShowErrorMessage(int error_msg_id, HelpAppLauncher::HelpTopic help_topic_id, bool sign_out_only) { diff --git a/chrome/browser/chromeos/login/screen_locker.h b/chrome/browser/chromeos/login/screen_locker.h index 89ddac9e..33fa3a5 100644 --- a/chrome/browser/chromeos/login/screen_locker.h +++ b/chrome/browser/chromeos/login/screen_locker.h @@ -7,6 +7,7 @@ #include <string> +#include "base/callback_forward.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" @@ -22,10 +23,15 @@ namespace content { class WebUI; } +namespace gfx { +class Image; +} + namespace chromeos { class Authenticator; class LoginFailure; +class ScreenlockIconProvider; namespace test { class ScreenLockerTester; @@ -78,6 +84,11 @@ class ScreenLocker : public LoginStatusConsumer { // Displays |message| in a banner on the lock screen. void ShowBannerMessage(const std::string& message); + // Shows a button inside the user pod on the lock screen with an icon. + void ShowUserPodButton(const std::string& username, + const gfx::Image& icon, + const base::Closure& click_callback); + // Disables all UI needed and shows error bubble with |message|. // If |sign_out_only| is true then all other input except "Sign Out" // button is blocked. @@ -172,6 +183,9 @@ class ScreenLocker : public LoginStatusConsumer { // UnlockOnLoginSuccess(). scoped_ptr<AuthenticationParametersCapture> authentication_capture_; + // Provider for button icon set by the screenlockPrivate API. + scoped_ptr<ScreenlockIconProvider> screenlock_icon_provider_; + base::WeakPtrFactory<ScreenLocker> weak_factory_; DISALLOW_COPY_AND_ASSIGN(ScreenLocker); diff --git a/chrome/browser/chromeos/login/screen_locker_delegate.h b/chrome/browser/chromeos/login/screen_locker_delegate.h index 4dd0046..d26928a 100644 --- a/chrome/browser/chromeos/login/screen_locker_delegate.h +++ b/chrome/browser/chromeos/login/screen_locker_delegate.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREEN_LOCKER_DELEGATE_H_ #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREEN_LOCKER_DELEGATE_H_ +#include "base/callback_forward.h" #include "base/strings/string16.h" #include "chrome/browser/chromeos/login/help_app_launcher.h" #include "ui/gfx/native_widget_types.h" @@ -15,6 +16,10 @@ namespace content { class WebUI; } +namespace gfx { +class Image; +} + namespace chromeos { class ScreenLocker; @@ -42,6 +47,11 @@ class ScreenLockerDelegate { // Displays a banner containing |message| on the lock screen. virtual void ShowBannerMessage(const std::string& message) = 0; + // Shows a button inside the user pod on the lock screen with an icon. + virtual void ShowUserPodButton(const std::string& username, + const std::string& iconURL, + const base::Closure& click_callback) = 0; + // Disables all UI needed and shows error bubble with |message|. // If |sign_out_only| is true then all other input except "Sign Out" // button is blocked. diff --git a/chrome/browser/chromeos/login/webui_login_display.cc b/chrome/browser/chromeos/login/webui_login_display.cc index e17cee1..94b7a20 100644 --- a/chrome/browser/chromeos/login/webui_login_display.cc +++ b/chrome/browser/chromeos/login/webui_login_display.cc @@ -132,6 +132,15 @@ void WebUILoginDisplay::ShowBannerMessage(const std::string& message) { webui_handler_->ShowBannerMessage(message); } +void WebUILoginDisplay::ShowUserPodButton( + const std::string& username, + const std::string& iconURL, + const base::Closure& click_callback) { + if (!webui_handler_) + return; + webui_handler_->ShowUserPodButton(username, iconURL, click_callback); +} + void WebUILoginDisplay::ShowError(int error_msg_id, int login_attempts, HelpAppLauncher::HelpTopic help_topic_id) { diff --git a/chrome/browser/chromeos/login/webui_login_display.h b/chrome/browser/chromeos/login/webui_login_display.h index ad8d6a2..0fb97d0 100644 --- a/chrome/browser/chromeos/login/webui_login_display.h +++ b/chrome/browser/chromeos/login/webui_login_display.h @@ -42,6 +42,9 @@ class WebUILoginDisplay : public LoginDisplay, virtual void SetUIEnabled(bool is_enabled) OVERRIDE; virtual void SelectPod(int index) OVERRIDE; virtual void ShowBannerMessage(const std::string& message) OVERRIDE; + virtual void ShowUserPodButton(const std::string& username, + const std::string& iconURL, + const base::Closure& click_callback) OVERRIDE; virtual void ShowError(int error_msg_id, int login_attempts, HelpAppLauncher::HelpTopic help_topic_id) OVERRIDE; diff --git a/chrome/browser/chromeos/login/webui_screen_locker.cc b/chrome/browser/chromeos/login/webui_screen_locker.cc index 1cd167d..dad714e 100644 --- a/chrome/browser/chromeos/login/webui_screen_locker.cc +++ b/chrome/browser/chromeos/login/webui_screen_locker.cc @@ -104,6 +104,15 @@ void WebUIScreenLocker::ShowBannerMessage(const std::string& message) { login_display_->ShowBannerMessage(message); } +void WebUIScreenLocker::ShowUserPodButton( + const std::string& username, + const std::string& iconURL, + const base::Closure& click_callback) { + if (!webui_ready_) + return; + login_display_->ShowUserPodButton(username, iconURL, click_callback); +} + void WebUIScreenLocker::ShowErrorMessage( int error_msg_id, HelpAppLauncher::HelpTopic help_topic_id) { diff --git a/chrome/browser/chromeos/login/webui_screen_locker.h b/chrome/browser/chromeos/login/webui_screen_locker.h index a6177bc..929ca1d 100644 --- a/chrome/browser/chromeos/login/webui_screen_locker.h +++ b/chrome/browser/chromeos/login/webui_screen_locker.h @@ -58,6 +58,9 @@ class WebUIScreenLocker : public WebUILoginView, virtual void OnAuthenticate() OVERRIDE; virtual void SetInputEnabled(bool enabled) OVERRIDE; virtual void ShowBannerMessage(const std::string& message) OVERRIDE; + virtual void ShowUserPodButton(const std::string& username, + const std::string& iconURL, + const base::Closure& click_callback) OVERRIDE; virtual void ShowErrorMessage( int error_msg_id, HelpAppLauncher::HelpTopic help_topic_id) OVERRIDE; diff --git a/chrome/browser/resources/chromeos/login/screen_account_picker.js b/chrome/browser/resources/chromeos/login/screen_account_picker.js index 72b5c6d..0064e46 100644 --- a/chrome/browser/resources/chromeos/login/screen_account_picker.js +++ b/chrome/browser/resources/chromeos/login/screen_account_picker.js @@ -30,6 +30,7 @@ login.createScreen('AccountPickerScreen', 'account-picker', function() { 'onWallpaperLoaded', 'removeUser', 'showBannerMessage', + 'showUserPodButton', ], preferredWidth_: 0, @@ -239,6 +240,16 @@ login.createScreen('AccountPickerScreen', 'account-picker', function() { var banner = $('signin-banner'); banner.textContent = message; banner.classList.toggle('message-set', true); + }, + + /** + * Shows a button with an icon on the user pod of |username|. This function + * is used by the chrome.screenlockPrivate API. + * @param {string} username Username of pod to add button + * @param {string} iconURL URL of the button icon + */ + showUserPodButton: function(username, iconURL) { + $('pod-row').showUserPodButton(username, iconURL); } }; }); diff --git a/chrome/browser/resources/chromeos/login/user_pod_row.css b/chrome/browser/resources/chromeos/login/user_pod_row.css index f805e28..1f5fbf1 100644 --- a/chrome/browser/resources/chromeos/login/user_pod_row.css +++ b/chrome/browser/resources/chromeos/login/user_pod_row.css @@ -115,20 +115,54 @@ podrow[ncolumns='6'] .pod { display: none; } +.password-area { + display: none; +} + +.password-input-container { + -webkit-box-flex: 1; + /* This relative position is so the capslock hint is positioned correctly. */ + position: relative; +} + +.custom-button { + -webkit-box-align: center; + background-color: rgba(0, 0, 0, 0); + background-image: none; + cursor: pointer; + display: -webkit-box; + height: 40px; + margin: 0; + max-width: 40px; + min-height: 0; + min-width: 0; + padding: 0; +} + +button.custom-button:focus:active, +button.custom-button:focus:hover { + border: 1px solid transparent !important; +} + +.custom-button img { + max-height: 100%; + max-width: 100%; +} + .pod input[type='password'] { -webkit-transition: opacity linear 150ms; background: white; border: none; box-sizing: border-box; - display: none; + display: inline-block; height: 40px; outline: none; padding: 4px 6px; width: 100%; } -.pod.need-password.focused input[type='password'] { - display: inline-block; +.pod.need-password.focused .password-area { + display: -webkit-box; } .pod .signin-button { diff --git a/chrome/browser/resources/chromeos/login/user_pod_row.js b/chrome/browser/resources/chromeos/login/user_pod_row.js index 787ff88..ed3d8ac 100644 --- a/chrome/browser/resources/chromeos/login/user_pod_row.js +++ b/chrome/browser/resources/chromeos/login/user_pod_row.js @@ -142,6 +142,7 @@ cr.define('login', function() { /** @override */ decorate: function() { this.tabIndex = UserPodTabOrder.POD_INPUT; + this.customButton.tabIndex = UserPodTabOrder.POD_INPUT; this.actionBoxAreaElement.tabIndex = UserPodTabOrder.ACTION_BOX; // Mousedown has to be used instead of click to be able to prevent 'focus' @@ -171,6 +172,9 @@ cr.define('login', function() { 'click', this.handleRemoveUserConfirmationClick_.bind(this)); } + + this.customButton.addEventListener('click', + this.handleCustomButtonClick_.bind(this)); }, /** @@ -361,6 +365,15 @@ cr.define('login', function() { }, /** + * Gets the custom button. This button is normally hidden, but can be + * shown using the chrome.screenlockPrivate API. + * @type {!HTMLInputElement} + */ + get customButton() { + return this.querySelector('.custom-button'); + }, + + /** * Updates the user pod element. */ update: function() { @@ -692,6 +705,13 @@ cr.define('login', function() { // Prevent default so that we don't trigger 'focus' event. e.preventDefault(); } + }, + + /** + * Called when the custom button is clicked. + */ + handleCustomButtonClick_: function() { + chrome.send('customButtonClicked', [this.user.username]); } }; @@ -1201,6 +1221,26 @@ cr.define('login', function() { }, /** + * Shows a button on a user pod with an icon. Clicking on this button + * triggers an event used by the chrome.screenlockPrivate API. + * @param {string} username Username of pod to add button + * @param {string} iconURL URL of the button icon + */ + showUserPodButton: function(username, iconURL) { + var pod = this.getPodWithUsername_(username); + if (pod == null) { + console.error('Unable to show user pod button for ' + username + + ': user pod not found.'); + return; + } + + pod.customButton.hidden = false; + var icon = + pod.customButton.querySelector('.custom-button-icon'); + icon.src = iconURL; + }, + + /** * Called when window was resized. */ onWindowResize: function() { diff --git a/chrome/browser/resources/chromeos/login/user_pod_template.html b/chrome/browser/resources/chromeos/login/user_pod_template.html index 6a05bda..d9ff755 100644 --- a/chrome/browser/resources/chromeos/login/user_pod_template.html +++ b/chrome/browser/resources/chromeos/login/user_pod_template.html @@ -3,10 +3,17 @@ <div class="signed-in-indicator" i18n-content="signedIn" hidden></div> <img class="user-image" alt=""> <div class="name"></div> - <input type="password" class="password" - i18n-values="placeholder:passwordHint"> - <img class="capslock-hint" - src="chrome://theme/IDR_LOGIN_PASSWORD_CAPS_LOCK" alt=""> + <div class="password-area"> + <div class="password-input-container"> + <input type="password" class="password" + i18n-values="placeholder:passwordHint"> + <img class="capslock-hint" + src="chrome://theme/IDR_LOGIN_PASSWORD_CAPS_LOCK" alt=""> + </div> + <button class="custom-button custom-appearance" hidden> + <img class="custom-button-icon"></img> + </button> + </div> <button class="signin-button" i18n-content="signinButton"></button> <div class="locked-indicator" hidden></div> </div> diff --git a/chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.cc b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.cc new file mode 100644 index 0000000..a5e771a --- /dev/null +++ b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.cc @@ -0,0 +1,28 @@ +// Copyright 2013 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/ui/webui/chromeos/login/screenlock_icon_provider.h" + +namespace chromeos { + +ScreenlockIconProvider::ScreenlockIconProvider() {} + +ScreenlockIconProvider::~ScreenlockIconProvider() {} + +void ScreenlockIconProvider::AddIcon(const std::string& username, + const gfx::Image& icon) { + user_icon_map_[username] = icon; +} + +gfx::Image ScreenlockIconProvider::GetIcon(const std::string& username) { + if (user_icon_map_.find(username) == user_icon_map_.end()) + return gfx::Image(); + return user_icon_map_[username]; +} + +void ScreenlockIconProvider::Clear() { + user_icon_map_.clear(); +} + +} // namespace chromeos diff --git a/chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h new file mode 100644 index 0000000..c69713c --- /dev/null +++ b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h @@ -0,0 +1,42 @@ +// Copyright 2013 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_UI_WEBUI_CHROMEOS_LOGIN_SCREENLOCK_ICON_PROVIDER_H_ +#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SCREENLOCK_ICON_PROVIDER_H_ + +#include <map> + +#include "base/memory/weak_ptr.h" +#include "ui/gfx/image/image.h" + +namespace chromeos { + +// Stores icon images used by the screenlockPrivate API. This class is +// separate from ScreenlockIconSource for finer memory management. +class ScreenlockIconProvider + : public base::SupportsWeakPtr<ScreenlockIconProvider> { + public: + ScreenlockIconProvider(); + ~ScreenlockIconProvider(); + + // Adds an icon image for |username| to be stored. + void AddIcon(const std::string& username, const gfx::Image& icon); + + // Returns the icon image set for |username|. If no icon is found, then + // this function returns an empty image. + gfx::Image GetIcon(const std::string& username); + + // Removes all stored icon images. + void Clear(); + + private: + // Map of icons for the user pod buttons set by screenlockPrivate.showButton. + std::map<std::string, gfx::Image> user_icon_map_; + + DISALLOW_COPY_AND_ASSIGN(ScreenlockIconProvider); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SCREENLOCK_ICON_PROVIDER_H_ diff --git a/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.cc b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.cc new file mode 100644 index 0000000..d6ec467 --- /dev/null +++ b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.cc @@ -0,0 +1,70 @@ +// Copyright 2013 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/ui/webui/chromeos/login/screenlock_icon_source.h" + +#include "chrome/browser/chromeos/login/screen_locker.h" +#include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h" +#include "chrome/common/url_constants.h" +#include "net/base/escape.h" + +namespace { + +gfx::Image GetDefaultIcon() { + return gfx::Image(); +} + +} // namespace + +namespace chromeos { + +//////////////////////////////////////////////////////////////////////////////// +// ScreenlockIconSource + +ScreenlockIconSource::ScreenlockIconSource( + base::WeakPtr<ScreenlockIconProvider> icon_provider) + : icon_provider_(icon_provider) { +} + +ScreenlockIconSource::~ScreenlockIconSource() {} + +std::string ScreenlockIconSource::GetSource() const { + return std::string(chrome::kChromeUIScreenlockIconHost); +} + +void ScreenlockIconSource::StartDataRequest( + const std::string& path, + int render_process_id, + int render_view_id, + const content::URLDataSource::GotDataCallback& callback) { + if (!icon_provider_) { + callback.Run(GetDefaultIcon().As1xPNGBytes()); + return; + } + + std::string username = net::UnescapeURLComponent( + path, + net::UnescapeRule::URL_SPECIAL_CHARS | net::UnescapeRule::SPACES); + + gfx::Image image = icon_provider_->GetIcon(username); + if (image.IsEmpty()) { + callback.Run(GetDefaultIcon().As1xPNGBytes()); + return; + } + + callback.Run(image.As1xPNGBytes().get()); +} + +std::string ScreenlockIconSource::GetMimeType(const std::string&) const { + return "image/png"; +} + +// static. +std::string ScreenlockIconSource::GetIconURLForUser( + const std::string& username) { + return std::string(chrome::kChromeUIScreenlockIconURL) + + net::EscapePath(username); +} + +} // namespace chromeos diff --git a/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h new file mode 100644 index 0000000..fcabc2d --- /dev/null +++ b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h @@ -0,0 +1,44 @@ +// Copyright 2013 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_UI_WEBUI_CHROMEOS_LOGIN_SCREENLOCK_ICON_SOURCE_H_ +#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SCREENLOCK_ICON_SOURCE_H_ + +#include "base/memory/weak_ptr.h" +#include "content/public/browser/url_data_source.h" + +namespace chromeos { + +class ScreenlockIconProvider; + +// A URL data source that serves icon images for the screenlockPrivate API. +class ScreenlockIconSource : public content::URLDataSource { + public: + explicit ScreenlockIconSource( + base::WeakPtr<ScreenlockIconProvider> icon_provider); + + // content::URLDataSource implementation. + virtual std::string GetSource() const OVERRIDE; + virtual void StartDataRequest( + const std::string& path, + int render_process_id, + int render_view_id, + const content::URLDataSource::GotDataCallback& callback) OVERRIDE; + + virtual std::string GetMimeType(const std::string& path) const OVERRIDE; + + // Constructs and returns the icon URL for a given user. + static std::string GetIconURLForUser(const std::string& username); + + private: + virtual ~ScreenlockIconSource(); + + base::WeakPtr<ScreenlockIconProvider> icon_provider_; + + DISALLOW_COPY_AND_ASSIGN(ScreenlockIconSource); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SCREENLOCK_ICON_SOURCE_H_ diff --git a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc index bdc49e9..abdd3de 100644 --- a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc +++ b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc @@ -805,6 +805,8 @@ void SigninScreenHandler::RegisterMessages() { AddCallback("updateOfflineLogin", &SigninScreenHandler::HandleUpdateOfflineLogin); AddCallback("focusPod", &SigninScreenHandler::HandleFocusPod); + AddCallback("customButtonClicked", + &SigninScreenHandler::HandleCustomButtonClicked); // This message is sent by the kiosk app menu, but is handled here // so we can tell the delegate to launch the app. @@ -870,6 +872,14 @@ void SigninScreenHandler::ShowBannerMessage(const std::string& message) { CallJS("login.AccountPickerScreen.showBannerMessage", message); } +void SigninScreenHandler::ShowUserPodButton( + const std::string& username, + const std::string& iconURL, + const base::Closure& click_callback) { + user_pod_button_callback_map_[username] = click_callback; + CallJS("login.AccountPickerScreen.showUserPodButton", username, iconURL); +} + void SigninScreenHandler::ShowError(int login_attempts, const std::string& error_text, const std::string& help_link_text, @@ -1503,6 +1513,16 @@ void SigninScreenHandler::HandleFocusPod(const std::string& user_id) { SetUserInputMethod(user_id); } +void SigninScreenHandler::HandleCustomButtonClicked( + const std::string& username) { + if (user_pod_button_callback_map_.find(username) + == user_pod_button_callback_map_.end()) { + LOG(WARNING) << "User pod custom button clicked but no callback found"; + return; + } + user_pod_button_callback_map_[username].Run(); +} + void SigninScreenHandler::HandleLaunchKioskApp(const std::string& app_id) { delegate_->LoginAsKioskApp(app_id); } diff --git a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h index 27e1a14..3aa2b74 100644 --- a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h +++ b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h @@ -74,6 +74,9 @@ class LoginDisplayWebUIHandler { virtual void OnPreferencesChanged() = 0; virtual void ResetSigninScreenHandlerDelegate() = 0; virtual void ShowBannerMessage(const std::string& message) = 0; + virtual void ShowUserPodButton(const std::string& username, + const std::string& iconURL, + const base::Closure& click_callback) = 0; virtual void ShowError(int login_attempts, const std::string& error_text, const std::string& help_link_text, @@ -276,6 +279,9 @@ class SigninScreenHandler virtual void OnPreferencesChanged() OVERRIDE; virtual void ResetSigninScreenHandlerDelegate() OVERRIDE; virtual void ShowBannerMessage(const std::string& message) OVERRIDE; + virtual void ShowUserPodButton(const std::string& username, + const std::string& iconURL, + const base::Closure& click_callback) OVERRIDE; virtual void ShowError(int login_attempts, const std::string& error_text, const std::string& help_link_text, @@ -356,6 +362,7 @@ class SigninScreenHandler void HandleShowLocallyManagedUserCreationScreen(); void HandleFocusPod(const std::string& user_id); void HandleLaunchKioskApp(const std::string& app_id); + void HandleCustomButtonClicked(const std::string& username); // Fills |user_dict| with information about |user|. static void FillUserDictionary(User* user, @@ -505,6 +512,9 @@ class SigninScreenHandler base::Closure kiosk_enable_flow_aborted_callback_for_test_; + // Map of callbacks run when the custom button on a user pod is clicked. + std::map<std::string, base::Closure> user_pod_button_callback_map_; + // Non-owning ptr. // TODO (ygorshenin@): remove this dependency. GaiaScreenHandler* gaia_screen_handler_; diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index b0250df..345f0f6 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -921,6 +921,8 @@ 'browser/chromeos/extensions/first_run_private_api.h', 'browser/chromeos/extensions/input_method_api.cc', 'browser/chromeos/extensions/input_method_api.h', + 'browser/chromeos/extensions/screenlock_private_api.cc', + 'browser/chromeos/extensions/screenlock_private_api.h', 'browser/chromeos/extensions/media_player_api.cc', 'browser/chromeos/extensions/media_player_api.h', 'browser/chromeos/extensions/wallpaper_manager_util.cc', diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index 950f99e..0a28b36 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -934,8 +934,6 @@ 'browser/extensions/api/log_private/log_private_api_chromeos.cc', 'browser/extensions/api/log_private/syslog_parser.cc', 'browser/extensions/api/log_private/syslog_parser.h', - 'browser/chromeos/extensions/screenlock_private_api.cc', - 'browser/chromeos/extensions/screenlock_private_api.h', 'browser/extensions/api/networking_private/networking_private_api_chromeos.cc', 'browser/extensions/api/networking_private/networking_private_api.h', 'browser/extensions/api/networking_private/networking_private_event_router_chromeos.cc', diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index d2ea87c..47054c7 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -2245,6 +2245,10 @@ 'browser/ui/webui/chromeos/login/oobe_ui.h', 'browser/ui/webui/chromeos/login/reset_screen_handler.cc', 'browser/ui/webui/chromeos/login/reset_screen_handler.h', + 'browser/ui/webui/chromeos/login/screenlock_icon_provider.cc', + 'browser/ui/webui/chromeos/login/screenlock_icon_provider.h', + 'browser/ui/webui/chromeos/login/screenlock_icon_source.cc', + 'browser/ui/webui/chromeos/login/screenlock_icon_source.h', 'browser/ui/webui/chromeos/login/screen_manager_handler.cc', 'browser/ui/webui/chromeos/login/screen_manager_handler.h', 'browser/ui/webui/chromeos/login/signin_screen_handler.cc', diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index c799c40..1e2650c 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -113,6 +113,7 @@ const char kChromeUIMobileSetupURL[] = "chrome://mobilesetup/"; const char kChromeUIOobeURL[] = "chrome://oobe/"; const char kChromeUIOSCreditsURL[] = "chrome://os-credits/"; const char kChromeUIProxySettingsURL[] = "chrome://proxy-settings/"; +const char kChromeUIScreenlockIconURL[] = "chrome://screenlock-icon/"; const char kChromeUISimUnlockURL[] = "chrome://sim-unlock/"; const char kChromeUISlideshowURL[] = "chrome://slideshow/"; const char kChromeUISlowURL[] = "chrome://slow/"; @@ -266,6 +267,7 @@ const char kChromeUIOobeHost[] = "oobe"; const char kChromeUIOSCreditsHost[] = "os-credits"; const char kChromeUIProxySettingsHost[] = "proxy-settings"; const char kChromeUIRotateHost[] = "rotate"; +const char kChromeUIScreenlockIconHost[] = "screenlock-icon"; const char kChromeUISimUnlockHost[] = "sim-unlock"; const char kChromeUISlideshowHost[] = "slideshow"; const char kChromeUISlowHost[] = "slow"; diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index 573f947..e50f802 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -108,6 +108,7 @@ extern const char kChromeUIMobileSetupURL[]; extern const char kChromeUIOobeURL[]; extern const char kChromeUIOSCreditsURL[]; extern const char kChromeUIProxySettingsURL[]; +extern const char kChromeUIScreenlockIconURL[]; extern const char kChromeUISimUnlockURL[]; extern const char kChromeUISlideshowURL[]; extern const char kChromeUISlowURL[]; @@ -260,6 +261,7 @@ extern const char kChromeUIOobeHost[]; extern const char kChromeUIOSCreditsHost[]; extern const char kChromeUIProxySettingsHost[]; extern const char kChromeUIRotateHost[]; +extern const char kChromeUIScreenlockIconHost[]; extern const char kChromeUISimUnlockHost[]; extern const char kChromeUISlideshowHost[]; extern const char kChromeUISlowHost[]; |