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

Unified 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: Respond to comments, add OWNERS file and GYP build 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 side-by-side diff with in-line comments
Download patch
Index: components/supervised_user_error_page/supervised_user_error_page.cc
diff --git a/components/supervised_user_error_page/supervised_user_error_page.cc b/components/supervised_user_error_page/supervised_user_error_page.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bc57756d7b159da0911205248924430e20786dbb
--- /dev/null
+++ b/components/supervised_user_error_page/supervised_user_error_page.cc
@@ -0,0 +1,182 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/supervised_user_error_page/supervised_user_error_page.h"
+
+#include "base/macros.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/values.h"
+#include "grit/components_resources.h"
+#include "grit/components_strings.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/webui/jstemplate_builder.h"
+#include "ui/base/webui/web_ui_util.h"
+
+namespace {
+
+static const int kAvatarSize1x = 45;
+static const int kAvatarSize2x = 90;
+
+std::string BuildAvatarImageUrl(const std::string& url, int size) {
+ std::string result = url;
+ size_t slash = result.rfind('/');
+ if (slash != std::string::npos)
+ result.insert(slash, "/s" + base::IntToString(size));
+ return result;
+}
+
+int GetBlockHeaderID(
+ supervised_user_error_page::FilteringBehaviorReason reason) {
+ switch (reason) {
+ case supervised_user_error_page::DEFAULT:
+ return IDS_SUPERVISED_USER_BLOCK_HEADER_DEFAULT;
+ case supervised_user_error_page::BLACKLIST:
+ case supervised_user_error_page::ASYNC_CHECKER:
+ return IDS_SUPERVISED_USER_BLOCK_HEADER_SAFE_SITES;
+ case supervised_user_error_page::WHITELIST:
+ NOTREACHED();
+ break;
+ case supervised_user_error_page::MANUAL:
+ return IDS_SUPERVISED_USER_BLOCK_HEADER_MANUAL;
+ }
+ NOTREACHED();
+ return 0;
+}
+} // namespace
+
+namespace supervised_user_error_page {
+
+int GetBlockMessageID(FilteringBehaviorReason reason,
+ bool is_child_account,
+ bool single_parent) {
+ switch (reason) {
+ case DEFAULT:
+ 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.
+ if (single_parent) {
+ 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.
+ } else {
+ return IDS_CHILD_BLOCK_MESSAGE_DEFAULT_MULTI_PARENT;
+ }
+ } else {
+ return IDS_SUPERVISED_USER_BLOCK_MESSAGE_DEFAULT;
+ }
+ case BLACKLIST:
+ case ASYNC_CHECKER:
+ return IDS_SUPERVISED_USER_BLOCK_MESSAGE_SAFE_SITES;
+ case WHITELIST:
+ NOTREACHED();
+ break;
+ case MANUAL:
+ if (is_child_account) {
+ if (single_parent) {
+ return IDS_CHILD_BLOCK_MESSAGE_MANUAL_SINGLE_PARENT;
+ } else {
+ return IDS_CHILD_BLOCK_MESSAGE_MANUAL_MULTI_PARENT;
+ }
+ } else {
+ return IDS_SUPERVISED_USER_BLOCK_MESSAGE_MANUAL;
+ }
+ }
+ NOTREACHED();
+ return 0;
+}
+
+std::string BuildHtml(bool allow_access_requests,
+ const std::string& profile_image_url,
+ const std::string& profile_image_url2,
+ const base::string16& custodian,
+ const base::string16& custodian_email,
+ const base::string16& second_custodian,
+ const base::string16& second_custodian_email,
+ bool is_child_account,
+ FilteringBehaviorReason reason,
+ const std::string& app_locale) {
+ base::DictionaryValue strings;
+ strings.SetString("blockPageTitle",
+ l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE));
+ strings.SetBoolean("allowAccessRequests", allow_access_requests);
+ strings.SetString("avatarURL1x",
+ BuildAvatarImageUrl(profile_image_url, kAvatarSize1x));
+ strings.SetString("avatarURL2x",
+ BuildAvatarImageUrl(profile_image_url, kAvatarSize2x));
+ strings.SetString("secondAvatarURL1x",
+ BuildAvatarImageUrl(profile_image_url2, kAvatarSize1x));
+ strings.SetString("secondAvatarURL2x",
+ BuildAvatarImageUrl(profile_image_url2, kAvatarSize2x));
+ strings.SetString("custodianName", custodian);
+ strings.SetString("custodianEmail", custodian_email);
+ strings.SetString("secondCustodianName", second_custodian);
+ strings.SetString("secondCustodianEmail", second_custodian_email);
+ base::string16 block_message;
+ if (allow_access_requests) {
+ if (is_child_account) {
+ block_message = l10n_util::GetStringUTF16(
+ second_custodian.empty()
+ ? IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_SINGLE_PARENT
+ : IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_MULTI_PARENT);
+ } else {
+ block_message =
+ l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, custodian);
+ }
+ } else {
+ block_message = l10n_util::GetStringUTF16(
+ IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED);
+ }
+ strings.SetString("blockPageMessage", block_message);
+ strings.SetString("blockReasonMessage",
+ l10n_util::GetStringUTF16(GetBlockMessageID(
+ reason, is_child_account, second_custodian.empty())));
+ strings.SetString("blockReasonHeader",
+ l10n_util::GetStringUTF16(GetBlockHeaderID(reason)));
+ bool show_feedback = false;
+#if defined(GOOGLE_CHROME_BUILD)
+ show_feedback =
+ is_child_account && SupervisedUserURLFilter::ReasonIsAutomatic(reason);
+#endif
+ strings.SetBoolean("showFeedbackLink", show_feedback);
+ strings.SetString("feedbackLink", l10n_util::GetStringUTF16(
+ IDS_BLOCK_INTERSTITIAL_SEND_FEEDBACK));
+ strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON));
+ strings.SetString(
+ "requestAccessButton",
+ l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON));
+ strings.SetString(
+ "showDetailsLink",
+ l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_SHOW_DETAILS));
+ strings.SetString(
+ "hideDetailsLink",
+ l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_HIDE_DETAILS));
+ base::string16 request_sent_message;
+ base::string16 request_failed_message;
+ if (is_child_account) {
+ if (second_custodian.empty()) {
+ request_sent_message = l10n_util::GetStringUTF16(
+ IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT);
+ request_failed_message = l10n_util::GetStringUTF16(
+ IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT);
+ } else {
+ request_sent_message = l10n_util::GetStringUTF16(
+ IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT);
+ request_failed_message = l10n_util::GetStringUTF16(
+ IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT);
+ }
+ } else {
+ request_sent_message = l10n_util::GetStringFUTF16(
+ IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian);
+ request_failed_message = l10n_util::GetStringFUTF16(
+ IDS_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE, custodian);
+ }
+ strings.SetString("requestSentMessage", request_sent_message);
+ strings.SetString("requestFailedMessage", request_failed_message);
+ webui::SetLoadTimeDataDefaults(app_locale, &strings);
+ std::string html =
+ ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML)
+ .as_string();
+ webui::AppendWebUiCssTextDefaults(&html);
+ return webui::GetI18nTemplateHtml(html, &strings);
+}
+
+} // namespace supervised_user_error_page
« no previous file with comments | « components/supervised_user_error_page/supervised_user_error_page.h ('k') | components/supervised_user_error_page_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698