| 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 "components/supervised_user_error_page/supervised_user_error_page.h" | 5 #include "components/supervised_user_error_page/supervised_user_error_page.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 10 #include "base/values.h" |
| 10 #include "grit/components_resources.h" | 11 #include "grit/components_resources.h" |
| 11 #include "grit/components_strings.h" | 12 #include "grit/components_strings.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/base/webui/jstemplate_builder.h" | 15 #include "ui/base/webui/jstemplate_builder.h" |
| 15 #include "ui/base/webui/web_ui_util.h" | 16 #include "ui/base/webui/web_ui_util.h" |
| 16 | 17 |
| 17 namespace supervised_user_error_page { | 18 namespace supervised_user_error_page { |
| 18 | 19 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 if (!is_child_account) | 74 if (!is_child_account) |
| 74 return IDS_SUPERVISED_USER_BLOCK_MESSAGE_MANUAL; | 75 return IDS_SUPERVISED_USER_BLOCK_MESSAGE_MANUAL; |
| 75 if (single_parent) | 76 if (single_parent) |
| 76 return IDS_CHILD_BLOCK_MESSAGE_MANUAL_SINGLE_PARENT; | 77 return IDS_CHILD_BLOCK_MESSAGE_MANUAL_SINGLE_PARENT; |
| 77 return IDS_CHILD_BLOCK_MESSAGE_MANUAL_MULTI_PARENT; | 78 return IDS_CHILD_BLOCK_MESSAGE_MANUAL_MULTI_PARENT; |
| 78 } | 79 } |
| 79 NOTREACHED(); | 80 NOTREACHED(); |
| 80 return 0; | 81 return 0; |
| 81 } | 82 } |
| 82 | 83 |
| 84 std::string BuildHtmlFromWebRestrictionsResult( |
| 85 const web_restrictions::mojom::ClientResultPtr& result, |
| 86 const std::string app_locale) { |
| 87 return BuildHtml( |
| 88 result->intParams["Allow access requests"], |
| 89 result->stringParams["Profile image URL"], |
| 90 result->stringParams["Second profile image URL"], |
| 91 result->stringParams["Custodian"], |
| 92 result->stringParams["Custodian email"], |
| 93 result->stringParams["Second custodian"], |
| 94 result->stringParams["Second custodian email"], |
| 95 result->intParams["Is child account"], |
| 96 static_cast<FilteringBehaviorReason>(result->intParams["Reason"]), |
| 97 app_locale); |
| 98 } |
| 99 |
| 83 std::string BuildHtml(bool allow_access_requests, | 100 std::string BuildHtml(bool allow_access_requests, |
| 84 const std::string& profile_image_url, | 101 const std::string& profile_image_url, |
| 85 const std::string& profile_image_url2, | 102 const std::string& profile_image_url2, |
| 86 const base::string16& custodian, | 103 const std::string& custodian, |
| 87 const base::string16& custodian_email, | 104 const std::string& custodian_email, |
| 88 const base::string16& second_custodian, | 105 const std::string& second_custodian, |
| 89 const base::string16& second_custodian_email, | 106 const std::string& second_custodian_email, |
| 90 bool is_child_account, | 107 bool is_child_account, |
| 91 FilteringBehaviorReason reason, | 108 FilteringBehaviorReason reason, |
| 92 const std::string& app_locale) { | 109 const std::string& app_locale) { |
| 93 base::DictionaryValue strings; | 110 base::DictionaryValue strings; |
| 94 strings.SetString("blockPageTitle", | 111 strings.SetString("blockPageTitle", |
| 95 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); | 112 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); |
| 96 strings.SetBoolean("allowAccessRequests", allow_access_requests); | 113 strings.SetBoolean("allowAccessRequests", allow_access_requests); |
| 97 strings.SetString("avatarURL1x", | 114 strings.SetString("avatarURL1x", |
| 98 BuildAvatarImageUrl(profile_image_url, kAvatarSize1x)); | 115 BuildAvatarImageUrl(profile_image_url, kAvatarSize1x)); |
| 99 strings.SetString("avatarURL2x", | 116 strings.SetString("avatarURL2x", |
| 100 BuildAvatarImageUrl(profile_image_url, kAvatarSize2x)); | 117 BuildAvatarImageUrl(profile_image_url, kAvatarSize2x)); |
| 101 strings.SetString("secondAvatarURL1x", | 118 strings.SetString("secondAvatarURL1x", |
| 102 BuildAvatarImageUrl(profile_image_url2, kAvatarSize1x)); | 119 BuildAvatarImageUrl(profile_image_url2, kAvatarSize1x)); |
| 103 strings.SetString("secondAvatarURL2x", | 120 strings.SetString("secondAvatarURL2x", |
| 104 BuildAvatarImageUrl(profile_image_url2, kAvatarSize2x)); | 121 BuildAvatarImageUrl(profile_image_url2, kAvatarSize2x)); |
| 105 strings.SetString("custodianName", custodian); | 122 base::string16 custodian16 = base::UTF8ToUTF16(custodian); |
| 106 strings.SetString("custodianEmail", custodian_email); | 123 strings.SetString("custodianName", custodian16); |
| 107 strings.SetString("secondCustodianName", second_custodian); | 124 strings.SetString("custodianEmail", base::UTF8ToUTF16(custodian_email)); |
| 108 strings.SetString("secondCustodianEmail", second_custodian_email); | 125 strings.SetString("secondCustodianName", base::UTF8ToUTF16(second_custodian)); |
| 126 strings.SetString("secondCustodianEmail", |
| 127 base::UTF8ToUTF16(second_custodian_email)); |
| 109 base::string16 block_message; | 128 base::string16 block_message; |
| 110 if (allow_access_requests) { | 129 if (allow_access_requests) { |
| 111 if (is_child_account) { | 130 if (is_child_account) { |
| 112 block_message = l10n_util::GetStringUTF16( | 131 block_message = l10n_util::GetStringUTF16( |
| 113 second_custodian.empty() | 132 second_custodian.empty() |
| 114 ? IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_SINGLE_PARENT | 133 ? IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_SINGLE_PARENT |
| 115 : IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_MULTI_PARENT); | 134 : IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_MULTI_PARENT); |
| 116 } else { | 135 } else { |
| 117 block_message = | 136 block_message = l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, |
| 118 l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, custodian); | 137 custodian16); |
| 119 } | 138 } |
| 120 } else { | 139 } else { |
| 121 block_message = l10n_util::GetStringUTF16( | 140 block_message = l10n_util::GetStringUTF16( |
| 122 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED); | 141 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED); |
| 123 } | 142 } |
| 124 strings.SetString("blockPageMessage", block_message); | 143 strings.SetString("blockPageMessage", block_message); |
| 125 strings.SetString("blockReasonMessage", | 144 strings.SetString("blockReasonMessage", |
| 126 l10n_util::GetStringUTF16(GetBlockMessageID( | 145 l10n_util::GetStringUTF16(GetBlockMessageID( |
| 127 reason, is_child_account, second_custodian.empty()))); | 146 reason, is_child_account, second_custodian.empty()))); |
| 128 strings.SetString("blockReasonHeader", | 147 strings.SetString("blockReasonHeader", |
| (...skipping 24 matching lines...) Expand all Loading... |
| 153 request_failed_message = l10n_util::GetStringUTF16( | 172 request_failed_message = l10n_util::GetStringUTF16( |
| 154 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT); | 173 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT); |
| 155 } else { | 174 } else { |
| 156 request_sent_message = l10n_util::GetStringUTF16( | 175 request_sent_message = l10n_util::GetStringUTF16( |
| 157 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT); | 176 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT); |
| 158 request_failed_message = l10n_util::GetStringUTF16( | 177 request_failed_message = l10n_util::GetStringUTF16( |
| 159 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT); | 178 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT); |
| 160 } | 179 } |
| 161 } else { | 180 } else { |
| 162 request_sent_message = l10n_util::GetStringFUTF16( | 181 request_sent_message = l10n_util::GetStringFUTF16( |
| 163 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian); | 182 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian16); |
| 164 request_failed_message = l10n_util::GetStringFUTF16( | 183 request_failed_message = l10n_util::GetStringFUTF16( |
| 165 IDS_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE, custodian); | 184 IDS_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE, custodian16); |
| 166 } | 185 } |
| 167 strings.SetString("requestSentMessage", request_sent_message); | 186 strings.SetString("requestSentMessage", request_sent_message); |
| 168 strings.SetString("requestFailedMessage", request_failed_message); | 187 strings.SetString("requestFailedMessage", request_failed_message); |
| 169 webui::SetLoadTimeDataDefaults(app_locale, &strings); | 188 webui::SetLoadTimeDataDefaults(app_locale, &strings); |
| 170 std::string html = | 189 std::string html = |
| 171 ResourceBundle::GetSharedInstance() | 190 ResourceBundle::GetSharedInstance() |
| 172 .GetRawDataResource(IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML) | 191 .GetRawDataResource(IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML) |
| 173 .as_string(); | 192 .as_string(); |
| 174 webui::AppendWebUiCssTextDefaults(&html); | 193 webui::AppendWebUiCssTextDefaults(&html); |
| 175 return webui::GetI18nTemplateHtml(html, &strings); | 194 std::string error_html = webui::GetI18nTemplateHtml(html, &strings); |
| 195 return error_html; |
| 176 } | 196 } |
| 177 | 197 |
| 178 } // namespace supervised_user_error_page | 198 } // namespace supervised_user_error_page |
| OLD | NEW |