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

Side by Side Diff: components/supervised_user_error_page/supervised_user_error_page.cc

Issue 1808653003: Move the supervised user error page to a component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 "components/supervised_user_error_page/supervised_user_error_page.h"
6
7 #include "base/macros.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/values.h"
10 #include "grit/components_resources.h"
11 #include "grit/components_strings.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/base/webui/jstemplate_builder.h"
15 #include "ui/base/webui/web_ui_util.h"
16
17 namespace {
18
19 static const int kAvatarSize1x = 45;
20 static const int kAvatarSize2x = 90;
21
22 std::string BuildAvatarImageUrl(const std::string& url, int size) {
23 std::string result = url;
24 size_t slash = result.rfind('/');
25 if (slash != std::string::npos)
26 result.insert(slash, "/s" + base::IntToString(size));
27 return result;
28 }
29
30 int GetBlockHeaderID(
31 supervised_user_error_page::FilteringBehaviorReason reason) {
32 switch (reason) {
33 case supervised_user_error_page::DEFAULT:
34 return IDS_SUPERVISED_USER_BLOCK_HEADER_DEFAULT;
35 case supervised_user_error_page::BLACKLIST:
36 case supervised_user_error_page::ASYNC_CHECKER:
37 return IDS_SUPERVISED_USER_BLOCK_HEADER_SAFE_SITES;
38 case supervised_user_error_page::WHITELIST:
39 NOTREACHED();
40 break;
41 case supervised_user_error_page::MANUAL:
42 return IDS_SUPERVISED_USER_BLOCK_HEADER_MANUAL;
43 }
44 NOTREACHED();
45 return 0;
46 }
47 } // namespace
48
49 namespace supervised_user_error_page {
50
51 int GetBlockMessageID(FilteringBehaviorReason reason,
52 bool is_child_account,
53 bool single_parent) {
54 switch (reason) {
55 case DEFAULT:
56 return is_child_account
Bernhard Bauer 2016/03/16 13:59:45 Could you split these up into several if () { retu
aberent 2016/03/16 16:06:41 You want me to improve the code as well as moving
Bernhard Bauer 2016/03/16 17:12:26 I know, I'm a slave driver. Thanks!
57 ? (single_parent
58 ? IDS_CHILD_BLOCK_MESSAGE_DEFAULT_SINGLE_PARENT
59 : IDS_CHILD_BLOCK_MESSAGE_DEFAULT_MULTI_PARENT)
60 : IDS_SUPERVISED_USER_BLOCK_MESSAGE_DEFAULT;
61 case BLACKLIST:
62 case ASYNC_CHECKER:
63 return IDS_SUPERVISED_USER_BLOCK_MESSAGE_SAFE_SITES;
64 case WHITELIST:
65 NOTREACHED();
66 break;
67 case MANUAL:
68 return is_child_account
69 ? (single_parent ? IDS_CHILD_BLOCK_MESSAGE_MANUAL_SINGLE_PARENT
70 : IDS_CHILD_BLOCK_MESSAGE_MANUAL_MULTI_PARENT)
71 : IDS_SUPERVISED_USER_BLOCK_MESSAGE_MANUAL;
72 }
73 NOTREACHED();
74 return 0;
75 }
76
77 std::string BuildHtml(bool allow_access_requests,
78 const std::string& profile_image_url,
79 const std::string& profile_image_url2,
80 const base::string16& custodian,
81 const base::string16& custodian_email,
82 const base::string16& second_custodian,
83 const base::string16& second_custodian_email,
84 bool is_child_account,
85 FilteringBehaviorReason reason,
86 const std::string& app_locale) {
87 base::DictionaryValue strings;
88 strings.SetString("blockPageTitle",
89 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE));
90 strings.SetBoolean("allowAccessRequests", allow_access_requests);
91 strings.SetString("avatarURL1x",
92 BuildAvatarImageUrl(profile_image_url, kAvatarSize1x));
93 strings.SetString("avatarURL2x",
94 BuildAvatarImageUrl(profile_image_url, kAvatarSize2x));
95 strings.SetString("secondAvatarURL1x",
96 BuildAvatarImageUrl(profile_image_url2, kAvatarSize1x));
97 strings.SetString("secondAvatarURL2x",
98 BuildAvatarImageUrl(profile_image_url2, kAvatarSize2x));
99 strings.SetString("custodianName", custodian);
100 strings.SetString("custodianEmail", custodian_email);
101 strings.SetString("secondCustodianName", second_custodian);
102 strings.SetString("secondCustodianEmail", second_custodian_email);
103 base::string16 block_message;
104 if (allow_access_requests) {
105 if (is_child_account) {
106 block_message = l10n_util::GetStringUTF16(
107 second_custodian.empty()
108 ? IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_SINGLE_PARENT
109 : IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_MULTI_PARENT);
110 } else {
111 block_message =
112 l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, custodian);
113 }
114 } else {
115 block_message = l10n_util::GetStringUTF16(
116 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED);
117 }
118 strings.SetString("blockPageMessage", block_message);
119 strings.SetString("blockReasonMessage",
120 l10n_util::GetStringUTF16(GetBlockMessageID(
121 reason, is_child_account, second_custodian.empty())));
122 strings.SetString("blockReasonHeader",
123 l10n_util::GetStringUTF16(GetBlockHeaderID(reason)));
124 bool show_feedback = false;
125 #if defined(GOOGLE_CHROME_BUILD)
126 show_feedback =
127 is_child_account && SupervisedUserURLFilter::ReasonIsAutomatic(reason);
128 #endif
129 strings.SetBoolean("showFeedbackLink", show_feedback);
130 strings.SetString("feedbackLink", l10n_util::GetStringUTF16(
131 IDS_BLOCK_INTERSTITIAL_SEND_FEEDBACK));
132 strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON));
133 strings.SetString(
134 "requestAccessButton",
135 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON));
136 strings.SetString(
137 "showDetailsLink",
138 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_SHOW_DETAILS));
139 strings.SetString(
140 "hideDetailsLink",
141 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_HIDE_DETAILS));
142 base::string16 request_sent_message;
143 base::string16 request_failed_message;
144 if (is_child_account) {
145 if (second_custodian.empty()) {
146 request_sent_message = l10n_util::GetStringUTF16(
147 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT);
148 request_failed_message = l10n_util::GetStringUTF16(
149 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT);
150 } else {
151 request_sent_message = l10n_util::GetStringUTF16(
152 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT);
153 request_failed_message = l10n_util::GetStringUTF16(
154 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT);
155 }
156 } else {
157 request_sent_message = l10n_util::GetStringFUTF16(
158 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian);
159 request_failed_message = l10n_util::GetStringFUTF16(
160 IDS_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE, custodian);
161 }
162 strings.SetString("requestSentMessage", request_sent_message);
163 strings.SetString("requestFailedMessage", request_failed_message);
164 webui::SetLoadTimeDataDefaults(app_locale, &strings);
165 std::string html =
166 ResourceBundle::GetSharedInstance()
167 .GetRawDataResource(IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML)
168 .as_string();
169 webui::AppendWebUiCssTextDefaults(&html);
170 return webui::GetI18nTemplateHtml(html, &strings);
171 }
172
173 } // namespace supervised_user_error_page
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698