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

Side by Side Diff: content/browser/ssl/ssl_manager.cc

Issue 2410023003: Add unit test for notifying WebContents when SSLStatus changes due to HTTP-bad (Closed)
Patch Set: add test comments Created 4 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/browser/ssl/ssl_manager.h" 5 #include "content/browser/ssl/ssl_manager.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 return; 106 return;
107 } 107 }
108 108
109 SSLManager* manager = 109 SSLManager* manager =
110 static_cast<NavigationControllerImpl*>(&web_contents->GetController()) 110 static_cast<NavigationControllerImpl*>(&web_contents->GetController())
111 ->ssl_manager(); 111 ->ssl_manager();
112 manager->OnCertError(std::move(handler)); 112 manager->OnCertError(std::move(handler));
113 } 113 }
114 114
115 // Updates |entry|'s flags to account for the presence of insecure
116 // content (mixed content or subresources with certificate errors).
117 void UpdateEntryForInsecureContent(
118 NavigationEntryImpl* entry,
119 WebContentsImpl* web_contents_impl,
120 SSLHostStateDelegate* ssl_host_state_delegate) {
121 // Update the entry's flags for insecure content.
122 if (!web_contents_impl->DisplayedInsecureContent())
123 entry->GetSSL().content_status &= ~SSLStatus::DISPLAYED_INSECURE_CONTENT;
124 if (web_contents_impl->DisplayedInsecureContent())
elawrence 2016/10/12 15:22:47 Can the value of this change from line 123? If not
estark 2016/10/12 16:20:16 Done.
125 entry->GetSSL().content_status |= SSLStatus::DISPLAYED_INSECURE_CONTENT;
126 if (!web_contents_impl->DisplayedContentWithCertErrors()) {
127 entry->GetSSL().content_status &=
128 ~SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS;
129 }
130 if (web_contents_impl->DisplayedContentWithCertErrors()) {
elawrence 2016/10/12 15:22:46 ditto
estark 2016/10/12 16:20:16 Done.
131 entry->GetSSL().content_status |=
132 SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS;
133 }
134
135 SiteInstance* site_instance = entry->site_instance();
136 // Note that |site_instance| can be NULL here because NavigationEntries don't
137 // necessarily have site instances. Without a process, the entry can't
138 // possibly have insecure content. See bug http://crbug.com/12423.
elawrence 2016/10/12 15:22:46 HTTPS for all URLs please. :) Utterly trivial, bu
estark 2016/10/12 16:20:16 Neither of those are my fault, I was just moving o
139 if (site_instance && ssl_host_state_delegate &&
elawrence 2016/10/12 15:22:46 Similar to earlier, is there a reason we shouldn't
estark 2016/10/12 16:20:16 Done.
140 ssl_host_state_delegate->DidHostRunInsecureContent(
141 entry->GetURL().host(), site_instance->GetProcess()->GetID(),
142 SSLHostStateDelegate::MIXED_CONTENT)) {
143 entry->GetSSL().content_status |= SSLStatus::RAN_INSECURE_CONTENT;
144 }
145
146 if (site_instance && ssl_host_state_delegate &&
147 ssl_host_state_delegate->DidHostRunInsecureContent(
148 entry->GetURL().host(), site_instance->GetProcess()->GetID(),
149 SSLHostStateDelegate::CERT_ERRORS_CONTENT)) {
150 entry->GetSSL().content_status |= SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS;
151 }
152 }
153
115 } // namespace 154 } // namespace
116 155
117 // static 156 // static
118 void SSLManager::OnSSLCertificateError( 157 void SSLManager::OnSSLCertificateError(
119 const base::WeakPtr<SSLErrorHandler::Delegate>& delegate, 158 const base::WeakPtr<SSLErrorHandler::Delegate>& delegate,
120 const ResourceType resource_type, 159 const ResourceType resource_type,
121 const GURL& url, 160 const GURL& url,
122 const base::Callback<WebContents*(void)>& web_contents_getter, 161 const base::Callback<WebContents*(void)>& web_contents_getter,
123 const net::SSLInfo& ssl_info, 162 const net::SSLInfo& ssl_info,
124 bool fatal) { 163 bool fatal) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 if (web_contents_impl->DisplayedPasswordFieldOnHttp()) { 396 if (web_contents_impl->DisplayedPasswordFieldOnHttp()) {
358 entry->GetSSL().content_status |= 397 entry->GetSSL().content_status |=
359 SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP; 398 SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP;
360 } 399 }
361 400
362 if (web_contents_impl->DisplayedCreditCardFieldOnHttp()) { 401 if (web_contents_impl->DisplayedCreditCardFieldOnHttp()) {
363 entry->GetSSL().content_status |= 402 entry->GetSSL().content_status |=
364 SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP; 403 SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP;
365 } 404 }
366 405
367 // Do not record information about insecure subresources if the main 406 // Only record information about insecure subresources if the main
368 // page is HTTP or HTTPS without a certificate. 407 // page is HTTPS with a certificate.
369 if (!entry->GetURL().SchemeIsCryptographic() || !entry->GetSSL().certificate) 408 if (entry->GetURL().SchemeIsCryptographic() && entry->GetSSL().certificate) {
370 return; 409 UpdateEntryForInsecureContent(entry, web_contents_impl,
371 410 ssl_host_state_delegate_);
372 // Update the entry's flags for insecure content.
373 if (!web_contents_impl->DisplayedInsecureContent())
374 entry->GetSSL().content_status &= ~SSLStatus::DISPLAYED_INSECURE_CONTENT;
375 if (web_contents_impl->DisplayedInsecureContent())
376 entry->GetSSL().content_status |= SSLStatus::DISPLAYED_INSECURE_CONTENT;
377 if (!web_contents_impl->DisplayedContentWithCertErrors()) {
378 entry->GetSSL().content_status &=
379 ~SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS;
380 }
381 if (web_contents_impl->DisplayedContentWithCertErrors()) {
382 entry->GetSSL().content_status |=
383 SSLStatus::DISPLAYED_CONTENT_WITH_CERT_ERRORS;
384 } 411 }
385 412
386 SiteInstance* site_instance = entry->site_instance(); 413 if (!entry->GetSSL().Equals(original_ssl_status)) {
elawrence 2016/10/12 15:22:46 Will this be reached much more often than it was p
estark 2016/10/12 16:20:16 Ohh, nice catch. I thought that in the common case
elawrence 2016/10/12 16:28:58 Acknowledged.
387 // Note that |site_instance| can be NULL here because NavigationEntries don't 414 NotifyDidChangeVisibleSSLState();
388 // necessarily have site instances. Without a process, the entry can't
389 // possibly have insecure content. See bug http://crbug.com/12423.
390 if (site_instance && ssl_host_state_delegate_ &&
391 ssl_host_state_delegate_->DidHostRunInsecureContent(
392 entry->GetURL().host(), site_instance->GetProcess()->GetID(),
393 SSLHostStateDelegate::MIXED_CONTENT)) {
394 entry->GetSSL().content_status |= SSLStatus::RAN_INSECURE_CONTENT;
395 } 415 }
396
397 if (site_instance && ssl_host_state_delegate_ &&
398 ssl_host_state_delegate_->DidHostRunInsecureContent(
399 entry->GetURL().host(), site_instance->GetProcess()->GetID(),
400 SSLHostStateDelegate::CERT_ERRORS_CONTENT)) {
401 entry->GetSSL().content_status |= SSLStatus::RAN_CONTENT_WITH_CERT_ERRORS;
402 }
403
404 if (!entry->GetSSL().Equals(original_ssl_status))
405 NotifyDidChangeVisibleSSLState();
406 } 416 }
407 417
408 void SSLManager::NotifyDidChangeVisibleSSLState() { 418 void SSLManager::NotifyDidChangeVisibleSSLState() {
409 WebContentsImpl* contents = 419 WebContentsImpl* contents =
410 static_cast<WebContentsImpl*>(controller_->delegate()->GetWebContents()); 420 static_cast<WebContentsImpl*>(controller_->delegate()->GetWebContents());
411 contents->DidChangeVisibleSSLState(); 421 contents->DidChangeVisibleSSLState();
412 } 422 }
413 423
414 } // namespace content 424 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/ssl/ssl_manager_unittest.cc » ('j') | content/browser/ssl/ssl_manager_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698