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

Unified Diff: chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc

Issue 2701313002: Adds a modal dialog implementation of the settings reset prompt. (Closed)
Patch Set: Created 3 years, 10 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: chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc
diff --git a/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc b/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..61e2fb182d2a36a2ff7ffdedabec138b96468701
--- /dev/null
+++ b/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc
@@ -0,0 +1,252 @@
+// Copyright 2017 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 "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.h"
+
+#include <utility>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/i18n/rtl.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/time/time.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_config.h"
+#include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_model.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
+#include "chrome/grit/chromium_strings.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/url_formatter/elide_url.h"
+#include "components/url_formatter/url_formatter.h"
+#include "content/public/browser/browser_thread.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "url/gurl.h"
+
+namespace safe_browsing {
+
+namespace {
+
+base::string16 FormatUrlForDisplay(const GURL& url) {
+ return base::i18n::GetDisplayStringInLTRDirectionality(
+ url_formatter::FormatUrl(url));
+}
+
+base::string16 FormatSearchEngineForDisplay(const GURL& search_url) {
+ return url_formatter::FormatUrlForSecurityDisplay(search_url);
+}
+
+} // namespace.
+
+SettingsResetPromptController::LabelInfo::LabelInfo(LabelType type,
+ const base::string16& text)
+ : type(type), text(text) {}
+
+SettingsResetPromptController::LabelInfo::LabelInfo(LabelType type,
+ int message_id)
+ : type(type), text(l10n_util::GetStringUTF16(message_id)) {}
+
+SettingsResetPromptController::LabelInfo::~LabelInfo() {}
+
+SettingsResetPromptController::SettingsResetPromptController(
+ std::unique_ptr<SettingsResetPromptModel> model)
+ : model_(std::move(model)) {
+ DCHECK(model_);
+ DCHECK(model_->ShouldPromptForReset());
+
+ InitMainText();
+ InitDetailsText();
+}
+
+SettingsResetPromptController::~SettingsResetPromptController() {}
+
+base::string16 SettingsResetPromptController::GetWindowTitle() {
+ return l10n_util::GetStringUTF16(IDS_SETTINGS_RESET_PROMPT_TITLE);
+}
+
+base::string16 SettingsResetPromptController::GetButtonLabel() {
+ return l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_ACCEPT_BUTTON_LABEL);
+}
+
+std::vector<SettingsResetPromptController::LabelInfo>
+SettingsResetPromptController::GetMainText() {
+ DCHECK(!main_text_.empty());
+ return main_text_;
+}
+
+std::vector<SettingsResetPromptController::LabelInfo>
+SettingsResetPromptController::GetDetailsText() {
+ DCHECK(!details_text_.empty());
+ return details_text_;
+}
+
+base::string16 SettingsResetPromptController::GetShowDetailsLabel() {
+ return l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_SHOW_DETAILS_BUTTON_LABEL);
+}
+
+base::string16 SettingsResetPromptController::GetHideDetailsLabel() {
+ return l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_HIDE_DETAILS_BUTTON_LABEL);
+}
+
+void SettingsResetPromptController::Accept() {
+ model_->PerformReset(
+ base::Bind(&SettingsResetPromptController::OnInteractionDone,
+ base::Unretained(this)));
+}
+
+void SettingsResetPromptController::Cancel() {
+ OnInteractionDone();
+}
+
+void SettingsResetPromptController::InitMainText() {
+ DCHECK(main_text_.empty());
+
+ using LabelInfo = SettingsResetPromptController::LabelInfo;
sky 2017/02/21 17:37:27 I don't think you need the using here. LabelInfo s
alito 2017/02/23 02:31:59 Done.
+
+ const bool reset_search = model_->default_search_reset_state() ==
+ SettingsResetPromptModel::RESET_REQUIRED;
+ const bool reset_startup_urls = model_->startup_urls_reset_state() ==
+ SettingsResetPromptModel::RESET_REQUIRED;
+ const bool reset_homepage = model_->homepage_reset_state() ==
+ SettingsResetPromptModel::RESET_REQUIRED;
+ DCHECK(reset_search || reset_startup_urls || reset_homepage);
+
+ base::string16 action_message;
+ if (reset_search + reset_startup_urls + reset_homepage > 1) {
sky 2017/02/21 17:37:28 Uses casts to make this more obvious.
alito 2017/02/23 02:31:59 Now using int{} to cast the bools to int. Is this
+ // When multiple settings need to be reset, display a bulleted list of
+ // settings with a common explanation text.
+ main_text_.push_back(
+ LabelInfo(LabelInfo::PARAGRAPH,
+ IDS_SETTINGS_RESET_PROMPT_EXPLANATION_FOR_MULTIPLE_SETTINGS));
+ if (reset_search) {
+ main_text_.push_back(
+ LabelInfo(LabelInfo::BULLET_ITEM,
+ IDS_SETTINGS_RESET_PROMPT_SEARCH_ENGINE_SETTING_NAME));
+ }
+ if (reset_startup_urls) {
+ main_text_.push_back(
+ LabelInfo(LabelInfo::BULLET_ITEM,
+ IDS_SETTINGS_RESET_PROMPT_STARTUP_PAGE_SETTING_NAME));
+ }
+ if (reset_homepage) {
+ main_text_.push_back(
+ LabelInfo(LabelInfo::BULLET_ITEM,
+ IDS_SETTINGS_RESET_PROMPT_HOMEPAGE_SETTING_NAME));
+ }
+
+ // Use a common action message asking if user wants to reset the settings
+ // that were displayed in the list above.
+ action_message = l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_ACTION_EXPLANATION_FOR_MULTIPLE_SETTINGS);
+ } else {
+ // When only one setting needs to be reset, display tailored explanation and
+ // action message for each setting.
+ if (reset_search) {
+ main_text_.push_back(
+ LabelInfo(LabelInfo::PARAGRAPH,
+ IDS_SETTINGS_RESET_PROMPT_EXPLANATION_FOR_SEARCH_ENGINE));
+ action_message = l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_ACTION_EXPLANATION_FOR_SEARCH_ENGINE);
+ }
+ if (reset_startup_urls) {
+ main_text_.push_back(
+ LabelInfo(LabelInfo::PARAGRAPH,
+ IDS_SETTINGS_RESET_PROMPT_EXPLANATION_FOR_STARTUP_PAGE));
+ action_message = l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_ACTION_EXPLANATION_FOR_STARTUP_PAGE);
+ }
+ if (reset_homepage) {
+ main_text_.push_back(
+ LabelInfo(LabelInfo::PARAGRAPH,
+ IDS_SETTINGS_RESET_PROMPT_EXPLANATION_FOR_HOMEPAGE));
+ action_message = l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_ACTION_EXPLANATION_FOR_HOMEPAGE);
+ }
+ }
+
+ // Append the explanation about the number of extensions that will be disabled
sky 2017/02/21 17:37:27 Define a format for this as appending isn't always
alito 2017/02/23 02:31:59 Done.
+ // to the action message.
+ if (!model_->extensions_to_disable().empty()) {
+ action_message.push_back(L' ');
+ if (model_->extensions_to_disable().size() == 1) {
+ action_message.append(l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_ACTION_EXPLANATION_FOR_SINGLE_EXTENSION));
+ } else {
+ action_message.append(l10n_util::GetStringFUTF16(
+ IDS_SETTINGS_RESET_PROMPT_ACTION_EXPLANATION_FOR_MULTIPLE_EXTENSIONS,
+ base::SizeTToString16(model_->extensions_to_disable().size())));
+ }
+ }
+ main_text_.push_back(LabelInfo(LabelInfo::PARAGRAPH, action_message));
+}
+
+void SettingsResetPromptController::InitDetailsText() {
+ using LabelInfo = SettingsResetPromptController::LabelInfo;
sky 2017/02/21 17:37:28 Same comment not needing using.
alito 2017/02/23 02:31:59 Done.
+ details_text_.clear();
sky 2017/02/21 17:37:28 Why don't you DCHECK on empty like you do for main
alito 2017/02/23 02:31:59 Just forgot to change it. Now using DCHECK just li
+
+ // Add the text explaining which settings are going to be reset.
+ details_text_.push_back(LabelInfo(
+ LabelInfo::PARAGRAPH,
+ l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_DETAILS_SECTION_SETTINGS_EXPLANATION)));
+
+ // Enumerate the settings that are going to be reset.
+ if (model_->default_search_reset_state() ==
+ SettingsResetPromptModel::RESET_REQUIRED) {
+ details_text_.push_back(LabelInfo(
+ LabelInfo::PARAGRAPH,
+ l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_DETAILED_SEARCH_ENGINE_SETTING)));
+ details_text_.push_back(
+ LabelInfo(LabelInfo::BULLET_ITEM,
+ FormatSearchEngineForDisplay(model_->default_search())));
+ }
+ if (model_->homepage_reset_state() ==
+ SettingsResetPromptModel::RESET_REQUIRED) {
+ details_text_.push_back(
+ LabelInfo(LabelInfo::PARAGRAPH,
+ l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_DETAILED_HOMEPAGE_SETTING)));
+ details_text_.push_back(LabelInfo(LabelInfo::BULLET_ITEM,
+ FormatUrlForDisplay(model_->homepage())));
+ }
+ if (model_->startup_urls_reset_state() ==
+ SettingsResetPromptModel::RESET_REQUIRED) {
+ details_text_.push_back(
+ LabelInfo(LabelInfo::PARAGRAPH,
+ l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_DETAILED_STARTUP_SETTINGS)));
+ for (const GURL& url : model_->startup_urls())
+ details_text_.push_back(
+ LabelInfo(LabelInfo::BULLET_ITEM, FormatUrlForDisplay(url)));
+ }
+
+ if (!model_->extensions_to_disable().empty()) {
+ // Add the text explaining which extensions will be disabled.
+ details_text_.push_back(LabelInfo(
+ LabelInfo::PARAGRAPH,
+ l10n_util::GetStringUTF16(
+ IDS_SETTINGS_RESET_PROMPT_DETAILS_SECTION_EXTENSION_EXPLANATION)));
+
+ for (const auto& item : model_->extensions_to_disable()) {
+ const ExtensionInfo& extension_info = item.second;
+ details_text_.push_back(LabelInfo(
+ LabelInfo::BULLET_ITEM, base::UTF8ToUTF16(extension_info.name)));
+ }
+ }
+}
+
+void SettingsResetPromptController::OnInteractionDone() {
+ // TODO(alito): Add metrics reporting here.
+ delete this;
sky 2017/02/21 17:37:27 If this object is going to control it's lifetime,
alito 2017/02/23 02:31:59 Done.
+}
+
+} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698