| 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/metrics/field_trial.h" |
| 8 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/time/time.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 12 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 13 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 12 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 14 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/search/search.h" | 16 #include "chrome/browser/search/search.h" |
| 15 #include "chrome/browser/ssl/ssl_error_info.h" | 17 #include "chrome/browser/ssl/ssl_error_info.h" |
| 16 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" | 18 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" |
| 17 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
| 18 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 39 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
| 40 #include "chrome/browser/chromeos/policy/policy_cert_service.h" | 42 #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
| 41 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" | 43 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
| 42 #endif | 44 #endif |
| 43 | 45 |
| 44 using content::NavigationController; | 46 using content::NavigationController; |
| 45 using content::NavigationEntry; | 47 using content::NavigationEntry; |
| 46 using content::SSLStatus; | 48 using content::SSLStatus; |
| 47 using content::WebContents; | 49 using content::WebContents; |
| 48 | 50 |
| 51 namespace { |
| 52 |
| 53 // Converts a SHA-1 field trial group into the appropriate SecurityLevel. |
| 54 bool GetSecurityLevelForFieldTrialGroup(const std::string& group, |
| 55 ToolbarModel::SecurityLevel* level) { |
| 56 if (group == "Error") |
| 57 *level = ToolbarModel::SECURITY_ERROR; |
| 58 else if (group == "Warning") |
| 59 *level = ToolbarModel::SECURITY_WARNING; |
| 60 else if (group == "HTTP") |
| 61 *level = ToolbarModel::NONE; |
| 62 else |
| 63 return false; |
| 64 return true; |
| 65 } |
| 66 |
| 67 } // namespace |
| 68 |
| 49 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate) | 69 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate) |
| 50 : delegate_(delegate) { | 70 : delegate_(delegate) { |
| 51 } | 71 } |
| 52 | 72 |
| 53 ToolbarModelImpl::~ToolbarModelImpl() { | 73 ToolbarModelImpl::~ToolbarModelImpl() { |
| 54 } | 74 } |
| 55 | 75 |
| 56 // static | 76 // static |
| 57 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevelForWebContents( | 77 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevelForWebContents( |
| 58 content::WebContents* web_contents) { | 78 content::WebContents* web_contents) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 75 case content::SECURITY_STYLE_AUTHENTICATED: { | 95 case content::SECURITY_STYLE_AUTHENTICATED: { |
| 76 #if defined(OS_CHROMEOS) | 96 #if defined(OS_CHROMEOS) |
| 77 policy::PolicyCertService* service = | 97 policy::PolicyCertService* service = |
| 78 policy::PolicyCertServiceFactory::GetForProfile( | 98 policy::PolicyCertServiceFactory::GetForProfile( |
| 79 Profile::FromBrowserContext(web_contents->GetBrowserContext())); | 99 Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
| 80 if (service && service->UsedPolicyCertificates()) | 100 if (service && service->UsedPolicyCertificates()) |
| 81 return SECURITY_POLICY_WARNING; | 101 return SECURITY_POLICY_WARNING; |
| 82 #endif | 102 #endif |
| 83 if (!!(ssl.content_status & SSLStatus::DISPLAYED_INSECURE_CONTENT)) | 103 if (!!(ssl.content_status & SSLStatus::DISPLAYED_INSECURE_CONTENT)) |
| 84 return SECURITY_WARNING; | 104 return SECURITY_WARNING; |
| 105 scoped_refptr<net::X509Certificate> cert; |
| 106 if (content::CertStore::GetInstance()->RetrieveCert(ssl.cert_id, &cert) && |
| 107 (ssl.cert_status & net::CERT_STATUS_SHA1_SIGNATURE_PRESENT)) { |
| 108 // The internal representation of the dates for UI treatment of SHA-1. |
| 109 // See http://crbug.com/401365 for details |
| 110 static const int64_t kJanuary2017 = INT64_C(13127702400000000); |
| 111 static const int64_t kJune2016 = INT64_C(13109213000000000); |
| 112 static const int64_t kJanuary2016 = INT64_C(13096080000000000); |
| 113 |
| 114 ToolbarModel::SecurityLevel security_level = NONE; |
| 115 // Gated behind a field trial, so that it is possible to adjust the |
| 116 // UI treatment (to be more or less severe, as necessary) over the |
| 117 // course of multiple releases. |
| 118 // See http://crbug.com/401365 for the timeline, with the end state |
| 119 // being that > kJanuary2017 = Error, and > kJanuary2016 = |
| 120 // Warning, and kJune2016 disappearing entirely. |
| 121 if (cert->valid_expiry() >= |
| 122 base::Time::FromInternalValue(kJanuary2017) && |
| 123 GetSecurityLevelForFieldTrialGroup( |
| 124 base::FieldTrialList::FindFullName("SHA1ToolbarUIJanuary2017"), |
| 125 &security_level)) { |
| 126 return security_level; |
| 127 } |
| 128 if (cert->valid_expiry() >= base::Time::FromInternalValue(kJune2016) && |
| 129 GetSecurityLevelForFieldTrialGroup( |
| 130 base::FieldTrialList::FindFullName("SHA1ToolbarUIJune2016"), |
| 131 &security_level)) { |
| 132 return security_level; |
| 133 } |
| 134 if (cert->valid_expiry() >= |
| 135 base::Time::FromInternalValue(kJanuary2016) && |
| 136 GetSecurityLevelForFieldTrialGroup( |
| 137 base::FieldTrialList::FindFullName("SHA1ToolbarUIJanuary2016"), |
| 138 &security_level)) { |
| 139 return security_level; |
| 140 } |
| 141 } |
| 85 if (net::IsCertStatusError(ssl.cert_status)) { | 142 if (net::IsCertStatusError(ssl.cert_status)) { |
| 86 DCHECK(net::IsCertStatusMinorError(ssl.cert_status)); | 143 DCHECK(net::IsCertStatusMinorError(ssl.cert_status)); |
| 87 return SECURITY_WARNING; | 144 return SECURITY_WARNING; |
| 88 } | 145 } |
| 89 if ((ssl.cert_status & net::CERT_STATUS_IS_EV) && | 146 if ((ssl.cert_status & net::CERT_STATUS_IS_EV) && cert.get()) |
| 90 content::CertStore::GetInstance()->RetrieveCert(ssl.cert_id, NULL)) | |
| 91 return EV_SECURE; | 147 return EV_SECURE; |
| 92 return SECURE; | 148 return SECURE; |
| 93 } | 149 } |
| 94 default: | 150 default: |
| 95 NOTREACHED(); | 151 NOTREACHED(); |
| 96 return NONE; | 152 return NONE; |
| 97 } | 153 } |
| 98 } | 154 } |
| 99 | 155 |
| 100 // ToolbarModelImpl Implementation. | 156 // ToolbarModelImpl Implementation. |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 if (entry && | 385 if (entry && |
| 330 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) | 386 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) |
| 331 return search_terms; | 387 return search_terms; |
| 332 | 388 |
| 333 // Otherwise, extract search terms for HTTPS pages that do not have a security | 389 // Otherwise, extract search terms for HTTPS pages that do not have a security |
| 334 // error. | 390 // error. |
| 335 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); | 391 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); |
| 336 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? | 392 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? |
| 337 base::string16() : search_terms; | 393 base::string16() : search_terms; |
| 338 } | 394 } |
| OLD | NEW |