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

Side by Side Diff: chrome/browser/google/google_util.cc

Issue 10908226: Introduces a search term extraction mechanism working for arbitrary search providers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed version_46.sql, committed separately. Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/google/google_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/google/google_util.h" 5 #include "chrome/browser/google/google_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/string_split.h" 13 #include "base/string_split.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/google/google_url_tracker.h" 17 #include "chrome/browser/google/google_url_tracker.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/net/url_util.h" 19 #include "chrome/common/net/url_util.h"
20 #include "chrome/installer/util/google_update_settings.h" 20 #include "chrome/installer/util/google_update_settings.h"
21 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
22 #include "googleurl/src/url_parse.h"
23 #include "net/base/escape.h"
24 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
25 23
26 #if defined(OS_MACOSX) 24 #if defined(OS_MACOSX)
27 #include "chrome/browser/mac/keystone_glue.h" 25 #include "chrome/browser/mac/keystone_glue.h"
28 #endif 26 #endif
29 27
30 #if defined(GOOGLE_CHROME_BUILD) 28 #if defined(GOOGLE_CHROME_BUILD)
31 #include "chrome/browser/google/linkdoctor_internal/linkdoctor_internal.h" 29 #include "chrome/browser/google/linkdoctor_internal/linkdoctor_internal.h"
32 #endif 30 #endif
33 31
(...skipping 16 matching lines...) Expand all
50 itr != parameters.end(); 48 itr != parameters.end();
51 ++itr) { 49 ++itr) {
52 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2) 50 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2)
53 return true; 51 return true;
54 } 52 }
55 return false; 53 return false;
56 } 54 }
57 55
58 bool gUseMockLinkDoctorBaseURLForTesting = false; 56 bool gUseMockLinkDoctorBaseURLForTesting = false;
59 57
60 // Finds the first key-value pair where the key matches |query_key|. Returns
61 // true if a match is found and sets |search_terms| to the value.
62 bool ExtractSearchTermsFromComponent(const std::string& url,
63 url_parse::Component* component,
64 string16* search_terms) {
65 const std::string query_key = "q";
66 url_parse::Component key, value;
67
68 while (url_parse::ExtractQueryKeyValue(url.c_str(), component,
69 &key, &value)) {
70 if (url.compare(key.begin, key.len, query_key) != 0)
71 continue;
72 std::string value_str = url.substr(value.begin, value.len);
73 *search_terms = net::UnescapeAndDecodeUTF8URLComponent(
74 value_str,
75 net::UnescapeRule::SPACES |
76 net::UnescapeRule::URL_SPECIAL_CHARS |
77 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE,
78 NULL);
79 return true;
80 }
81 return false;
82 }
83
84 } // anonymous namespace 58 } // anonymous namespace
85 59
86 namespace google_util { 60 namespace google_util {
87 61
88 GURL LinkDoctorBaseURL() { 62 GURL LinkDoctorBaseURL() {
89 if (gUseMockLinkDoctorBaseURLForTesting) 63 if (gUseMockLinkDoctorBaseURLForTesting)
90 return GURL("http://mock.linkdoctor.url/for?testing"); 64 return GURL("http://mock.linkdoctor.url/for?testing");
91 return GURL(LINKDOCTOR_SERVER_REQUEST_URL); 65 return GURL(LINKDOCTOR_SERVER_REQUEST_URL);
92 } 66 }
93 67
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return true; 146 return true;
173 } 147 }
174 148
175 bool GetReactivationBrand(std::string* brand) { 149 bool GetReactivationBrand(std::string* brand) {
176 brand->clear(); 150 brand->clear();
177 return true; 151 return true;
178 } 152 }
179 153
180 #endif 154 #endif
181 155
182 string16 GetSearchTermsFromGoogleSearchURL(const std::string& url) {
183 if (!IsInstantExtendedAPIGoogleSearchUrl(url))
184 return string16();
185
186 url_parse::Parsed parsed_url;
187 url_parse::ParseStandardURL(url.c_str(), url.length(), &parsed_url);
188
189 string16 search_terms;
190 // The search terms can be in either the query or ref component - for
191 // instance, in a regular Google search they'll be in the query but in a
192 // Google Instant search they can be in both. The ref is the correct one to
193 // return in this case, so test the ref component first.
194 if (ExtractSearchTermsFromComponent(url, &parsed_url.ref, &search_terms) ||
195 ExtractSearchTermsFromComponent(url, &parsed_url.query, &search_terms)) {
196 return search_terms;
197 }
198 return string16();
199 }
200
201 bool IsGoogleDomainUrl(const std::string& url, 156 bool IsGoogleDomainUrl(const std::string& url,
202 SubdomainPermission subdomain_permission, 157 SubdomainPermission subdomain_permission,
203 PortPermission port_permission) { 158 PortPermission port_permission) {
204 GURL original_url(url); 159 GURL original_url(url);
205 if (!original_url.is_valid() || 160 if (!original_url.is_valid() ||
206 !(original_url.SchemeIs("http") || original_url.SchemeIs("https"))) 161 !(original_url.SchemeIs("http") || original_url.SchemeIs("https")))
207 return false; 162 return false;
208 163
209 // If we have the Instant URL overridden with a command line flag, accept 164 // If we have the Instant URL overridden with a command line flag, accept
210 // its domain/port combination as well. 165 // its domain/port combination as well.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 const char* const kBrands[] = { 316 const char* const kBrands[] = {
362 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", 317 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE",
363 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", 318 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM",
364 }; 319 };
365 const char* const* end = &kBrands[arraysize(kBrands)]; 320 const char* const* end = &kBrands[arraysize(kBrands)];
366 const char* const* found = std::find(&kBrands[0], end, brand); 321 const char* const* found = std::find(&kBrands[0], end, brand);
367 return found != end; 322 return found != end;
368 } 323 }
369 324
370 } // namespace google_util 325 } // namespace google_util
OLDNEW
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/google/google_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698