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

Unified Diff: chrome/browser/search/search.cc

Issue 141893009: Create a new helper function to extract search terms from the URL irrespective of the availablility (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/search/search.cc
diff --git a/chrome/browser/search/search.cc b/chrome/browser/search/search.cc
index bb42ef0ea09612ad5016e7c9274ec533af65ee43..c3b4f205abcc8cbc9272e94d1648cdd0a72a6c42 100644
--- a/chrome/browser/search/search.cc
+++ b/chrome/browser/search/search.cc
@@ -210,7 +210,8 @@ bool IsRenderedInInstantProcess(const content::WebContents* contents,
// (2) Either it has a secure scheme, or else the user has manually specified a
// --google-base-url and it uses that base URL. (This allows testers to use
// --google-base-url to point at non-HTTPS servers, which eases testing.)
-bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) {
+bool IsSuitableURLForInstantImpl(const GURL& url,
+ const TemplateURL* template_url) {
return template_url->HasSearchTermsReplacementKey(url) &&
(url.SchemeIsSecure() ||
google_util::StartsWithCommandLineGoogleBaseURL(url));
@@ -233,7 +234,7 @@ bool IsInstantURL(const GURL& url, Profile* profile) {
if (!template_url)
return false;
- if (!IsSuitableURLForInstant(url, template_url))
+ if (!IsSuitableURLForInstantImpl(url, template_url))
return false;
const TemplateURLRef& instant_url_ref = template_url->instant_url_ref();
@@ -274,7 +275,9 @@ base::string16 GetSearchTermsImpl(const content::WebContents* contents,
return search_terms;
// Otherwise, extract from the URL.
- return GetSearchTermsFromURL(profile, entry->GetVirtualURL());
+ return IsSuitableURLForInstant(profile, entry->GetVirtualURL()) ?
Jered 2014/02/11 19:10:10 nit: This would be clearer as if (!IsSuitableURLF
kmadhusu 2014/02/11 23:24:32 Done.
+ ExtractSearchTermsFromURL(profile, entry->GetVirtualURL()) :
+ base::string16();
}
bool IsURLAllowedForSupervisedUser(const GURL& url, Profile* profile) {
@@ -381,7 +384,7 @@ bool IsQueryExtractionEnabled() {
#endif // defined(OS_IOS) || defined(OS_ANDROID)
}
-base::string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) {
+base::string16 ExtractSearchTermsFromURL(Profile* profile, const GURL& url) {
if (url.is_valid() && url == GetSearchResultPrefetchBaseURL(profile)) {
// InstantSearchPrerenderer has the search query for the Instant search base
// page.
@@ -391,13 +394,18 @@ base::string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) {
return prerenderer->get_last_query();
}
- base::string16 search_terms;
TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
- if (template_url && IsSuitableURLForInstant(url, template_url))
+ base::string16 search_terms;
+ if (template_url)
template_url->ExtractSearchTermsFromURL(url, &search_terms);
return search_terms;
}
+bool IsSuitableURLForInstant(Profile* profile, const GURL& url) {
+ TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
+ return IsSuitableURLForInstantImpl(url, template_url);
Jered 2014/02/11 19:10:10 template_url && ...
kmadhusu 2014/02/11 23:24:32 Done.
+}
+
base::string16 GetSearchTermsFromNavigationEntry(
const content::NavigationEntry* entry) {
base::string16 search_terms;
@@ -447,9 +455,9 @@ bool IsNTPURL(const GURL& url, Profile* profile) {
if (!IsInstantExtendedAPIEnabled())
return url == GURL(chrome::kChromeUINewTabURL);
+ const base::string16 search_terms = ExtractSearchTermsFromURL(profile, url);
return profile &&
- ((IsInstantURL(url, profile) &&
- GetSearchTermsFromURL(profile, url).empty()) ||
+ ((IsInstantURL(url, profile) && search_terms.empty()) ||
url == GURL(chrome::kChromeSearchLocalNtpUrl));
}
@@ -501,7 +509,7 @@ GURL GetInstantURL(Profile* profile, int start_margin,
// Extended mode requires HTTPS. Force it unless the base URL was overridden
// on the command line, in which case we allow HTTP (see comments on
- // IsSuitableURLForInstant()).
+ // IsSuitableURLForInstantImpl()).
if (!instant_url.SchemeIsSecure() &&
!google_util::StartsWithCommandLineGoogleBaseURL(instant_url)) {
GURL::Replacements replacements;

Powered by Google App Engine
This is Rietveld 408576698