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 supervised_user_error_page { |
| 18 |
| 19 namespace { |
| 20 |
| 21 static const int kAvatarSize1x = 45; |
| 22 static const int kAvatarSize2x = 90; |
| 23 |
| 24 #if defined(GOOGLE_CHROME_BUILD) |
| 25 bool ReasonIsAutomatic(FilteringBehaviorReason reason) { |
| 26 return reason == ASYNC_CHECKER || reason == BLACKLIST; |
| 27 } |
| 28 #endif |
| 29 |
| 30 std::string BuildAvatarImageUrl(const std::string& url, int size) { |
| 31 std::string result = url; |
| 32 size_t slash = result.rfind('/'); |
| 33 if (slash != std::string::npos) |
| 34 result.insert(slash, "/s" + base::IntToString(size)); |
| 35 return result; |
| 36 } |
| 37 |
| 38 int GetBlockHeaderID(FilteringBehaviorReason reason) { |
| 39 switch (reason) { |
| 40 case DEFAULT: |
| 41 return IDS_SUPERVISED_USER_BLOCK_HEADER_DEFAULT; |
| 42 case BLACKLIST: |
| 43 case ASYNC_CHECKER: |
| 44 return IDS_SUPERVISED_USER_BLOCK_HEADER_SAFE_SITES; |
| 45 case WHITELIST: |
| 46 NOTREACHED(); |
| 47 break; |
| 48 case MANUAL: |
| 49 return IDS_SUPERVISED_USER_BLOCK_HEADER_MANUAL; |
| 50 } |
| 51 NOTREACHED(); |
| 52 return 0; |
| 53 } |
| 54 } // namespace |
| 55 |
| 56 int GetBlockMessageID(FilteringBehaviorReason reason, |
| 57 bool is_child_account, |
| 58 bool single_parent) { |
| 59 switch (reason) { |
| 60 case DEFAULT: |
| 61 if (!is_child_account) |
| 62 return IDS_SUPERVISED_USER_BLOCK_MESSAGE_DEFAULT; |
| 63 if (single_parent) |
| 64 return IDS_CHILD_BLOCK_MESSAGE_DEFAULT_SINGLE_PARENT; |
| 65 return IDS_CHILD_BLOCK_MESSAGE_DEFAULT_MULTI_PARENT; |
| 66 case BLACKLIST: |
| 67 case ASYNC_CHECKER: |
| 68 return IDS_SUPERVISED_USER_BLOCK_MESSAGE_SAFE_SITES; |
| 69 case WHITELIST: |
| 70 NOTREACHED(); |
| 71 break; |
| 72 case MANUAL: |
| 73 if (!is_child_account) |
| 74 return IDS_SUPERVISED_USER_BLOCK_MESSAGE_MANUAL; |
| 75 if (single_parent) |
| 76 return IDS_CHILD_BLOCK_MESSAGE_MANUAL_SINGLE_PARENT; |
| 77 return IDS_CHILD_BLOCK_MESSAGE_MANUAL_MULTI_PARENT; |
| 78 } |
| 79 NOTREACHED(); |
| 80 return 0; |
| 81 } |
| 82 |
| 83 std::string BuildHtml(bool allow_access_requests, |
| 84 const std::string& profile_image_url, |
| 85 const std::string& profile_image_url2, |
| 86 const base::string16& custodian, |
| 87 const base::string16& custodian_email, |
| 88 const base::string16& second_custodian, |
| 89 const base::string16& second_custodian_email, |
| 90 bool is_child_account, |
| 91 FilteringBehaviorReason reason, |
| 92 const std::string& app_locale) { |
| 93 base::DictionaryValue strings; |
| 94 strings.SetString("blockPageTitle", |
| 95 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); |
| 96 strings.SetBoolean("allowAccessRequests", allow_access_requests); |
| 97 strings.SetString("avatarURL1x", |
| 98 BuildAvatarImageUrl(profile_image_url, kAvatarSize1x)); |
| 99 strings.SetString("avatarURL2x", |
| 100 BuildAvatarImageUrl(profile_image_url, kAvatarSize2x)); |
| 101 strings.SetString("secondAvatarURL1x", |
| 102 BuildAvatarImageUrl(profile_image_url2, kAvatarSize1x)); |
| 103 strings.SetString("secondAvatarURL2x", |
| 104 BuildAvatarImageUrl(profile_image_url2, kAvatarSize2x)); |
| 105 strings.SetString("custodianName", custodian); |
| 106 strings.SetString("custodianEmail", custodian_email); |
| 107 strings.SetString("secondCustodianName", second_custodian); |
| 108 strings.SetString("secondCustodianEmail", second_custodian_email); |
| 109 base::string16 block_message; |
| 110 if (allow_access_requests) { |
| 111 if (is_child_account) { |
| 112 block_message = l10n_util::GetStringUTF16( |
| 113 second_custodian.empty() |
| 114 ? IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_SINGLE_PARENT |
| 115 : IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_MULTI_PARENT); |
| 116 } else { |
| 117 block_message = |
| 118 l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, custodian); |
| 119 } |
| 120 } else { |
| 121 block_message = l10n_util::GetStringUTF16( |
| 122 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED); |
| 123 } |
| 124 strings.SetString("blockPageMessage", block_message); |
| 125 strings.SetString("blockReasonMessage", |
| 126 l10n_util::GetStringUTF16(GetBlockMessageID( |
| 127 reason, is_child_account, second_custodian.empty()))); |
| 128 strings.SetString("blockReasonHeader", |
| 129 l10n_util::GetStringUTF16(GetBlockHeaderID(reason))); |
| 130 bool show_feedback = false; |
| 131 #if defined(GOOGLE_CHROME_BUILD) |
| 132 show_feedback = is_child_account && ReasonIsAutomatic(reason); |
| 133 #endif |
| 134 strings.SetBoolean("showFeedbackLink", show_feedback); |
| 135 strings.SetString("feedbackLink", l10n_util::GetStringUTF16( |
| 136 IDS_BLOCK_INTERSTITIAL_SEND_FEEDBACK)); |
| 137 strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON)); |
| 138 strings.SetString( |
| 139 "requestAccessButton", |
| 140 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON)); |
| 141 strings.SetString( |
| 142 "showDetailsLink", |
| 143 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_SHOW_DETAILS)); |
| 144 strings.SetString( |
| 145 "hideDetailsLink", |
| 146 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_HIDE_DETAILS)); |
| 147 base::string16 request_sent_message; |
| 148 base::string16 request_failed_message; |
| 149 if (is_child_account) { |
| 150 if (second_custodian.empty()) { |
| 151 request_sent_message = l10n_util::GetStringUTF16( |
| 152 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT); |
| 153 request_failed_message = l10n_util::GetStringUTF16( |
| 154 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT); |
| 155 } else { |
| 156 request_sent_message = l10n_util::GetStringUTF16( |
| 157 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT); |
| 158 request_failed_message = l10n_util::GetStringUTF16( |
| 159 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT); |
| 160 } |
| 161 } else { |
| 162 request_sent_message = l10n_util::GetStringFUTF16( |
| 163 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian); |
| 164 request_failed_message = l10n_util::GetStringFUTF16( |
| 165 IDS_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE, custodian); |
| 166 } |
| 167 strings.SetString("requestSentMessage", request_sent_message); |
| 168 strings.SetString("requestFailedMessage", request_failed_message); |
| 169 webui::SetLoadTimeDataDefaults(app_locale, &strings); |
| 170 std::string html = |
| 171 ResourceBundle::GetSharedInstance() |
| 172 .GetRawDataResource(IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML) |
| 173 .as_string(); |
| 174 webui::AppendWebUiCssTextDefaults(&html); |
| 175 return webui::GetI18nTemplateHtml(html, &strings); |
| 176 } |
| 177 |
| 178 } // namespace supervised_user_error_page |
OLD | NEW |