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

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

Issue 10910286: alternate ntp: show search provider logo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased, merged conflicts 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/ui/webui/instant_ui.h ('k') | chrome/common/pref_names.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/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 10 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
(...skipping 26 matching lines...) Expand all
37 InstantUIMessageHandler(); 37 InstantUIMessageHandler();
38 virtual ~InstantUIMessageHandler(); 38 virtual ~InstantUIMessageHandler();
39 39
40 // WebUIMessageHandler implementation. 40 // WebUIMessageHandler implementation.
41 virtual void RegisterMessages() OVERRIDE; 41 virtual void RegisterMessages() OVERRIDE;
42 42
43 static int slow_animation_scale_factor() { 43 static int slow_animation_scale_factor() {
44 return slow_animation_scale_factor_; 44 return slow_animation_scale_factor_;
45 } 45 }
46 46
47 static bool show_search_provider_logo() {
48 return show_search_provider_logo_;
49 }
50
47 private: 51 private:
48 void GetPreferenceValue(const base::ListValue* args); 52 void GetPreferenceValue(const base::ListValue* args);
49 void SetPreferenceValue(const base::ListValue* args); 53 void SetPreferenceValue(const base::ListValue* args);
50 54
51 // Slows down Instant animations by a time factor. 55 // Slows down Instant animations by a time factor.
52 static int slow_animation_scale_factor_; 56 static int slow_animation_scale_factor_;
53 57
58 // True if search provider logo should be shown.
59 static bool show_search_provider_logo_;
60
54 DISALLOW_COPY_AND_ASSIGN(InstantUIMessageHandler); 61 DISALLOW_COPY_AND_ASSIGN(InstantUIMessageHandler);
55 }; 62 };
56 63
57 // static 64 // static
58 int InstantUIMessageHandler::slow_animation_scale_factor_ = 1; 65 int InstantUIMessageHandler::slow_animation_scale_factor_ = 1;
66 bool InstantUIMessageHandler::show_search_provider_logo_ = false;
59 67
60 InstantUIMessageHandler::InstantUIMessageHandler() {} 68 InstantUIMessageHandler::InstantUIMessageHandler() {}
61 69
62 InstantUIMessageHandler::~InstantUIMessageHandler() {} 70 InstantUIMessageHandler::~InstantUIMessageHandler() {}
63 71
64 void InstantUIMessageHandler::RegisterMessages() { 72 void InstantUIMessageHandler::RegisterMessages() {
65 web_ui()->RegisterMessageCallback( 73 web_ui()->RegisterMessageCallback(
66 "getPreferenceValue", 74 "getPreferenceValue",
67 base::Bind(&InstantUIMessageHandler::GetPreferenceValue, 75 base::Bind(&InstantUIMessageHandler::GetPreferenceValue,
68 base::Unretained(this))); 76 base::Unretained(this)));
69 web_ui()->RegisterMessageCallback( 77 web_ui()->RegisterMessageCallback(
70 "setPreferenceValue", 78 "setPreferenceValue",
71 base::Bind(&InstantUIMessageHandler::SetPreferenceValue, 79 base::Bind(&InstantUIMessageHandler::SetPreferenceValue,
72 base::Unretained(this))); 80 base::Unretained(this)));
73 } 81 }
74 82
75 void InstantUIMessageHandler::GetPreferenceValue(const base::ListValue* args) { 83 void InstantUIMessageHandler::GetPreferenceValue(const base::ListValue* args) {
76 std::string pref_name; 84 std::string pref_name;
77 if (!args->GetString(0, &pref_name)) return; 85 if (!args->GetString(0, &pref_name)) return;
78 86
79 base::StringValue pref_name_value(pref_name); 87 base::StringValue pref_name_value(pref_name);
80 if (pref_name == prefs::kInstantAnimationScaleFactor) { 88 if (pref_name == prefs::kInstantAnimationScaleFactor) {
81 double value = 0.0; 89 double value = 0.0;
82 #if defined(TOOLKIT_VIEWS) 90 #if defined(TOOLKIT_VIEWS)
83 value = slow_animation_scale_factor_; 91 value = slow_animation_scale_factor_;
84 #endif 92 #endif
85 base::FundamentalValue arg(value); 93 base::FundamentalValue arg(value);
86 web_ui()->CallJavascriptFunction( 94 web_ui()->CallJavascriptFunction(
87 "instantConfig.getPreferenceValueResult", pref_name_value, arg); 95 "instantConfig.getPreferenceValueResult", pref_name_value, arg);
96 } else if (pref_name == prefs::kInstantShowSearchProviderLogo) {
97 base::FundamentalValue arg(show_search_provider_logo_);
98 web_ui()->CallJavascriptFunction(
99 "instantConfig.getPreferenceValueResult", pref_name_value, arg);
88 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) { 100 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) {
89 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 101 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
90 base::StringValue arg(prefs->GetString(pref_name.c_str())); 102 base::StringValue arg(prefs->GetString(pref_name.c_str()));
91 web_ui()->CallJavascriptFunction( 103 web_ui()->CallJavascriptFunction(
92 "instantConfig.getPreferenceValueResult", pref_name_value, arg); 104 "instantConfig.getPreferenceValueResult", pref_name_value, arg);
93 } 105 }
94 } 106 }
95 107
96 void InstantUIMessageHandler::SetPreferenceValue(const base::ListValue* args) { 108 void InstantUIMessageHandler::SetPreferenceValue(const base::ListValue* args) {
97 std::string pref_name; 109 std::string pref_name;
98 if (!args->GetString(0, &pref_name)) return; 110 if (!args->GetString(0, &pref_name)) return;
99 111
100 if (pref_name == prefs::kInstantAnimationScaleFactor) { 112 if (pref_name == prefs::kInstantAnimationScaleFactor) {
101 double value; 113 double value;
102 if (!args->GetDouble(1, &value)) return; 114 if (!args->GetDouble(1, &value))
115 return;
103 #if defined(TOOLKIT_VIEWS) 116 #if defined(TOOLKIT_VIEWS)
104 // Clamp to something reasonable. 117 // Clamp to something reasonable.
105 value = std::max(0.1, std::min(value, 10.0)); 118 value = std::max(0.1, std::min(value, 20.0));
106 slow_animation_scale_factor_ = static_cast<int>(value); 119 slow_animation_scale_factor_ = static_cast<int>(value);
107 #else 120 #else
108 NOTIMPLEMENTED(); 121 NOTIMPLEMENTED();
109 #endif 122 #endif // defined(TOOLKIT_VIEWS)
123 } else if (pref_name == prefs::kInstantShowSearchProviderLogo) {
124 bool value;
125 if (!args->GetBoolean(1, &value))
126 return;
127 show_search_provider_logo_ = value;
110 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) { 128 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) {
111 std::string value; 129 std::string value;
112 if (!args->GetString(1, &value)) return; 130 if (!args->GetString(1, &value))
131 return;
113 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 132 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
114 prefs->SetString(pref_name.c_str(), value); 133 prefs->SetString(pref_name.c_str(), value);
115 } 134 }
116 } 135 }
117 136
118 } // namespace 137 } // namespace
119 138
120 //////////////////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////////////////
121 // InstantUI 140 // InstantUI
122 141
123 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) { 142 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) {
124 web_ui->AddMessageHandler(new InstantUIMessageHandler()); 143 web_ui->AddMessageHandler(new InstantUIMessageHandler());
125 144
126 // Set up the chrome://instant/ source. 145 // Set up the chrome://instant/ source.
127 Profile* profile = Profile::FromWebUI(web_ui); 146 Profile* profile = Profile::FromWebUI(web_ui);
128 ChromeURLDataManager::AddDataSource(profile, CreateInstantHTMLSource()); 147 ChromeURLDataManager::AddDataSource(profile, CreateInstantHTMLSource());
129 } 148 }
130 149
131 // static 150 // static
132 int InstantUI::GetSlowAnimationScaleFactor() { 151 int InstantUI::GetSlowAnimationScaleFactor() {
133 return InstantUIMessageHandler::slow_animation_scale_factor(); 152 return InstantUIMessageHandler::slow_animation_scale_factor();
134 } 153 }
154
155 // static
156 bool InstantUI::ShouldShowSearchProviderLogo() {
157 return InstantUIMessageHandler::show_search_provider_logo();
158 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/instant_ui.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698