Commit c105747d authored by zmin's avatar zmin Committed by Commit bot

Display local signin error without browser and record the path of selected profile in user manager.

BUG=642059
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2351173004
Cr-Commit-Position: refs/heads/master@{#420713}
parent 1beabecc
...@@ -11,6 +11,9 @@ cr.define('signin.error', function() { ...@@ -11,6 +11,9 @@ cr.define('signin.error', function() {
$('closeButton').addEventListener('click', onConfirm); $('closeButton').addEventListener('click', onConfirm);
$('switchButton').addEventListener('click', onSwitchToExistingProfile); $('switchButton').addEventListener('click', onSwitchToExistingProfile);
$('learnMoreLink').addEventListener('click', onLearnMore); $('learnMoreLink').addEventListener('click', onLearnMore);
if (loadTimeData.getBoolean('isSystemProfile')) {
$('learnMoreLink').hidden = true;
}
chrome.send('initializedWithSize', [document.body.scrollHeight]); chrome.send('initializedWithSize', [document.body.scrollHeight]);
} }
......
...@@ -18,6 +18,21 @@ class FilePath; ...@@ -18,6 +18,21 @@ class FilePath;
// Cross-platform methods for displaying the user manager. // Cross-platform methods for displaying the user manager.
class UserManager { class UserManager {
public: public:
// TODO(noms): Figure out if this size can be computed dynamically or adjusted
// for smaller screens.
static constexpr int kWindowWidth = 800;
static constexpr int kWindowHeight = 600;
// Dimensions of the reauth dialog displaying the old-style signin flow with
// the username and password challenge on the same form.
static constexpr int kPasswordCombinedReauthDialogHeight = 440;
static constexpr int kPasswordCombinedReauthDialogWidth = 360;
// Dimensions of the reauth dialog displaying the password-separated signin
// flow.
static constexpr int kReauthDialogHeight = 512;
static constexpr int kReauthDialogWidth = 448;
// Shows the User Manager or re-activates an existing one, focusing the // Shows the User Manager or re-activates an existing one, focusing the
// profile given by |profile_path_to_focus|; passing an empty base::FilePath // profile given by |profile_path_to_focus|; passing an empty base::FilePath
// focuses no user pod. Based on the value of |tutorial_mode|, a tutorial // focuses no user pod. Based on the value of |tutorial_mode|, a tutorial
...@@ -30,7 +45,9 @@ class UserManager { ...@@ -30,7 +45,9 @@ class UserManager {
// Hides the User Manager. // Hides the User Manager.
static void Hide(); static void Hide();
// Returns whether the User Manager is showing. // Returns whether the User Manager is showing and active.
// TODO(zmin): Rename the function to something less confusing.
// https://crbug.com/649380.
static bool IsShowing(); static bool IsShowing();
// To be called once the User Manager's contents are showing. // To be called once the User Manager's contents are showing.
...@@ -55,20 +72,20 @@ class UserManager { ...@@ -55,20 +72,20 @@ class UserManager {
// Hides the reauth dialog if it is showing. // Hides the reauth dialog if it is showing.
static void HideReauthDialog(); static void HideReauthDialog();
// TODO(noms): Figure out if this size can be computed dynamically or adjusted // TODO(zmin): Remove the condition for MACOSX once user_manager_mac.cc is
// for smaller screens. // updated.
static const int kWindowWidth = 800; #if !defined(OS_MACOSX)
static const int kWindowHeight = 600; // Shows a dialog where the user login his or her profile by the first time
// via user manager.
static void ShowSigninDialog(content::BrowserContext* browser_context,
const base::FilePath& profile_path);
// Dimensions of the reauth dialog displaying the old-style signin flow with // Display local sign in error message without browser.
// the username and password challenge on the same form. static void DisplayErrorMessage();
static const int kPasswordCombinedReauthDialogHeight = 440;
static const int kPasswordCombinedReauthDialogWidth = 360;
// Dimensions of the reauth dialog displaying the password-separated signin // Get the path of profile that is being signed in.
// flow. static base::FilePath GetSigninProfilePath();
static const int kReauthDialogHeight = 512; #endif
static const int kReauthDialogWidth = 448;
// Abstract base class for performing online reauthentication of profiles in // Abstract base class for performing online reauthentication of profiles in
// the User Manager. It is concretely implemented in UserManagerMac and // the User Manager. It is concretely implemented in UserManagerMac and
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/user_manager.h" #include "chrome/browser/ui/user_manager.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/guest_view/browser/guest_view_manager.h" #include "components/guest_view/browser/guest_view_manager.h"
...@@ -66,7 +67,7 @@ ReauthDelegate::ReauthDelegate(UserManagerView* parent, ...@@ -66,7 +67,7 @@ ReauthDelegate::ReauthDelegate(UserManagerView* parent,
AddChildView(web_view_); AddChildView(web_view_);
SetLayoutManager(new views::FillLayout()); SetLayoutManager(new views::FillLayout());
web_view->GetWebContents()->SetDelegate(this); web_view_->GetWebContents()->SetDelegate(this);
// Load the re-auth URL, prepopulated with the user's email address. // Load the re-auth URL, prepopulated with the user's email address.
// Add the index of the profile to the URL so that the inline login page // Add the index of the profile to the URL so that the inline login page
...@@ -87,6 +88,10 @@ gfx::Size ReauthDelegate::GetPreferredSize() const { ...@@ -87,6 +88,10 @@ gfx::Size ReauthDelegate::GetPreferredSize() const {
UserManager::kPasswordCombinedReauthDialogHeight); UserManager::kPasswordCombinedReauthDialogHeight);
} }
void ReauthDelegate::DisplayErrorMessage() {
web_view_->LoadInitialURL(GURL(chrome::kChromeUISigninErrorURL));
}
bool ReauthDelegate::CanResize() const { bool ReauthDelegate::CanResize() const {
return true; return true;
} }
...@@ -210,17 +215,14 @@ void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, ...@@ -210,17 +215,14 @@ void UserManager::ShowReauthDialog(content::BrowserContext* browser_context,
// This method should only be called if the user manager is already showing. // This method should only be called if the user manager is already showing.
if (!IsShowing()) if (!IsShowing())
return; return;
instance_->ShowReauthDialog(browser_context, email, reason); instance_->ShowReauthDialog(browser_context, email, reason);
} }
// static // static
void UserManager::HideReauthDialog() { void UserManager::HideReauthDialog() {
// This method should only be called if the user manager is already showing. // This method should only be called if the user manager is already showing.
if (!IsShowing()) if (instance_ && instance_->GetWidget()->IsVisible())
return; instance_->HideReauthDialog();
instance_->HideReauthDialog();
} }
// static // static
...@@ -230,6 +232,28 @@ void UserManager::AddOnUserManagerShownCallbackForTesting( ...@@ -230,6 +232,28 @@ void UserManager::AddOnUserManagerShownCallbackForTesting(
user_manager_shown_callback_for_testing_ = new base::Closure(callback); user_manager_shown_callback_for_testing_ = new base::Closure(callback);
} }
// static
void UserManager::ShowSigninDialog(content::BrowserContext* browser_context,
const base::FilePath& profile_path) {
if (!IsShowing())
return;
instance_->SetSigninProfilePath(profile_path);
ShowReauthDialog(browser_context, std::string(),
signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT);
}
// static
void UserManager::DisplayErrorMessage() {
// This method should only be called if the user manager is already showing.
DCHECK(instance_);
instance_->DisplayErrorMessage();
}
// static
base::FilePath UserManager::GetSigninProfilePath() {
return instance_->GetSigninProfilePath();
}
// UserManagerView ------------------------------------------------------------- // UserManagerView -------------------------------------------------------------
UserManagerView::UserManagerView() UserManagerView::UserManagerView()
...@@ -408,3 +432,16 @@ void UserManagerView::WindowClosing() { ...@@ -408,3 +432,16 @@ void UserManagerView::WindowClosing() {
bool UserManagerView::ShouldUseCustomFrame() const { bool UserManagerView::ShouldUseCustomFrame() const {
return false; return false;
} }
void UserManagerView::DisplayErrorMessage() {
if (delegate_)
delegate_->DisplayErrorMessage();
}
void UserManagerView::SetSigninProfilePath(const base::FilePath& profile_path) {
signin_profile_path_ = profile_path;
}
base::FilePath UserManagerView::GetSigninProfilePath() {
return signin_profile_path_;
}
...@@ -31,6 +31,9 @@ class ReauthDelegate : public views::DialogDelegateView, ...@@ -31,6 +31,9 @@ class ReauthDelegate : public views::DialogDelegateView,
// UserManager::BaseReauthDialogDelegate: // UserManager::BaseReauthDialogDelegate:
void CloseReauthDialog() override; void CloseReauthDialog() override;
// Display the local error message inside login window.
void DisplayErrorMessage();
private: private:
ReauthDelegate(); ReauthDelegate();
...@@ -50,7 +53,7 @@ class ReauthDelegate : public views::DialogDelegateView, ...@@ -50,7 +53,7 @@ class ReauthDelegate : public views::DialogDelegateView,
int GetDialogButtons() const override; int GetDialogButtons() const override;
views::View* GetInitiallyFocusedView() override; views::View* GetInitiallyFocusedView() override;
UserManagerView* parent_; // Not owned. UserManagerView* parent_; // Not owned.
views::WebView* web_view_; views::WebView* web_view_;
const std::string email_address_; const std::string email_address_;
...@@ -97,6 +100,15 @@ class UserManagerView : public views::DialogDelegateView { ...@@ -97,6 +100,15 @@ class UserManagerView : public views::DialogDelegateView {
// Hides the reauth dialog if it is showing. // Hides the reauth dialog if it is showing.
void HideReauthDialog(); void HideReauthDialog();
// Display sign in error message that is created by Chrome but not GAIA
// without browser window.
void DisplayErrorMessage();
// Setter and getter of the path of profile which is selected in user manager
// for first time signin.
void SetSigninProfilePath(const base::FilePath& profile_path);
base::FilePath GetSigninProfilePath();
private: private:
friend class ReauthDelegate; friend class ReauthDelegate;
friend std::default_delete<UserManagerView>; friend std::default_delete<UserManagerView>;
...@@ -129,6 +141,8 @@ class UserManagerView : public views::DialogDelegateView { ...@@ -129,6 +141,8 @@ class UserManagerView : public views::DialogDelegateView {
std::unique_ptr<ScopedKeepAlive> keep_alive_; std::unique_ptr<ScopedKeepAlive> keep_alive_;
base::Time user_manager_started_showing_; base::Time user_manager_started_showing_;
base::FilePath signin_profile_path_;
DISALLOW_COPY_AND_ASSIGN(UserManagerView); DISALLOW_COPY_AND_ASSIGN(UserManagerView);
}; };
......
...@@ -10,10 +10,14 @@ ...@@ -10,10 +10,14 @@
#include "chrome/browser/profiles/profile_window.h" #include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/signin/signin_ui_util.h" #include "chrome/browser/signin/signin_ui_util.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/user_manager.h"
#include "chrome/browser/ui/webui/signin/signin_utils.h" #include "chrome/browser/ui/webui/signin/signin_utils.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "url/gurl.h" #include "url/gurl.h"
SigninErrorHandler::SigninErrorHandler(bool is_system_profile)
: is_system_profile_(is_system_profile) {}
void SigninErrorHandler::RegisterMessages() { void SigninErrorHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"confirm", "confirm",
...@@ -70,7 +74,13 @@ void SigninErrorHandler::HandleInitializedWithSize( ...@@ -70,7 +74,13 @@ void SigninErrorHandler::HandleInitializedWithSize(
} }
void SigninErrorHandler::CloseDialog() { void SigninErrorHandler::CloseDialog() {
Browser* browser = signin::GetDesktopBrowser(web_ui()); if (is_system_profile_) {
DCHECK(browser); // Avoid closing the user manager window when the error message is displayed
browser->CloseModalSigninWindow(); // without browser window.
UserManager::HideReauthDialog();
} else {
Browser* browser = signin::GetDesktopBrowser(web_ui());
DCHECK(browser);
browser->CloseModalSigninWindow();
}
} }
...@@ -19,7 +19,8 @@ class ListValue; ...@@ -19,7 +19,8 @@ class ListValue;
class SigninErrorHandler : public content::WebUIMessageHandler { class SigninErrorHandler : public content::WebUIMessageHandler {
public: public:
SigninErrorHandler() {} explicit SigninErrorHandler(bool is_system_profile);
~SigninErrorHandler() override {} ~SigninErrorHandler() override {}
// content::WebUIMessageHandler: // content::WebUIMessageHandler:
...@@ -58,6 +59,8 @@ class SigninErrorHandler : public content::WebUIMessageHandler { ...@@ -58,6 +59,8 @@ class SigninErrorHandler : public content::WebUIMessageHandler {
private: private:
const ProfileAttributesEntry* duplicate_profile_entry_ = nullptr; const ProfileAttributesEntry* duplicate_profile_entry_ = nullptr;
bool is_system_profile_;
DISALLOW_COPY_AND_ASSIGN(SigninErrorHandler); DISALLOW_COPY_AND_ASSIGN(SigninErrorHandler);
}; };
......
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
#include "chrome/browser/ui/webui/signin/signin_error_ui.h" #include "chrome/browser/ui/webui/signin/signin_error_ui.h"
#include <vector>
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_attributes_entry.h" #include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/user_manager.h"
#include "chrome/browser/ui/webui/signin/login_ui_service.h" #include "chrome/browser/ui/webui/signin/login_ui_service.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/browser/ui/webui/signin/signin_error_handler.h" #include "chrome/browser/ui/webui/signin/signin_error_handler.h"
...@@ -23,22 +26,43 @@ ...@@ -23,22 +26,43 @@
#include "ui/gfx/text_elider.h" #include "ui/gfx/text_elider.h"
SigninErrorUI::SigninErrorUI(content::WebUI* web_ui) SigninErrorUI::SigninErrorUI(content::WebUI* web_ui)
: SigninErrorUI(web_ui, new SigninErrorHandler) {} : SigninErrorUI(web_ui,
new SigninErrorHandler(Profile::FromWebUI(web_ui)
->GetOriginalProfile()
->IsSystemProfile())) {}
SigninErrorUI::SigninErrorUI(content::WebUI* web_ui, SigninErrorUI::SigninErrorUI(content::WebUI* web_ui,
SigninErrorHandler* handler) SigninErrorHandler* handler)
: WebDialogUI(web_ui) { : WebDialogUI(web_ui) {
Profile* profile = Profile::FromWebUI(web_ui); Profile* webui_profile = Profile::FromWebUI(web_ui);
Profile* signin_profile;
bool is_system_profile =
webui_profile->GetOriginalProfile()->IsSystemProfile();
// TODO(zmin): Remove the condition for MACOSX once user_manager_mac.cc is
// updated.
#if !defined(OS_MACOSX)
if (is_system_profile) {
signin_profile = g_browser_process->profile_manager()->GetProfileByPath(
UserManager::GetSigninProfilePath());
} else {
signin_profile = webui_profile;
}
#else
signin_profile = webui_profile;
#endif
content::WebUIDataSource* source = content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUISigninErrorHost); content::WebUIDataSource::Create(chrome::kChromeUISigninErrorHost);
source->SetJsonPath("strings.js"); source->SetJsonPath("strings.js");
source->SetDefaultResource(IDR_SIGNIN_ERROR_HTML); source->SetDefaultResource(IDR_SIGNIN_ERROR_HTML);
source->AddResourcePath("signin_error.js", IDR_SIGNIN_ERROR_JS); source->AddResourcePath("signin_error.js", IDR_SIGNIN_ERROR_JS);
source->AddResourcePath("signin_shared_css.html", IDR_SIGNIN_SHARED_CSS_HTML); source->AddResourcePath("signin_shared_css.html", IDR_SIGNIN_SHARED_CSS_HTML);
source->AddBoolean("isSystemProfile", is_system_profile);
// Retrieve the last signin error message and email used. // Retrieve the last signin error message and email used.
LoginUIService* login_ui_service = LoginUIService* login_ui_service =
LoginUIServiceFactory::GetForProfile(profile); LoginUIServiceFactory::GetForProfile(signin_profile);
const base::string16 last_login_result( const base::string16 last_login_result(
login_ui_service->GetLastLoginResult()); login_ui_service->GetLastLoginResult());
const base::string16 email = login_ui_service->GetLastLoginErrorEmail(); const base::string16 email = login_ui_service->GetLastLoginErrorEmail();
...@@ -51,9 +75,10 @@ SigninErrorUI::SigninErrorUI(content::WebUI* web_ui, ...@@ -51,9 +75,10 @@ SigninErrorUI::SigninErrorUI(content::WebUI* web_ui,
} }
// Tweak the dialog UI depending on whether the signin error is // Tweak the dialog UI depending on whether the signin error is
// username-in-use error. // username-in-use error and the error UI is shown with a browser window.
base::string16 existing_name; base::string16 existing_name;
if (last_login_result.compare( if (!is_system_profile &&
last_login_result.compare(
l10n_util::GetStringUTF16(IDS_SYNC_USER_NAME_IN_USE_ERROR)) == 0) { l10n_util::GetStringUTF16(IDS_SYNC_USER_NAME_IN_USE_ERROR)) == 0) {
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
if (profile_manager) { if (profile_manager) {
...@@ -99,6 +124,6 @@ SigninErrorUI::SigninErrorUI(content::WebUI* web_ui, ...@@ -99,6 +124,6 @@ SigninErrorUI::SigninErrorUI(content::WebUI* web_ui,
&strings); &strings);
source->AddLocalizedStrings(strings); source->AddLocalizedStrings(strings);
content::WebUIDataSource::Add(profile, source); content::WebUIDataSource::Add(webui_profile, source);
web_ui->AddMessageHandler(handler); web_ui->AddMessageHandler(handler);
} }
...@@ -469,11 +469,25 @@ void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( ...@@ -469,11 +469,25 @@ void UserManagerScreenHandler::HandleAuthenticatedLaunchUser(
} }
} }
// In order to support the upgrade case where we have a local hash but no content::BrowserContext* browser_context =
// password token, the user perform a full online reauth. web_ui()->GetWebContents()->GetBrowserContext();
UserManager::ShowReauthDialog(web_ui()->GetWebContents()->GetBrowserContext(),
email_address_, // In order to support the upgrade case where we have a local hash but no
// password token, the user perform a full online reauth.
// TODO(zmin): Remove the condition for MACOSX once user_manager_mac.cc is
// updated.
#if !defined(OS_MACOSX)
if (!email_address_.empty()) {
UserManager::ShowReauthDialog(browser_context, email_address_,
signin_metrics::Reason::REASON_UNLOCK);
} else {
// Fresh sign in via user manager without existing email address.
UserManager::ShowSigninDialog(browser_context, profile_path);
}
#else
UserManager::ShowReauthDialog(browser_context, email_address_,
signin_metrics::Reason::REASON_UNLOCK); signin_metrics::Reason::REASON_UNLOCK);
#endif
} }
void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) {
......
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