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

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: revert one tiny part of ujs 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/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 9 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
(...skipping 25 matching lines...) Expand all
36 InstantUIMessageHandler(); 36 InstantUIMessageHandler();
37 virtual ~InstantUIMessageHandler(); 37 virtual ~InstantUIMessageHandler();
38 38
39 // WebUIMessageHandler implementation. 39 // WebUIMessageHandler implementation.
40 virtual void RegisterMessages() OVERRIDE; 40 virtual void RegisterMessages() OVERRIDE;
41 41
42 static int slow_animation_scale_factor() { 42 static int slow_animation_scale_factor() {
43 return slow_animation_scale_factor_; 43 return slow_animation_scale_factor_;
44 } 44 }
45 45
46 static int show_search_provider_logo() {
sky 2012/09/14 21:35:30 bool
kuan 2012/09/14 22:34:09 Done.
47 return show_search_provider_logo_;
48 }
49
46 private: 50 private:
47 void GetPreferenceValue(const base::ListValue* args); 51 void GetPreferenceValue(const base::ListValue* args);
48 void SetPreferenceValue(const base::ListValue* args); 52 void SetPreferenceValue(const base::ListValue* args);
49 53
50 // Slows down Instant animations by a time factor. 54 // Slows down Instant animations by a time factor.
51 static int slow_animation_scale_factor_; 55 static int slow_animation_scale_factor_;
52 56
57 // if search provider logo should be shown.
58 static bool show_search_provider_logo_;
59
53 DISALLOW_COPY_AND_ASSIGN(InstantUIMessageHandler); 60 DISALLOW_COPY_AND_ASSIGN(InstantUIMessageHandler);
54 }; 61 };
55 62
56 // static 63 // static
57 int InstantUIMessageHandler::slow_animation_scale_factor_ = 1; 64 int InstantUIMessageHandler::slow_animation_scale_factor_ = 1;
65 bool InstantUIMessageHandler::show_search_provider_logo_ = false;
58 66
59 InstantUIMessageHandler::InstantUIMessageHandler() {} 67 InstantUIMessageHandler::InstantUIMessageHandler() {}
60 68
61 InstantUIMessageHandler::~InstantUIMessageHandler() {} 69 InstantUIMessageHandler::~InstantUIMessageHandler() {}
62 70
63 void InstantUIMessageHandler::RegisterMessages() { 71 void InstantUIMessageHandler::RegisterMessages() {
64 web_ui()->RegisterMessageCallback( 72 web_ui()->RegisterMessageCallback(
65 "getPreferenceValue", 73 "getPreferenceValue",
66 base::Bind(&InstantUIMessageHandler::GetPreferenceValue, 74 base::Bind(&InstantUIMessageHandler::GetPreferenceValue,
67 base::Unretained(this))); 75 base::Unretained(this)));
68 web_ui()->RegisterMessageCallback( 76 web_ui()->RegisterMessageCallback(
69 "setPreferenceValue", 77 "setPreferenceValue",
70 base::Bind(&InstantUIMessageHandler::SetPreferenceValue, 78 base::Bind(&InstantUIMessageHandler::SetPreferenceValue,
71 base::Unretained(this))); 79 base::Unretained(this)));
72 } 80 }
73 81
74 void InstantUIMessageHandler::GetPreferenceValue(const base::ListValue* args) { 82 void InstantUIMessageHandler::GetPreferenceValue(const base::ListValue* args) {
75 std::string pref_name; 83 std::string pref_name;
76 if (!args->GetString(0, &pref_name)) return; 84 if (!args->GetString(0, &pref_name)) return;
77 85
78 double value = 0.0; 86 double value = 0.0;
79 #if defined(TOOLKIT_VIEWS) 87 #if defined(TOOLKIT_VIEWS)
80 if (pref_name == prefs::kInstantAnimationScaleFactor) 88 if (pref_name == prefs::kInstantAnimationScaleFactor)
81 value = slow_animation_scale_factor_; 89 value = slow_animation_scale_factor_;
90 else if (pref_name == prefs::kInstantShowSearchProviderLogo)
91 value = show_search_provider_logo_;
82 #endif 92 #endif
83 93
84 base::StringValue arg1(pref_name); 94 base::StringValue arg1(pref_name);
85 base::FundamentalValue arg2(value); 95 base::FundamentalValue arg2(value);
86 web_ui()->CallJavascriptFunction( 96 web_ui()->CallJavascriptFunction(
87 "instantConfig.getPreferenceValueResult", 97 "instantConfig.getPreferenceValueResult",
88 arg1, 98 arg1,
89 arg2); 99 arg2);
90 } 100 }
91 101
92 void InstantUIMessageHandler::SetPreferenceValue(const base::ListValue* args) { 102 void InstantUIMessageHandler::SetPreferenceValue(const base::ListValue* args) {
93 std::string pref_name; 103 std::string pref_name;
94 if (!args->GetString(0, &pref_name)) return; 104 if (!args->GetString(0, &pref_name)) return;
95 105
96 double value;
97 if (!args->GetDouble(1, &value)) return;
98
99 #if defined(TOOLKIT_VIEWS) 106 #if defined(TOOLKIT_VIEWS)
100 if (pref_name == prefs::kInstantAnimationScaleFactor) { 107 if (pref_name == prefs::kInstantAnimationScaleFactor) {
108 double value;
109 if (!args->GetDouble(1, &value))
110 return;
101 // Clamp to something reasonable. 111 // Clamp to something reasonable.
102 value = std::max(0.1, std::min(value, 10.0)); 112 value = std::max(0.1, std::min(value, 20.0));
103 slow_animation_scale_factor_ = static_cast<int>(value); 113 slow_animation_scale_factor_ = static_cast<int>(value);
114 } else if (pref_name == prefs::kInstantShowSearchProviderLogo) {
115 bool value;
116 if (!args->GetBoolean(1, &value))
117 return;
118 show_search_provider_logo_ = value;
104 } 119 }
105 #else 120 #else
106 NOTIMPLEMENTED(); 121 NOTIMPLEMENTED();
107 #endif 122 #endif
108 } 123 }
109 124
110 } // namespace 125 } // namespace
111 126
112 //////////////////////////////////////////////////////////////////////////////// 127 ////////////////////////////////////////////////////////////////////////////////
113 // InstantUI 128 // InstantUI
114 129
115 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) { 130 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) {
116 web_ui->AddMessageHandler(new InstantUIMessageHandler()); 131 web_ui->AddMessageHandler(new InstantUIMessageHandler());
117 132
118 // Set up the chrome://instant/ source. 133 // Set up the chrome://instant/ source.
119 Profile* profile = Profile::FromWebUI(web_ui); 134 Profile* profile = Profile::FromWebUI(web_ui);
120 ChromeURLDataManager::AddDataSource(profile, CreateInstantHTMLSource()); 135 ChromeURLDataManager::AddDataSource(profile, CreateInstantHTMLSource());
121 } 136 }
122 137
123 // static 138 // static
124 int InstantUI::GetSlowAnimationScaleFactor() { 139 int InstantUI::GetSlowAnimationScaleFactor() {
125 return InstantUIMessageHandler::slow_animation_scale_factor(); 140 return InstantUIMessageHandler::slow_animation_scale_factor();
126 } 141 }
142
143 // static
144 int InstantUI::ShouldShowSearchProviderLogo() {
dhollowa 2012/09/14 22:01:56 bool
kuan 2012/09/14 22:34:09 Done.
145 return InstantUIMessageHandler::show_search_provider_logo();
146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698