summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui
diff options
context:
space:
mode:
authorbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-24 11:59:35 +0000
committerbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-24 11:59:35 +0000
commit380532aa316df3370f1c26d85b239771eea6c52f (patch)
treefb65f63e3923bd3e3af6df95bdb130879fc90566 /chrome/browser/ui/webui
parent575a11db587cab53119edf7c60adf7e7e7e33903 (diff)
downloadchromium_src-380532aa316df3370f1c26d85b239771eea6c52f.zip
chromium_src-380532aa316df3370f1c26d85b239771eea6c52f.tar.gz
chromium_src-380532aa316df3370f1c26d85b239771eea6c52f.tar.bz2
WebUI for Profile Settings Reset
This CL implements chrome://settings/profileSettingsReset, a feature to reset profile settings that malware often modifies. BUG=235037 Review URL: https://chromiumcodereview.appspot.com/14924002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202064 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/webui')
-rw-r--r--chrome/browser/ui/webui/options/browser_options_handler.cc9
-rw-r--r--chrome/browser/ui/webui/options/options_ui.cc2
-rw-r--r--chrome/browser/ui/webui/options/profile_settings_reset_browsertest.js25
-rw-r--r--chrome/browser/ui/webui/options/reset_profile_settings_handler.cc133
-rw-r--r--chrome/browser/ui/webui/options/reset_profile_settings_handler.h51
5 files changed, 220 insertions, 0 deletions
diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc
index 66fe9f0c..cd6c008 100644
--- a/chrome/browser/ui/webui/options/browser_options_handler.cc
+++ b/chrome/browser/ui/webui/options/browser_options_handler.cc
@@ -285,6 +285,11 @@ void BrowserOptionsHandler::GetLocalizedValues(DictionaryValue* values) {
{ "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL },
{ "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL,
IDS_PRODUCT_NAME },
+ { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON },
+ { "resetProfileSettingsDescription",
+ IDS_RESET_PROFILE_SETTINGS_DESCRIPTION },
+ { "resetProfileSettingsSectionTitle",
+ IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE },
{ "safeBrowsingEnableProtection",
IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION },
{ "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME },
@@ -510,6 +515,10 @@ void BrowserOptionsHandler::GetLocalizedValues(DictionaryValue* values) {
"gpuEnabledAtStart",
g_browser_process->gpu_mode_manager()->initial_gpu_mode_pref());
#endif
+
+ values->SetBoolean("enableResetProfileSettingsSection",
+ CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableResetProfileSettings));
}
void BrowserOptionsHandler::RegisterCloudPrintValues(DictionaryValue* values) {
diff --git a/chrome/browser/ui/webui/options/options_ui.cc b/chrome/browser/ui/webui/options/options_ui.cc
index 494d18e..11cfa35 100644
--- a/chrome/browser/ui/webui/options/options_ui.cc
+++ b/chrome/browser/ui/webui/options/options_ui.cc
@@ -40,6 +40,7 @@
#include "chrome/browser/ui/webui/options/media_galleries_handler.h"
#include "chrome/browser/ui/webui/options/options_sync_setup_handler.h"
#include "chrome/browser/ui/webui/options/password_manager_handler.h"
+#include "chrome/browser/ui/webui/options/reset_profile_settings_handler.h"
#include "chrome/browser/ui/webui/options/search_engine_manager_handler.h"
#include "chrome/browser/ui/webui/options/startup_pages_handler.h"
#include "chrome/browser/ui/webui/theme_source.h"
@@ -270,6 +271,7 @@ OptionsUI::OptionsUI(content::WebUI* web_ui)
AddOptionsPageUIHandler(localized_strings, new ManageProfileHandler());
AddOptionsPageUIHandler(localized_strings, new ManagedUserLearnMoreHandler());
AddOptionsPageUIHandler(localized_strings, new PasswordManagerHandler());
+ AddOptionsPageUIHandler(localized_strings, new ResetProfileSettingsHandler());
AddOptionsPageUIHandler(localized_strings, new SearchEngineManagerHandler());
AddOptionsPageUIHandler(localized_strings, new ImportDataHandler());
AddOptionsPageUIHandler(localized_strings, new StartupPagesHandler());
diff --git a/chrome/browser/ui/webui/options/profile_settings_reset_browsertest.js b/chrome/browser/ui/webui/options/profile_settings_reset_browsertest.js
new file mode 100644
index 0000000..ba40eaa
--- /dev/null
+++ b/chrome/browser/ui/webui/options/profile_settings_reset_browsertest.js
@@ -0,0 +1,25 @@
+// Copyright 2013 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.
+
+/**
+ * TestFixture for profile settings reset WebUI testing.
+ * @extends {testing.Test}
+ * @constructor
+ **/
+function ProfileSettingsResetWebUITest() {}
+
+ProfileSettingsResetWebUITest.prototype = {
+ __proto__: testing.Test.prototype,
+
+ /**
+ * Browse to the reset profile settings page.
+ **/
+ browsePreload: 'chrome://settings-frame/resetProfileSettings',
+};
+
+// Test opening the profile settings reset has correct location.
+TEST_F('ProfileSettingsResetWebUITest', 'testOpenProfileSettingsReset',
+ function() {
+ assertEquals(this.browsePreload, document.location.href);
+ });
diff --git a/chrome/browser/ui/webui/options/reset_profile_settings_handler.cc b/chrome/browser/ui/webui/options/reset_profile_settings_handler.cc
new file mode 100644
index 0000000..de84fdf
--- /dev/null
+++ b/chrome/browser/ui/webui/options/reset_profile_settings_handler.cc
@@ -0,0 +1,133 @@
+// Copyright 2013 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/ui/webui/options/reset_profile_settings_handler.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/prefs/pref_service.h"
+#include "base/string16.h"
+#include "base/values.h"
+#include "chrome/browser/google/google_util.h"
+#include "chrome/browser/profile_resetter/profile_resetter.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/pref_names.h"
+#include "content/public/browser/web_ui.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+namespace {
+const char kResetProfileSettingsLearnMoreUrl[] =
+ "https://support.google.com/chrome/?p=settings_reset_profile_settings";
+} // namespace
+
+namespace options {
+
+ResetProfileSettingsHandler::ResetProfileSettingsHandler() {
+}
+
+ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {
+}
+
+void ResetProfileSettingsHandler::InitializeHandler() {
+ Profile* profile = Profile::FromWebUI(web_ui());
+ resetter_.reset(new ProfileResetter(profile));
+}
+
+void ResetProfileSettingsHandler::GetLocalizedValues(
+ DictionaryValue* localized_strings) {
+ DCHECK(localized_strings);
+
+ static OptionsStringResource resources[] = {
+ { "resetProfileSettingsLabel", IDS_RESET_PROFILE_SETTINGS_LABEL },
+ { "resetDefaultSearchEngineCheckbox",
+ IDS_RESET_PROFILE_DEFAULT_SEARCH_ENGINE_CHECKBOX },
+ { "resetHomepageCheckbox", IDS_RESET_PROFILE_HOMEPAGE_CHECKBOX },
+ { "resetContentSettingsCheckbox",
+ IDS_RESET_PROFILE_CONTENT_SETTINGS_CHECKBOX },
+ { "resetCookiesAndSiteDataCheckbox", IDS_RESET_PROFILE_COOKIES_CHECKBOX },
+ { "resetExtensionsCheckbox", IDS_RESET_PROFILE_EXTENSIONS_CHECKBOX },
+ { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON },
+ };
+
+ RegisterStrings(localized_strings, resources, arraysize(resources));
+ RegisterTitle(localized_strings, "resetProfileSettingsOverlay",
+ IDS_RESET_PROFILE_SETTINGS_TITLE);
+ localized_strings->SetString(
+ "resetProfileSettingsLearnMoreUrl",
+ google_util::StringAppendGoogleLocaleParam(
+ kResetProfileSettingsLearnMoreUrl));
+
+ scoped_ptr<ListValue> reset_extensions_handling(new ListValue);
+ for (int i = 0; i < 2; i++) {
+ string16 label_string;
+ switch (i) {
+ case 0:
+ label_string = l10n_util::GetStringUTF16(
+ IDS_RESET_PROFILE_EXTENSIONS_DISABLE);
+ break;
+ case 1:
+ label_string = l10n_util::GetStringUTF16(
+ IDS_RESET_PROFILE_EXTENSIONS_UNINSTALL);
+ break;
+ }
+ scoped_ptr<ListValue> option(new ListValue);
+ option->Append(new base::FundamentalValue(i));
+ option->Append(new base::StringValue(label_string));
+ reset_extensions_handling->Append(option.release());
+ }
+ localized_strings->Set("resetExtensionsHandling",
+ reset_extensions_handling.release());
+}
+
+void ResetProfileSettingsHandler::RegisterMessages() {
+ // Setup handlers specific to this panel.
+ web_ui()->RegisterMessageCallback("performResetProfileSettings",
+ base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings,
+ base::Unretained(this)));
+}
+
+void ResetProfileSettingsHandler::HandleResetProfileSettings(
+ const ListValue* /*value*/) {
+ DCHECK(resetter_);
+ DCHECK(!resetter_->IsActive());
+
+ Profile* profile = Profile::FromWebUI(web_ui());
+ PrefService* prefs = profile->GetPrefs();
+
+ ProfileResetter::ResettableFlags reset_mask = 0;
+
+ struct {
+ const char* flag_name;
+ ProfileResetter::Resettable mask;
+ } name_to_flag[] = {
+ { prefs::kResetDefaultSearchEngine,
+ ProfileResetter::DEFAULT_SEARCH_ENGINE },
+ { prefs::kResetHomepage, ProfileResetter::HOMEPAGE },
+ { prefs::kResetContentSettings, ProfileResetter::CONTENT_SETTINGS },
+ { prefs::kResetCookiesAndSiteData, ProfileResetter::COOKIES_AND_SITE_DATA },
+ { prefs::kResetExtensions, ProfileResetter::EXTENSIONS },
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(name_to_flag); ++i) {
+ if (prefs->GetBoolean(name_to_flag[i].flag_name))
+ reset_mask |= name_to_flag[i].mask;
+ }
+
+ ProfileResetter::ExtensionHandling extension_handling =
+ (prefs->GetInteger(prefs::kResetExtensionsHandling) == 0)
+ ? ProfileResetter::DISABLE_EXTENSIONS
+ : ProfileResetter::UNINSTALL_EXTENSIONS;
+
+ resetter_->Reset(
+ reset_mask,
+ extension_handling,
+ base::Bind(&ResetProfileSettingsHandler::OnResetProfileSettingsDone,
+ AsWeakPtr()));
+}
+
+void ResetProfileSettingsHandler::OnResetProfileSettingsDone() {
+ web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting");
+}
+
+} // namespace options
diff --git a/chrome/browser/ui/webui/options/reset_profile_settings_handler.h b/chrome/browser/ui/webui/options/reset_profile_settings_handler.h
new file mode 100644
index 0000000..3375fdf
--- /dev/null
+++ b/chrome/browser/ui/webui/options/reset_profile_settings_handler.h
@@ -0,0 +1,51 @@
+// Copyright 2013 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.
+
+#ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_RESET_PROFILE_SETTINGS_HANDLER_H_
+#define CHROME_BROWSER_UI_WEBUI_OPTIONS_RESET_PROFILE_SETTINGS_HANDLER_H_
+
+#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
+#include "chrome/browser/ui/webui/options/options_ui.h"
+
+namespace base {
+class DictionaryValue;
+class ListValue;
+} // namespace base
+
+class ProfileResetter;
+
+namespace options {
+
+// Reset Profile Settings handler page UI handler.
+class ResetProfileSettingsHandler
+ : public OptionsPageUIHandler,
+ public base::SupportsWeakPtr<ResetProfileSettingsHandler> {
+ public:
+ ResetProfileSettingsHandler();
+ virtual ~ResetProfileSettingsHandler();
+
+ // OptionsPageUIHandler implementation.
+ virtual void GetLocalizedValues(
+ base::DictionaryValue* localized_strings) OVERRIDE;
+ virtual void InitializeHandler() OVERRIDE;
+
+ // WebUIMessageHandler implementation.
+ virtual void RegisterMessages() OVERRIDE;
+
+ private:
+ // Javascript callback to start clearing data.
+ void HandleResetProfileSettings(const base::ListValue* value);
+
+ // Closes the dialog once all requested settings has been reset.
+ void OnResetProfileSettingsDone();
+
+ scoped_ptr<ProfileResetter> resetter_;
+
+ DISALLOW_COPY_AND_ASSIGN(ResetProfileSettingsHandler);
+};
+
+} // namespace options
+
+#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_RESET_PROFILE_SETTINGS_HANDLER_H_