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; |
} |