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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_model_impl.cc

Issue 233623002: Shows the info bubble when the location bar icon is clicked in the origin chip. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/toolbar_model_impl.h" 5 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 using content::SSLStatus; 44 using content::SSLStatus;
45 using content::WebContents; 45 using content::WebContents;
46 46
47 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate) 47 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate)
48 : delegate_(delegate) { 48 : delegate_(delegate) {
49 } 49 }
50 50
51 ToolbarModelImpl::~ToolbarModelImpl() { 51 ToolbarModelImpl::~ToolbarModelImpl() {
52 } 52 }
53 53
54 // static
54 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevelForWebContents( 55 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevelForWebContents(
55 content::WebContents* web_contents) { 56 content::WebContents* web_contents) {
56 if (!web_contents) 57 if (!web_contents)
57 return NONE; 58 return NONE;
58 59
59 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); 60 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry();
60 if (!entry) 61 if (!entry)
61 return NONE; 62 return NONE;
62 63
63 const SSLStatus& ssl = entry->GetSSL(); 64 const SSLStatus& ssl = entry->GetSSL();
(...skipping 23 matching lines...) Expand all
87 content::CertStore::GetInstance()->RetrieveCert(ssl.cert_id, NULL)) 88 content::CertStore::GetInstance()->RetrieveCert(ssl.cert_id, NULL))
88 return EV_SECURE; 89 return EV_SECURE;
89 return SECURE; 90 return SECURE;
90 } 91 }
91 default: 92 default:
92 NOTREACHED(); 93 NOTREACHED();
93 return NONE; 94 return NONE;
94 } 95 }
95 } 96 }
96 97
98 // static
99 base::string16 ToolbarModelImpl::GetEVCertName(
100 const net::X509Certificate& cert) {
101 // EV are required to have an organization name and country.
102 DCHECK(!cert.subject().organization_names.empty());
103 DCHECK(!cert.subject().country_name.empty());
104
105 return l10n_util::GetStringFUTF16(
106 IDS_SECURE_CONNECTION_EV,
107 base::UTF8ToUTF16(cert.subject().organization_names[0]),
108 base::UTF8ToUTF16(cert.subject().country_name));
109 }
110
97 // ToolbarModelImpl Implementation. 111 // ToolbarModelImpl Implementation.
98 base::string16 ToolbarModelImpl::GetText() const { 112 base::string16 ToolbarModelImpl::GetText() const {
99 base::string16 search_terms(GetSearchTerms(false)); 113 base::string16 search_terms(GetSearchTerms(false));
100 if (!search_terms.empty()) 114 if (!search_terms.empty())
101 return search_terms; 115 return search_terms;
102 116
103 if (WouldOmitURLDueToOriginChip()) 117 if (WouldOmitURLDueToOriginChip())
104 return base::string16(); 118 return base::string16();
105 119
106 return GetFormattedURL(); 120 return GetFormattedURL();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 const NavigationController* navigation_controller = GetNavigationController(); 161 const NavigationController* navigation_controller = GetNavigationController();
148 if (navigation_controller) { 162 if (navigation_controller) {
149 const NavigationEntry* entry = navigation_controller->GetVisibleEntry(); 163 const NavigationEntry* entry = navigation_controller->GetVisibleEntry();
150 if (entry) 164 if (entry)
151 return ShouldDisplayURL() ? entry->GetVirtualURL() : GURL(); 165 return ShouldDisplayURL() ? entry->GetVirtualURL() : GURL();
152 } 166 }
153 167
154 return GURL(content::kAboutBlankURL); 168 return GURL(content::kAboutBlankURL);
155 } 169 }
156 170
157 bool ToolbarModelImpl::WouldOmitURLDueToOriginChip() const {
158 const char kInterstitialShownKey[] = "interstitial_shown";
159
160 // When users type URLs and hit enter, continue to show those URLs until
161 // the navigation commits or an interstitial is shown, because having the
162 // omnibox clear immediately feels like the input was ignored.
163 NavigationController* navigation_controller = GetNavigationController();
164 if (navigation_controller) {
165 NavigationEntry* pending_entry = navigation_controller->GetPendingEntry();
166 if (pending_entry) {
167 const NavigationEntry* visible_entry =
168 navigation_controller->GetVisibleEntry();
169 base::string16 unused;
170 // Keep track that we've shown the origin chip on an interstitial so it
171 // can be shown even after the interstitial was dismissed, to avoid
172 // showing the chip, removing it and then showing it again.
173 if (visible_entry &&
174 visible_entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL &&
175 !pending_entry->GetExtraData(kInterstitialShownKey, &unused))
176 pending_entry->SetExtraData(kInterstitialShownKey, base::string16());
177 const content::PageTransition transition_type =
178 pending_entry->GetTransitionType();
179 if ((transition_type & content::PAGE_TRANSITION_TYPED) != 0 &&
180 !pending_entry->GetExtraData(kInterstitialShownKey, &unused))
181 return false;
182 }
183 }
184
185 if (!delegate_->InTabbedBrowser() || !ShouldDisplayURL() ||
186 !url_replacement_enabled())
187 return false;
188
189 if (chrome::ShouldDisplayOriginChip())
190 return true;
191
192 const chrome::OriginChipV2Condition chip_condition =
193 chrome::GetOriginChipV2Condition();
194 return (chip_condition != chrome::ORIGIN_CHIP_V2_DISABLED) &&
195 ((chip_condition != chrome::ORIGIN_CHIP_V2_ON_SRP) ||
196 WouldPerformSearchTermReplacement(false));
197 }
198
199 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( 171 bool ToolbarModelImpl::WouldPerformSearchTermReplacement(
200 bool ignore_editing) const { 172 bool ignore_editing) const {
201 return !GetSearchTerms(ignore_editing).empty(); 173 return !GetSearchTerms(ignore_editing).empty();
202 } 174 }
203 175
204 bool ToolbarModelImpl::ShouldDisplayURL() const {
205 // Note: The order here is important.
206 // - The WebUI test must come before the extension scheme test because there
207 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In
208 // that case, we should prefer what the WebUI instance says.
209 // - The view-source test must come before the NTP test because of the case
210 // of view-source:chrome://newtab, which should display its URL despite what
211 // chrome://newtab says.
212 NavigationController* controller = GetNavigationController();
213 NavigationEntry* entry = controller ? controller->GetVisibleEntry() : NULL;
214 if (entry) {
215 if (entry->IsViewSourceMode() ||
216 entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) {
217 return true;
218 }
219
220 GURL url = entry->GetURL();
221 GURL virtual_url = entry->GetVirtualURL();
222 if (url.SchemeIs(content::kChromeUIScheme) ||
223 virtual_url.SchemeIs(content::kChromeUIScheme)) {
224 if (!url.SchemeIs(content::kChromeUIScheme))
225 url = virtual_url;
226 return url.host() != chrome::kChromeUINewTabHost;
227 }
228 }
229
230 if (chrome::IsInstantNTP(delegate_->GetActiveWebContents()))
231 return false;
232
233 return true;
234 }
235
236 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( 176 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel(
237 bool ignore_editing) const { 177 bool ignore_editing) const {
238 // When editing, assume no security style. 178 // When editing, assume no security style.
239 return (input_in_progress() && !ignore_editing) ? 179 return (input_in_progress() && !ignore_editing) ?
240 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents()); 180 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents());
241 } 181 }
242 182
243 int ToolbarModelImpl::GetIcon() const { 183 int ToolbarModelImpl::GetIcon() const {
244 if (WouldPerformSearchTermReplacement(false)) { 184 if (WouldPerformSearchTermReplacement(false)) {
245 // The secured version of the search icon is necessary if neither the search 185 // The secured version of the search icon is necessary if neither the search
(...skipping 28 matching lines...) Expand all
274 base::string16 ToolbarModelImpl::GetEVCertName() const { 214 base::string16 ToolbarModelImpl::GetEVCertName() const {
275 DCHECK_EQ(EV_SECURE, GetSecurityLevel(false)); 215 DCHECK_EQ(EV_SECURE, GetSecurityLevel(false));
276 scoped_refptr<net::X509Certificate> cert; 216 scoped_refptr<net::X509Certificate> cert;
277 // Note: Navigation controller and active entry are guaranteed non-NULL or 217 // Note: Navigation controller and active entry are guaranteed non-NULL or
278 // the security level would be NONE. 218 // the security level would be NONE.
279 content::CertStore::GetInstance()->RetrieveCert( 219 content::CertStore::GetInstance()->RetrieveCert(
280 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); 220 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert);
281 return GetEVCertName(*cert.get()); 221 return GetEVCertName(*cert.get());
282 } 222 }
283 223
284 // static 224 bool ToolbarModelImpl::ShouldDisplayURL() const {
285 base::string16 ToolbarModelImpl::GetEVCertName( 225 // Note: The order here is important.
286 const net::X509Certificate& cert) { 226 // - The WebUI test must come before the extension scheme test because there
287 // EV are required to have an organization name and country. 227 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In
288 if (cert.subject().organization_names.empty() || 228 // that case, we should prefer what the WebUI instance says.
289 cert.subject().country_name.empty()) { 229 // - The view-source test must come before the NTP test because of the case
290 NOTREACHED(); 230 // of view-source:chrome://newtab, which should display its URL despite what
291 return base::string16(); 231 // chrome://newtab says.
232 NavigationController* controller = GetNavigationController();
233 NavigationEntry* entry = controller ? controller->GetVisibleEntry() : NULL;
234 if (entry) {
235 if (entry->IsViewSourceMode() ||
236 entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) {
237 return true;
238 }
239
240 GURL url = entry->GetURL();
241 GURL virtual_url = entry->GetVirtualURL();
242 if (url.SchemeIs(content::kChromeUIScheme) ||
243 virtual_url.SchemeIs(content::kChromeUIScheme)) {
244 if (!url.SchemeIs(content::kChromeUIScheme))
245 url = virtual_url;
246 return url.host() != chrome::kChromeUINewTabHost;
247 }
292 } 248 }
293 249
294 return l10n_util::GetStringFUTF16( 250 return !chrome::IsInstantNTP(delegate_->GetActiveWebContents());
295 IDS_SECURE_CONNECTION_EV, 251 }
296 base::UTF8ToUTF16(cert.subject().organization_names[0]), 252
297 base::UTF8ToUTF16(cert.subject().country_name)); 253 bool ToolbarModelImpl::WouldOmitURLDueToOriginChip() const {
254 const char kInterstitialShownKey[] = "interstitial_shown";
255
256 // When users type URLs and hit enter, continue to show those URLs until
257 // the navigation commits or an interstitial is shown, because having the
258 // omnibox clear immediately feels like the input was ignored.
259 NavigationController* navigation_controller = GetNavigationController();
260 if (navigation_controller) {
261 NavigationEntry* pending_entry = navigation_controller->GetPendingEntry();
262 if (pending_entry) {
263 const NavigationEntry* visible_entry =
264 navigation_controller->GetVisibleEntry();
265 base::string16 unused;
266 // Keep track that we've shown the origin chip on an interstitial so it
267 // can be shown even after the interstitial was dismissed, to avoid
268 // showing the chip, removing it and then showing it again.
269 if (visible_entry &&
270 visible_entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL &&
271 !pending_entry->GetExtraData(kInterstitialShownKey, &unused))
272 pending_entry->SetExtraData(kInterstitialShownKey, base::string16());
273 const content::PageTransition transition_type =
274 pending_entry->GetTransitionType();
275 if ((transition_type & content::PAGE_TRANSITION_TYPED) != 0 &&
276 !pending_entry->GetExtraData(kInterstitialShownKey, &unused))
277 return false;
278 }
279 }
280
281 if (!delegate_->InTabbedBrowser() || !ShouldDisplayURL() ||
282 !url_replacement_enabled())
283 return false;
284
285 if (chrome::ShouldDisplayOriginChip())
286 return true;
287
288 const chrome::OriginChipV2Condition chip_condition =
289 chrome::GetOriginChipV2Condition();
290 return (chip_condition != chrome::ORIGIN_CHIP_V2_DISABLED) &&
291 ((chip_condition != chrome::ORIGIN_CHIP_V2_ON_SRP) ||
292 WouldPerformSearchTermReplacement(false));
298 } 293 }
299 294
300 NavigationController* ToolbarModelImpl::GetNavigationController() const { 295 NavigationController* ToolbarModelImpl::GetNavigationController() const {
301 // This |current_tab| can be NULL during the initialization of the 296 // This |current_tab| can be NULL during the initialization of the
302 // toolbar during window creation (i.e. before any tabs have been added 297 // toolbar during window creation (i.e. before any tabs have been added
303 // to the window). 298 // to the window).
304 WebContents* current_tab = delegate_->GetActiveWebContents(); 299 WebContents* current_tab = delegate_->GetActiveWebContents();
305 return current_tab ? &current_tab->GetController() : NULL; 300 return current_tab ? &current_tab->GetController() : NULL;
306 } 301 }
307 302
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 if (entry && 335 if (entry &&
341 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) 336 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL()))
342 return search_terms; 337 return search_terms;
343 338
344 // Otherwise, extract search terms for HTTPS pages that do not have a security 339 // Otherwise, extract search terms for HTTPS pages that do not have a security
345 // error. 340 // error.
346 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); 341 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing);
347 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? 342 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ?
348 base::string16() : search_terms; 343 base::string16() : search_terms;
349 } 344 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_model_impl.h ('k') | chrome/browser/ui/views/location_bar/location_bar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698