Chromium Code Reviews| Index: chrome/browser/ui/webui/signin/signin_error_ui.cc |
| diff --git a/chrome/browser/ui/webui/signin/signin_error_ui.cc b/chrome/browser/ui/webui/signin/signin_error_ui.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a6f747ec8c225b457cfcf001e44addc062252d27 |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/signin/signin_error_ui.cc |
| @@ -0,0 +1,103 @@ |
| +// Copyright 2016 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/signin/signin_error_ui.h" |
| + |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/profiles/profile_attributes_entry.h" |
| +#include "chrome/browser/profiles/profile_attributes_storage.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/browser/ui/browser_window.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/signin_error_handler.h" |
| +#include "chrome/common/url_constants.h" |
| +#include "chrome/grit/browser_resources.h" |
| +#include "chrome/grit/generated_resources.h" |
| +#include "content/public/browser/web_ui.h" |
| +#include "content/public/browser/web_ui_data_source.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/webui/web_ui_util.h" |
| +#include "ui/gfx/text_elider.h" |
| + |
| +SigninErrorUI::SigninErrorUI(content::WebUI* web_ui) |
| + : SigninErrorUI(web_ui, new SigninErrorHandler) {} |
| + |
| +SigninErrorUI::SigninErrorUI(content::WebUI* web_ui, |
| + SigninErrorHandler* handler) |
| + : WebDialogUI(web_ui) { |
| + Profile* profile = Profile::FromWebUI(web_ui); |
| + content::WebUIDataSource* source = |
| + content::WebUIDataSource::Create(chrome::kChromeUISigninErrorHost); |
| + source->SetJsonPath("strings.js"); |
| + source->SetDefaultResource(IDR_SIGNIN_ERROR_HTML); |
| + source->AddResourcePath("signin_error.js", IDR_SIGNIN_ERROR_JS); |
| + source->AddResourcePath("signin_shared_css.html", IDR_SIGNIN_SHARED_CSS_HTML); |
| + |
| + // Retrieve the last signin error message and email used. |
| + LoginUIService* login_ui_service = |
| + LoginUIServiceFactory::GetForProfile(profile); |
| + base::string16 last_login_result(login_ui_service->GetLastLoginResult()); |
|
achuithb
2016/09/12 19:19:26
const
anthonyvd
2016/09/13 14:25:58
Done.
|
| + base::string16 email = login_ui_service->GetLastLoginErrorEmail(); |
| + if (email.empty()) { |
|
achuithb
2016/09/12 19:19:26
const
anthonyvd
2016/09/13 14:25:58
Done.
|
| + source->AddLocalizedString("signinErrorTitle", IDS_SIGNIN_ERROR_TITLE); |
| + } else { |
| + source->AddString( |
| + "signinErrorTitle", |
| + l10n_util::GetStringFUTF16(IDS_SIGNIN_ERROR_EMAIL_TITLE, email)); |
| + } |
| + |
| + // Tweak the dialog UI depending on whether the signin error is |
| + // username-in-use error. |
| + base::string16 existing_name; |
| + if (last_login_result.compare( |
| + l10n_util::GetStringUTF16(IDS_SYNC_USER_NAME_IN_USE_ERROR)) == 0) { |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + if (profile_manager) { |
| + std::vector<ProfileAttributesEntry*> entries = |
| + profile_manager->GetProfileAttributesStorage() |
| + .GetAllProfilesAttributes(); |
| + DCHECK(!email.empty()); |
| + for (const ProfileAttributesEntry* entry : entries) { |
| + if (gaia::AreEmailsSame(base::UTF16ToUTF8(email), |
| + base::UTF16ToUTF8(entry->GetUserName()))) { |
| + handler->set_duplicate_profile_entry(entry); |
| + existing_name = entry->GetName(); |
| + } |
| + } |
| + } |
| + DCHECK(!existing_name.empty()); |
| + source->AddString( |
| + "signinErrorMessage", |
| + l10n_util::GetStringFUTF16( |
| + IDS_SIGNIN_ERROR_LEARN_MORE_LINK, |
| + l10n_util::GetStringFUTF16(IDS_SYNC_USER_NAME_IN_USE_BY_ERROR, |
| + existing_name))); |
| + // Elide the existing name for the switch uer button label. |
|
achuithb
2016/09/12 19:19:26
uer -> user
anthonyvd
2016/09/13 14:25:58
Done.
|
| + existing_name = |
| + gfx::TruncateString(existing_name, 10, gfx::CHARACTER_BREAK); |
| + } else { |
| + source->AddString("signinErrorMessage", |
| + l10n_util::GetStringFUTF16( |
| + IDS_SIGNIN_ERROR_LEARN_MORE_LINK, last_login_result)); |
| + } |
| + |
| + // Add button label strings. |
| + source->AddString("signinErrorSwitchLabel", |
| + l10n_util::GetStringFUTF16( |
| + IDS_SIGNIN_ERROR_SWITCH_BUTTON_LABEL, existing_name)); |
| + source->AddLocalizedString("signinErrorCloseLabel", |
| + IDS_SIGNIN_ERROR_CLOSE_BUTTON_LABEL); |
| + source->AddLocalizedString("signinErrorOkLabel", |
| + IDS_SIGNIN_ERROR_OK_BUTTON_LABEL); |
| + |
| + base::DictionaryValue strings; |
| + webui::SetLoadTimeDataDefaults(g_browser_process->GetApplicationLocale(), |
| + &strings); |
| + source->AddLocalizedStrings(strings); |
| + |
| + content::WebUIDataSource::Add(profile, source); |
| + web_ui->AddMessageHandler(handler); |
| +} |