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

Unified Diff: chrome/browser/ui/webui/gesture_config_ui.cc

Issue 10532005: Initial check-in of gesture config WebUI. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Latest review fixes and added tooltips. Created 8 years, 6 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/ui/webui/gesture_config_ui.cc
diff --git a/chrome/browser/ui/webui/gesture_config_ui.cc b/chrome/browser/ui/webui/gesture_config_ui.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a07615db71bb64427a5ec2349c40d9870366972d
--- /dev/null
+++ b/chrome/browser/ui/webui/gesture_config_ui.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 2012 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/gesture_config_ui.h"
+
+#include "base/values.h"
+#include "base/bind.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
+#include "chrome/common/url_constants.h"
+#include "content/public/browser/web_ui.h"
+#include "grit/browser_resources.h"
+#include "grit/generated_resources.h"
+
+/**
+ * WebUI for configuring gesture.* preference values used by
+ * Chrome's gesture recognition system.
+ */
+GestureConfigUI::GestureConfigUI(content::WebUI* web_ui)
+ : content::WebUIController(web_ui) {
+ // Set up the chrome://gesture-config source.
+ ChromeWebUIDataSource* html_source =
+ new ChromeWebUIDataSource(chrome::kChromeUIGestureConfigHost);
+
+ // Register callback handlers.
+ web_ui->RegisterMessageCallback(
+ "getPreferenceValue",
+ base::Bind(&GestureConfigUI::GetPreferenceValue,
+ base::Unretained(this)));
+ web_ui->RegisterMessageCallback(
+ "setPreferenceValue",
+ base::Bind(&GestureConfigUI::SetPreferenceValue,
+ base::Unretained(this)));
+
+ // Add required resources.
+ html_source->add_resource_path("gesture_config.css", IDR_GESTURE_CONFIG_CSS);
+ html_source->add_resource_path("gesture_config.js", IDR_GESTURE_CONFIG_JS);
+ html_source->set_default_resource(IDR_GESTURE_CONFIG_HTML);
+
+ Profile* profile = Profile::FromWebUI(web_ui);
+ ChromeURLDataManager::AddDataSource(profile, html_source);
+}
+
+/**
+ * Request a preference setting's value.
+ * This method is asynchronous; the result is provided by a call to
+ * the JS method 'gesture_config.getPreferenceValueResult'.
+ */
+void GestureConfigUI::GetPreferenceValue(const base::ListValue* args) {
+ std::string pref_name;
+
+ if (!args->GetString(0, &pref_name)) return;
+
+ Profile* profile = Profile::FromWebUI(web_ui());
+ PrefService* prefs = profile->GetPrefs();
+
+ base::StringValue arg1(pref_name);
+ base::FundamentalValue arg2(prefs->GetDouble(pref_name.c_str()));
+
+ web_ui()->CallJavascriptFunction(
+ "gesture_config.getPreferenceValueResult",
+ arg1,
+ arg2);
+}
+
+/**
+ * Set a preference setting's value.
+ * Two parameters are provided in a JS list: prefName and value, the
+ * key of the preference value to be set, and the value it's to be set to.
+ */
+void GestureConfigUI::SetPreferenceValue(const base::ListValue* args) {
+ std::string pref_name;
+ double value;
+
+ if (!args->GetString(0, &pref_name) || !args->GetDouble(1, &value)) return;
+
+ Profile* profile = Profile::FromWebUI(web_ui());
+ PrefService* prefs = profile->GetPrefs();
+
+ prefs->SetDouble(pref_name.c_str(), value);
+}
+
+GestureConfigUI::~GestureConfigUI() {
+}

Powered by Google App Engine
This is Rietveld 408576698