OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h" | 5 #include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 8 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search/search.h" | 10 #include "chrome/browser/search/search.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 ChromeToolbarModelDelegate::GetSecurityLevel() const { | 73 ChromeToolbarModelDelegate::GetSecurityLevel() const { |
74 content::WebContents* web_contents = GetActiveWebContents(); | 74 content::WebContents* web_contents = GetActiveWebContents(); |
75 // If there is no active WebContents (which can happen during toolbar | 75 // If there is no active WebContents (which can happen during toolbar |
76 // initialization), assume no security style. | 76 // initialization), assume no security style. |
77 if (!web_contents) | 77 if (!web_contents) |
78 return security_state::SecurityStateModel::NONE; | 78 return security_state::SecurityStateModel::NONE; |
79 auto* client = ChromeSecurityStateModelClient::FromWebContents(web_contents); | 79 auto* client = ChromeSecurityStateModelClient::FromWebContents(web_contents); |
80 return client->GetSecurityInfo().security_level; | 80 return client->GetSecurityInfo().security_level; |
81 } | 81 } |
82 | 82 |
83 base::string16 ChromeToolbarModelDelegate::GetSearchTerms( | |
84 security_state::SecurityStateModel::SecurityLevel security_level) const { | |
85 content::WebContents* web_contents = GetActiveWebContents(); | |
86 base::string16 search_terms(search::GetSearchTerms(web_contents)); | |
87 if (search_terms.empty()) { | |
88 // We mainly do this to enforce the subsequent DCHECK. | |
89 return base::string16(); | |
90 } | |
91 | |
92 // If the page is still loading and the security style is unknown, consider | |
93 // the page secure. Without this, after the user hit enter on some search | |
94 // terms, the omnibox would change to displaying the loading URL before | |
95 // changing back to the search terms once they could be extracted, thus | |
96 // causing annoying flicker. | |
97 DCHECK(web_contents); | |
98 content::NavigationController& nav_controller = web_contents->GetController(); | |
99 content::NavigationEntry* entry = nav_controller.GetVisibleEntry(); | |
100 if ((entry != nav_controller.GetLastCommittedEntry()) && | |
101 (entry->GetSSL().security_style == content::SECURITY_STYLE_UNKNOWN)) | |
102 return search_terms; | |
103 | |
104 // If the URL is using a Google base URL specified via the command line, we | |
105 // bypass the security check below. | |
106 if (entry && | |
107 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) | |
108 return search_terms; | |
109 | |
110 // Otherwise, extract search terms for HTTPS pages that do not have a security | |
111 // error. | |
112 bool extract_search_terms = | |
113 (security_level != security_state::SecurityStateModel::NONE) && | |
114 (security_level != security_state::SecurityStateModel::SECURITY_ERROR); | |
115 return extract_search_terms ? search_terms : base::string16(); | |
116 } | |
117 | |
118 scoped_refptr<net::X509Certificate> ChromeToolbarModelDelegate::GetCertificate() | 83 scoped_refptr<net::X509Certificate> ChromeToolbarModelDelegate::GetCertificate() |
119 const { | 84 const { |
120 scoped_refptr<net::X509Certificate> cert; | 85 scoped_refptr<net::X509Certificate> cert; |
121 content::NavigationEntry* entry = GetNavigationEntry(); | 86 content::NavigationEntry* entry = GetNavigationEntry(); |
122 if (entry) { | 87 if (entry) { |
123 content::CertStore::GetInstance()->RetrieveCert(entry->GetSSL().cert_id, | 88 content::CertStore::GetInstance()->RetrieveCert(entry->GetSSL().cert_id, |
124 &cert); | 89 &cert); |
125 } | 90 } |
126 return cert; | 91 return cert; |
127 } | 92 } |
(...skipping 12 matching lines...) Expand all Loading... |
140 content::NavigationController* controller = GetNavigationController(); | 105 content::NavigationController* controller = GetNavigationController(); |
141 return controller ? controller->GetVisibleEntry() : nullptr; | 106 return controller ? controller->GetVisibleEntry() : nullptr; |
142 } | 107 } |
143 | 108 |
144 Profile* ChromeToolbarModelDelegate::GetProfile() const { | 109 Profile* ChromeToolbarModelDelegate::GetProfile() const { |
145 content::NavigationController* controller = GetNavigationController(); | 110 content::NavigationController* controller = GetNavigationController(); |
146 return controller | 111 return controller |
147 ? Profile::FromBrowserContext(controller->GetBrowserContext()) | 112 ? Profile::FromBrowserContext(controller->GetBrowserContext()) |
148 : nullptr; | 113 : nullptr; |
149 } | 114 } |
OLD | NEW |