OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search/search.h" | 5 #include "chrome/browser/search/search.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/search/instant_service.h" | 14 #include "chrome/browser/search/instant_service.h" |
15 #include "chrome/browser/search/instant_service_factory.h" | 15 #include "chrome/browser/search/instant_service_factory.h" |
16 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 16 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
17 #include "chrome/browser/search_engines/template_url_service.h" | 17 #include "chrome/browser/search_engines/template_url_service.h" |
18 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 22 #include "components/sessions/serialized_navigation_entry.h" |
22 #include "components/user_prefs/pref_registry_syncable.h" | 23 #include "components/user_prefs/pref_registry_syncable.h" |
23 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
24 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 | 27 |
27 namespace chrome { | 28 namespace chrome { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 // The default value we should assign to the instant_extended.enabled pref. As | 32 // The default value we should assign to the instant_extended.enabled pref. As |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 kDisableStartMargin); | 224 kDisableStartMargin); |
224 | 225 |
225 if (url.SchemeIsSecure() && template_url->HasSearchTermsReplacementKey(url)) | 226 if (url.SchemeIsSecure() && template_url->HasSearchTermsReplacementKey(url)) |
226 template_url->ExtractSearchTermsFromURL(url, &search_terms); | 227 template_url->ExtractSearchTermsFromURL(url, &search_terms); |
227 | 228 |
228 return search_terms; | 229 return search_terms; |
229 } | 230 } |
230 | 231 |
231 } // namespace | 232 } // namespace |
232 | 233 |
233 const char kInstantExtendedSearchTermsKey[] = "search_terms"; | |
234 | |
235 // Negative start-margin values prevent the "es_sm" parameter from being used. | 234 // Negative start-margin values prevent the "es_sm" parameter from being used. |
236 const int kDisableStartMargin = -1; | 235 const int kDisableStartMargin = -1; |
237 | 236 |
238 bool IsInstantExtendedAPIEnabled() { | 237 bool IsInstantExtendedAPIEnabled() { |
239 #if defined(OS_IOS) || defined(OS_ANDROID) | 238 #if defined(OS_IOS) || defined(OS_ANDROID) |
240 return false; | 239 return false; |
241 #else | 240 #else |
242 // On desktop, query extraction is part of Instant extended, so if one is | 241 // On desktop, query extraction is part of Instant extended, so if one is |
243 // enabled, the other is too. | 242 // enabled, the other is too. |
244 return IsQueryExtractionEnabled() || IsLocalOnlyInstantExtendedAPIEnabled(); | 243 return IsQueryExtractionEnabled() || IsLocalOnlyInstantExtendedAPIEnabled(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 &flags, NULL)) { | 295 &flags, NULL)) { |
297 return GetBoolValueForFlagWithDefault(kLocalOnlyFlagName, false, flags); | 296 return GetBoolValueForFlagWithDefault(kLocalOnlyFlagName, false, flags); |
298 } | 297 } |
299 return false; | 298 return false; |
300 } | 299 } |
301 | 300 |
302 string16 GetSearchTermsFromNavigationEntry( | 301 string16 GetSearchTermsFromNavigationEntry( |
303 const content::NavigationEntry* entry) { | 302 const content::NavigationEntry* entry) { |
304 string16 search_terms; | 303 string16 search_terms; |
305 if (entry) | 304 if (entry) |
306 entry->GetExtraData(kInstantExtendedSearchTermsKey, &search_terms); | 305 entry->GetExtraData(sessions::kSearchTermsKey, &search_terms); |
307 return search_terms; | 306 return search_terms; |
308 } | 307 } |
309 | 308 |
310 string16 GetSearchTerms(const content::WebContents* contents) { | 309 string16 GetSearchTerms(const content::WebContents* contents) { |
311 if (!contents) | 310 if (!contents) |
312 return string16(); | 311 return string16(); |
313 | 312 |
314 const content::NavigationEntry* entry = | 313 const content::NavigationEntry* entry = |
315 contents->GetController().GetVisibleEntry(); | 314 contents->GetController().GetVisibleEntry(); |
316 if (!entry) | 315 if (!entry) |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 replacements.SetHostStr(search_host); | 608 replacements.SetHostStr(search_host); |
610 replacements.SetPortStr(search_port); | 609 replacements.SetPortStr(search_port); |
611 return instant_url.ReplaceComponents(replacements); | 610 return instant_url.ReplaceComponents(replacements); |
612 } | 611 } |
613 | 612 |
614 bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { | 613 bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { |
615 return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path(); | 614 return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path(); |
616 } | 615 } |
617 | 616 |
618 } // namespace chrome | 617 } // namespace chrome |
OLD | NEW |