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

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

Issue 2448943002: Refactor SecurityStateModel/Clients for simplicity and reusability. (Closed)
Patch Set: fix DEPS. Created 4 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ssl/security_state_tab_helper.h"
6
7 #include "base/bind.h"
8 #include "base/metrics/histogram_macros.h"
9 #include "build/build_config.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
12 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
15 #include "chrome/browser/safe_browsing/ui_manager.h"
16 #include "components/security_state/content/content_utils.h"
17 #include "components/security_state/core/security_state.h"
18 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/navigation_handle.h"
20 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/origin_util.h"
23 #include "net/base/net_errors.h"
24 #include "net/cert/x509_certificate.h"
25 #include "net/ssl/ssl_cipher_suite_names.h"
26 #include "net/ssl/ssl_connection_status_flags.h"
27 #include "third_party/boringssl/src/include/openssl/ssl.h"
28 #include "ui/base/l10n/l10n_util.h"
29
30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SecurityStateTabHelper);
31
32 using safe_browsing::SafeBrowsingUIManager;
33
34 SecurityStateTabHelper::SecurityStateTabHelper(
35 content::WebContents* web_contents)
36 : content::WebContentsObserver(web_contents),
37 logged_http_warning_on_current_navigation_(false) {}
38
39 SecurityStateTabHelper::~SecurityStateTabHelper() {}
40
41 void SecurityStateTabHelper::GetSecurityInfo(
42 security_state::SecurityInfo* result) const {
43 security_state::GetSecurityInfo(GetVisibleSecurityState(),
44 UsedPolicyInstalledCertificate(),
45 base::Bind(&content::IsOriginSecure), result);
46 }
47
48 void SecurityStateTabHelper::VisibleSecurityStateChanged() {
49 if (logged_http_warning_on_current_navigation_)
50 return;
51
52 security_state::SecurityInfo security_info;
53 GetSecurityInfo(&security_info);
54 if (!security_info.displayed_private_user_data_input_on_http)
55 return;
56
57 std::string warning;
58 bool warning_is_user_visible = false;
59 switch (security_info.security_level) {
60 case security_state::HTTP_SHOW_WARNING:
61 warning =
62 "This page includes a password or credit card input in a non-secure "
63 "context. A warning has been added to the URL bar. For more "
64 "information, see https://goo.gl/zmWq3m.";
65 warning_is_user_visible = true;
66 break;
67 case security_state::NONE:
68 case security_state::DANGEROUS:
69 warning =
70 "This page includes a password or credit card input in a non-secure "
71 "context. A warning will be added to the URL bar in Chrome 56 (Jan "
72 "2017). For more information, see https://goo.gl/zmWq3m.";
73 break;
74 default:
75 return;
76 }
77
78 logged_http_warning_on_current_navigation_ = true;
79 web_contents()->GetMainFrame()->AddMessageToConsole(
80 content::CONSOLE_MESSAGE_LEVEL_WARNING, warning);
81 UMA_HISTOGRAM_BOOLEAN("Security.HTTPBad.UserWarnedAboutSensitiveInput",
82 warning_is_user_visible);
83 }
84
85 void SecurityStateTabHelper::DidFinishNavigation(
86 content::NavigationHandle* navigation_handle) {
87 if (navigation_handle->IsInMainFrame() && !navigation_handle->IsSamePage()) {
88 // Only reset the console message flag for main-frame navigations,
89 // and not for same-page navigations like reference fragments and pushState.
90 logged_http_warning_on_current_navigation_ = false;
91 }
92 }
93
94 bool SecurityStateTabHelper::UsedPolicyInstalledCertificate() const {
95 #if defined(OS_CHROMEOS)
96 policy::PolicyCertService* service =
97 policy::PolicyCertServiceFactory::GetForProfile(
98 Profile::FromBrowserContext(web_contents()->GetBrowserContext()));
99 if (service && service->UsedPolicyCertificates())
100 return true;
101 #endif
102 return false;
103 }
104
105 bool SecurityStateTabHelper::GetMalwareStatus() const {
106 content::NavigationEntry* entry =
107 web_contents()->GetController().GetVisibleEntry();
108 if (!entry)
109 return false;
110 safe_browsing::SafeBrowsingService* sb_service =
111 g_browser_process->safe_browsing_service();
112 if (!sb_service)
113 return false;
114 scoped_refptr<SafeBrowsingUIManager> sb_ui_manager = sb_service->ui_manager();
115 if (sb_ui_manager->IsUrlWhitelistedOrPendingForWebContents(
116 entry->GetURL(), false, entry, web_contents(), false)) {
117 return true;
118 }
119 return false;
120 }
121
122 std::unique_ptr<security_state::VisibleSecurityState>
123 SecurityStateTabHelper::GetVisibleSecurityState() const {
124 auto state = security_state::GetVisibleSecurityState(web_contents());
125
126 // Malware status might already be known even if connection security
127 // information is still being initialized, thus no need to check for that.
128 state->fails_malware_check = GetMalwareStatus();
129
130 return state;
131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698