This source file includes following definitions.
- get
- OnSSLCertificateError
- NotifySSLInternalStateChanged
- controller_
- DidCommitProvisionalLoad
- DidDisplayInsecureContent
- DidRunInsecureContent
- DidLoadFromMemoryCache
- DidStartResourceResponse
- DidReceiveResourceRedirect
- UpdateEntry
#include "content/browser/ssl/ssl_manager.h"
#include <set>
#include "base/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "base/supports_user_data.h"
#include "content/browser/frame_host/navigation_entry_impl.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/browser/loader/resource_request_info_impl.h"
#include "content/browser/ssl/ssl_cert_error_handler.h"
#include "content/browser/ssl/ssl_policy.h"
#include "content/browser/ssl/ssl_request_info.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/ssl_status_serialization.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/load_from_memory_cache_details.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/resource_request_details.h"
#include "content/public/common/ssl_status.h"
#include "net/url_request/url_request.h"
namespace content {
namespace {
const char kSSLManagerKeyName[] = "content_ssl_manager";
class SSLManagerSet : public base::SupportsUserData::Data {
public:
SSLManagerSet() {
}
std::set<SSLManager*>& get() { return set_; }
private:
std::set<SSLManager*> set_;
DISALLOW_COPY_AND_ASSIGN(SSLManagerSet);
};
}
void SSLManager::OnSSLCertificateError(
const base::WeakPtr<SSLErrorHandler::Delegate>& delegate,
const GlobalRequestID& id,
const ResourceType::Type resource_type,
const GURL& url,
int render_process_id,
int render_frame_id,
const net::SSLInfo& ssl_info,
bool fatal) {
DCHECK(delegate.get());
DVLOG(1) << "OnSSLCertificateError() cert_error: "
<< net::MapCertStatusToNetError(ssl_info.cert_status) << " id: "
<< id.child_id << "," << id.request_id << " resource_type: "
<< resource_type << " url: " << url.spec() << " render_process_id: "
<< render_process_id << " render_frame_id: " << render_frame_id
<< " cert_status: " << std::hex << ssl_info.cert_status;
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&SSLCertErrorHandler::Dispatch,
new SSLCertErrorHandler(delegate,
id,
resource_type,
url,
render_process_id,
render_frame_id,
ssl_info,
fatal)));
}
void SSLManager::NotifySSLInternalStateChanged(BrowserContext* context) {
SSLManagerSet* managers = static_cast<SSLManagerSet*>(
context->GetUserData(kSSLManagerKeyName));
for (std::set<SSLManager*>::iterator i = managers->get().begin();
i != managers->get().end(); ++i) {
(*i)->UpdateEntry(NavigationEntryImpl::FromNavigationEntry(
(*i)->controller()->GetLastCommittedEntry()));
}
}
SSLManager::SSLManager(NavigationControllerImpl* controller)
: backend_(controller),
policy_(new SSLPolicy(&backend_)),
controller_(controller) {
DCHECK(controller_);
SSLManagerSet* managers = static_cast<SSLManagerSet*>(
controller_->GetBrowserContext()->GetUserData(kSSLManagerKeyName));
if (!managers) {
managers = new SSLManagerSet;
controller_->GetBrowserContext()->SetUserData(kSSLManagerKeyName, managers);
}
managers->get().insert(this);
}
SSLManager::~SSLManager() {
SSLManagerSet* managers = static_cast<SSLManagerSet*>(
controller_->GetBrowserContext()->GetUserData(kSSLManagerKeyName));
managers->get().erase(this);
}
void SSLManager::DidCommitProvisionalLoad(const LoadCommittedDetails& details) {
NavigationEntryImpl* entry =
NavigationEntryImpl::FromNavigationEntry(
controller_->GetLastCommittedEntry());
if (details.is_main_frame) {
if (entry) {
int ssl_cert_id;
net::CertStatus ssl_cert_status;
int ssl_security_bits;
int ssl_connection_status;
SignedCertificateTimestampIDStatusList
ssl_signed_certificate_timestamp_ids;
DeserializeSecurityInfo(details.serialized_security_info,
&ssl_cert_id,
&ssl_cert_status,
&ssl_security_bits,
&ssl_connection_status,
&ssl_signed_certificate_timestamp_ids);
entry->GetSSL() = SSLStatus();
entry->GetSSL().cert_id = ssl_cert_id;
entry->GetSSL().cert_status = ssl_cert_status;
entry->GetSSL().security_bits = ssl_security_bits;
entry->GetSSL().connection_status = ssl_connection_status;
entry->GetSSL().signed_certificate_timestamp_ids =
ssl_signed_certificate_timestamp_ids;
}
}
UpdateEntry(entry);
}
void SSLManager::DidDisplayInsecureContent() {
UpdateEntry(
NavigationEntryImpl::FromNavigationEntry(
controller_->GetLastCommittedEntry()));
}
void SSLManager::DidRunInsecureContent(const std::string& security_origin) {
NavigationEntryImpl* navigation_entry =
NavigationEntryImpl::FromNavigationEntry(
controller_->GetLastCommittedEntry());
policy()->DidRunInsecureContent(navigation_entry, security_origin);
UpdateEntry(navigation_entry);
}
void SSLManager::DidLoadFromMemoryCache(
const LoadFromMemoryCacheDetails& details) {
scoped_refptr<SSLRequestInfo> info(new SSLRequestInfo(
details.url,
ResourceType::SUB_RESOURCE,
details.pid,
details.cert_id,
details.cert_status));
policy()->OnRequestStarted(info.get());
}
void SSLManager::DidStartResourceResponse(
const ResourceRequestDetails& details) {
scoped_refptr<SSLRequestInfo> info(new SSLRequestInfo(
details.url,
details.resource_type,
details.origin_child_id,
details.ssl_cert_id,
details.ssl_cert_status));
policy()->OnRequestStarted(info.get());
}
void SSLManager::DidReceiveResourceRedirect(
const ResourceRedirectDetails& details) {
}
void SSLManager::UpdateEntry(NavigationEntryImpl* entry) {
if (!entry)
return;
SSLStatus original_ssl_status = entry->GetSSL();
WebContentsImpl* contents =
static_cast<WebContentsImpl*>(controller_->delegate()->GetWebContents());
policy()->UpdateEntry(entry, contents);
if (!entry->GetSSL().Equals(original_ssl_status))
contents->DidChangeVisibleSSLState();
}
}