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

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

Issue 2917873004: Implement 'Not secure' warning for non-secure pages in Incognito mode (Closed)
Patch Set: Remove obsolete includes Created 3 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/security_state_tab_helper.h" 5 #include "chrome/browser/ssl/security_state_tab_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
14 #include "chrome/browser/safe_browsing/ui_manager.h" 14 #include "chrome/browser/safe_browsing/ui_manager.h"
15 #include "components/prefs/pref_service.h" 15 #include "components/prefs/pref_service.h"
16 #include "components/security_state/content/content_utils.h" 16 #include "components/security_state/content/content_utils.h"
17 #include "components/ssl_config/ssl_config_prefs.h" 17 #include "components/ssl_config/ssl_config_prefs.h"
18 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/navigation_handle.h" 20 #include "content/public/browser/navigation_handle.h"
20 #include "content/public/browser/render_frame_host.h" 21 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/origin_util.h" 23 #include "content/public/common/origin_util.h"
23 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
24 #include "net/cert/x509_certificate.h" 25 #include "net/cert/x509_certificate.h"
25 #include "net/ssl/ssl_cipher_suite_names.h" 26 #include "net/ssl/ssl_cipher_suite_names.h"
26 #include "net/ssl/ssl_connection_status_flags.h" 27 #include "net/ssl/ssl_connection_status_flags.h"
27 #include "third_party/boringssl/src/include/openssl/ssl.h" 28 #include "third_party/boringssl/src/include/openssl/ssl.h"
28 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
29 30
30 #if defined(OS_CHROMEOS) 31 #if defined(OS_CHROMEOS)
31 #include "chrome/browser/chromeos/policy/policy_cert_service.h" 32 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
32 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" 33 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
33 #endif // defined(OS_CHROMEOS) 34 #endif // defined(OS_CHROMEOS)
34 35
35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SecurityStateTabHelper); 36 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SecurityStateTabHelper);
36 37
37 using safe_browsing::SafeBrowsingUIManager; 38 using safe_browsing::SafeBrowsingUIManager;
38 39
39 SecurityStateTabHelper::SecurityStateTabHelper( 40 SecurityStateTabHelper::SecurityStateTabHelper(
40 content::WebContents* web_contents) 41 content::WebContents* web_contents)
41 : content::WebContentsObserver(web_contents), 42 : content::WebContentsObserver(web_contents),
42 logged_http_warning_on_current_navigation_(false) {} 43 logged_http_warning_on_current_navigation_(false),
44 is_incognito_(false) {
45 content::BrowserContext* context = web_contents->GetBrowserContext();
46 if (context->IsOffTheRecord() &&
47 !Profile::FromBrowserContext(context)->IsGuestSession()) {
48 is_incognito_ = true;
49 }
50 }
43 51
44 SecurityStateTabHelper::~SecurityStateTabHelper() {} 52 SecurityStateTabHelper::~SecurityStateTabHelper() {}
45 53
46 void SecurityStateTabHelper::GetSecurityInfo( 54 void SecurityStateTabHelper::GetSecurityInfo(
47 security_state::SecurityInfo* result) const { 55 security_state::SecurityInfo* result) const {
48 security_state::GetSecurityInfo(GetVisibleSecurityState(), 56 security_state::GetSecurityInfo(GetVisibleSecurityState(),
49 UsedPolicyInstalledCertificate(), 57 UsedPolicyInstalledCertificate(),
50 base::Bind(&content::IsOriginSecure), result); 58 base::Bind(&content::IsOriginSecure), result);
51 } 59 }
52 60
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 base::Time::Now() - time_of_http_warning_on_current_navigation_); 114 base::Time::Now() - time_of_http_warning_on_current_navigation_);
107 // After recording the histogram, clear the time of the warning. A 115 // After recording the histogram, clear the time of the warning. A
108 // timing histogram will not be recorded again on this page, because 116 // timing histogram will not be recorded again on this page, because
109 // the time is only set the first time the HTTP-bad warning is shown 117 // the time is only set the first time the HTTP-bad warning is shown
110 // per page. 118 // per page.
111 time_of_http_warning_on_current_navigation_ = base::Time(); 119 time_of_http_warning_on_current_navigation_ = base::Time();
112 } 120 }
113 121
114 void SecurityStateTabHelper::DidFinishNavigation( 122 void SecurityStateTabHelper::DidFinishNavigation(
115 content::NavigationHandle* navigation_handle) { 123 content::NavigationHandle* navigation_handle) {
116 if (navigation_handle->IsInMainFrame() && 124 // Ignore subframe navigations, same-document navigations, and navigations
117 !navigation_handle->IsSameDocument()) { 125 // that did not commit (e.g. HTTP/204 or file downloads).
118 // Only reset the console message flag for main-frame navigations, 126 if (!navigation_handle->IsInMainFrame() ||
119 // and not for same-document navigations like reference fragments and 127 navigation_handle->IsSameDocument() ||
120 // pushState. 128 !navigation_handle->HasCommitted()) {
121 logged_http_warning_on_current_navigation_ = false; 129 return;
130 }
131
132 logged_http_warning_on_current_navigation_ = false;
133
134 security_state::SecurityInfo security_info;
135 GetSecurityInfo(&security_info);
136 if (security_info.incognito_downgraded_security_level) {
137 web_contents()->GetMainFrame()->AddMessageToConsole(
138 content::CONSOLE_MESSAGE_LEVEL_WARNING,
139 "This page was loaded non-securely in an incognito mode browser. A "
140 "warning has been added to the URL bar. For more information, see "
141 "https://goo.gl/y8SRRv.");
122 } 142 }
123 } 143 }
124 144
125 void SecurityStateTabHelper::WebContentsDestroyed() { 145 void SecurityStateTabHelper::WebContentsDestroyed() {
126 if (time_of_http_warning_on_current_navigation_.is_null()) { 146 if (time_of_http_warning_on_current_navigation_.is_null()) {
127 return; 147 return;
128 } 148 }
129 // Record how quickly the tab is closed after a user encounters an 149 // Record how quickly the tab is closed after a user encounters an
130 // HTTP-bad warning. This histogram will only be recorded if the 150 // HTTP-bad warning. This histogram will only be recorded if the
131 // WebContents is destroyed before another navigation begins. 151 // WebContents is destroyed before another navigation begins.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 212 }
193 213
194 std::unique_ptr<security_state::VisibleSecurityState> 214 std::unique_ptr<security_state::VisibleSecurityState>
195 SecurityStateTabHelper::GetVisibleSecurityState() const { 215 SecurityStateTabHelper::GetVisibleSecurityState() const {
196 auto state = security_state::GetVisibleSecurityState(web_contents()); 216 auto state = security_state::GetVisibleSecurityState(web_contents());
197 217
198 // Malware status might already be known even if connection security 218 // Malware status might already be known even if connection security
199 // information is still being initialized, thus no need to check for that. 219 // information is still being initialized, thus no need to check for that.
200 state->malicious_content_status = GetMaliciousContentStatus(); 220 state->malicious_content_status = GetMaliciousContentStatus();
201 221
222 state->is_incognito = is_incognito_;
223
202 return state; 224 return state;
203 } 225 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/security_state_tab_helper.h ('k') | chrome/browser/ssl/security_state_tab_helper_browser_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698