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 |
25 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui) | 28 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui) |
26 : SigninErrorUI(web_ui, new SigninErrorHandler) {} | 29 : SigninErrorUI(web_ui, |
| 30 new SigninErrorHandler(Profile::FromWebUI(web_ui) |
| 31 ->GetOriginalProfile() |
| 32 ->IsSystemProfile())) {} |
27 | 33 |
28 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui, | 34 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui, |
29 SigninErrorHandler* handler) | 35 SigninErrorHandler* handler) |
30 : WebDialogUI(web_ui) { | 36 : WebDialogUI(web_ui) { |
31 Profile* profile = Profile::FromWebUI(web_ui); | 37 Profile* webui_profile = Profile::FromWebUI(web_ui); |
| 38 Profile* signin_profile; |
| 39 bool is_system_profile = |
| 40 webui_profile->GetOriginalProfile()->IsSystemProfile(); |
| 41 |
| 42 // TODO(zmin): Remove the condition for MACOSX once user_manager_mac.cc is |
| 43 // updated. |
| 44 #if !defined(OS_MACOSX) |
| 45 if (is_system_profile) { |
| 46 signin_profile = g_browser_process->profile_manager()->GetProfileByPath( |
| 47 UserManager::GetSigninProfilePath()); |
| 48 } else { |
| 49 signin_profile = webui_profile; |
| 50 } |
| 51 #else |
| 52 signin_profile = webui_profile; |
| 53 #endif |
| 54 |
32 content::WebUIDataSource* source = | 55 content::WebUIDataSource* source = |
33 content::WebUIDataSource::Create(chrome::kChromeUISigninErrorHost); | 56 content::WebUIDataSource::Create(chrome::kChromeUISigninErrorHost); |
34 source->SetJsonPath("strings.js"); | 57 source->SetJsonPath("strings.js"); |
35 source->SetDefaultResource(IDR_SIGNIN_ERROR_HTML); | 58 source->SetDefaultResource(IDR_SIGNIN_ERROR_HTML); |
36 source->AddResourcePath("signin_error.js", IDR_SIGNIN_ERROR_JS); | 59 source->AddResourcePath("signin_error.js", IDR_SIGNIN_ERROR_JS); |
37 source->AddResourcePath("signin_shared_css.html", IDR_SIGNIN_SHARED_CSS_HTML); | 60 source->AddResourcePath("signin_shared_css.html", IDR_SIGNIN_SHARED_CSS_HTML); |
| 61 source->AddBoolean("isSystemProfile", is_system_profile); |
38 | 62 |
39 // Retrieve the last signin error message and email used. | 63 // Retrieve the last signin error message and email used. |
40 LoginUIService* login_ui_service = | 64 LoginUIService* login_ui_service = |
41 LoginUIServiceFactory::GetForProfile(profile); | 65 LoginUIServiceFactory::GetForProfile(signin_profile); |
42 const base::string16 last_login_result( | 66 const base::string16 last_login_result( |
43 login_ui_service->GetLastLoginResult()); | 67 login_ui_service->GetLastLoginResult()); |
44 const base::string16 email = login_ui_service->GetLastLoginErrorEmail(); | 68 const base::string16 email = login_ui_service->GetLastLoginErrorEmail(); |
45 if (email.empty()) { | 69 if (email.empty()) { |
46 source->AddLocalizedString("signinErrorTitle", IDS_SIGNIN_ERROR_TITLE); | 70 source->AddLocalizedString("signinErrorTitle", IDS_SIGNIN_ERROR_TITLE); |
47 } else { | 71 } else { |
48 source->AddString( | 72 source->AddString( |
49 "signinErrorTitle", | 73 "signinErrorTitle", |
50 l10n_util::GetStringFUTF16(IDS_SIGNIN_ERROR_EMAIL_TITLE, email)); | 74 l10n_util::GetStringFUTF16(IDS_SIGNIN_ERROR_EMAIL_TITLE, email)); |
51 } | 75 } |
52 | 76 |
53 // Tweak the dialog UI depending on whether the signin error is | 77 // Tweak the dialog UI depending on whether the signin error is |
54 // username-in-use error. | 78 // username-in-use error and the error UI is shown with a browser window. |
55 base::string16 existing_name; | 79 base::string16 existing_name; |
56 if (last_login_result.compare( | 80 if (!is_system_profile && |
| 81 last_login_result.compare( |
57 l10n_util::GetStringUTF16(IDS_SYNC_USER_NAME_IN_USE_ERROR)) == 0) { | 82 l10n_util::GetStringUTF16(IDS_SYNC_USER_NAME_IN_USE_ERROR)) == 0) { |
58 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 83 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
59 if (profile_manager) { | 84 if (profile_manager) { |
60 std::vector<ProfileAttributesEntry*> entries = | 85 std::vector<ProfileAttributesEntry*> entries = |
61 profile_manager->GetProfileAttributesStorage() | 86 profile_manager->GetProfileAttributesStorage() |
62 .GetAllProfilesAttributes(); | 87 .GetAllProfilesAttributes(); |
63 DCHECK(!email.empty()); | 88 DCHECK(!email.empty()); |
64 for (const ProfileAttributesEntry* entry : entries) { | 89 for (const ProfileAttributesEntry* entry : entries) { |
65 if (gaia::AreEmailsSame(base::UTF16ToUTF8(email), | 90 if (gaia::AreEmailsSame(base::UTF16ToUTF8(email), |
66 base::UTF16ToUTF8(entry->GetUserName()))) { | 91 base::UTF16ToUTF8(entry->GetUserName()))) { |
(...skipping 25 matching lines...) Expand all Loading... |
92 source->AddLocalizedString("signinErrorCloseLabel", | 117 source->AddLocalizedString("signinErrorCloseLabel", |
93 IDS_SIGNIN_ERROR_CLOSE_BUTTON_LABEL); | 118 IDS_SIGNIN_ERROR_CLOSE_BUTTON_LABEL); |
94 source->AddLocalizedString("signinErrorOkLabel", | 119 source->AddLocalizedString("signinErrorOkLabel", |
95 IDS_SIGNIN_ERROR_OK_BUTTON_LABEL); | 120 IDS_SIGNIN_ERROR_OK_BUTTON_LABEL); |
96 | 121 |
97 base::DictionaryValue strings; | 122 base::DictionaryValue strings; |
98 webui::SetLoadTimeDataDefaults(g_browser_process->GetApplicationLocale(), | 123 webui::SetLoadTimeDataDefaults(g_browser_process->GetApplicationLocale(), |
99 &strings); | 124 &strings); |
100 source->AddLocalizedStrings(strings); | 125 source->AddLocalizedStrings(strings); |
101 | 126 |
102 content::WebUIDataSource::Add(profile, source); | 127 content::WebUIDataSource::Add(webui_profile, source); |
103 web_ui->AddMessageHandler(handler); | 128 web_ui->AddMessageHandler(handler); |
104 } | 129 } |
OLD | NEW |