Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/signin/signin_error_ui.h" | 5 #include "chrome/browser/ui/webui/signin/signin_error_ui.h" |
| 6 | 6 |
| 7 #include <vector> | |
| 8 | |
| 7 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/profiles/profile_attributes_entry.h" | 11 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 10 #include "chrome/browser/profiles/profile_attributes_storage.h" | 12 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/user_manager.h" | |
| 13 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 16 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 14 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 17 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 15 #include "chrome/browser/ui/webui/signin/signin_error_handler.h" | 18 #include "chrome/browser/ui/webui/signin/signin_error_handler.h" |
| 16 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/grit/browser_resources.h" | 20 #include "chrome/grit/browser_resources.h" |
| 18 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 19 #include "content/public/browser/web_ui.h" | 22 #include "content/public/browser/web_ui.h" |
| 20 #include "content/public/browser/web_ui_data_source.h" | 23 #include "content/public/browser/web_ui_data_source.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/webui/web_ui_util.h" | 25 #include "ui/base/webui/web_ui_util.h" |
| 23 #include "ui/gfx/text_elider.h" | 26 #include "ui/gfx/text_elider.h" |
| 24 | 27 |
| 28 namespace { | |
| 29 bool IsSystemProfile(Profile* profile) { | |
| 30 return profile->GetOriginalProfile()->IsSystemProfile(); | |
| 31 } | |
| 32 } // namespace | |
| 33 | |
| 25 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui) | 34 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui) |
| 26 : SigninErrorUI(web_ui, new SigninErrorHandler) {} | 35 : SigninErrorUI( |
| 36 web_ui, | |
| 37 new SigninErrorHandler(IsSystemProfile(Profile::FromWebUI(web_ui)))) { | |
| 38 } | |
| 27 | 39 |
| 28 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui, | 40 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui, |
| 29 SigninErrorHandler* handler) | 41 SigninErrorHandler* handler) |
| 30 : WebDialogUI(web_ui) { | 42 : WebDialogUI(web_ui) { |
| 31 Profile* profile = Profile::FromWebUI(web_ui); | 43 Profile* webui_profile = Profile::FromWebUI(web_ui); |
| 44 Profile* signin_profile; | |
| 45 bool is_system_profile = IsSystemProfile(webui_profile); | |
| 46 | |
| 47 #if !defined(OS_MACOSX) | |
|
tommycli
2016/09/21 21:26:16
Please add a TODO with an explanation about the se
zmin
2016/09/21 21:52:05
Done.
| |
| 48 if (is_system_profile) { | |
| 49 signin_profile = g_browser_process->profile_manager()->GetProfileByPath( | |
| 50 UserManager::GetSigninProfilePath()); | |
| 51 } else { | |
| 52 signin_profile = webui_profile; | |
| 53 } | |
| 54 #else | |
| 55 signin_profile = webui_profile; | |
| 56 #endif | |
| 57 | |
| 32 content::WebUIDataSource* source = | 58 content::WebUIDataSource* source = |
| 33 content::WebUIDataSource::Create(chrome::kChromeUISigninErrorHost); | 59 content::WebUIDataSource::Create(chrome::kChromeUISigninErrorHost); |
| 34 source->SetJsonPath("strings.js"); | 60 source->SetJsonPath("strings.js"); |
| 35 source->SetDefaultResource(IDR_SIGNIN_ERROR_HTML); | 61 source->SetDefaultResource(IDR_SIGNIN_ERROR_HTML); |
| 36 source->AddResourcePath("signin_error.js", IDR_SIGNIN_ERROR_JS); | 62 source->AddResourcePath("signin_error.js", IDR_SIGNIN_ERROR_JS); |
| 37 source->AddResourcePath("signin_shared_css.html", IDR_SIGNIN_SHARED_CSS_HTML); | 63 source->AddResourcePath("signin_shared_css.html", IDR_SIGNIN_SHARED_CSS_HTML); |
| 64 source->AddBoolean("isSystemProfile", is_system_profile); | |
| 38 | 65 |
| 39 // Retrieve the last signin error message and email used. | 66 // Retrieve the last signin error message and email used. |
| 40 LoginUIService* login_ui_service = | 67 LoginUIService* login_ui_service = |
| 41 LoginUIServiceFactory::GetForProfile(profile); | 68 LoginUIServiceFactory::GetForProfile(signin_profile); |
| 42 const base::string16 last_login_result( | 69 const base::string16 last_login_result( |
| 43 login_ui_service->GetLastLoginResult()); | 70 login_ui_service->GetLastLoginResult()); |
| 44 const base::string16 email = login_ui_service->GetLastLoginErrorEmail(); | 71 const base::string16 email = login_ui_service->GetLastLoginErrorEmail(); |
| 45 if (email.empty()) { | 72 if (email.empty()) { |
| 46 source->AddLocalizedString("signinErrorTitle", IDS_SIGNIN_ERROR_TITLE); | 73 source->AddLocalizedString("signinErrorTitle", IDS_SIGNIN_ERROR_TITLE); |
| 47 } else { | 74 } else { |
| 48 source->AddString( | 75 source->AddString( |
| 49 "signinErrorTitle", | 76 "signinErrorTitle", |
| 50 l10n_util::GetStringFUTF16(IDS_SIGNIN_ERROR_EMAIL_TITLE, email)); | 77 l10n_util::GetStringFUTF16(IDS_SIGNIN_ERROR_EMAIL_TITLE, email)); |
| 51 } | 78 } |
| 52 | 79 |
| 53 // Tweak the dialog UI depending on whether the signin error is | 80 // Tweak the dialog UI depending on whether the signin error is |
| 54 // username-in-use error. | 81 // username-in-use error and the error UI is shown with a browser window. |
| 55 base::string16 existing_name; | 82 base::string16 existing_name; |
| 56 if (last_login_result.compare( | 83 if (!is_system_profile && |
| 84 last_login_result.compare( | |
| 57 l10n_util::GetStringUTF16(IDS_SYNC_USER_NAME_IN_USE_ERROR)) == 0) { | 85 l10n_util::GetStringUTF16(IDS_SYNC_USER_NAME_IN_USE_ERROR)) == 0) { |
| 58 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 86 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 59 if (profile_manager) { | 87 if (profile_manager) { |
| 60 std::vector<ProfileAttributesEntry*> entries = | 88 std::vector<ProfileAttributesEntry*> entries = |
| 61 profile_manager->GetProfileAttributesStorage() | 89 profile_manager->GetProfileAttributesStorage() |
| 62 .GetAllProfilesAttributes(); | 90 .GetAllProfilesAttributes(); |
| 63 DCHECK(!email.empty()); | 91 DCHECK(!email.empty()); |
| 64 for (const ProfileAttributesEntry* entry : entries) { | 92 for (const ProfileAttributesEntry* entry : entries) { |
| 65 if (gaia::AreEmailsSame(base::UTF16ToUTF8(email), | 93 if (gaia::AreEmailsSame(base::UTF16ToUTF8(email), |
| 66 base::UTF16ToUTF8(entry->GetUserName()))) { | 94 base::UTF16ToUTF8(entry->GetUserName()))) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 92 source->AddLocalizedString("signinErrorCloseLabel", | 120 source->AddLocalizedString("signinErrorCloseLabel", |
| 93 IDS_SIGNIN_ERROR_CLOSE_BUTTON_LABEL); | 121 IDS_SIGNIN_ERROR_CLOSE_BUTTON_LABEL); |
| 94 source->AddLocalizedString("signinErrorOkLabel", | 122 source->AddLocalizedString("signinErrorOkLabel", |
| 95 IDS_SIGNIN_ERROR_OK_BUTTON_LABEL); | 123 IDS_SIGNIN_ERROR_OK_BUTTON_LABEL); |
| 96 | 124 |
| 97 base::DictionaryValue strings; | 125 base::DictionaryValue strings; |
| 98 webui::SetLoadTimeDataDefaults(g_browser_process->GetApplicationLocale(), | 126 webui::SetLoadTimeDataDefaults(g_browser_process->GetApplicationLocale(), |
| 99 &strings); | 127 &strings); |
| 100 source->AddLocalizedStrings(strings); | 128 source->AddLocalizedStrings(strings); |
| 101 | 129 |
| 102 content::WebUIDataSource::Add(profile, source); | 130 content::WebUIDataSource::Add(webui_profile, source); |
| 103 web_ui->AddMessageHandler(handler); | 131 web_ui->AddMessageHandler(handler); |
| 104 } | 132 } |
| OLD | NEW |