OLD | NEW |
---|---|
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 const NavigationController* navigation_controller = GetNavigationController(); | 147 const NavigationController* navigation_controller = GetNavigationController(); |
148 if (navigation_controller) { | 148 if (navigation_controller) { |
149 const NavigationEntry* entry = navigation_controller->GetVisibleEntry(); | 149 const NavigationEntry* entry = navigation_controller->GetVisibleEntry(); |
150 if (entry) | 150 if (entry) |
151 return ShouldDisplayURL() ? entry->GetVirtualURL() : GURL(); | 151 return ShouldDisplayURL() ? entry->GetVirtualURL() : GURL(); |
152 } | 152 } |
153 | 153 |
154 return GURL(content::kAboutBlankURL); | 154 return GURL(content::kAboutBlankURL); |
155 } | 155 } |
156 | 156 |
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 bool should_display_origin_chip = | |
186 chrome::ShouldDisplayOriginChip() || chrome::ShouldDisplayOriginChipV2(); | |
187 return should_display_origin_chip && delegate_->InTabbedBrowser() && | |
188 ShouldDisplayURL() && url_replacement_enabled(); | |
189 } | |
190 | |
191 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( | 157 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( |
192 bool ignore_editing) const { | 158 bool ignore_editing) const { |
193 return !GetSearchTerms(ignore_editing).empty(); | 159 return !GetSearchTerms(ignore_editing).empty(); |
194 } | 160 } |
195 | 161 |
196 bool ToolbarModelImpl::ShouldDisplayURL() const { | 162 bool ToolbarModelImpl::ShouldDisplayURL() const { |
197 // Note: The order here is important. | 163 // Note: The order here is important. |
198 // - The WebUI test must come before the extension scheme test because there | 164 // - The WebUI test must come before the extension scheme test because there |
199 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In | 165 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In |
200 // that case, we should prefer what the WebUI instance says. | 166 // that case, we should prefer what the WebUI instance says. |
(...skipping 17 matching lines...) Expand all Loading... | |
218 return url.host() != chrome::kChromeUINewTabHost; | 184 return url.host() != chrome::kChromeUINewTabHost; |
219 } | 185 } |
220 } | 186 } |
221 | 187 |
222 if (chrome::IsInstantNTP(delegate_->GetActiveWebContents())) | 188 if (chrome::IsInstantNTP(delegate_->GetActiveWebContents())) |
223 return false; | 189 return false; |
224 | 190 |
225 return true; | 191 return true; |
226 } | 192 } |
227 | 193 |
194 bool ToolbarModelImpl::WouldOmitURLDueToOriginChip() const { | |
Peter Kasting
2014/05/05 22:39:04
Please move both ShouldDisplayURL() and this funct
macourteau
2014/05/08 21:35:55
Done.
| |
195 const char kInterstitialShownKey[] = "interstitial_shown"; | |
196 | |
197 // When users type URLs and hit enter, continue to show those URLs until | |
198 // the navigation commits or an interstitial is shown, because having the | |
199 // omnibox clear immediately feels like the input was ignored. | |
200 NavigationController* navigation_controller = GetNavigationController(); | |
201 if (navigation_controller) { | |
202 NavigationEntry* pending_entry = navigation_controller->GetPendingEntry(); | |
203 if (pending_entry) { | |
204 const NavigationEntry* visible_entry = | |
205 navigation_controller->GetVisibleEntry(); | |
206 base::string16 unused; | |
207 // Keep track that we've shown the origin chip on an interstitial so it | |
208 // can be shown even after the interstitial was dismissed, to avoid | |
209 // showing the chip, removing it and then showing it again. | |
210 if (visible_entry && | |
211 visible_entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL && | |
212 !pending_entry->GetExtraData(kInterstitialShownKey, &unused)) | |
213 pending_entry->SetExtraData(kInterstitialShownKey, base::string16()); | |
214 const content::PageTransition transition_type = | |
215 pending_entry->GetTransitionType(); | |
216 if ((transition_type & content::PAGE_TRANSITION_TYPED) != 0 && | |
217 !pending_entry->GetExtraData(kInterstitialShownKey, &unused)) | |
218 return false; | |
219 } | |
220 } | |
221 | |
222 bool should_display_origin_chip = | |
223 chrome::ShouldDisplayOriginChip() || chrome::ShouldDisplayOriginChipV2(); | |
224 return should_display_origin_chip && delegate_->InTabbedBrowser() && | |
225 ShouldDisplayURL() && url_replacement_enabled(); | |
226 } | |
227 | |
228 bool ToolbarModelImpl::ShouldShowOriginChip() const { | |
229 return (chrome::ShouldDisplayOriginChipV2() && | |
Peter Kasting
2014/05/05 22:39:04
Nit: No ()
macourteau
2014/05/08 21:35:55
Done.
| |
230 WouldOmitURLDueToOriginChip() && | |
231 origin_chip_enabled()); | |
232 } | |
233 | |
228 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( | 234 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( |
229 bool ignore_editing) const { | 235 bool ignore_editing) const { |
230 // When editing, assume no security style. | 236 // When editing, assume no security style. |
231 return (input_in_progress() && !ignore_editing) ? | 237 return (input_in_progress() && !ignore_editing) ? |
232 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents()); | 238 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents()); |
233 } | 239 } |
234 | 240 |
235 int ToolbarModelImpl::GetIcon() const { | 241 int ToolbarModelImpl::GetIcon() const { |
236 if (WouldPerformSearchTermReplacement(false)) { | 242 if (WouldPerformSearchTermReplacement(false)) { |
237 // The secured version of the search icon is necessary if neither the search | 243 // The secured version of the search icon is necessary if neither the search |
(...skipping 29 matching lines...) Expand all Loading... | |
267 DCHECK_EQ(EV_SECURE, GetSecurityLevel(false)); | 273 DCHECK_EQ(EV_SECURE, GetSecurityLevel(false)); |
268 scoped_refptr<net::X509Certificate> cert; | 274 scoped_refptr<net::X509Certificate> cert; |
269 // Note: Navigation controller and active entry are guaranteed non-NULL or | 275 // Note: Navigation controller and active entry are guaranteed non-NULL or |
270 // the security level would be NONE. | 276 // the security level would be NONE. |
271 content::CertStore::GetInstance()->RetrieveCert( | 277 content::CertStore::GetInstance()->RetrieveCert( |
272 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); | 278 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); |
273 return GetEVCertName(*cert.get()); | 279 return GetEVCertName(*cert.get()); |
274 } | 280 } |
275 | 281 |
276 // static | 282 // static |
277 base::string16 ToolbarModelImpl::GetEVCertName( | 283 base::string16 ToolbarModelImpl::GetEVCertName( |
Peter Kasting
2014/05/05 22:39:04
While here, move this up to below GetSecurityLevel
macourteau
2014/05/08 21:35:55
Done.
| |
278 const net::X509Certificate& cert) { | 284 const net::X509Certificate& cert) { |
279 // EV are required to have an organization name and country. | 285 // EV are required to have an organization name and country. |
280 if (cert.subject().organization_names.empty() || | 286 if (cert.subject().organization_names.empty() || |
281 cert.subject().country_name.empty()) { | 287 cert.subject().country_name.empty()) { |
282 NOTREACHED(); | 288 NOTREACHED(); |
283 return base::string16(); | 289 return base::string16(); |
284 } | 290 } |
285 | 291 |
286 return l10n_util::GetStringFUTF16( | 292 return l10n_util::GetStringFUTF16( |
287 IDS_SECURE_CONNECTION_EV, | 293 IDS_SECURE_CONNECTION_EV, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 if (entry && | 338 if (entry && |
333 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) | 339 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) |
334 return search_terms; | 340 return search_terms; |
335 | 341 |
336 // Otherwise, extract search terms for HTTPS pages that do not have a security | 342 // Otherwise, extract search terms for HTTPS pages that do not have a security |
337 // error. | 343 // error. |
338 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); | 344 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); |
339 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? | 345 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? |
340 base::string16() : search_terms; | 346 base::string16() : search_terms; |
341 } | 347 } |
OLD | NEW |