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 "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/extensions/chrome_extension_function.h" | 10 #include "chrome/browser/extensions/chrome_extension_function.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/search/hotword_audio_history_handler.h" | 12 #include "chrome/browser/search/hotword_audio_history_handler.h" |
13 #include "chrome/browser/search/hotword_service.h" | 13 #include "chrome/browser/search/hotword_service.h" |
14 #include "chrome/browser/search/hotword_service_factory.h" | 14 #include "chrome/browser/search/hotword_service_factory.h" |
15 #include "chrome/browser/search_engines/template_url_service_factory.h" | 15 #include "chrome/browser/search_engines/template_url_service_factory.h" |
16 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
20 #include "components/search_engines/template_url_service.h" | 20 #include "components/search_engines/template_url_service.h" |
21 #include "components/signin/core/browser/signin_manager.h" | 21 #include "components/signin/core/browser/signin_manager.h" |
22 #include "components/signin/core/browser/signin_manager_base.h" | 22 #include "components/signin/core/browser/signin_manager_base.h" |
23 #include "extensions/browser/extension_function_registry.h" | 23 #include "extensions/browser/extension_function_registry.h" |
24 #include "net/base/net_util.h" | |
24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
25 | 26 |
26 namespace extensions { | 27 namespace extensions { |
27 | 28 |
28 namespace search_engines_private = api::search_engines_private; | 29 namespace search_engines_private = api::search_engines_private; |
29 | 30 |
30 const char kHotwordServiceMissing[] = "Cannot retrieve hotword service"; | 31 const char kHotwordServiceMissing[] = "Cannot retrieve hotword service"; |
31 const char kRetrainWithoutAlwaysOnEnabledError[] = | 32 const char kRetrainWithoutAlwaysOnEnabledError[] = |
32 "Cannot retrain without always search and audio logging enabled"; | 33 "Cannot retrain without always search and audio logging enabled"; |
33 const char kOptInWithAudioLoggingError[] = | 34 const char kOptInWithAudioLoggingError[] = |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 ~SearchEnginesPrivateAddOtherSearchEngineFunction() { | 114 ~SearchEnginesPrivateAddOtherSearchEngineFunction() { |
114 } | 115 } |
115 | 116 |
116 ExtensionFunction::ResponseAction | 117 ExtensionFunction::ResponseAction |
117 SearchEnginesPrivateAddOtherSearchEngineFunction::Run() { | 118 SearchEnginesPrivateAddOtherSearchEngineFunction::Run() { |
118 scoped_ptr<search_engines_private::AddOtherSearchEngine::Params> parameters = | 119 scoped_ptr<search_engines_private::AddOtherSearchEngine::Params> parameters = |
119 search_engines_private::AddOtherSearchEngine::Params::Create(*args_); | 120 search_engines_private::AddOtherSearchEngine::Params::Create(*args_); |
120 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 121 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
121 | 122 |
122 TemplateURLData data; | 123 TemplateURLData data; |
123 data.SetShortName(base::UTF8ToUTF16(parameters->name)); | 124 // Unpunycode short name and keyword. |
Peter Kasting
2015/07/14 18:05:33
Why do we need to do this for these particular cas
alshabalin
2015/07/15 14:18:01
Because I want to perform IDN conversion on user i
Peter Kasting
2015/07/15 21:19:12
I don't understand your paragraph. It seems to fi
alshabalin
2015/07/16 15:13:07
I was thinking server-side user at the time and ac
Peter Kasting
2015/07/16 19:16:27
Well, it's not normal in the sense that we don't c
Matt Giuca
2015/07/17 04:13:11
It sounds like you're saying that because site mai
| |
124 data.SetKeyword(base::UTF8ToUTF16(parameters->keyword)); | 125 data.SetShortName(net::IDNToUnicode(parameters->name, "")); |
Peter Kasting
2015/07/14 18:05:33
Nit: Use std::string() in place of "" everywhere i
alshabalin
2015/07/15 15:19:50
Done.
| |
126 data.SetKeyword(net::IDNToUnicode(parameters->keyword, "")); | |
125 data.SetURL(parameters->url); | 127 data.SetURL(parameters->url); |
126 TemplateURL* turl = new TemplateURL(data); | 128 TemplateURL* turl = new TemplateURL(data); |
127 | 129 |
128 TemplateURLService* template_url_service = | 130 TemplateURLService* template_url_service = |
129 TemplateURLServiceFactory::GetForProfile(chrome_details_.GetProfile()); | 131 TemplateURLServiceFactory::GetForProfile(chrome_details_.GetProfile()); |
130 template_url_service->Add(turl); | 132 template_url_service->Add(turl); |
131 return RespondNow(NoArguments()); | 133 return RespondNow(NoArguments()); |
132 } | 134 } |
133 | 135 |
134 //////////////////////////////////////////////////////////////////////////////// | 136 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 } else { | 331 } else { |
330 if (prefs->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled)) | 332 if (prefs->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled)) |
331 return RespondNow(Error(kAlreadyOptedInError)); | 333 return RespondNow(Error(kAlreadyOptedInError)); |
332 } | 334 } |
333 | 335 |
334 hotword_service->OptIntoHotwording(launch_mode); | 336 hotword_service->OptIntoHotwording(launch_mode); |
335 return RespondNow(NoArguments()); | 337 return RespondNow(NoArguments()); |
336 } | 338 } |
337 | 339 |
338 } // namespace extensions | 340 } // namespace extensions |
OLD | NEW |