OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/search_engines/desktop_search_win.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/prefs/pref_service.h" | |
11 #include "base/strings/string_util.h" | |
12 #include "components/pref_registry/pref_registry_syncable.h" | |
13 #include "components/search_engines/prepopulated_engines.h" | |
14 #include "components/search_engines/template_url.h" | |
15 #include "components/search_engines/template_url_prepopulate_data.h" | |
16 #include "net/base/url_util.h" | |
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 | |
41 bool DetectWindowsDesktopSearch(const GURL& url, | |
42 const SearchTermsData& search_terms_data, | |
43 base::string16* search_terms) { | |
44 DCHECK(search_terms); | |
45 | |
46 scoped_ptr<TemplateURLData> template_url_data = | |
47 TemplateURLPrepopulateData::MakeTemplateURLDataFromPrepopulatedEngine( | |
48 TemplateURLPrepopulateData::bing); | |
49 TemplateURL template_url(*template_url_data); | |
50 | |
51 if (!template_url.ExtractSearchTermsFromURL(url, search_terms_data, | |
52 search_terms)) | |
53 return false; | |
54 | |
55 // Query parameter that tells the source of a Bing search URL, and values | |
56 // associated with Windows desktop search. | |
57 const char kBingSourceQueryKey[] = "form"; | |
58 const char kBingSourceDesktopText[] = "WNSGPH"; | |
59 const char kBingSourceDesktopVoice[] = "WNSBOX"; | |
60 | |
61 for (net::QueryIterator it(url); !it.IsAtEnd(); it.Advance()) { | |
62 // Use a case-insensitive comparison because the key is sometimes in capital | |
63 // letters. | |
64 if (base::EqualsCaseInsensitiveASCII(it.GetKey(), kBingSourceQueryKey)) { | |
65 const std::string source = it.GetValue(); | |
66 if (source == kBingSourceDesktopText || source == kBingSourceDesktopVoice) | |
67 return true; | |
68 } | |
69 } | |
70 | |
71 search_terms->clear(); | |
72 return false; | |
73 } | |
OLD | NEW |