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

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

Issue 14259008: Instant Extended: Add prominent search term support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
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 fb6d815ac947f7fa577751bcd0bb371de4ca8230..4aed5a30cf546e9a38434f7b26aac0897057f663 100644
--- a/chrome/browser/ui/toolbar/toolbar_model_impl.cc
+++ b/chrome/browser/ui/toolbar/toolbar_model_impl.cc
@@ -41,7 +41,8 @@ using content::WebContents;
ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate)
: delegate_(delegate),
- input_in_progress_(false) {
+ input_in_progress_(false),
+ supports_extraction_of_url_like_search_terms_(false) {
}
ToolbarModelImpl::~ToolbarModelImpl() {
@@ -87,8 +88,9 @@ ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevelForWebContents(
string16 ToolbarModelImpl::GetText(
bool display_search_urls_as_search_terms) const {
if (display_search_urls_as_search_terms) {
- string16 search_terms = GetSearchTerms();
- if (!search_terms.empty())
+ string16 search_terms(
+ chrome::GetSearchTerms(delegate_->GetActiveWebContents()));
+ if (GetSearchTermsTypeInternal(search_terms) != NO_SEARCH_TERMS)
return search_terms;
}
std::string languages; // Empty if we don't have a |navigation_controller|.
@@ -108,7 +110,7 @@ string16 ToolbarModelImpl::GetText(
}
string16 ToolbarModelImpl::GetCorpusNameForMobile() const {
- if (!WouldReplaceSearchURLWithSearchTerms())
+ if (GetSearchTermsType() == NO_SEARCH_TERMS)
return string16();
GURL url(GetURL());
// If there is a query in the url fragment look for the corpus name there,
@@ -139,8 +141,13 @@ GURL ToolbarModelImpl::GetURL() const {
return GURL(chrome::kAboutBlankURL);
}
-bool ToolbarModelImpl::WouldReplaceSearchURLWithSearchTerms() const {
- return !GetSearchTerms().empty();
+ToolbarModel::SearchTermsType ToolbarModelImpl::GetSearchTermsType() const {
+ return GetSearchTermsTypeInternal(
+ chrome::GetSearchTerms(delegate_->GetActiveWebContents()));
+}
+
+void ToolbarModelImpl::SetSupportsExtractionOfURLLikeSearchTerms(bool value) {
+ supports_extraction_of_url_like_search_terms_ = value;
}
bool ToolbarModelImpl::ShouldDisplayURL() const {
@@ -183,8 +190,13 @@ ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel() const {
}
int ToolbarModelImpl::GetIcon() const {
- if (WouldReplaceSearchURLWithSearchTerms())
+ SearchTermsType search_terms_type = GetSearchTermsType();
+ SecurityLevel security_level = GetSecurityLevel();
+ bool is_secure = security_level == EV_SECURE || security_level == SECURE;
+ if (search_terms_type == NORMAL_SEARCH_TERMS ||
+ (search_terms_type == URL_LIKE_SEARCH_TERMS && is_secure))
return IDR_OMNIBOX_SEARCH;
+
static int icon_ids[NUM_SECURITY_LEVELS] = {
IDR_LOCATION_BAR_HTTP,
IDR_OMNIBOX_HTTPS_VALID,
@@ -193,7 +205,7 @@ int ToolbarModelImpl::GetIcon() const {
IDR_OMNIBOX_HTTPS_INVALID,
};
DCHECK(arraysize(icon_ids) == NUM_SECURITY_LEVELS);
- return icon_ids[GetSecurityLevel()];
+ return icon_ids[security_level];
}
string16 ToolbarModelImpl::GetEVCertName() const {
@@ -244,23 +256,22 @@ Profile* ToolbarModelImpl::GetProfile() const {
NULL;
}
-string16 ToolbarModelImpl::GetSearchTerms() const {
- const WebContents* contents = delegate_->GetActiveWebContents();
- string16 search_terms = chrome::GetSearchTerms(contents);
-
- // Don't extract search terms that the omnibox would treat as a navigation.
- // This might confuse users into believing that the search terms were the
- // URL of the current page, and could cause problems if users hit enter in
- // the omnibox expecting to reload the page.
- if (!search_terms.empty()) {
- AutocompleteMatch match;
- Profile* profile =
- Profile::FromBrowserContext(contents->GetBrowserContext());
- AutocompleteClassifierFactory::GetForProfile(profile)->Classify(
- search_terms, false, false, &match, NULL);
- if (!AutocompleteMatch::IsSearchType(match.type))
- search_terms.clear();
- }
-
- return search_terms;
+ToolbarModel::SearchTermsType ToolbarModelImpl::GetSearchTermsTypeInternal(
+ const string16& search_terms) const {
+ if (search_terms.empty())
+ return NO_SEARCH_TERMS;
+
+ AutocompleteMatch match;
+ AutocompleteClassifierFactory::GetForProfile(Profile::FromBrowserContext(
+ delegate_->GetActiveWebContents()->GetBrowserContext()))->Classify(
+ search_terms, false, false, &match, NULL);
+ // TODO(sail): Remove this once server side mixed content problems are fixed.
+ // For now treat mixed content similar to url shaped queries.
Peter Kasting 2013/04/25 22:48:39 I don't think this TODO is correct, because I thin
sail 2013/04/25 23:39:16 Done.
+ ToolbarModel::SecurityLevel security_level = GetSecurityLevel();
+ if (AutocompleteMatch::IsSearchType(match.type) &&
+ ((security_level == SECURE) || (security_level == EV_SECURE)))
+ return NORMAL_SEARCH_TERMS;
+
+ return supports_extraction_of_url_like_search_terms_?
+ URL_LIKE_SEARCH_TERMS : NO_SEARCH_TERMS;
}

Powered by Google App Engine
This is Rietveld 408576698