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

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

Issue 11585008: Remove call to IsInstantExtendedAPIGoogleSearchUrl from SearchTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unit tests. Created 7 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/search/search_tab_helper.cc
diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc
index 07e36ace1169b7e957beb706154994f20e6d18ca..1222b70056d0938f2e31524de141bbd512dbaadd 100644
--- a/chrome/browser/ui/search/search_tab_helper.cc
+++ b/chrome/browser/ui/search/search_tab_helper.cc
@@ -6,6 +6,9 @@
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/search/search.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/navigation_controller.h"
@@ -24,12 +27,31 @@ bool IsNTP(const GURL& url) {
url.host() == chrome::kChromeUINewTabHost;
}
-bool IsSearchEnabled(content::WebContents* web_contents) {
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
+Profile* ProfileFromWebContents(const content::WebContents* web_contents) {
+ return Profile::FromBrowserContext(web_contents->GetBrowserContext());
+}
+
+bool IsSearchEnabled(Profile* profile) {
return chrome::search::IsInstantExtendedAPIEnabled(profile);
}
+
+bool IsSearchResults(const GURL& url, Profile* profile) {
+ // Profile can be NULL in unit tests.
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile);
+ if (!template_url_service)
+ return false;
+
+ TemplateURL* template_url = template_url_service->GetDefaultSearchProvider();
+ if (!template_url)
+ return false;
+
+ string16 result;
+ return template_url->HasSearchTermsReplacementKey(url) &&
+ template_url->ExtractSearchTermsFromURL(url, &result) && !result.empty();
+}
+
} // namespace
namespace chrome {
@@ -37,7 +59,7 @@ namespace search {
SearchTabHelper::SearchTabHelper(content::WebContents* web_contents)
: WebContentsObserver(web_contents),
- is_search_enabled_(IsSearchEnabled(web_contents)),
+ is_search_enabled_(IsSearchEnabled(ProfileFromWebContents(web_contents))),
user_input_in_progress_(false),
model_(web_contents) {
if (!is_search_enabled_)
@@ -103,7 +125,7 @@ void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url) {
if (IsNTP(url)) {
type = Mode::MODE_NTP;
origin = Mode::ORIGIN_NTP;
- } else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) {
+ } else if (IsSearchResults(url, ProfileFromWebContents(web_contents()))) {
type = Mode::MODE_SEARCH_RESULTS;
origin = Mode::ORIGIN_SEARCH;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698