OLD | NEW |
---|---|
(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 if (is_child_account) { | |
Bernhard Bauer
2016/03/16 17:12:27
Invert this condition so you can return early?
aberent
2016/03/18 12:50:01
Done.
| |
57 if (single_parent) { | |
58 return IDS_CHILD_BLOCK_MESSAGE_DEFAULT_SINGLE_PARENT; | |
Bernhard Bauer
2016/03/16 17:12:27
No braces necessary for one-line bodies, and no el
aberent
2016/03/18 12:50:01
Done.
| |
59 } else { | |
60 return IDS_CHILD_BLOCK_MESSAGE_DEFAULT_MULTI_PARENT; | |
61 } | |
62 } else { | |
63 return IDS_SUPERVISED_USER_BLOCK_MESSAGE_DEFAULT; | |
64 } | |
65 case BLACKLIST: | |
66 case ASYNC_CHECKER: | |
67 return IDS_SUPERVISED_USER_BLOCK_MESSAGE_SAFE_SITES; | |
68 case WHITELIST: | |
69 NOTREACHED(); | |
70 break; | |
71 case MANUAL: | |
72 if (is_child_account) { | |
73 if (single_parent) { | |
74 return IDS_CHILD_BLOCK_MESSAGE_MANUAL_SINGLE_PARENT; | |
75 } else { | |
76 return IDS_CHILD_BLOCK_MESSAGE_MANUAL_MULTI_PARENT; | |
77 } | |
78 } else { | |
79 return IDS_SUPERVISED_USER_BLOCK_MESSAGE_MANUAL; | |
80 } | |
81 } | |
82 NOTREACHED(); | |
83 return 0; | |
84 } | |
85 | |
86 std::string BuildHtml(bool allow_access_requests, | |
87 const std::string& profile_image_url, | |
88 const std::string& profile_image_url2, | |
89 const base::string16& custodian, | |
90 const base::string16& custodian_email, | |
91 const base::string16& second_custodian, | |
92 const base::string16& second_custodian_email, | |
93 bool is_child_account, | |
94 FilteringBehaviorReason reason, | |
95 const std::string& app_locale) { | |
96 base::DictionaryValue strings; | |
97 strings.SetString("blockPageTitle", | |
98 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); | |
99 strings.SetBoolean("allowAccessRequests", allow_access_requests); | |
100 strings.SetString("avatarURL1x", | |
101 BuildAvatarImageUrl(profile_image_url, kAvatarSize1x)); | |
102 strings.SetString("avatarURL2x", | |
103 BuildAvatarImageUrl(profile_image_url, kAvatarSize2x)); | |
104 strings.SetString("secondAvatarURL1x", | |
105 BuildAvatarImageUrl(profile_image_url2, kAvatarSize1x)); | |
106 strings.SetString("secondAvatarURL2x", | |
107 BuildAvatarImageUrl(profile_image_url2, kAvatarSize2x)); | |
108 strings.SetString("custodianName", custodian); | |
109 strings.SetString("custodianEmail", custodian_email); | |
110 strings.SetString("secondCustodianName", second_custodian); | |
111 strings.SetString("secondCustodianEmail", second_custodian_email); | |
112 base::string16 block_message; | |
113 if (allow_access_requests) { | |
114 if (is_child_account) { | |
115 block_message = l10n_util::GetStringUTF16( | |
116 second_custodian.empty() | |
117 ? IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_SINGLE_PARENT | |
118 : IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_MULTI_PARENT); | |
119 } else { | |
120 block_message = | |
121 l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, custodian); | |
122 } | |
123 } else { | |
124 block_message = l10n_util::GetStringUTF16( | |
125 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED); | |
126 } | |
127 strings.SetString("blockPageMessage", block_message); | |
128 strings.SetString("blockReasonMessage", | |
129 l10n_util::GetStringUTF16(GetBlockMessageID( | |
130 reason, is_child_account, second_custodian.empty()))); | |
131 strings.SetString("blockReasonHeader", | |
132 l10n_util::GetStringUTF16(GetBlockHeaderID(reason))); | |
133 bool show_feedback = false; | |
134 #if defined(GOOGLE_CHROME_BUILD) | |
135 show_feedback = | |
136 is_child_account && SupervisedUserURLFilter::ReasonIsAutomatic(reason); | |
137 #endif | |
138 strings.SetBoolean("showFeedbackLink", show_feedback); | |
139 strings.SetString("feedbackLink", l10n_util::GetStringUTF16( | |
140 IDS_BLOCK_INTERSTITIAL_SEND_FEEDBACK)); | |
141 strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON)); | |
142 strings.SetString( | |
143 "requestAccessButton", | |
144 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON)); | |
145 strings.SetString( | |
146 "showDetailsLink", | |
147 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_SHOW_DETAILS)); | |
148 strings.SetString( | |
149 "hideDetailsLink", | |
150 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_HIDE_DETAILS)); | |
151 base::string16 request_sent_message; | |
152 base::string16 request_failed_message; | |
153 if (is_child_account) { | |
154 if (second_custodian.empty()) { | |
155 request_sent_message = l10n_util::GetStringUTF16( | |
156 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT); | |
157 request_failed_message = l10n_util::GetStringUTF16( | |
158 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT); | |
159 } else { | |
160 request_sent_message = l10n_util::GetStringUTF16( | |
161 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT); | |
162 request_failed_message = l10n_util::GetStringUTF16( | |
163 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT); | |
164 } | |
165 } else { | |
166 request_sent_message = l10n_util::GetStringFUTF16( | |
167 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian); | |
168 request_failed_message = l10n_util::GetStringFUTF16( | |
169 IDS_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE, custodian); | |
170 } | |
171 strings.SetString("requestSentMessage", request_sent_message); | |
172 strings.SetString("requestFailedMessage", request_failed_message); | |
173 webui::SetLoadTimeDataDefaults(app_locale, &strings); | |
174 std::string html = | |
175 ResourceBundle::GetSharedInstance() | |
176 .GetRawDataResource(IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML) | |
177 .as_string(); | |
178 webui::AppendWebUiCssTextDefaults(&html); | |
179 return webui::GetI18nTemplateHtml(html, &strings); | |
180 } | |
181 | |
182 } // namespace supervised_user_error_page | |
OLD | NEW |