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

Side by Side 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: Addressed all outstanding review comments. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/gesture_config_ui.h"
6
7 #include "base/values.h"
8 #include "base/bind.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
13 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
14 #include "chrome/common/url_constants.h"
15 #include "content/public/browser/web_ui.h"
16 #include "grit/browser_resources.h"
17 #include "grit/generated_resources.h"
18
19 /**
20 * WebUI for configuring 'gesture.*' preference values used by
21 * Chrome's gesture recognition system.
22 */
23 GestureConfigUI::GestureConfigUI(content::WebUI* web_ui)
24 : content::WebUIController(web_ui) {
25 // Set up the chrome://gesture-config source.
26 ChromeWebUIDataSource* html_source =
27 new ChromeWebUIDataSource(chrome::kChromeUIGestureConfigHost);
28
29 // Register callback handlers.
30 web_ui->RegisterMessageCallback(
31 "getPreferenceValue",
32 base::Bind(&GestureConfigUI::GetPreferenceValue,
33 base::Unretained(this)));
34 web_ui->RegisterMessageCallback(
35 "setPreferenceValue",
36 base::Bind(&GestureConfigUI::SetPreferenceValue,
37 base::Unretained(this)));
38
39 // Add required resources.
40 html_source->add_resource_path("gesture_config.css", IDR_GESTURE_CONFIG_CSS);
41 html_source->add_resource_path("gesture_config.js", IDR_GESTURE_CONFIG_JS);
42 html_source->set_default_resource(IDR_GESTURE_CONFIG_HTML);
43
44 Profile* profile = Profile::FromWebUI(web_ui);
45 ChromeURLDataManager::AddDataSource(profile, html_source);
46 }
47
48 GestureConfigUI::~GestureConfigUI() {
49 }
50
51 void GestureConfigUI::GetPreferenceValue(const base::ListValue* args) {
52 std::string pref_name;
53
54 if (!args->GetString(0, &pref_name)) return;
55
56 Profile* profile = Profile::FromWebUI(web_ui());
57 PrefService* prefs = profile->GetPrefs();
58
59 base::StringValue arg1(pref_name);
60 base::FundamentalValue arg2(prefs->GetDouble(pref_name.c_str()));
61
62 web_ui()->CallJavascriptFunction(
63 "gesture_config.getPreferenceValueResult",
64 arg1,
65 arg2);
66 }
67
68 void GestureConfigUI::SetPreferenceValue(const base::ListValue* args) {
69 std::string pref_name;
70 double value;
71
72 if (!args->GetString(0, &pref_name) || !args->GetDouble(1, &value)) return;
73
74 Profile* profile = Profile::FromWebUI(web_ui());
75 PrefService* prefs = profile->GetPrefs();
76
77 prefs->SetDouble(pref_name.c_str(), value);
78 }
79
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698