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

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

Issue 11415292: [Search] No longer reverting omnibox text on instant search (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: indent Created 8 years 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/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 64a3716f5ea591a6d5c9b0e4a8fdadcac3c62dab..392cbfa830653e1958b60c4df81623a808df8908 100644
--- a/chrome/browser/ui/toolbar/toolbar_model_impl.cc
+++ b/chrome/browser/ui/toolbar/toolbar_model_impl.cc
@@ -6,10 +6,8 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_input.h"
-#include "chrome/browser/google/google_util.h"
#include "chrome/browser/prefs/pref_service.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"
@@ -50,7 +48,17 @@ ToolbarModelImpl::~ToolbarModelImpl() {
string16 ToolbarModelImpl::GetText(
bool display_search_urls_as_search_terms) const {
if (display_search_urls_as_search_terms) {
- string16 search_terms = TryToExtractSearchTermsFromURL();
+ const NavigationController* navigation_controller =
+ GetNavigationController();
+ NavigationEntry* entry = NULL;
sky 2012/12/12 22:41:57 Move this inside if.
Mathieu 2012/12/12 23:37:24 Done.
+ if (navigation_controller) {
+ entry = navigation_controller->GetActiveEntry();
+ if (entry && !entry->GetSearchTerms().empty()) {
+ // Entry has existing search terms.
+ return entry->GetSearchTerms();
+ }
+ }
+ string16 search_terms = TryToExtractSearchTermsFromCurrentURL();
if (!search_terms.empty())
return search_terms;
}
@@ -82,7 +90,17 @@ GURL ToolbarModelImpl::GetURL() const {
}
bool ToolbarModelImpl::WouldReplaceSearchURLWithSearchTerms() const {
- return !TryToExtractSearchTermsFromURL().empty();
+ return !TryToExtractSearchTermsFromCurrentURL().empty();
+}
+
+string16 ToolbarModelImpl::TryToExtractSearchTermsFromCurrentURL() const {
+ const GURL& url = GetURL();
+ Profile* profile = GetProfile();
+ if (!profile)
+ return string16();
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile);
+ return template_url_service->TryToExtractSearchTermsFromURL(url);
}
bool ToolbarModelImpl::ShouldDisplayURL() const {
@@ -211,28 +229,6 @@ NavigationController* ToolbarModelImpl::GetNavigationController() const {
return current_tab ? &current_tab->GetController() : NULL;
}
-string16 ToolbarModelImpl::TryToExtractSearchTermsFromURL() const {
- const GURL& url = GetURL();
- Profile* profile = GetProfile();
-
- // Ensure instant extended API is enabled and query URL is HTTPS.
- if (!profile || !chrome::search::IsInstantExtendedAPIEnabled(profile) ||
- !url.SchemeIs(chrome::kHttpsScheme) ||
- !google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec()))
- return string16();
-
- TemplateURLService* template_url_service =
- TemplateURLServiceFactory::GetForProfile(profile);
-
- TemplateURL *template_url = template_url_service->GetDefaultSearchProvider();
- if (!template_url)
- return string16();
-
- string16 result;
- template_url->ExtractSearchTermsFromURL(url, &result);
- return result;
-}
-
Profile* ToolbarModelImpl::GetProfile() const {
NavigationController* navigation_controller = GetNavigationController();
return navigation_controller ?

Powered by Google App Engine
This is Rietveld 408576698