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

Unified Diff: chrome/browser/ui/toolbar/toolbar_model_impl.cc

Issue 12250033: Consolidate search terms extraction and Instant process determination. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style nit Created 7 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
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_model_impl.h ('k') | chrome/browser/ui/toolbar/toolbar_model_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/toolbar/toolbar_model_impl.cc
diff --git a/chrome/browser/ui/toolbar/toolbar_model_impl.cc b/chrome/browser/ui/toolbar/toolbar_model_impl.cc
index 493411478697ded23b1452cad90cd3e1b3193917..9daf849cac20c23216236a3dbb6e760703cc6fbd 100644
--- a/chrome/browser/ui/toolbar/toolbar_model_impl.cc
+++ b/chrome/browser/ui/toolbar/toolbar_model_impl.cc
@@ -8,11 +8,7 @@
#include "base/prefs/pref_service.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_input.h"
-#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/ssl/ssl_error_info.h"
#include "chrome/browser/ui/search/search.h"
#include "chrome/browser/ui/toolbar/toolbar_model_delegate.h"
@@ -40,26 +36,6 @@ using content::NavigationEntry;
using content::SSLStatus;
using content::WebContents;
-namespace {
-
-// Coerces an instant URL to look like a regular search URL so we can extract
-// query terms from the URL.
-GURL ConvertInstantURLToSearchURL(const GURL& instant_url,
- const TemplateURL& template_url) {
- GURL search_url(template_url.url_ref().ReplaceSearchTerms(
- TemplateURLRef::SearchTermsArgs(string16())));
- const std::string& scheme = search_url.scheme();
- const std::string& host = search_url.host();
- const std::string& port = search_url.port();
- GURL::Replacements replacements;
- replacements.SetSchemeStr(scheme);
- replacements.SetHostStr(host);
- replacements.SetPortStr(port);
- return instant_url.ReplaceComponents(replacements);
-}
-
-} // namespace
-
ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate)
: delegate_(delegate),
input_in_progress_(false) {
@@ -72,7 +48,8 @@ ToolbarModelImpl::~ToolbarModelImpl() {
string16 ToolbarModelImpl::GetText(
bool display_search_urls_as_search_terms) const {
if (display_search_urls_as_search_terms) {
- string16 search_terms = TryToExtractSearchTermsFromURL();
+ string16 search_terms =
+ chrome::search::GetSearchTerms(delegate_->GetActiveWebContents());
if (!search_terms.empty())
return search_terms;
}
@@ -104,7 +81,8 @@ GURL ToolbarModelImpl::GetURL() const {
}
bool ToolbarModelImpl::WouldReplaceSearchURLWithSearchTerms() const {
- return !TryToExtractSearchTermsFromURL().empty();
+ const content::WebContents* contents = delegate_->GetActiveWebContents();
+ return !chrome::search::GetSearchTerms(contents).empty();
}
bool ToolbarModelImpl::ShouldDisplayURL() const {
@@ -236,35 +214,6 @@ NavigationController* ToolbarModelImpl::GetNavigationController() const {
return current_tab ? &current_tab->GetController() : NULL;
}
-string16 ToolbarModelImpl::TryToExtractSearchTermsFromURL() const {
- GURL url = GetURL();
- Profile* profile = GetProfile();
-
- // Ensure query extraction is enabled and query URL is HTTPS.
- if (!profile || !chrome::search::IsQueryExtractionEnabled(profile) ||
- !url.SchemeIs(chrome::kHttpsScheme))
- return string16();
-
- TemplateURLService* template_url_service =
- TemplateURLServiceFactory::GetForProfile(profile);
-
- TemplateURL* template_url = template_url_service->GetDefaultSearchProvider();
- if (!template_url)
- return string16();
-
- // Coerce URLs set via --instant-url to look like a regular search URL so we
- // can extract search terms from them.
- if (chrome::search::IsForcedInstantURL(url))
- url = ConvertInstantURLToSearchURL(url, *template_url);
-
- if (!template_url->HasSearchTermsReplacementKey(url))
- return string16();
-
- string16 result;
- template_url->ExtractSearchTermsFromURL(url, &result);
- return result;
-}
-
Profile* ToolbarModelImpl::GetProfile() const {
NavigationController* navigation_controller = GetNavigationController();
return navigation_controller ?
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_model_impl.h ('k') | chrome/browser/ui/toolbar/toolbar_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698