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 | |
tommycli
2016/09/21 18:26:59
nit: I don't think this shortening is worth it. It
zmin
2016/09/21 21:21:37
Why not? That is still a code copy.
tommycli
2016/09/21 21:26:16
I think since it's so short, it would be easier to
zmin
2016/09/21 21:52:05
Done.
| |
33 | |
25 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui) | 34 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui) |
26 : SigninErrorUI(web_ui, new SigninErrorHandler) {} | 35 : SigninErrorUI(web_ui, |
36 SigninErrorHandler::Create( | |
37 IsSystemProfile(Profile::FromWebUI(web_ui)))) {} | |
27 | 38 |
28 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui, | 39 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui, |
29 SigninErrorHandler* handler) | 40 SigninErrorHandler* handler) |
30 : WebDialogUI(web_ui) { | 41 : WebDialogUI(web_ui) { |
31 Profile* profile = Profile::FromWebUI(web_ui); | 42 Profile* webui_profile = Profile::FromWebUI(web_ui); |
43 Profile* signin_profile; | |
44 bool is_system_profile = IsSystemProfile(webui_profile); | |
45 if (is_system_profile) { | |
tommycli
2016/09/21 18:26:59
nit: Maybe clearer with a ternary expression? Not
zmin
2016/09/21 21:21:37
I'm personally not a fan of ternary expression. Es
tommycli
2016/09/21 21:26:15
Acknowledged.
| |
46 signin_profile = g_browser_process->profile_manager()->GetProfileByPath( | |
47 UserManager::GetSigninProfilePath()); | |
48 } else { | |
49 signin_profile = webui_profile; | |
50 } | |
51 | |
32 content::WebUIDataSource* source = | 52 content::WebUIDataSource* source = |
33 content::WebUIDataSource::Create(chrome::kChromeUISigninErrorHost); | 53 content::WebUIDataSource::Create(chrome::kChromeUISigninErrorHost); |
34 source->SetJsonPath("strings.js"); | 54 source->SetJsonPath("strings.js"); |
35 source->SetDefaultResource(IDR_SIGNIN_ERROR_HTML); | 55 source->SetDefaultResource(IDR_SIGNIN_ERROR_HTML); |
36 source->AddResourcePath("signin_error.js", IDR_SIGNIN_ERROR_JS); | 56 source->AddResourcePath("signin_error.js", IDR_SIGNIN_ERROR_JS); |
37 source->AddResourcePath("signin_shared_css.html", IDR_SIGNIN_SHARED_CSS_HTML); | 57 source->AddResourcePath("signin_shared_css.html", IDR_SIGNIN_SHARED_CSS_HTML); |
58 source->AddBoolean("isSystemProfile", is_system_profile); | |
38 | 59 |
39 // Retrieve the last signin error message and email used. | 60 // Retrieve the last signin error message and email used. |
40 LoginUIService* login_ui_service = | 61 LoginUIService* login_ui_service = |
41 LoginUIServiceFactory::GetForProfile(profile); | 62 LoginUIServiceFactory::GetForProfile(signin_profile); |
42 const base::string16 last_login_result( | 63 const base::string16 last_login_result( |
43 login_ui_service->GetLastLoginResult()); | 64 login_ui_service->GetLastLoginResult()); |
44 const base::string16 email = login_ui_service->GetLastLoginErrorEmail(); | 65 const base::string16 email = login_ui_service->GetLastLoginErrorEmail(); |
45 if (email.empty()) { | 66 if (email.empty()) { |
46 source->AddLocalizedString("signinErrorTitle", IDS_SIGNIN_ERROR_TITLE); | 67 source->AddLocalizedString("signinErrorTitle", IDS_SIGNIN_ERROR_TITLE); |
47 } else { | 68 } else { |
48 source->AddString( | 69 source->AddString( |
49 "signinErrorTitle", | 70 "signinErrorTitle", |
50 l10n_util::GetStringFUTF16(IDS_SIGNIN_ERROR_EMAIL_TITLE, email)); | 71 l10n_util::GetStringFUTF16(IDS_SIGNIN_ERROR_EMAIL_TITLE, email)); |
51 } | 72 } |
52 | 73 |
53 // Tweak the dialog UI depending on whether the signin error is | 74 // Tweak the dialog UI depending on whether the signin error is |
54 // username-in-use error. | 75 // username-in-use error and the error UI is shown with a browser window. |
55 base::string16 existing_name; | 76 base::string16 existing_name; |
56 if (last_login_result.compare( | 77 if (!is_system_profile && |
78 last_login_result.compare( | |
57 l10n_util::GetStringUTF16(IDS_SYNC_USER_NAME_IN_USE_ERROR)) == 0) { | 79 l10n_util::GetStringUTF16(IDS_SYNC_USER_NAME_IN_USE_ERROR)) == 0) { |
58 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 80 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
59 if (profile_manager) { | 81 if (profile_manager) { |
60 std::vector<ProfileAttributesEntry*> entries = | 82 std::vector<ProfileAttributesEntry*> entries = |
61 profile_manager->GetProfileAttributesStorage() | 83 profile_manager->GetProfileAttributesStorage() |
62 .GetAllProfilesAttributes(); | 84 .GetAllProfilesAttributes(); |
63 DCHECK(!email.empty()); | 85 DCHECK(!email.empty()); |
64 for (const ProfileAttributesEntry* entry : entries) { | 86 for (const ProfileAttributesEntry* entry : entries) { |
65 if (gaia::AreEmailsSame(base::UTF16ToUTF8(email), | 87 if (gaia::AreEmailsSame(base::UTF16ToUTF8(email), |
66 base::UTF16ToUTF8(entry->GetUserName()))) { | 88 base::UTF16ToUTF8(entry->GetUserName()))) { |
(...skipping 25 matching lines...) Expand all Loading... | |
92 source->AddLocalizedString("signinErrorCloseLabel", | 114 source->AddLocalizedString("signinErrorCloseLabel", |
93 IDS_SIGNIN_ERROR_CLOSE_BUTTON_LABEL); | 115 IDS_SIGNIN_ERROR_CLOSE_BUTTON_LABEL); |
94 source->AddLocalizedString("signinErrorOkLabel", | 116 source->AddLocalizedString("signinErrorOkLabel", |
95 IDS_SIGNIN_ERROR_OK_BUTTON_LABEL); | 117 IDS_SIGNIN_ERROR_OK_BUTTON_LABEL); |
96 | 118 |
97 base::DictionaryValue strings; | 119 base::DictionaryValue strings; |
98 webui::SetLoadTimeDataDefaults(g_browser_process->GetApplicationLocale(), | 120 webui::SetLoadTimeDataDefaults(g_browser_process->GetApplicationLocale(), |
99 &strings); | 121 &strings); |
100 source->AddLocalizedStrings(strings); | 122 source->AddLocalizedStrings(strings); |
101 | 123 |
102 content::WebUIDataSource::Add(profile, source); | 124 content::WebUIDataSource::Add(webui_profile, source); |
103 web_ui->AddMessageHandler(handler); | 125 web_ui->AddMessageHandler(handler); |
104 } | 126 } |
OLD | NEW |