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" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 namespace { | 46 namespace { |
47 | 47 |
48 // Configuration options for Embedded Search. | 48 // Configuration options for Embedded Search. |
49 // EmbeddedSearch field trials are named in such a way that we can parse out | 49 // EmbeddedSearch field trials are named in such a way that we can parse out |
50 // the experiment configuration from the trial's group name in order to give | 50 // the experiment configuration from the trial's group name in order to give |
51 // us maximum flexability in running experiments. | 51 // us maximum flexability in running experiments. |
52 // Field trial groups should be named things like "Group7 espv:2 instant:1". | 52 // Field trial groups should be named things like "Group7 espv:2 instant:1". |
53 // The first token is always GroupN for some integer N, followed by a | 53 // The first token is always GroupN for some integer N, followed by a |
54 // space-delimited list of key:value pairs which correspond to these flags: | 54 // space-delimited list of key:value pairs which correspond to these flags: |
55 const char kEmbeddedPageVersionFlagName[] = "espv"; | 55 const char kEmbeddedPageVersionFlagName[] = "espv"; |
56 #if defined(OS_IOS) || defined(OS_ANDROID) | 56 #if defined(OS_IOS) |
57 const uint64 kEmbeddedPageVersionDefault = 1; | 57 const uint64 kEmbeddedPageVersionDefault = 1; |
58 #elif defined(OS_ANDROID) | |
59 const uint64 kEmbeddedPageVersionDefault = 1; | |
60 // Use this variant to enable EmbeddedSearch SearchBox API in the results page. | |
61 const uint64 kEmbeddedPageVersionVariant = 2; | |
58 #else | 62 #else |
59 const uint64 kEmbeddedPageVersionDefault = 2; | 63 const uint64 kEmbeddedPageVersionDefault = 2; |
60 #endif | 64 #endif |
61 | 65 |
62 const char kHideVerbatimFlagName[] = "hide_verbatim"; | 66 const char kHideVerbatimFlagName[] = "hide_verbatim"; |
63 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; | 67 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; |
64 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; | 68 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; |
65 | 69 |
66 // Controls whether to reuse prerendered Instant Search base page to commit any | 70 // Controls whether to reuse prerendered Instant Search base page to commit any |
67 // search query. | 71 // search query. |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 | 256 |
253 // For security reasons, don't extract search terms if the page is not being | 257 // For security reasons, don't extract search terms if the page is not being |
254 // rendered in the privileged Instant renderer process. This is to protect | 258 // rendered in the privileged Instant renderer process. This is to protect |
255 // against a malicious page somehow scripting the search results page and | 259 // against a malicious page somehow scripting the search results page and |
256 // faking search terms in the URL. Random pages can't get into the Instant | 260 // faking search terms in the URL. Random pages can't get into the Instant |
257 // renderer and scripting doesn't work cross-process, so if the page is in | 261 // renderer and scripting doesn't work cross-process, so if the page is in |
258 // the Instant process, we know it isn't being exploited. | 262 // the Instant process, we know it isn't being exploited. |
259 // Since iOS and Android doesn't use the instant framework, these checks are | 263 // Since iOS and Android doesn't use the instant framework, these checks are |
260 // disabled for the two platforms. | 264 // disabled for the two platforms. |
261 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 265 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
262 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 266 #if defined(OS_IOS) |
263 if (!IsRenderedInInstantProcess(contents, profile) && | 267 bool check_renderer_process = false; |
268 #elif defined(OS_ANDROID) | |
269 bool check_renderer_process = | |
270 EmbeddedSearchPageVersion() == kEmbeddedPageVersionVariant; | |
271 #else | |
272 bool check_renderer_process = true; | |
273 #endif // defined(OS_IOS) | |
274 if (check_renderer_process && | |
275 !IsRenderedInInstantProcess(contents, profile) && | |
264 ((entry == contents->GetController().GetLastCommittedEntry()) || | 276 ((entry == contents->GetController().GetLastCommittedEntry()) || |
265 !ShouldAssignURLToInstantRenderer(entry->GetURL(), profile))) | 277 !ShouldAssignURLToInstantRenderer(entry->GetURL(), profile))) |
266 return base::string16(); | 278 return base::string16(); |
267 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) | 279 |
268 // Check to see if search terms have already been extracted. | 280 // Check to see if search terms have already been extracted. |
269 base::string16 search_terms = GetSearchTermsFromNavigationEntry(entry); | 281 base::string16 search_terms = GetSearchTermsFromNavigationEntry(entry); |
270 if (!search_terms.empty()) | 282 if (!search_terms.empty()) |
271 return search_terms; | 283 return search_terms; |
272 | 284 |
273 if (!IsQueryExtractionAllowedForURL(profile, entry->GetVirtualURL())) | 285 if (!IsQueryExtractionAllowedForURL(profile, entry->GetVirtualURL())) |
274 return base::string16(); | 286 return base::string16(); |
275 | 287 |
276 // Otherwise, extract from the URL. | 288 // Otherwise, extract from the URL. |
277 return ExtractSearchTermsFromURL(profile, entry->GetVirtualURL()); | 289 return ExtractSearchTermsFromURL(profile, entry->GetVirtualURL()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 GURL url; | 348 GURL url; |
337 NewTabURLState state; | 349 NewTabURLState state; |
338 }; | 350 }; |
339 | 351 |
340 } // namespace | 352 } // namespace |
341 | 353 |
342 // Negative start-margin values prevent the "es_sm" parameter from being used. | 354 // Negative start-margin values prevent the "es_sm" parameter from being used. |
343 const int kDisableStartMargin = -1; | 355 const int kDisableStartMargin = -1; |
344 | 356 |
345 bool IsInstantExtendedAPIEnabled() { | 357 bool IsInstantExtendedAPIEnabled() { |
346 #if defined(OS_IOS) || defined(OS_ANDROID) | 358 #if defined(OS_IOS) |
347 return false; | 359 return false; |
360 #elif defined(OS_ANDROID) | |
361 return EmbeddedSearchPageVersion() == kEmbeddedPageVersionVariant; | |
348 #else | 362 #else |
349 return true; | 363 return true; |
350 #endif // defined(OS_IOS) || defined(OS_ANDROID) | 364 #endif // defined(OS_IOS) |
351 } | 365 } |
352 | 366 |
353 // Determine what embedded search page version to request from the user's | 367 // Determine what embedded search page version to request from the user's |
354 // default search provider. If 0, the embedded search UI should not be enabled. | 368 // default search provider. If 0, the embedded search UI should not be enabled. |
355 uint64 EmbeddedSearchPageVersion() { | 369 uint64 EmbeddedSearchPageVersion() { |
370 #if defined(OS_ANDROID) | |
371 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
372 switches::kEnableEmbeddedSearchAPI)) { | |
Ted C
2014/04/24 16:24:13
I believe this should be indented 4 from the if no
kmadhusu
2014/04/24 17:38:48
Done.
| |
373 return kEmbeddedPageVersionVariant; | |
374 } | |
375 #endif | |
376 | |
356 FieldTrialFlags flags; | 377 FieldTrialFlags flags; |
357 if (GetFieldTrialInfo(&flags)) { | 378 if (GetFieldTrialInfo(&flags)) { |
358 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, | 379 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, |
359 kEmbeddedPageVersionDefault, | 380 kEmbeddedPageVersionDefault, |
360 flags); | 381 flags); |
361 } | 382 } |
362 return kEmbeddedPageVersionDefault; | 383 return kEmbeddedPageVersionDefault; |
363 } | 384 } |
364 | 385 |
365 std::string InstantExtendedEnabledParam(bool for_search) { | 386 std::string InstantExtendedEnabledParam(bool for_search) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 | 444 |
424 base::string16 GetSearchTerms(const content::WebContents* contents) { | 445 base::string16 GetSearchTerms(const content::WebContents* contents) { |
425 if (!contents) | 446 if (!contents) |
426 return base::string16(); | 447 return base::string16(); |
427 | 448 |
428 const content::NavigationEntry* entry = | 449 const content::NavigationEntry* entry = |
429 contents->GetController().GetVisibleEntry(); | 450 contents->GetController().GetVisibleEntry(); |
430 if (!entry) | 451 if (!entry) |
431 return base::string16(); | 452 return base::string16(); |
432 | 453 |
433 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 454 if (IsInstantExtendedAPIEnabled()) { |
434 // iOS and Android doesn't use the Instant framework, disable this check for | 455 InstantSupportState state = |
435 // the two platforms. | 456 GetInstantSupportStateFromNavigationEntry(*entry); |
436 InstantSupportState state = GetInstantSupportStateFromNavigationEntry(*entry); | 457 if (state == INSTANT_SUPPORT_NO) |
437 if (state == INSTANT_SUPPORT_NO) | 458 return base::string16(); |
438 return base::string16(); | 459 } |
439 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) | |
440 | 460 |
441 return GetSearchTermsImpl(contents, entry); | 461 return GetSearchTermsImpl(contents, entry); |
442 } | 462 } |
443 | 463 |
444 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { | 464 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { |
445 return url.is_valid() && | 465 return url.is_valid() && |
446 profile && | 466 profile && |
447 IsInstantExtendedAPIEnabled() && | 467 IsInstantExtendedAPIEnabled() && |
448 (url.SchemeIs(chrome::kChromeSearchScheme) || | 468 (url.SchemeIs(chrome::kChromeSearchScheme) || |
449 IsInstantURL(url, profile)); | 469 IsInstantURL(url, profile)); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
829 | 849 |
830 // Given a FieldTrialFlags object, returns the boolean value of the provided | 850 // Given a FieldTrialFlags object, returns the boolean value of the provided |
831 // flag. | 851 // flag. |
832 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 852 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
833 bool default_value, | 853 bool default_value, |
834 const FieldTrialFlags& flags) { | 854 const FieldTrialFlags& flags) { |
835 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 855 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
836 } | 856 } |
837 | 857 |
838 } // namespace chrome | 858 } // namespace chrome |
OLD | NEW |