| 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/detect_desktop_search_win.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/strings/string_util.h" | |
| 11 #include "components/search_engines/prepopulated_engines.h" | |
| 12 #include "components/search_engines/template_url.h" | |
| 13 #include "components/search_engines/template_url_prepopulate_data.h" | |
| 14 #include "net/base/url_util.h" | |
| 15 | |
| 16 bool DetectWindowsDesktopSearch(const GURL& url, | |
| 17 const SearchTermsData& search_terms_data, | |
| 18 base::string16* search_terms) { | |
| 19 DCHECK(search_terms); | |
| 20 | |
| 21 scoped_ptr<TemplateURLData> template_url_data = | |
| 22 TemplateURLPrepopulateData::MakeTemplateURLDataFromPrepopulatedEngine( | |
| 23 TemplateURLPrepopulateData::bing); | |
| 24 TemplateURL template_url(*template_url_data); | |
| 25 | |
| 26 if (!template_url.ExtractSearchTermsFromURL(url, search_terms_data, | |
| 27 search_terms)) | |
| 28 return false; | |
| 29 | |
| 30 // Query parameter that tells the source of a Bing search URL, and values | |
| 31 // associated with Windows desktop search. | |
| 32 const char kBingSourceQueryKey[] = "form"; | |
| 33 const char kBingSourceDesktopText[] = "WNSGPH"; | |
| 34 const char kBingSourceDesktopVoice[] = "WNSBOX"; | |
| 35 | |
| 36 for (net::QueryIterator it(url); !it.IsAtEnd(); it.Advance()) { | |
| 37 // Use a case-insensitive comparison because the key is sometimes in capital | |
| 38 // letters. | |
| 39 if (base::EqualsCaseInsensitiveASCII(it.GetKey(), kBingSourceQueryKey)) { | |
| 40 std::string source = it.GetValue(); | |
| 41 if (source == kBingSourceDesktopText || source == kBingSourceDesktopVoice) | |
| 42 return true; | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 search_terms->clear(); | |
| 47 return false; | |
| 48 } | |
| OLD | NEW |