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

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

Issue 2275883003: [Signin Error Dialog] (2/3) Added handlers and UI constructors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@error-modal-web
Patch Set: Final nit from tommycli 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/generated_resources.h"
18 #include "content/public/browser/web_ui.h"
19 #include "content/public/browser/web_ui_data_source.h"
20 #include "grit/browser_resources.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 base::string16 last_login_result(login_ui_service->GetLastLoginResult());
43 base::string16 email = login_ui_service->GetLastLoginErrorEmail();
44 if (email.empty()) {
45 source->AddLocalizedString("signinErrorTitle", IDS_SIGNIN_ERROR_TITLE);
46 } else {
47 source->AddString(
48 "signinErrorTitle",
49 l10n_util::GetStringFUTF16(IDS_SIGNIN_ERROR_EMAIL_TITLE, email));
50 }
51
52 // Tweak the dialog UI depending on whether the signin error is
53 // username-in-use error.
54 base::string16 existing_name;
55 if (last_login_result.compare(
56 l10n_util::GetStringUTF16(IDS_SYNC_USER_NAME_IN_USE_ERROR)) == 0) {
57 ProfileManager* profile_manager = g_browser_process->profile_manager();
58 if (profile_manager) {
59 std::vector<ProfileAttributesEntry*> entries =
60 profile_manager->GetProfileAttributesStorage()
61 .GetAllProfilesAttributes();
62 DCHECK(!email.empty());
63 for (const ProfileAttributesEntry* entry : entries) {
64 if (gaia::AreEmailsSame(base::UTF16ToUTF8(email),
65 base::UTF16ToUTF8(entry->GetUserName()))) {
66 handler->set_duplicate_profile_entry(entry);
67 existing_name = entry->GetName();
68 }
69 }
70 }
71 DCHECK(!existing_name.empty());
72 source->AddString(
73 "signinErrorMessage",
74 l10n_util::GetStringFUTF16(
75 IDS_SIGNIN_ERROR_LEARN_MORE_LINK,
76 l10n_util::GetStringFUTF16(IDS_SYNC_USER_NAME_IN_USE_BY_ERROR,
77 existing_name)));
78 // Elide the existing name for the switch uer button label.
79 existing_name =
80 gfx::TruncateString(existing_name, 10, gfx::CHARACTER_BREAK);
81 } else {
82 source->AddString("signinErrorMessage",
83 l10n_util::GetStringFUTF16(
84 IDS_SIGNIN_ERROR_LEARN_MORE_LINK, last_login_result));
85 }
86
87 // Add button label strings.
88 source->AddString("signinErrorSwitchLabel",
89 l10n_util::GetStringFUTF16(
90 IDS_SIGNIN_ERROR_SWITCH_BUTTON_LABEL, existing_name));
91 source->AddLocalizedString("signinErrorCloseLabel",
92 IDS_SIGNIN_ERROR_CLOSE_BUTTON_LABEL);
93 source->AddLocalizedString("signinErrorOkLabel",
94 IDS_SIGNIN_ERROR_OK_BUTTON_LABEL);
95
96 base::DictionaryValue strings;
97 webui::SetLoadTimeDataDefaults(g_browser_process->GetApplicationLocale(),
98 &strings);
99 source->AddLocalizedStrings(strings);
100
101 content::WebUIDataSource::Add(profile, source);
102 web_ui->AddMessageHandler(handler);
103 }
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