| 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 "ios/chrome/browser/ssl/ios_chrome_security_state_model_client.h" | 5 #include "ios/chrome/browser/ssl/ios_security_state_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/ptr_util.h" |
| 8 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 10 #include "ios/web/public/navigation_item.h" | 12 #include "ios/web/public/navigation_item.h" |
| 11 #import "ios/web/public/navigation_manager.h" | 13 #import "ios/web/public/navigation_manager.h" |
| 12 #import "ios/web/public/origin_util.h" | 14 #import "ios/web/public/origin_util.h" |
| 13 #include "ios/web/public/security_style.h" | 15 #include "ios/web/public/security_style.h" |
| 14 #include "ios/web/public/ssl_status.h" | 16 #include "ios/web/public/ssl_status.h" |
| 15 #include "ios/web/public/web_state/web_state.h" | 17 #include "ios/web/public/web_state/web_state.h" |
| 16 #include "net/cert/x509_certificate.h" | 18 #include "net/cert/x509_certificate.h" |
| 17 | 19 |
| 18 DEFINE_WEB_STATE_USER_DATA_KEY(IOSChromeSecurityStateModelClient); | 20 DEFINE_WEB_STATE_USER_DATA_KEY(IOSSecurityStateTabHelper); |
| 19 | 21 |
| 20 IOSChromeSecurityStateModelClient::IOSChromeSecurityStateModelClient( | 22 IOSSecurityStateTabHelper::IOSSecurityStateTabHelper(web::WebState* web_state) |
| 21 web::WebState* web_state) | |
| 22 : web_state_(web_state), | 23 : web_state_(web_state), |
| 23 security_state_model_(new security_state::SecurityStateModel()) { | 24 security_state_model_(new security_state::SecurityStateModel()) {} |
| 24 security_state_model_->SetClient(this); | 25 |
| 26 IOSSecurityStateTabHelper::~IOSSecurityStateTabHelper() {} |
| 27 |
| 28 void IOSSecurityStateTabHelper::GetSecurityInfo( |
| 29 security_state::SecurityStateModel::SecurityInfo* result) const { |
| 30 security_state_model_->GetSecurityInfo(result, GetVisibleSecurityState(), |
| 31 UsedPolicyInstalledCertificate(), |
| 32 base::Bind(&web::IsOriginSecure)); |
| 25 } | 33 } |
| 26 | 34 |
| 27 IOSChromeSecurityStateModelClient::~IOSChromeSecurityStateModelClient() {} | 35 bool IOSSecurityStateTabHelper::UsedPolicyInstalledCertificate() const { |
| 28 | |
| 29 void IOSChromeSecurityStateModelClient::GetSecurityInfo( | |
| 30 security_state::SecurityStateModel::SecurityInfo* result) const { | |
| 31 return security_state_model_->GetSecurityInfo(result); | |
| 32 } | |
| 33 | |
| 34 bool IOSChromeSecurityStateModelClient::UsedPolicyInstalledCertificate() { | |
| 35 return false; | 36 return false; |
| 36 } | 37 } |
| 37 | 38 |
| 38 bool IOSChromeSecurityStateModelClient::IsOriginSecure(const GURL& url) { | 39 std::unique_ptr<security_state::SecurityStateModel::VisibleSecurityState> |
| 39 return web::IsOriginSecure(url); | 40 IOSSecurityStateTabHelper::GetVisibleSecurityState() const { |
| 40 } | 41 auto state = base::MakeUnique< |
| 42 security_state::SecurityStateModel::VisibleSecurityState>(); |
| 41 | 43 |
| 42 void IOSChromeSecurityStateModelClient::GetVisibleSecurityState( | |
| 43 security_state::SecurityStateModel::VisibleSecurityState* state) { | |
| 44 web::NavigationItem* item = | 44 web::NavigationItem* item = |
| 45 web_state_->GetNavigationManager()->GetVisibleItem(); | 45 web_state_->GetNavigationManager()->GetVisibleItem(); |
| 46 if (!item || item->GetSSL().security_style == web::SECURITY_STYLE_UNKNOWN) { | 46 if (!item || item->GetSSL().security_style == web::SECURITY_STYLE_UNKNOWN) |
| 47 *state = security_state::SecurityStateModel::VisibleSecurityState(); | 47 return state; |
| 48 return; | |
| 49 } | |
| 50 | 48 |
| 51 state->connection_info_initialized = true; | 49 state->connection_info_initialized = true; |
| 52 state->url = item->GetURL(); | 50 state->url = item->GetURL(); |
| 53 const web::SSLStatus& ssl = item->GetSSL(); | 51 const web::SSLStatus& ssl = item->GetSSL(); |
| 54 state->certificate = ssl.certificate; | 52 state->certificate = ssl.certificate; |
| 55 state->cert_status = ssl.cert_status; | 53 state->cert_status = ssl.cert_status; |
| 56 state->connection_status = ssl.connection_status; | 54 state->connection_status = ssl.connection_status; |
| 57 state->security_bits = ssl.security_bits; | 55 state->security_bits = ssl.security_bits; |
| 58 state->displayed_mixed_content = | 56 state->displayed_mixed_content = |
| 59 (ssl.content_status & web::SSLStatus::DISPLAYED_INSECURE_CONTENT) ? true | 57 (ssl.content_status & web::SSLStatus::DISPLAYED_INSECURE_CONTENT) ? true |
| 60 : false; | 58 : false; |
| 59 return state; |
| 61 } | 60 } |
| OLD | NEW |