Commit 3d7a9332 authored by beaudoin@chromium.org's avatar beaudoin@chromium.org

Remove call to IsInstantExtendedAPIGoogleSearchUrl from SearchTabHelper.

This patch ensures SearchTabHelper no longer relies on the hardcoded "espv" parameter.

Depends on:
  https://codereview.chromium.org/11552020/
  https://codereview.chromium.org/11576044/

BUG=161602

Review URL: https://chromiumcodereview.appspot.com/11585008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175910 0039d316-1c4b-4281-b951-d872f2087c98
parent bd2715f4
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment