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

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

Issue 2448943002: Refactor SecurityStateModel/Clients for simplicity and reusability. (Closed)
Patch Set: Remove *SecurityModelClient. 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/chrome_security_state_model.h"
6
7 #include "build/build_config.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
10 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
13 #include "chrome/browser/safe_browsing/ui_manager.h"
14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/navigation_handle.h"
16 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/web_contents.h"
18
19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeSecurityStateModel);
20
21 using safe_browsing::SafeBrowsingUIManager;
22 using security_state::SecurityStateModel;
23
24 ChromeSecurityStateModel::ChromeSecurityStateModel(
25 content::WebContents* web_contents)
26 : content::WebContentsObserver(web_contents),
27 web_contents_model_(
28 new security_state::WebContentsSecurityStateModel(web_contents)),
29 logged_http_warning_on_current_navigation_(false) {}
30
31 ChromeSecurityStateModel::~ChromeSecurityStateModel() {}
32
33 void ChromeSecurityStateModel::GetSecurityInfo(
34 SecurityStateModel::SecurityInfo* result) const {
35 web_contents_model_->GetSecurityInfo(result, UsedPolicyInstalledCertificate(),
36 GetMalwareStatus());
37 }
38
39 void ChromeSecurityStateModel::VisibleSSLStateChanged() {
40 if (logged_http_warning_on_current_navigation_)
41 return;
42
43 security_state::SecurityStateModel::SecurityInfo security_info;
44 GetSecurityInfo(&security_info);
45 if (!security_info.displayed_private_user_data_input_on_http)
46 return;
47
48 std::string warning;
49 switch (security_info.security_level) {
50 case security_state::SecurityStateModel::HTTP_SHOW_WARNING:
51 warning =
52 "This page includes a password or credit card input in a non-secure "
53 "context. A warning has been added to the URL bar. For more "
54 "information, see https://goo.gl/zmWq3m.";
55 break;
56 case security_state::SecurityStateModel::NONE:
57 warning =
58 "This page includes a password or credit card input in a non-secure "
59 "context. A warning will be added to the URL bar in Chrome 56 (Jan "
60 "2017). For more information, see https://goo.gl/zmWq3m.";
61 break;
62 default:
63 return;
64 }
65
66 logged_http_warning_on_current_navigation_ = true;
67 web_contents()->GetMainFrame()->AddMessageToConsole(
68 content::CONSOLE_MESSAGE_LEVEL_WARNING, warning);
69 }
70
71 void ChromeSecurityStateModel::DidFinishNavigation(
72 content::NavigationHandle* navigation_handle) {
73 if (navigation_handle->IsInMainFrame() &&
74 !navigation_handle->IsSynchronousNavigation()) {
75 // Only reset the console message flag for main-frame navigations,
76 // and not for synchronous navigations like reference fragments and
77 // pushState.
78 logged_http_warning_on_current_navigation_ = false;
79 }
80 }
81
82 bool ChromeSecurityStateModel::UsedPolicyInstalledCertificate() const {
83 #if defined(OS_CHROMEOS)
84 policy::PolicyCertService* service =
85 policy::PolicyCertServiceFactory::GetForProfile(
86 Profile::FromBrowserContext(web_contents()->GetBrowserContext()));
87 if (service && service->UsedPolicyCertificates())
88 return true;
89 #endif
90 return false;
91 }
92
93 bool ChromeSecurityStateModel::GetMalwareStatus() const {
94 content::NavigationEntry* entry =
95 web_contents()->GetController().GetVisibleEntry();
96 if (!entry)
97 return false;
98 safe_browsing::SafeBrowsingService* sb_service =
99 g_browser_process->safe_browsing_service();
100 if (!sb_service)
101 return false;
102 scoped_refptr<SafeBrowsingUIManager> sb_ui_manager = sb_service->ui_manager();
103 if (sb_ui_manager->IsUrlWhitelistedOrPendingForWebContents(
104 entry->GetURL(), false, entry, web_contents(), false)) {
105 return true;
106 }
107 return false;
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698