Index: chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.cc |
diff --git a/chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.cc b/chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.cc |
index 5f924b100bbe0e68065b24764969daff3e497274..15190c9db5f3debdb3704cfd6ddc07e6dc78d1d1 100644 |
--- a/chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.cc |
+++ b/chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.cc |
@@ -4,14 +4,23 @@ |
#include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h" |
+#include "base/logging.h" |
#include "base/prefs/pref_service.h" |
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/search/search.h" |
+#include "chrome/browser/ssl/chrome_security_state_model_client.h" |
#include "chrome/common/pref_names.h" |
+#include "chrome/common/url_constants.h" |
+#include "components/google/core/browser/google_util.h" |
#include "components/omnibox/browser/autocomplete_input.h" |
+#include "content/public/browser/cert_store.h" |
#include "content/public/browser/navigation_controller.h" |
#include "content/public/browser/navigation_entry.h" |
#include "content/public/browser/web_contents.h" |
+#include "content/public/common/ssl_status.h" |
+ |
+ChromeToolbarModelDelegate::~ChromeToolbarModelDelegate() {} |
std::string ChromeToolbarModelDelegate::GetAcceptLanguages() const { |
Profile* profile = GetProfile(); |
@@ -26,7 +35,102 @@ base::string16 ChromeToolbarModelDelegate::FormattedStringWithEquivalentMeaning( |
url, formatted_url, ChromeAutocompleteSchemeClassifier(GetProfile())); |
} |
-ChromeToolbarModelDelegate::~ChromeToolbarModelDelegate() {} |
+bool ChromeToolbarModelDelegate::GetURL(GURL* url) const { |
+ DCHECK(url); |
+ content::NavigationEntry* entry = GetNavigationEntry(); |
+ if (entry) { |
Peter Kasting
2016/02/02 23:51:30
Nit: Reverse conditional and early-return to avoid
sdefresne
2016/02/03 13:14:17
Done.
|
+ *url = ShouldDisplayURL() ? entry->GetVirtualURL() : GURL(); |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+bool ChromeToolbarModelDelegate::ShouldDisplayURL() const { |
+ // Note: The order here is important. |
+ // - The WebUI test must come before the extension scheme test because there |
+ // can be WebUIs that have extension schemes (e.g. the bookmark manager). In |
+ // that case, we should prefer what the WebUI instance says. |
+ // - The view-source test must come before the NTP test because of the case |
+ // of view-source:chrome://newtab, which should display its URL despite what |
+ // chrome://newtab says. |
+ content::NavigationEntry* entry = GetNavigationEntry(); |
+ if (entry) { |
+ if (entry->IsViewSourceMode() || |
+ entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) { |
+ return true; |
+ } |
+ |
+ GURL url = entry->GetURL(); |
+ GURL virtual_url = entry->GetVirtualURL(); |
+ if (url.SchemeIs(content::kChromeUIScheme) || |
+ virtual_url.SchemeIs(content::kChromeUIScheme)) { |
+ if (!url.SchemeIs(content::kChromeUIScheme)) |
+ url = virtual_url; |
+ return url.host() != chrome::kChromeUINewTabHost; |
+ } |
+ } |
+ |
+ return !search::IsInstantNTP(GetActiveWebContents()); |
+} |
+ |
+security_state::SecurityStateModel::SecurityLevel |
+ChromeToolbarModelDelegate::GetSecurityLevel() const { |
+ content::WebContents* web_contents = GetActiveWebContents(); |
+ // If there is no active WebContents (which can happen during toolbar |
+ // initialization), assume no security style. |
+ if (!web_contents) |
+ return security_state::SecurityStateModel::NONE; |
+ return ChromeSecurityStateModelClient::FromWebContents(web_contents) |
Peter Kasting
2016/02/02 23:51:30
Nit: Shorter:
auto* client = ChromeSecurityStat
sdefresne
2016/02/03 13:14:17
Done.
|
+ ->GetSecurityInfo() |
+ .security_level; |
+} |
+ |
+base::string16 ChromeToolbarModelDelegate::GetSearchTerms( |
+ security_state::SecurityStateModel::SecurityLevel security_level) const { |
+ content::WebContents* web_contents = GetActiveWebContents(); |
+ base::string16 search_terms(search::GetSearchTerms(web_contents)); |
+ if (search_terms.empty()) { |
+ // We mainly do this to enforce the subsequent DCHECK. |
+ return base::string16(); |
+ } |
+ |
+ // If the page is still loading and the security style is unknown, consider |
+ // the page secure. Without this, after the user hit enter on some search |
+ // terms, the omnibox would change to displaying the loading URL before |
+ // changing back to the search terms once they could be extracted, thus |
+ // causing annoying flicker. |
+ DCHECK(web_contents); |
+ content::NavigationController& nav_controller = web_contents->GetController(); |
+ content::NavigationEntry* entry = nav_controller.GetVisibleEntry(); |
+ if ((entry != nav_controller.GetLastCommittedEntry()) && |
+ (entry->GetSSL().security_style == content::SECURITY_STYLE_UNKNOWN)) |
+ return search_terms; |
+ |
+ // If the URL is using a Google base URL specified via the command line, we |
+ // bypass the security check below. |
+ if (entry && |
+ google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) |
+ return search_terms; |
+ |
+ // Otherwise, extract search terms for HTTPS pages that do not have a security |
+ // error. |
+ return ((security_level == security_state::SecurityStateModel::NONE) || |
+ (security_level == |
+ security_state::SecurityStateModel::SECURITY_ERROR)) |
+ ? base::string16() |
+ : search_terms; |
Peter Kasting
2016/02/02 23:51:30
Nit: Shorter:
bool extract_search_terms =
sdefresne
2016/02/03 13:14:17
Done.
|
+} |
+ |
+scoped_refptr<net::X509Certificate> ChromeToolbarModelDelegate::GetCertificate() |
+ const { |
+ scoped_refptr<net::X509Certificate> cert; |
+ content::NavigationEntry* entry = GetNavigationEntry(); |
+ if (entry) { |
+ content::CertStore::GetInstance()->RetrieveCert(entry->GetSSL().cert_id, |
+ &cert); |
+ } |
+ return cert; |
+} |
content::NavigationController* |
ChromeToolbarModelDelegate::GetNavigationController() const { |
@@ -37,10 +141,15 @@ ChromeToolbarModelDelegate::GetNavigationController() const { |
return current_tab ? ¤t_tab->GetController() : nullptr; |
} |
+content::NavigationEntry* ChromeToolbarModelDelegate::GetNavigationEntry() |
+ const { |
+ content::NavigationController* controller = GetNavigationController(); |
+ return controller ? controller->GetVisibleEntry() : nullptr; |
+} |
+ |
Profile* ChromeToolbarModelDelegate::GetProfile() const { |
- content::NavigationController* navigation_controller = |
- GetNavigationController(); |
- return navigation_controller ? Profile::FromBrowserContext( |
- navigation_controller->GetBrowserContext()) |
- : nullptr; |
+ content::NavigationController* controller = GetNavigationController(); |
+ return controller |
+ ? Profile::FromBrowserContext(controller->GetBrowserContext()) |
+ : nullptr; |
} |