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

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

Issue 1653013002: Abstract ToolbarModelImpl dependencies on //content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@1
Patch Set: Address comments Created 4 years, 11 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/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 f69e939ba006b7126e20406a9d0ff0e744df5a3d..795e682edc63fcfaa5baa2fe904378cfdf278bbf 100644
--- a/chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.cc
+++ b/chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.cc
@@ -4,14 +4,25 @@
#include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h"
+#include "base/logging.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 "components/prefs/pref_service.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() {}
+
+ChromeToolbarModelDelegate::~ChromeToolbarModelDelegate() {}
std::string ChromeToolbarModelDelegate::GetAcceptLanguages() const {
Profile* profile = GetProfile();
@@ -26,9 +37,100 @@ 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)
+ return false;
-ChromeToolbarModelDelegate::~ChromeToolbarModelDelegate() {}
+ *url = ShouldDisplayURL() ? entry->GetVirtualURL() : GURL();
+ return true;
+}
+
+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;
+ auto* client = ChromeSecurityStateModelClient::FromWebContents(web_contents);
+ return client->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.
+ bool extract_search_terms =
+ (security_level != security_state::SecurityStateModel::NONE) &&
+ (security_level != security_state::SecurityStateModel::SECURITY_ERROR);
+ return extract_search_terms ? search_terms : base::string16();
+}
+
+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 {
@@ -39,10 +141,15 @@ ChromeToolbarModelDelegate::GetNavigationController() const {
return current_tab ? &current_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;
}
« no previous file with comments | « chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h ('k') | chrome/browser/ui/toolbar/toolbar_model_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698