Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(859)

Side by Side Diff: chrome/browser/ui/webui/signin/signin_error_ui.cc

Issue 2315393002: [Signin Error Dialog] (2/3) Added handlers and UI constructors (Closed)
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/signin/signin_error_ui.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile_attributes_entry.h"
10 #include "chrome/browser/profiles/profile_attributes_storage.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
14 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
15 #include "chrome/browser/ui/webui/signin/signin_error_handler.h"
16 #include "chrome/common/url_constants.h"
17 #include "chrome/grit/browser_resources.h"
18 #include "chrome/grit/generated_resources.h"
19 #include "content/public/browser/web_ui.h"
20 #include "content/public/browser/web_ui_data_source.h"
21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/webui/web_ui_util.h"
23 #include "ui/gfx/text_elider.h"
24
25 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui)
26 : SigninErrorUI(web_ui, new SigninErrorHandler) {}
27
28 SigninErrorUI::SigninErrorUI(content::WebUI* web_ui,
29 SigninErrorHandler* handler)
30 : WebDialogUI(web_ui) {
31 Profile* profile = Profile::FromWebUI(web_ui);
32 content::WebUIDataSource* source =
33 content::WebUIDataSource::Create(chrome::kChromeUISigninErrorHost);
34 source->SetJsonPath("strings.js");
35 source->SetDefaultResource(IDR_SIGNIN_ERROR_HTML);
36 source->AddResourcePath("signin_error.js", IDR_SIGNIN_ERROR_JS);
37 source->AddResourcePath("signin_shared_css.html", IDR_SIGNIN_SHARED_CSS_HTML);
38
39 // Retrieve the last signin error message and email used.
40 LoginUIService* login_ui_service =
41 LoginUIServiceFactory::GetForProfile(profile);
42 const base::string16 last_login_result(
43 login_ui_service->GetLastLoginResult());
44 const base::string16 email = login_ui_service->GetLastLoginErrorEmail();
45 if (email.empty()) {
46 source->AddLocalizedString("signinErrorTitle", IDS_SIGNIN_ERROR_TITLE);
47 } else {
48 source->AddString(
49 "signinErrorTitle",
50 l10n_util::GetStringFUTF16(IDS_SIGNIN_ERROR_EMAIL_TITLE, email));
51 }
52
53 // Tweak the dialog UI depending on whether the signin error is
54 // username-in-use error.
55 base::string16 existing_name;
56 if (last_login_result.compare(
57 l10n_util::GetStringUTF16(IDS_SYNC_USER_NAME_IN_USE_ERROR)) == 0) {
58 ProfileManager* profile_manager = g_browser_process->profile_manager();
59 if (profile_manager) {
60 std::vector<ProfileAttributesEntry*> entries =
61 profile_manager->GetProfileAttributesStorage()
62 .GetAllProfilesAttributes();
63 DCHECK(!email.empty());
64 for (const ProfileAttributesEntry* entry : entries) {
65 if (gaia::AreEmailsSame(base::UTF16ToUTF8(email),
66 base::UTF16ToUTF8(entry->GetUserName()))) {
67 handler->set_duplicate_profile_entry(entry);
68 existing_name = entry->GetName();
69 }
70 }
71 }
72 DCHECK(!existing_name.empty());
73 source->AddString(
74 "signinErrorMessage",
75 l10n_util::GetStringFUTF16(
76 IDS_SIGNIN_ERROR_LEARN_MORE_LINK,
77 l10n_util::GetStringFUTF16(IDS_SYNC_USER_NAME_IN_USE_BY_ERROR,
78 existing_name)));
79 // Elide the existing name for the switch user button label.
80 existing_name =
81 gfx::TruncateString(existing_name, 10, gfx::CHARACTER_BREAK);
82 } else {
83 source->AddString("signinErrorMessage",
84 l10n_util::GetStringFUTF16(
85 IDS_SIGNIN_ERROR_LEARN_MORE_LINK, last_login_result));
86 }
87
88 // Add button label strings.
89 source->AddString("signinErrorSwitchLabel",
90 l10n_util::GetStringFUTF16(
91 IDS_SIGNIN_ERROR_SWITCH_BUTTON_LABEL, existing_name));
92 source->AddLocalizedString("signinErrorCloseLabel",
93 IDS_SIGNIN_ERROR_CLOSE_BUTTON_LABEL);
94 source->AddLocalizedString("signinErrorOkLabel",
95 IDS_SIGNIN_ERROR_OK_BUTTON_LABEL);
96
97 base::DictionaryValue strings;
98 webui::SetLoadTimeDataDefaults(g_browser_process->GetApplicationLocale(),
99 &strings);
100 source->AddLocalizedStrings(strings);
101
102 content::WebUIDataSource::Add(profile, source);
103 web_ui->AddMessageHandler(handler);
104 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/signin/signin_error_ui.h ('k') | chrome/browser/ui/webui/signin/signin_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698