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

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: 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
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 web_ui()->CallJavascriptFunction(
84 base::StringValue arg1(pref_name); 86 "instantConfig.getPreferenceValueResult",
85 base::FundamentalValue arg2(value); 87 pref_name_value,
86 web_ui()->CallJavascriptFunction( 88 base::FundamentalValue(value));
87 "instantConfig.getPreferenceValueResult", 89 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) {
88 arg1, 90 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
89 arg2); 91 web_ui()->CallJavascriptFunction(
92 "instantConfig.getPreferenceValueResult",
93 pref_name_value,
94 base::StringValue(prefs->GetString(pref_name.c_str())));
95 }
90 } 96 }
91 97
92 void InstantUIMessageHandler::SetPreferenceValue(const base::ListValue* args) { 98 void InstantUIMessageHandler::SetPreferenceValue(const base::ListValue* args) {
93 std::string pref_name; 99 std::string pref_name;
94 if (!args->GetString(0, &pref_name)) return; 100 if (!args->GetString(0, &pref_name)) return;
95 101
96 double value; 102 if (pref_name == prefs::kInstantAnimationScaleFactor) {
97 if (!args->GetDouble(1, &value)) return; 103 double value;
98 104 if (!args->GetDouble(1, &value)) return;
99 #if defined(TOOLKIT_VIEWS) 105 #if defined(TOOLKIT_VIEWS)
100 if (pref_name == prefs::kInstantAnimationScaleFactor) {
101 // Clamp to something reasonable. 106 // Clamp to something reasonable.
102 value = std::max(0.1, std::min(value, 10.0)); 107 value = std::max(0.1, std::min(value, 10.0));
103 slow_animation_scale_factor_ = static_cast<int>(value); 108 slow_animation_scale_factor_ = static_cast<int>(value);
109 #else
110 NOTIMPLEMENTED();
111 #endif
112 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) {
113 std::string value;
114 if (!args->GetString(1, &value)) return;
115 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
116 prefs->SetString(pref_name.c_str(), value);
104 } 117 }
105 #else
106 NOTIMPLEMENTED();
107 #endif
108 } 118 }
109 119
110 } // namespace 120 } // namespace
111 121
112 //////////////////////////////////////////////////////////////////////////////// 122 ////////////////////////////////////////////////////////////////////////////////
113 // InstantUI 123 // InstantUI
114 124
115 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) { 125 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) {
116 web_ui->AddMessageHandler(new InstantUIMessageHandler()); 126 web_ui->AddMessageHandler(new InstantUIMessageHandler());
117 127
118 // Set up the chrome://instant/ source. 128 // Set up the chrome://instant/ source.
119 Profile* profile = Profile::FromWebUI(web_ui); 129 Profile* profile = Profile::FromWebUI(web_ui);
120 ChromeURLDataManager::AddDataSource(profile, CreateInstantHTMLSource()); 130 ChromeURLDataManager::AddDataSource(profile, CreateInstantHTMLSource());
121 } 131 }
122 132
123 // static 133 // static
124 int InstantUI::GetSlowAnimationScaleFactor() { 134 int InstantUI::GetSlowAnimationScaleFactor() {
125 return InstantUIMessageHandler::slow_animation_scale_factor(); 135 return InstantUIMessageHandler::slow_animation_scale_factor();
126 } 136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698