| 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..c47beacaa3e58132721517416b684254ed8b1d03 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,28 @@ 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);
|
| + // If the current page is not being displayed securely (e.g. due to mixed
|
| + // content errors), force any extracted search terms to be considered as
|
| + // "URL-like". This will cause callers to display a more obvious indicator
|
| + // that the terms are a search query. This aims to mitigate an attack
|
| + // scenario where attackers inject content into a search result page to make
|
| + // it look like e.g. Paypal and also navigate the URL to that of a search for
|
| + // "Paypal" -- hopefully, showing an obvious indicator that this is a search
|
| + // will decrease the chances of users falling for the phishing attempt.
|
| + 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;
|
| }
|
|
|