Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 /** | |
| 49 * Request a preference setting's value. | |
| 50 * This method is asynchronous; the result is provided by a call to | |
| 51 * the JS method 'gesture_config.getPreferenceValueResult'. | |
| 52 */ | |
| 53 void GestureConfigUI::GetPreferenceValue(const base::ListValue* args) { | |
| 54 std::string pref_name; | |
| 55 | |
| 56 if (!args->GetString(0, &pref_name)) return; | |
| 57 | |
| 58 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 59 PrefService* prefs = profile->GetPrefs(); | |
| 60 | |
| 61 base::StringValue arg1(pref_name); | |
| 62 base::FundamentalValue arg2(prefs->GetDouble(pref_name.c_str())); | |
| 63 | |
| 64 web_ui()->CallJavascriptFunction( | |
| 65 "gesture_config.getPreferenceValueResult", | |
| 66 arg1, | |
| 67 arg2); | |
| 68 } | |
| 69 | |
| 70 /** | |
| 71 * Set a preference setting's value. | |
| 72 * Two parameters are provided in a JS list: prefName and value, the | |
| 73 * key of the preference value to be set, and the value it's to be set to. | |
| 74 */ | |
| 75 void GestureConfigUI::SetPreferenceValue(const base::ListValue* args) { | |
| 76 std::string pref_name; | |
| 77 double value; | |
| 78 | |
| 79 if (!args->GetString(0, &pref_name) || !args->GetDouble(1, &value)) return; | |
| 80 | |
| 81 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 82 PrefService* prefs = profile->GetPrefs(); | |
| 83 | |
| 84 prefs->SetDouble(pref_name.c_str(), value); | |
| 85 } | |
| 86 | |
| 87 GestureConfigUI::~GestureConfigUI() { | |
|
James Hawkins
2012/06/12 15:48:14
Method ordering in the implementation does not mat
| |
| 88 } | |
| OLD | NEW |