Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: components/search_engines/desktop_search_win.cc

Issue 1598553003: Implement the Windows desktop search redirection feature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build errors due to prefs being moved in components Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « components/search_engines/desktop_search_win.h ('k') | components/search_engines/desktop_search_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698