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 "components/search_engines/detect_desktop_search_win.h" | 5 #include "components/search_engines/desktop_search_win.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "components/pref_registry/pref_registry_syncable.h" |
11 #include "components/search_engines/prepopulated_engines.h" | 13 #include "components/search_engines/prepopulated_engines.h" |
12 #include "components/search_engines/template_url.h" | 14 #include "components/search_engines/template_url.h" |
13 #include "components/search_engines/template_url_prepopulate_data.h" | 15 #include "components/search_engines/template_url_prepopulate_data.h" |
14 #include "net/base/url_util.h" | 16 #include "net/base/url_util.h" |
15 | 17 |
| 18 namespace prefs { |
| 19 const char kWindowsDesktopSearchRedirectionPref[] = |
| 20 "windows_desktop_search_redirection"; |
| 21 } // namespace prefs |
| 22 |
| 23 const base::Feature kWindowsDesktopSearchRedirectionFeature = { |
| 24 "WindowsDesktopSearchRedirection", base::FEATURE_DISABLED_BY_DEFAULT |
| 25 }; |
| 26 |
| 27 void RegisterWindowsDesktopSearchRedirectionPref( |
| 28 user_prefs::PrefRegistrySyncable* registry) { |
| 29 registry->RegisterBooleanPref(prefs::kWindowsDesktopSearchRedirectionPref, |
| 30 false); |
| 31 } |
| 32 |
| 33 bool ShouldRedirectWindowsDesktopSearchToDefaultSearchEngine( |
| 34 PrefService* pref_service) { |
| 35 DCHECK(pref_service); |
| 36 return base::FeatureList::IsEnabled( |
| 37 kWindowsDesktopSearchRedirectionFeature) && |
| 38 pref_service->GetBoolean(prefs::kWindowsDesktopSearchRedirectionPref); |
| 39 } |
| 40 |
16 bool DetectWindowsDesktopSearch(const GURL& url, | 41 bool DetectWindowsDesktopSearch(const GURL& url, |
17 const SearchTermsData& search_terms_data, | 42 const SearchTermsData& search_terms_data, |
18 base::string16* search_terms) { | 43 base::string16* search_terms) { |
19 DCHECK(search_terms); | 44 DCHECK(search_terms); |
20 | 45 |
21 scoped_ptr<TemplateURLData> template_url_data = | 46 scoped_ptr<TemplateURLData> template_url_data = |
22 TemplateURLPrepopulateData::MakeTemplateURLDataFromPrepopulatedEngine( | 47 TemplateURLPrepopulateData::MakeTemplateURLDataFromPrepopulatedEngine( |
23 TemplateURLPrepopulateData::bing); | 48 TemplateURLPrepopulateData::bing); |
24 TemplateURL template_url(*template_url_data); | 49 TemplateURL template_url(*template_url_data); |
25 | 50 |
26 if (!template_url.ExtractSearchTermsFromURL(url, search_terms_data, | 51 if (!template_url.ExtractSearchTermsFromURL(url, search_terms_data, |
27 search_terms)) | 52 search_terms)) |
28 return false; | 53 return false; |
29 | 54 |
30 // Query parameter that tells the source of a Bing search URL, and values | 55 // Query parameter that tells the source of a Bing search URL, and values |
31 // associated with Windows desktop search. | 56 // associated with Windows desktop search. |
32 const char kBingSourceQueryKey[] = "form"; | 57 const char kBingSourceQueryKey[] = "form"; |
33 const char kBingSourceDesktopText[] = "WNSGPH"; | 58 const char kBingSourceDesktopText[] = "WNSGPH"; |
34 const char kBingSourceDesktopVoice[] = "WNSBOX"; | 59 const char kBingSourceDesktopVoice[] = "WNSBOX"; |
35 | 60 |
36 for (net::QueryIterator it(url); !it.IsAtEnd(); it.Advance()) { | 61 for (net::QueryIterator it(url); !it.IsAtEnd(); it.Advance()) { |
37 // Use a case-insensitive comparison because the key is sometimes in capital | 62 // Use a case-insensitive comparison because the key is sometimes in capital |
38 // letters. | 63 // letters. |
39 if (base::EqualsCaseInsensitiveASCII(it.GetKey(), kBingSourceQueryKey)) { | 64 if (base::EqualsCaseInsensitiveASCII(it.GetKey(), kBingSourceQueryKey)) { |
40 std::string source = it.GetValue(); | 65 const std::string source = it.GetValue(); |
41 if (source == kBingSourceDesktopText || source == kBingSourceDesktopVoice) | 66 if (source == kBingSourceDesktopText || source == kBingSourceDesktopVoice) |
42 return true; | 67 return true; |
43 } | 68 } |
44 } | 69 } |
45 | 70 |
46 search_terms->clear(); | 71 search_terms->clear(); |
47 return false; | 72 return false; |
48 } | 73 } |
OLD | NEW |