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

Side by Side Diff: chrome/browser/ui/webui/instant_ui.cc

Issue 10933023: Control zero suggest with a pref, not a switch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for clang compile error. Created 8 years, 3 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
« no previous file with comments | « chrome/browser/resources/instant/instant.js ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/instant_ui.h" 5 #include "chrome/browser/ui/webui/instant_ui.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 10 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
10 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
11 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/web_ui.h" 13 #include "content/public/browser/web_ui.h"
13 #include "content/public/browser/web_ui_message_handler.h" 14 #include "content/public/browser/web_ui_message_handler.h"
14 #include "grit/browser_resources.h" 15 #include "grit/browser_resources.h"
15 16
16 namespace { 17 namespace {
17 18
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 web_ui()->RegisterMessageCallback( 69 web_ui()->RegisterMessageCallback(
69 "setPreferenceValue", 70 "setPreferenceValue",
70 base::Bind(&InstantUIMessageHandler::SetPreferenceValue, 71 base::Bind(&InstantUIMessageHandler::SetPreferenceValue,
71 base::Unretained(this))); 72 base::Unretained(this)));
72 } 73 }
73 74
74 void InstantUIMessageHandler::GetPreferenceValue(const base::ListValue* args) { 75 void InstantUIMessageHandler::GetPreferenceValue(const base::ListValue* args) {
75 std::string pref_name; 76 std::string pref_name;
76 if (!args->GetString(0, &pref_name)) return; 77 if (!args->GetString(0, &pref_name)) return;
77 78
78 double value = 0.0; 79 base::StringValue pref_name_value(pref_name);
80 if (pref_name == prefs::kInstantAnimationScaleFactor) {
81 double value = 0.0;
79 #if defined(TOOLKIT_VIEWS) 82 #if defined(TOOLKIT_VIEWS)
80 if (pref_name == prefs::kInstantAnimationScaleFactor)
81 value = slow_animation_scale_factor_; 83 value = slow_animation_scale_factor_;
82 #endif 84 #endif
83 85 base::FundamentalValue arg(value);
84 base::StringValue arg1(pref_name); 86 web_ui()->CallJavascriptFunction(
85 base::FundamentalValue arg2(value); 87 "instantConfig.getPreferenceValueResult", pref_name_value, arg);
86 web_ui()->CallJavascriptFunction( 88 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) {
87 "instantConfig.getPreferenceValueResult", 89 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
88 arg1, 90 base::StringValue arg(prefs->GetString(pref_name.c_str()));
89 arg2); 91 web_ui()->CallJavascriptFunction(
92 "instantConfig.getPreferenceValueResult", pref_name_value, arg);
93 }
90 } 94 }
91 95
92 void InstantUIMessageHandler::SetPreferenceValue(const base::ListValue* args) { 96 void InstantUIMessageHandler::SetPreferenceValue(const base::ListValue* args) {
93 std::string pref_name; 97 std::string pref_name;
94 if (!args->GetString(0, &pref_name)) return; 98 if (!args->GetString(0, &pref_name)) return;
95 99
96 double value; 100 if (pref_name == prefs::kInstantAnimationScaleFactor) {
97 if (!args->GetDouble(1, &value)) return; 101 double value;
98 102 if (!args->GetDouble(1, &value)) return;
99 #if defined(TOOLKIT_VIEWS) 103 #if defined(TOOLKIT_VIEWS)
100 if (pref_name == prefs::kInstantAnimationScaleFactor) {
101 // Clamp to something reasonable. 104 // Clamp to something reasonable.
102 value = std::max(0.1, std::min(value, 10.0)); 105 value = std::max(0.1, std::min(value, 10.0));
103 slow_animation_scale_factor_ = static_cast<int>(value); 106 slow_animation_scale_factor_ = static_cast<int>(value);
107 #else
108 NOTIMPLEMENTED();
109 #endif
110 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) {
111 std::string value;
112 if (!args->GetString(1, &value)) return;
113 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
114 prefs->SetString(pref_name.c_str(), value);
104 } 115 }
105 #else
106 NOTIMPLEMENTED();
107 #endif
108 } 116 }
109 117
110 } // namespace 118 } // namespace
111 119
112 //////////////////////////////////////////////////////////////////////////////// 120 ////////////////////////////////////////////////////////////////////////////////
113 // InstantUI 121 // InstantUI
114 122
115 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) { 123 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) {
116 web_ui->AddMessageHandler(new InstantUIMessageHandler()); 124 web_ui->AddMessageHandler(new InstantUIMessageHandler());
117 125
118 // Set up the chrome://instant/ source. 126 // Set up the chrome://instant/ source.
119 Profile* profile = Profile::FromWebUI(web_ui); 127 Profile* profile = Profile::FromWebUI(web_ui);
120 ChromeURLDataManager::AddDataSource(profile, CreateInstantHTMLSource()); 128 ChromeURLDataManager::AddDataSource(profile, CreateInstantHTMLSource());
121 } 129 }
122 130
123 // static 131 // static
124 int InstantUI::GetSlowAnimationScaleFactor() { 132 int InstantUI::GetSlowAnimationScaleFactor() {
125 return InstantUIMessageHandler::slow_animation_scale_factor(); 133 return InstantUIMessageHandler::slow_animation_scale_factor();
126 } 134 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/instant/instant.js ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698