Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/search_engines_private/search_engines_pr ivate_api.h" | 5 #include "chrome/browser/extensions/api/search_engines_private/search_engines_pr ivate_api.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 | |
| 7 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 11 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/chrome_extension_function.h" | 12 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/search/hotword_audio_history_handler.h" | 14 #include "chrome/browser/search/hotword_audio_history_handler.h" |
| 13 #include "chrome/browser/search/hotword_service.h" | 15 #include "chrome/browser/search/hotword_service.h" |
| 14 #include "chrome/browser/search/hotword_service_factory.h" | 16 #include "chrome/browser/search/hotword_service_factory.h" |
| 15 #include "chrome/browser/search_engines/template_url_service_factory.h" | 17 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 16 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
| 17 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 19 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 20 #include "components/search_engines/template_url_service.h" | 22 #include "components/search_engines/template_url_service.h" |
| 21 #include "components/signin/core/browser/signin_manager.h" | 23 #include "components/signin/core/browser/signin_manager.h" |
| 22 #include "components/signin/core/browser/signin_manager_base.h" | 24 #include "components/signin/core/browser/signin_manager_base.h" |
| 23 #include "extensions/browser/extension_function_registry.h" | 25 #include "extensions/browser/extension_function_registry.h" |
| 26 #include "net/base/net_util.h" | |
| 24 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 25 | 28 |
| 26 namespace extensions { | 29 namespace extensions { |
| 27 | 30 |
| 28 namespace search_engines_private = api::search_engines_private; | 31 namespace search_engines_private = api::search_engines_private; |
| 29 | 32 |
| 30 const char kHotwordServiceMissing[] = "Cannot retrieve hotword service"; | 33 const char kHotwordServiceMissing[] = "Cannot retrieve hotword service"; |
| 31 const char kRetrainWithoutAlwaysOnEnabledError[] = | 34 const char kRetrainWithoutAlwaysOnEnabledError[] = |
| 32 "Cannot retrain without always search and audio logging enabled"; | 35 "Cannot retrain without always search and audio logging enabled"; |
| 33 const char kOptInWithAudioLoggingError[] = | 36 const char kOptInWithAudioLoggingError[] = |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 ~SearchEnginesPrivateAddOtherSearchEngineFunction() { | 116 ~SearchEnginesPrivateAddOtherSearchEngineFunction() { |
| 114 } | 117 } |
| 115 | 118 |
| 116 ExtensionFunction::ResponseAction | 119 ExtensionFunction::ResponseAction |
| 117 SearchEnginesPrivateAddOtherSearchEngineFunction::Run() { | 120 SearchEnginesPrivateAddOtherSearchEngineFunction::Run() { |
| 118 scoped_ptr<search_engines_private::AddOtherSearchEngine::Params> parameters = | 121 scoped_ptr<search_engines_private::AddOtherSearchEngine::Params> parameters = |
| 119 search_engines_private::AddOtherSearchEngine::Params::Create(*args_); | 122 search_engines_private::AddOtherSearchEngine::Params::Create(*args_); |
| 120 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 123 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 121 | 124 |
| 122 TemplateURLData data; | 125 TemplateURLData data; |
| 123 data.SetShortName(base::UTF8ToUTF16(parameters->name)); | 126 // Unpunycode short name and keyword. |
| 124 data.SetKeyword(base::UTF8ToUTF16(parameters->keyword)); | 127 data.SetShortName(net::IDNToUnicode(parameters->name, std::string())); |
|
Matt Giuca
2015/07/17 04:13:11
This should not be unpunycoded. The name and keywo
alshabalin
2015/07/20 14:06:37
Done.
| |
| 128 data.SetKeyword(net::IDNToUnicode(parameters->keyword, std::string())); | |
| 125 data.SetURL(parameters->url); | 129 data.SetURL(parameters->url); |
| 126 TemplateURL* turl = new TemplateURL(data); | 130 TemplateURL* turl = new TemplateURL(data); |
| 127 | 131 |
| 128 TemplateURLService* template_url_service = | 132 TemplateURLService* template_url_service = |
| 129 TemplateURLServiceFactory::GetForProfile(chrome_details_.GetProfile()); | 133 TemplateURLServiceFactory::GetForProfile(chrome_details_.GetProfile()); |
| 130 template_url_service->Add(turl); | 134 template_url_service->Add(turl); |
| 131 return RespondNow(NoArguments()); | 135 return RespondNow(NoArguments()); |
| 132 } | 136 } |
| 133 | 137 |
| 134 //////////////////////////////////////////////////////////////////////////////// | 138 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 148 scoped_ptr<search_engines_private::UpdateSearchEngine::Params> parameters = | 152 scoped_ptr<search_engines_private::UpdateSearchEngine::Params> parameters = |
| 149 search_engines_private::UpdateSearchEngine::Params::Create(*args_); | 153 search_engines_private::UpdateSearchEngine::Params::Create(*args_); |
| 150 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 154 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 151 | 155 |
| 152 TemplateURLService* template_url_service = | 156 TemplateURLService* template_url_service = |
| 153 TemplateURLServiceFactory::GetForProfile(chrome_details_.GetProfile()); | 157 TemplateURLServiceFactory::GetForProfile(chrome_details_.GetProfile()); |
| 154 TemplateURL* turl = | 158 TemplateURL* turl = |
| 155 template_url_service->GetTemplateURLForGUID(parameters->guid); | 159 template_url_service->GetTemplateURLForGUID(parameters->guid); |
| 156 | 160 |
| 157 template_url_service->ResetTemplateURL( | 161 template_url_service->ResetTemplateURL( |
| 158 turl, base::UTF8ToUTF16(parameters->name), | 162 turl, base::UTF8ToUTF16(parameters->name), |
|
Matt Giuca
2015/07/17 04:13:11
If you're going to change addOtherSearchEngine, yo
| |
| 159 base::UTF8ToUTF16(parameters->keyword), parameters->url); | 163 base::UTF8ToUTF16(parameters->keyword), parameters->url); |
| 160 | 164 |
| 161 return RespondNow(NoArguments()); | 165 return RespondNow(NoArguments()); |
| 162 } | 166 } |
| 163 | 167 |
| 164 //////////////////////////////////////////////////////////////////////////////// | 168 //////////////////////////////////////////////////////////////////////////////// |
| 165 // SearchEnginesPrivateRemoveSearchEngineFunction | 169 // SearchEnginesPrivateRemoveSearchEngineFunction |
| 166 | 170 |
| 167 SearchEnginesPrivateRemoveSearchEngineFunction:: | 171 SearchEnginesPrivateRemoveSearchEngineFunction:: |
| 168 SearchEnginesPrivateRemoveSearchEngineFunction() | 172 SearchEnginesPrivateRemoveSearchEngineFunction() |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 } else { | 333 } else { |
| 330 if (prefs->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled)) | 334 if (prefs->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled)) |
| 331 return RespondNow(Error(kAlreadyOptedInError)); | 335 return RespondNow(Error(kAlreadyOptedInError)); |
| 332 } | 336 } |
| 333 | 337 |
| 334 hotword_service->OptIntoHotwording(launch_mode); | 338 hotword_service->OptIntoHotwording(launch_mode); |
| 335 return RespondNow(NoArguments()); | 339 return RespondNow(NoArguments()); |
| 336 } | 340 } |
| 337 | 341 |
| 338 } // namespace extensions | 342 } // namespace extensions |
| OLD | NEW |