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

Side by Side Diff: chrome/browser/ssl/connection_security.cc

Issue 1169213006: Make ConnectionSecurityHelper a namespace instead of a class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ssl/connection_security_helper.h" 5 #include "chrome/browser/ssl/connection_security.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/metrics/field_trial.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ssl/ssl_error_info.h" 12 #include "chrome/browser/ssl/ssl_error_info.h"
13 #include "chrome/common/chrome_constants.h" 13 #include "chrome/common/chrome_constants.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/cert_store.h" 16 #include "content/public/browser/cert_store.h"
17 #include "content/public/browser/navigation_controller.h" 17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/origin_util.h" 20 #include "content/public/common/origin_util.h"
21 #include "content/public/common/ssl_status.h" 21 #include "content/public/common/ssl_status.h"
22 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
23 #include "net/cert/cert_status_flags.h" 23 #include "net/cert/cert_status_flags.h"
24 #include "net/cert/x509_certificate.h" 24 #include "net/cert/x509_certificate.h"
25 #include "net/ssl/ssl_connection_status_flags.h" 25 #include "net/ssl/ssl_connection_status_flags.h"
26 26
27 #if defined(OS_CHROMEOS) 27 #if defined(OS_CHROMEOS)
28 #include "chrome/browser/chromeos/policy/policy_cert_service.h" 28 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
29 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" 29 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
30 #endif 30 #endif
31 31
32 namespace { 32 namespace {
33 33
34 ConnectionSecurityHelper::SecurityLevel 34 connection_security::SecurityLevel GetSecurityLevelForNonSecureFieldTrial() {
35 GetSecurityLevelForNonSecureFieldTrial() {
36 std::string choice = 35 std::string choice =
37 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 36 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
38 switches::kMarkNonSecureAs); 37 switches::kMarkNonSecureAs);
39 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); 38 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs");
40 39
41 // Do not change this enum. It is used in the histogram. 40 // Do not change this enum. It is used in the histogram.
42 enum MarkNonSecureStatus { NEUTRAL, DUBIOUS, NON_SECURE, LAST_STATUS }; 41 enum MarkNonSecureStatus { NEUTRAL, DUBIOUS, NON_SECURE, LAST_STATUS };
43 const char kEnumeration[] = "MarkNonSecureAs"; 42 const char kEnumeration[] = "MarkNonSecureAs";
44 43
45 ConnectionSecurityHelper::SecurityLevel level; 44 connection_security::SecurityLevel level;
46 MarkNonSecureStatus status; 45 MarkNonSecureStatus status;
47 46
48 if (choice == switches::kMarkNonSecureAsNeutral) { 47 if (choice == switches::kMarkNonSecureAsNeutral) {
49 status = NEUTRAL; 48 status = NEUTRAL;
50 level = ConnectionSecurityHelper::NONE; 49 level = connection_security::NONE;
51 } else if (choice == switches::kMarkNonSecureAsDubious) { 50 } else if (choice == switches::kMarkNonSecureAsDubious) {
52 status = DUBIOUS; 51 status = DUBIOUS;
53 level = ConnectionSecurityHelper::SECURITY_WARNING; 52 level = connection_security::SECURITY_WARNING;
54 } else if (choice == switches::kMarkNonSecureAsNonSecure) { 53 } else if (choice == switches::kMarkNonSecureAsNonSecure) {
55 status = NON_SECURE; 54 status = NON_SECURE;
56 level = ConnectionSecurityHelper::SECURITY_ERROR; 55 level = connection_security::SECURITY_ERROR;
57 } else if (group == switches::kMarkNonSecureAsNeutral) { 56 } else if (group == switches::kMarkNonSecureAsNeutral) {
58 status = NEUTRAL; 57 status = NEUTRAL;
59 level = ConnectionSecurityHelper::NONE; 58 level = connection_security::NONE;
60 } else if (group == switches::kMarkNonSecureAsDubious) { 59 } else if (group == switches::kMarkNonSecureAsDubious) {
61 status = DUBIOUS; 60 status = DUBIOUS;
62 level = ConnectionSecurityHelper::SECURITY_WARNING; 61 level = connection_security::SECURITY_WARNING;
63 } else if (group == switches::kMarkNonSecureAsNonSecure) { 62 } else if (group == switches::kMarkNonSecureAsNonSecure) {
64 status = NON_SECURE; 63 status = NON_SECURE;
65 level = ConnectionSecurityHelper::SECURITY_ERROR; 64 level = connection_security::SECURITY_ERROR;
66 } else { 65 } else {
67 status = NEUTRAL; 66 status = NEUTRAL;
68 level = ConnectionSecurityHelper::NONE; 67 level = connection_security::NONE;
69 } 68 }
70 69
71 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS); 70 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS);
72 return level; 71 return level;
73 } 72 }
74 73
75 } // namespace 74 } // namespace
76 75
77 ConnectionSecurityHelper::SecurityLevel 76 namespace connection_security {
78 ConnectionSecurityHelper::GetSecurityLevelForWebContents( 77
78 SecurityLevel GetSecurityLevelForWebContents(
79 const content::WebContents* web_contents) { 79 const content::WebContents* web_contents) {
80 if (!web_contents) 80 if (!web_contents)
81 return NONE; 81 return NONE;
82 82
83 content::NavigationEntry* entry = 83 content::NavigationEntry* entry =
84 web_contents->GetController().GetVisibleEntry(); 84 web_contents->GetController().GetVisibleEntry();
85 if (!entry) 85 if (!entry)
86 return NONE; 86 return NONE;
87 87
88 const content::SSLStatus& ssl = entry->GetSSL(); 88 const content::SSLStatus& ssl = entry->GetSSL();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 return EV_SECURE; 141 return EV_SECURE;
142 return SECURE; 142 return SECURE;
143 } 143 }
144 144
145 default: 145 default:
146 NOTREACHED(); 146 NOTREACHED();
147 return NONE; 147 return NONE;
148 } 148 }
149 } 149 }
150 150
151 content::SecurityStyle ConnectionSecurityHelper::GetSecurityStyleForWebContents( 151 content::SecurityStyle GetSecurityStyleForWebContents(
152 const content::WebContents* web_contents) { 152 const content::WebContents* web_contents) {
153 SecurityLevel security_level = GetSecurityLevelForWebContents(web_contents); 153 SecurityLevel security_level = GetSecurityLevelForWebContents(web_contents);
154 154
155 switch (security_level) { 155 switch (security_level) {
156 case NONE: 156 case NONE:
157 return content::SECURITY_STYLE_UNAUTHENTICATED; 157 return content::SECURITY_STYLE_UNAUTHENTICATED;
158 case EV_SECURE: 158 case EV_SECURE:
159 case SECURE: 159 case SECURE:
160 return content::SECURITY_STYLE_AUTHENTICATED; 160 return content::SECURITY_STYLE_AUTHENTICATED;
161 case SECURITY_WARNING: 161 case SECURITY_WARNING:
162 case SECURITY_POLICY_WARNING: 162 case SECURITY_POLICY_WARNING:
163 return content::SECURITY_STYLE_WARNING; 163 return content::SECURITY_STYLE_WARNING;
164 case SECURITY_ERROR: 164 case SECURITY_ERROR:
165 return content::SECURITY_STYLE_AUTHENTICATION_BROKEN; 165 return content::SECURITY_STYLE_AUTHENTICATION_BROKEN;
166 } 166 }
167 167
168 NOTREACHED(); 168 NOTREACHED();
169 return content::SECURITY_STYLE_UNKNOWN; 169 return content::SECURITY_STYLE_UNKNOWN;
170 } 170 }
171
172 } // namespace connection_security
OLDNEW
« no previous file with comments | « chrome/browser/ssl/connection_security.h ('k') | chrome/browser/ssl/connection_security_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698