Index: chrome/browser/autocomplete/search_provider.cc |
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc |
index 5e30efd45f105cb58fc679b46a80b28f7bb64884..d684ca922d27378e0862c96cc873aa2c100d5d39 100644 |
--- a/chrome/browser/autocomplete/search_provider.cc |
+++ b/chrome/browser/autocomplete/search_provider.cc |
@@ -25,6 +25,7 @@ |
#include "chrome/browser/autocomplete/autocomplete_result.h" |
#include "chrome/browser/autocomplete/keyword_provider.h" |
#include "chrome/browser/autocomplete/url_prefix.h" |
+#include "chrome/browser/google/google_util.h" |
#include "chrome/browser/history/history_service.h" |
#include "chrome/browser/history/history_service_factory.h" |
#include "chrome/browser/history/in_memory_database.h" |
@@ -35,6 +36,8 @@ |
#include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
#include "chrome/browser/search_engines/template_url_service.h" |
#include "chrome/browser/search_engines/template_url_service_factory.h" |
+#include "chrome/browser/sync/profile_sync_service.h" |
+#include "chrome/browser/sync/profile_sync_service_factory.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_finder.h" |
#include "chrome/browser/ui/browser_instant_controller.h" |
@@ -46,6 +49,7 @@ |
#include "net/base/escape.h" |
#include "net/base/load_flags.h" |
#include "net/base/net_util.h" |
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
#include "net/http/http_request_headers.h" |
#include "net/http/http_response_headers.h" |
#include "net/url_request/url_fetcher.h" |
@@ -905,6 +909,68 @@ void SearchProvider::ApplyCalculatedNavigationRelevance( |
} |
} |
+bool SearchProvider::CanSendURL( |
+ const GURL& current_page_url, |
+ const GURL& suggest_url, |
+ const TemplateURL* template_url, |
+ AutocompleteInput::PageClassification page_classification, |
+ Profile* profile){ |
+ if (!current_page_url.is_valid()) |
+ return false; |
+ |
+ // TODO(hfung): Show Most Visited on NTP with appropriate verbatim |
+ // description when the user actively focuses on the omnibox as discussed in |
+ // crbug/305366 if Most Visited (or something similar) will launch. |
+ if (page_classification == |
+ AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_FAKEBOX_AS_STARTING_FOCUS || |
Peter Kasting
2013/10/31 21:55:51
Nit: Parens around binary subexprs (several places
H Fung
2013/11/01 19:16:50
Done, but indention is awful now. :(
|
+ page_classification == |
+ AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_OMNIBOX_AS_STARTING_FOCUS) |
+ return false; |
+ |
+ // Only allow HTTP URLs or HTTPS URLs for the same domain as the search |
+ // provider. |
+ if ((current_page_url.scheme() != content::kHttpScheme) && |
Peter Kasting
2013/10/31 21:55:51
This only checks for "HTTP, or same domain as sear
H Fung
2013/11/01 19:16:50
Done.
|
+ !net::registry_controlled_domains::SameDomainOrHost( |
+ current_page_url, suggest_url, |
+ net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)) |
+ return false; |
+ |
+ // Make sure we are sending the suggest request through HTTPS to prevent |
+ // exposing the current page URL to networks before the search provider. |
+ if (!suggest_url.SchemeIs(content::kHttpsScheme)) |
+ return false; |
+ |
+ // Don't run if there's no profile or in incognito mode. |
+ if (profile == NULL || profile->IsOffTheRecord()) |
+ return false; |
+ |
+ // Don't run if we can't get preferences or search suggest is not enabled. |
+ PrefService* prefs = profile->GetPrefs(); |
+ if (!prefs->GetBoolean(prefs::kSearchSuggestEnabled)) |
+ return false; |
+ |
+ // Only make the request if we know that the provider supports zero suggest |
+ // (currently only the prepopulated Google provider). |
+ if (template_url == NULL || !template_url->SupportsReplacement() || |
+ TemplateURLPrepopulateData::GetEngineType(*template_url) != |
+ SEARCH_ENGINE_GOOGLE) |
+ return false; |
+ |
+ ProfileSyncService* service = |
+ ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
+ browser_sync::SyncPrefs sync_prefs(prefs); |
+ // Check field trials and settings allow sending the URL on suggest requests. |
Peter Kasting
2013/10/31 21:55:51
Nit: Place this comment at the top of this block
H Fung
2013/11/01 19:16:50
Done.
|
+ if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() || |
+ service == NULL || |
+ !service->IsSyncEnabledAndLoggedIn() || |
+ !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( |
+ syncer::PROXY_TABS) || |
+ service->GetEncryptedDataTypes().Has(syncer::SESSIONS)) { |
Peter Kasting
2013/10/31 21:55:51
Nit: No {} since the other conditionals above don'
H Fung
2013/11/01 19:16:50
Done.
|
+ return false; |
+ } |
+ return true; |
Peter Kasting
2013/10/31 21:55:51
Nit: Blank line above this
H Fung
2013/11/01 19:16:50
Done.
|
+} |
+ |
net::URLFetcher* SearchProvider::CreateSuggestFetcher( |
int id, |
const TemplateURL* template_url, |
@@ -920,6 +986,16 @@ net::URLFetcher* SearchProvider::CreateSuggestFetcher( |
search_term_args)); |
if (!suggest_url.is_valid()) |
return NULL; |
+ // Send the current page URL if user setting and URL requirements are met and |
+ // the user is in the field trial. |
+ if (CanSendURL(current_page_url_, suggest_url, template_url, |
+ input.current_page_classification(), profile_) && |
+ OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) { |
+ search_term_args.current_page_url = current_page_url_.spec(); |
+ // Create the suggest URL again with the current page URL. |
+ suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms( |
+ search_term_args)); |
+ } |
suggest_results_pending_++; |
LogOmniboxSuggestRequest(REQUEST_SENT); |