| OLD | NEW |
| 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 Loading... |
| 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 | |
| 51 private: | 47 private: |
| 52 void GetPreferenceValue(const base::ListValue* args); | 48 void GetPreferenceValue(const base::ListValue* args); |
| 53 void SetPreferenceValue(const base::ListValue* args); | 49 void SetPreferenceValue(const base::ListValue* args); |
| 54 | 50 |
| 55 // Slows down Instant animations by a time factor. | 51 // Slows down Instant animations by a time factor. |
| 56 static int slow_animation_scale_factor_; | 52 static int slow_animation_scale_factor_; |
| 57 | 53 |
| 58 // True if search provider logo should be shown. | |
| 59 static bool show_search_provider_logo_; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(InstantUIMessageHandler); | 54 DISALLOW_COPY_AND_ASSIGN(InstantUIMessageHandler); |
| 62 }; | 55 }; |
| 63 | 56 |
| 64 // static | 57 // static |
| 65 int InstantUIMessageHandler::slow_animation_scale_factor_ = 1; | 58 int InstantUIMessageHandler::slow_animation_scale_factor_ = 1; |
| 66 bool InstantUIMessageHandler::show_search_provider_logo_ = false; | |
| 67 | 59 |
| 68 InstantUIMessageHandler::InstantUIMessageHandler() {} | 60 InstantUIMessageHandler::InstantUIMessageHandler() {} |
| 69 | 61 |
| 70 InstantUIMessageHandler::~InstantUIMessageHandler() {} | 62 InstantUIMessageHandler::~InstantUIMessageHandler() {} |
| 71 | 63 |
| 72 void InstantUIMessageHandler::RegisterMessages() { | 64 void InstantUIMessageHandler::RegisterMessages() { |
| 73 web_ui()->RegisterMessageCallback( | 65 web_ui()->RegisterMessageCallback( |
| 74 "getPreferenceValue", | 66 "getPreferenceValue", |
| 75 base::Bind(&InstantUIMessageHandler::GetPreferenceValue, | 67 base::Bind(&InstantUIMessageHandler::GetPreferenceValue, |
| 76 base::Unretained(this))); | 68 base::Unretained(this))); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 87 base::StringValue pref_name_value(pref_name); | 79 base::StringValue pref_name_value(pref_name); |
| 88 if (pref_name == prefs::kInstantAnimationScaleFactor) { | 80 if (pref_name == prefs::kInstantAnimationScaleFactor) { |
| 89 double value = 0.0; | 81 double value = 0.0; |
| 90 #if defined(TOOLKIT_VIEWS) | 82 #if defined(TOOLKIT_VIEWS) |
| 91 value = slow_animation_scale_factor_; | 83 value = slow_animation_scale_factor_; |
| 92 #endif | 84 #endif |
| 93 base::FundamentalValue arg(value); | 85 base::FundamentalValue arg(value); |
| 94 web_ui()->CallJavascriptFunction( | 86 web_ui()->CallJavascriptFunction( |
| 95 "instantConfig.getPreferenceValueResult", pref_name_value, arg); | 87 "instantConfig.getPreferenceValueResult", pref_name_value, arg); |
| 96 } else if (pref_name == prefs::kInstantShowSearchProviderLogo) { | 88 } else if (pref_name == prefs::kInstantShowSearchProviderLogo) { |
| 97 base::FundamentalValue arg(show_search_provider_logo_); | 89 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 90 base::FundamentalValue arg(prefs->GetBoolean(pref_name.c_str())); |
| 98 web_ui()->CallJavascriptFunction( | 91 web_ui()->CallJavascriptFunction( |
| 99 "instantConfig.getPreferenceValueResult", pref_name_value, arg); | 92 "instantConfig.getPreferenceValueResult", pref_name_value, arg); |
| 100 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) { | 93 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) { |
| 101 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 94 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 102 base::StringValue arg(prefs->GetString(pref_name.c_str())); | 95 base::StringValue arg(prefs->GetString(pref_name.c_str())); |
| 103 web_ui()->CallJavascriptFunction( | 96 web_ui()->CallJavascriptFunction( |
| 104 "instantConfig.getPreferenceValueResult", pref_name_value, arg); | 97 "instantConfig.getPreferenceValueResult", pref_name_value, arg); |
| 105 } | 98 } |
| 106 } | 99 } |
| 107 | 100 |
| 108 void InstantUIMessageHandler::SetPreferenceValue(const base::ListValue* args) { | 101 void InstantUIMessageHandler::SetPreferenceValue(const base::ListValue* args) { |
| 109 std::string pref_name; | 102 std::string pref_name; |
| 110 if (!args->GetString(0, &pref_name)) return; | 103 if (!args->GetString(0, &pref_name)) return; |
| 111 | 104 |
| 112 if (pref_name == prefs::kInstantAnimationScaleFactor) { | 105 if (pref_name == prefs::kInstantAnimationScaleFactor) { |
| 113 double value; | 106 double value; |
| 114 if (!args->GetDouble(1, &value)) | 107 if (!args->GetDouble(1, &value)) |
| 115 return; | 108 return; |
| 116 #if defined(TOOLKIT_VIEWS) | 109 #if defined(TOOLKIT_VIEWS) |
| 117 // Clamp to something reasonable. | 110 // Clamp to something reasonable. |
| 118 value = std::max(0.1, std::min(value, 20.0)); | 111 value = std::max(0.1, std::min(value, 20.0)); |
| 119 slow_animation_scale_factor_ = static_cast<int>(value); | 112 slow_animation_scale_factor_ = static_cast<int>(value); |
| 120 #else | 113 #else |
| 121 NOTIMPLEMENTED(); | 114 NOTIMPLEMENTED(); |
| 122 #endif // defined(TOOLKIT_VIEWS) | 115 #endif // defined(TOOLKIT_VIEWS) |
| 123 } else if (pref_name == prefs::kInstantShowSearchProviderLogo) { | 116 } else if (pref_name == prefs::kInstantShowSearchProviderLogo) { |
| 124 bool value; | 117 bool value; |
| 125 if (!args->GetBoolean(1, &value)) | 118 if (!args->GetBoolean(1, &value)) |
| 126 return; | 119 return; |
| 127 show_search_provider_logo_ = value; | 120 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 121 prefs->SetBoolean(pref_name.c_str(), value); |
| 128 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) { | 122 } else if (pref_name == prefs::kExperimentalZeroSuggestUrlPrefix) { |
| 129 std::string value; | 123 std::string value; |
| 130 if (!args->GetString(1, &value)) | 124 if (!args->GetString(1, &value)) |
| 131 return; | 125 return; |
| 132 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 126 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 133 prefs->SetString(pref_name.c_str(), value); | 127 prefs->SetString(pref_name.c_str(), value); |
| 134 } | 128 } |
| 135 } | 129 } |
| 136 | 130 |
| 137 } // namespace | 131 } // namespace |
| 138 | 132 |
| 139 //////////////////////////////////////////////////////////////////////////////// | 133 //////////////////////////////////////////////////////////////////////////////// |
| 140 // InstantUI | 134 // InstantUI |
| 141 | 135 |
| 142 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 136 InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 143 web_ui->AddMessageHandler(new InstantUIMessageHandler()); | 137 web_ui->AddMessageHandler(new InstantUIMessageHandler()); |
| 144 | 138 |
| 145 // Set up the chrome://instant/ source. | 139 // Set up the chrome://instant/ source. |
| 146 Profile* profile = Profile::FromWebUI(web_ui); | 140 Profile* profile = Profile::FromWebUI(web_ui); |
| 147 ChromeURLDataManager::AddDataSource(profile, CreateInstantHTMLSource()); | 141 ChromeURLDataManager::AddDataSource(profile, CreateInstantHTMLSource()); |
| 148 } | 142 } |
| 149 | 143 |
| 150 // static | 144 // static |
| 151 int InstantUI::GetSlowAnimationScaleFactor() { | 145 int InstantUI::GetSlowAnimationScaleFactor() { |
| 152 return InstantUIMessageHandler::slow_animation_scale_factor(); | 146 return InstantUIMessageHandler::slow_animation_scale_factor(); |
| 153 } | 147 } |
| 154 | 148 |
| 155 // static | 149 // static |
| 156 bool InstantUI::ShouldShowSearchProviderLogo() { | 150 bool InstantUI::ShouldShowSearchProviderLogo( |
| 157 return InstantUIMessageHandler::show_search_provider_logo(); | 151 content::BrowserContext* browser_context) { |
| 152 PrefService* prefs = Profile::FromBrowserContext(browser_context)->GetPrefs(); |
| 153 return prefs->GetBoolean(prefs::kInstantShowSearchProviderLogo); |
| 158 } | 154 } |
| 155 |
| 156 // static |
| 157 void InstantUI::RegisterUserPrefs(PrefService* user_prefs) { |
| 158 user_prefs->RegisterBooleanPref(prefs::kInstantShowSearchProviderLogo, false, |
| 159 PrefService::UNSYNCABLE_PREF); |
| 160 user_prefs->RegisterStringPref(prefs::kExperimentalZeroSuggestUrlPrefix, "", |
| 161 PrefService::UNSYNCABLE_PREF); |
| 162 } |
| OLD | NEW |