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/metrics/field_trial.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 *level = ToolbarModel::SECURITY_ERROR; | 58 *level = ToolbarModel::SECURITY_ERROR; |
59 else if (group == "Warning") | 59 else if (group == "Warning") |
60 *level = ToolbarModel::SECURITY_WARNING; | 60 *level = ToolbarModel::SECURITY_WARNING; |
61 else if (group == "HTTP") | 61 else if (group == "HTTP") |
62 *level = ToolbarModel::NONE; | 62 *level = ToolbarModel::NONE; |
63 else | 63 else |
64 return false; | 64 return false; |
65 return true; | 65 return true; |
66 } | 66 } |
67 | 67 |
| 68 ToolbarModel::SecurityLevel GetSecurityLevelForNonSecureFieldTrial() { |
| 69 std::string choice = base::CommandLine::ForCurrentProcess()-> |
| 70 GetSwitchValueASCII(switches::kMarkNonSecureAs); |
| 71 if (choice == switches::kMarkNonSecureAsNeutral) |
| 72 return ToolbarModel::NONE; |
| 73 if (choice == switches::kMarkNonSecureAsDubious) |
| 74 return ToolbarModel::SECURITY_WARNING; |
| 75 if (choice == switches::kMarkNonSecureAsNonSecure) |
| 76 return ToolbarModel::SECURITY_ERROR; |
| 77 |
| 78 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); |
| 79 if (group == switches::kMarkNonSecureAsNeutral) |
| 80 return ToolbarModel::NONE; |
| 81 if (group == switches::kMarkNonSecureAsDubious) |
| 82 return ToolbarModel::SECURITY_WARNING; |
| 83 if (group == switches::kMarkNonSecureAsNonSecure) |
| 84 return ToolbarModel::SECURITY_ERROR; |
| 85 |
| 86 return ToolbarModel::NONE; |
| 87 } |
| 88 |
68 } // namespace | 89 } // namespace |
69 | 90 |
70 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate) | 91 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate) |
71 : delegate_(delegate) { | 92 : delegate_(delegate) { |
72 } | 93 } |
73 | 94 |
74 ToolbarModelImpl::~ToolbarModelImpl() { | 95 ToolbarModelImpl::~ToolbarModelImpl() { |
75 } | 96 } |
76 | 97 |
77 // static | 98 // static |
78 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevelForWebContents( | 99 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevelForWebContents( |
79 content::WebContents* web_contents) { | 100 content::WebContents* web_contents) { |
80 if (!web_contents) | 101 if (!web_contents) |
81 return NONE; | 102 return NONE; |
82 | 103 |
83 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); | 104 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); |
84 if (!entry) | 105 if (!entry) |
85 return NONE; | 106 return NONE; |
86 | 107 |
87 const SSLStatus& ssl = entry->GetSSL(); | 108 const SSLStatus& ssl = entry->GetSSL(); |
88 switch (ssl.security_style) { | 109 switch (ssl.security_style) { |
89 case content::SECURITY_STYLE_UNKNOWN: | 110 case content::SECURITY_STYLE_UNKNOWN: |
90 case content::SECURITY_STYLE_UNAUTHENTICATED: | |
91 return NONE; | 111 return NONE; |
92 | 112 |
| 113 case content::SECURITY_STYLE_UNAUTHENTICATED: { |
| 114 const GURL& url = entry->GetURL(); |
| 115 if (url.SchemeIs("http") || url.SchemeIs("ftp")) |
| 116 return GetSecurityLevelForNonSecureFieldTrial(); |
| 117 return NONE; |
| 118 } |
| 119 |
93 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN: | 120 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN: |
94 return SECURITY_ERROR; | 121 return SECURITY_ERROR; |
95 | 122 |
96 case content::SECURITY_STYLE_AUTHENTICATED: { | 123 case content::SECURITY_STYLE_AUTHENTICATED: { |
97 #if defined(OS_CHROMEOS) | 124 #if defined(OS_CHROMEOS) |
98 policy::PolicyCertService* service = | 125 policy::PolicyCertService* service = |
99 policy::PolicyCertServiceFactory::GetForProfile( | 126 policy::PolicyCertServiceFactory::GetForProfile( |
100 Profile::FromBrowserContext(web_contents->GetBrowserContext())); | 127 Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
101 if (service && service->UsedPolicyCertificates()) | 128 if (service && service->UsedPolicyCertificates()) |
102 return SECURITY_POLICY_WARNING; | 129 return SECURITY_POLICY_WARNING; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 if (entry && | 418 if (entry && |
392 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) | 419 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) |
393 return search_terms; | 420 return search_terms; |
394 | 421 |
395 // Otherwise, extract search terms for HTTPS pages that do not have a security | 422 // Otherwise, extract search terms for HTTPS pages that do not have a security |
396 // error. | 423 // error. |
397 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); | 424 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); |
398 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? | 425 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? |
399 base::string16() : search_terms; | 426 base::string16() : search_terms; |
400 } | 427 } |
OLD | NEW |