| OLD | NEW |
| 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/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/supports_user_data.h" | 11 #include "base/supports_user_data.h" |
| 12 #include "content/browser/frame_host/navigation_entry_impl.h" | 12 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 13 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 13 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 14 #include "content/browser/loader/resource_request_info_impl.h" | 14 #include "content/browser/loader/resource_request_info_impl.h" |
| 15 #include "content/browser/ssl/ssl_cert_error_handler.h" | 15 #include "content/browser/ssl/ssl_cert_error_handler.h" |
| 16 #include "content/browser/ssl/ssl_policy.h" | 16 #include "content/browser/ssl/ssl_policy.h" |
| 17 #include "content/browser/ssl/ssl_request_info.h" | 17 #include "content/browser/ssl/ssl_request_info.h" |
| 18 #include "content/browser/web_contents/web_contents_impl.h" | 18 #include "content/browser/web_contents/web_contents_impl.h" |
| 19 #include "content/common/ssl_status_serialization.h" | 19 #include "content/common/ssl_status_serialization.h" |
| 20 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/load_from_memory_cache_details.h" | 22 #include "content/public/browser/load_from_memory_cache_details.h" |
| 23 #include "content/public/browser/navigation_details.h" | 23 #include "content/public/browser/navigation_details.h" |
| 24 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/resource_request_details.h" | 25 #include "content/public/browser/resource_request_details.h" |
| 25 #include "content/public/common/ssl_status.h" | 26 #include "content/public/common/ssl_status.h" |
| 26 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 const char kSSLManagerKeyName[] = "content_ssl_manager"; | 33 const char kSSLManagerKeyName[] = "content_ssl_manager"; |
| 33 | 34 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 new SSLCertErrorHandler(delegate, | 73 new SSLCertErrorHandler(delegate, |
| 73 resource_type, | 74 resource_type, |
| 74 url, | 75 url, |
| 75 render_process_id, | 76 render_process_id, |
| 76 render_frame_id, | 77 render_frame_id, |
| 77 ssl_info, | 78 ssl_info, |
| 78 fatal))); | 79 fatal))); |
| 79 } | 80 } |
| 80 | 81 |
| 81 // static | 82 // static |
| 83 void SSLManager::OnAuthDialog(int render_process_id, |
| 84 int render_frame_id, |
| 85 const std::string& serialized_security_info, |
| 86 bool is_main_frame) { |
| 87 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 88 BrowserThread::PostTask( |
| 89 BrowserThread::UI, FROM_HERE, |
| 90 base::Bind(SSLManager::OnAuthDialog, render_process_id, render_frame_id, |
| 91 serialized_security_info, is_main_frame)); |
| 92 return; |
| 93 } |
| 94 RenderFrameHost* render_frame_host = |
| 95 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
| 96 WebContents* web_contents = |
| 97 WebContents::FromRenderFrameHost(render_frame_host); |
| 98 if (!web_contents) |
| 99 return; |
| 100 NavigationControllerImpl* controller = |
| 101 static_cast<NavigationControllerImpl*>(&web_contents->GetController()); |
| 102 NavigationEntry* pending_entry = controller->GetPendingEntry(); |
| 103 ui::PageTransition transition = pending_entry->GetTransitionType(); |
| 104 // For non-user initiated navigations, auth dialog is displayed when the |
| 105 // visible url points to the page that initiated the navigation and not the |
| 106 // actual auth url. Update the pending entry in that case. |
| 107 NavigationEntryImpl* entry = |
| 108 (transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) |
| 109 ? NavigationEntryImpl::FromNavigationEntry( |
| 110 controller->GetVisibleEntry()) |
| 111 : NavigationEntryImpl::FromNavigationEntry(pending_entry); |
| 112 controller->ssl_manager()->UpdateEntry(serialized_security_info, |
| 113 is_main_frame, entry); |
| 114 } |
| 115 |
| 116 // static |
| 82 void SSLManager::NotifySSLInternalStateChanged(BrowserContext* context) { | 117 void SSLManager::NotifySSLInternalStateChanged(BrowserContext* context) { |
| 83 SSLManagerSet* managers = static_cast<SSLManagerSet*>( | 118 SSLManagerSet* managers = static_cast<SSLManagerSet*>( |
| 84 context->GetUserData(kSSLManagerKeyName)); | 119 context->GetUserData(kSSLManagerKeyName)); |
| 85 | 120 |
| 86 for (std::set<SSLManager*>::iterator i = managers->get().begin(); | 121 for (std::set<SSLManager*>::iterator i = managers->get().begin(); |
| 87 i != managers->get().end(); ++i) { | 122 i != managers->get().end(); ++i) { |
| 88 (*i)->UpdateEntry((*i)->controller()->GetLastCommittedEntry()); | 123 (*i)->UpdateEntry((*i)->controller()->GetLastCommittedEntry()); |
| 89 } | 124 } |
| 90 } | 125 } |
| 91 | 126 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 105 } | 140 } |
| 106 | 141 |
| 107 SSLManager::~SSLManager() { | 142 SSLManager::~SSLManager() { |
| 108 SSLManagerSet* managers = static_cast<SSLManagerSet*>( | 143 SSLManagerSet* managers = static_cast<SSLManagerSet*>( |
| 109 controller_->GetBrowserContext()->GetUserData(kSSLManagerKeyName)); | 144 controller_->GetBrowserContext()->GetUserData(kSSLManagerKeyName)); |
| 110 managers->get().erase(this); | 145 managers->get().erase(this); |
| 111 } | 146 } |
| 112 | 147 |
| 113 void SSLManager::DidCommitProvisionalLoad(const LoadCommittedDetails& details) { | 148 void SSLManager::DidCommitProvisionalLoad(const LoadCommittedDetails& details) { |
| 114 NavigationEntryImpl* entry = controller_->GetLastCommittedEntry(); | 149 NavigationEntryImpl* entry = controller_->GetLastCommittedEntry(); |
| 150 UpdateEntry(details.serialized_security_info, details.is_main_frame, entry); |
| 151 } |
| 115 | 152 |
| 116 if (details.is_main_frame) { | 153 void SSLManager::UpdateEntry(const std::string& serialized_security_info, |
| 117 if (entry) { | 154 bool is_main_frame, |
| 118 // Decode the security details. | 155 NavigationEntryImpl* entry) { |
| 119 int ssl_cert_id; | 156 if (is_main_frame && entry) { |
| 120 net::CertStatus ssl_cert_status; | 157 // Decode the security details. |
| 121 int ssl_security_bits; | 158 int ssl_cert_id; |
| 122 int ssl_connection_status; | 159 net::CertStatus ssl_cert_status; |
| 123 SignedCertificateTimestampIDStatusList | 160 int ssl_security_bits; |
| 124 ssl_signed_certificate_timestamp_ids; | 161 int ssl_connection_status; |
| 125 DeserializeSecurityInfo(details.serialized_security_info, | 162 SignedCertificateTimestampIDStatusList ssl_signed_certificate_timestamp_ids; |
| 126 &ssl_cert_id, | 163 DeserializeSecurityInfo(serialized_security_info, &ssl_cert_id, |
| 127 &ssl_cert_status, | 164 &ssl_cert_status, &ssl_security_bits, |
| 128 &ssl_security_bits, | 165 &ssl_connection_status, |
| 129 &ssl_connection_status, | 166 &ssl_signed_certificate_timestamp_ids); |
| 130 &ssl_signed_certificate_timestamp_ids); | |
| 131 | 167 |
| 132 // We may not have an entry if this is a navigation to an initial blank | 168 // We may not have an entry if this is a navigation to an initial blank |
| 133 // page. Reset the SSL information and add the new data we have. | 169 // page. Reset the SSL information and add the new data we have. |
| 134 entry->GetSSL() = SSLStatus(); | 170 entry->GetSSL() = SSLStatus(); |
| 135 entry->GetSSL().cert_id = ssl_cert_id; | 171 entry->GetSSL().cert_id = ssl_cert_id; |
| 136 entry->GetSSL().cert_status = ssl_cert_status; | 172 entry->GetSSL().cert_status = ssl_cert_status; |
| 137 entry->GetSSL().security_bits = ssl_security_bits; | 173 entry->GetSSL().security_bits = ssl_security_bits; |
| 138 entry->GetSSL().connection_status = ssl_connection_status; | 174 entry->GetSSL().connection_status = ssl_connection_status; |
| 139 entry->GetSSL().signed_certificate_timestamp_ids = | 175 entry->GetSSL().signed_certificate_timestamp_ids = |
| 140 ssl_signed_certificate_timestamp_ids; | 176 ssl_signed_certificate_timestamp_ids; |
| 141 } | |
| 142 } | 177 } |
| 143 | 178 |
| 144 UpdateEntry(entry); | 179 UpdateEntry(entry); |
| 145 } | 180 } |
| 146 | 181 |
| 147 void SSLManager::DidDisplayInsecureContent() { | 182 void SSLManager::DidDisplayInsecureContent() { |
| 148 UpdateEntry(controller_->GetLastCommittedEntry()); | 183 UpdateEntry(controller_->GetLastCommittedEntry()); |
| 149 } | 184 } |
| 150 | 185 |
| 151 void SSLManager::DidRunInsecureContent(const std::string& security_origin) { | 186 void SSLManager::DidRunInsecureContent(const std::string& security_origin) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 241 |
| 207 WebContentsImpl* contents = | 242 WebContentsImpl* contents = |
| 208 static_cast<WebContentsImpl*>(controller_->delegate()->GetWebContents()); | 243 static_cast<WebContentsImpl*>(controller_->delegate()->GetWebContents()); |
| 209 policy()->UpdateEntry(entry, contents); | 244 policy()->UpdateEntry(entry, contents); |
| 210 | 245 |
| 211 if (!entry->GetSSL().Equals(original_ssl_status)) | 246 if (!entry->GetSSL().Equals(original_ssl_status)) |
| 212 contents->DidChangeVisibleSSLState(); | 247 contents->DidChangeVisibleSSLState(); |
| 213 } | 248 } |
| 214 | 249 |
| 215 } // namespace content | 250 } // namespace content |
| OLD | NEW |