summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-08 12:27:42 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-08 12:27:42 +0000
commitac0ed09208b6013cf6c00c46d2129e5a33eaa609 (patch)
tree5f907201321c45ec41a71809c25fcd6e85412f3a /content
parenteb9dc3f2bafcf6c8b040558ebec4fd32d23cdf38 (diff)
downloadchromium_src-ac0ed09208b6013cf6c00c46d2129e5a33eaa609.zip
chromium_src-ac0ed09208b6013cf6c00c46d2129e5a33eaa609.tar.gz
chromium_src-ac0ed09208b6013cf6c00c46d2129e5a33eaa609.tar.bz2
content: convert SSL notifications to observer usage
BUG=170921 Review URL: https://codereview.chromium.org/12041059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181488 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/ssl/ssl_manager.cc81
-rw-r--r--content/browser/ssl/ssl_manager.h9
-rw-r--r--content/browser/ssl/ssl_policy_backend.cc2
-rw-r--r--content/browser/web_contents/web_contents_impl.cc11
-rw-r--r--content/browser/web_contents/web_contents_impl.h3
-rw-r--r--content/public/browser/notification_types.h34
-rw-r--r--content/public/browser/web_contents_observer.h3
7 files changed, 74 insertions, 69 deletions
diff --git a/content/browser/ssl/ssl_manager.cc b/content/browser/ssl/ssl_manager.cc
index d41260e..18c64c8 100644
--- a/content/browser/ssl/ssl_manager.cc
+++ b/content/browser/ssl/ssl_manager.cc
@@ -4,7 +4,10 @@
#include "content/browser/ssl/ssl_manager.h"
+#include <set>
+
#include "base/bind.h"
+#include "base/supports_user_data.h"
#include "base/utf_string_conversions.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/browser/loader/resource_request_info_impl.h"
@@ -14,6 +17,7 @@
#include "content/browser/web_contents/navigation_entry_impl.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"
@@ -25,6 +29,25 @@
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);
+};
+
+} // namespace
+
// static
void SSLManager::OnSSLCertificateError(
const base::WeakPtr<SSLErrorHandler::Delegate>& delegate,
@@ -61,12 +84,15 @@ void SSLManager::OnSSLCertificateError(
}
// static
-void SSLManager::NotifySSLInternalStateChanged(
- NavigationControllerImpl* controller) {
- NotificationService::current()->Notify(
- NOTIFICATION_SSL_INTERNAL_STATE_CHANGED,
- Source<BrowserContext>(controller->GetBrowserContext()),
- NotificationService::NoDetails());
+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()->GetActiveEntry()));
+ }
}
SSLManager::SSLManager(NavigationControllerImpl* controller)
@@ -85,13 +111,20 @@ SSLManager::SSLManager(NavigationControllerImpl* controller)
registrar_.Add(
this, NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
Source<NavigationController>(controller_));
- registrar_.Add(
- this, NOTIFICATION_SSL_INTERNAL_STATE_CHANGED,
- Source<BrowserContext>(
- controller_->GetBrowserContext()));
+
+ 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(
@@ -128,10 +161,16 @@ void SSLManager::DidCommitProvisionalLoad(
UpdateEntry(entry);
}
+void SSLManager::DidDisplayInsecureContent() {
+ UpdateEntry(
+ NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry()));
+}
+
void SSLManager::DidRunInsecureContent(const std::string& security_origin) {
- policy()->DidRunInsecureContent(
- NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry()),
- security_origin);
+ NavigationEntryImpl* navigation_entry =
+ NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry());
+ policy()->DidRunInsecureContent(navigation_entry, security_origin);
+ UpdateEntry(navigation_entry);
}
void SSLManager::Observe(int type,
@@ -151,9 +190,6 @@ void SSLManager::Observe(int type,
DidLoadFromMemoryCache(
Details<LoadFromMemoryCacheDetails>(details).ptr());
break;
- case NOTIFICATION_SSL_INTERNAL_STATE_CHANGED:
- DidChangeSSLInternalState();
- break;
default:
NOTREACHED() << "The SSLManager received an unexpected notification.";
}
@@ -198,11 +234,6 @@ void SSLManager::DidReceiveResourceRedirect(ResourceRedirectDetails* details) {
// HTTP request to https://attacker.com/payload.js.
}
-void SSLManager::DidChangeSSLInternalState() {
- UpdateEntry(
- NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry()));
-}
-
void SSLManager::UpdateEntry(NavigationEntryImpl* entry) {
// We don't always have a navigation entry to update, for example in the
// case of the Web Inspector.
@@ -213,12 +244,8 @@ void SSLManager::UpdateEntry(NavigationEntryImpl* entry) {
policy()->UpdateEntry(entry, controller_->web_contents());
- if (!entry->GetSSL().Equals(original_ssl_status)) {
- NotificationService::current()->Notify(
- NOTIFICATION_SSL_VISIBLE_STATE_CHANGED,
- Source<NavigationController>(controller_),
- NotificationService::NoDetails());
- }
+ if (!entry->GetSSL().Equals(original_ssl_status))
+ controller_->web_contents()->DidChangeVisibleSSLState();
}
} // namespace content
diff --git a/content/browser/ssl/ssl_manager.h b/content/browser/ssl/ssl_manager.h
index 4349a90..8cd1668 100644
--- a/content/browser/ssl/ssl_manager.h
+++ b/content/browser/ssl/ssl_manager.h
@@ -25,6 +25,7 @@ class SSLInfo;
}
namespace content {
+class BrowserContext;
class NavigationEntryImpl;
class NavigationControllerImpl;
class SSLPolicy;
@@ -58,10 +59,8 @@ class SSLManager : public NotificationObserver {
const net::SSLInfo& ssl_info,
bool fatal);
- // Called when SSL state for a host or tab changes. Broadcasts the
- // SSL_INTERNAL_STATE_CHANGED notification.
- static void NotifySSLInternalStateChanged(
- NavigationControllerImpl* controller);
+ // Called when SSL state for a host or tab changes.
+ static void NotifySSLInternalStateChanged(BrowserContext* context);
// Construct an SSLManager for the specified tab.
// If |delegate| is NULL, SSLPolicy::GetDefaultPolicy() is used.
@@ -81,6 +80,7 @@ class SSLManager : public NotificationObserver {
void DidCommitProvisionalLoad(const NotificationDetails& details);
// Insecure content entry point.
+ void DidDisplayInsecureContent();
void DidRunInsecureContent(const std::string& security_origin);
// Entry point for navigation. This function begins the process of updating
@@ -99,7 +99,6 @@ class SSLManager : public NotificationObserver {
void DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details);
void DidStartResourceResponse(ResourceRequestDetails* details);
void DidReceiveResourceRedirect(ResourceRedirectDetails* details);
- void DidChangeSSLInternalState();
// Update the NavigationEntry with our current state.
void UpdateEntry(NavigationEntryImpl* entry);
diff --git a/content/browser/ssl/ssl_policy_backend.cc b/content/browser/ssl/ssl_policy_backend.cc
index c405b79..8aa8bc7 100644
--- a/content/browser/ssl/ssl_policy_backend.cc
+++ b/content/browser/ssl/ssl_policy_backend.cc
@@ -18,7 +18,7 @@ SSLPolicyBackend::SSLPolicyBackend(NavigationControllerImpl* controller)
void SSLPolicyBackend::HostRanInsecureContent(const std::string& host, int id) {
ssl_host_state_->HostRanInsecureContent(host, id);
- SSLManager::NotifySSLInternalStateChanged(controller_);
+ SSLManager::NotifySSLInternalStateChanged(controller_->GetBrowserContext());
}
bool SSLPolicyBackend::DidHostRunInsecureContent(const std::string& host,
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 07e6716..f8b462c 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2234,7 +2234,8 @@ void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
void WebContentsImpl::OnDidDisplayInsecureContent() {
RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
displayed_insecure_content_ = true;
- SSLManager::NotifySSLInternalStateChanged(&GetController());
+ SSLManager::NotifySSLInternalStateChanged(
+ GetController().GetBrowserContext());
}
void WebContentsImpl::OnDidRunInsecureContent(
@@ -2246,7 +2247,8 @@ void WebContentsImpl::OnDidRunInsecureContent(
RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
controller_.ssl_manager()->DidRunInsecureContent(security_origin);
displayed_insecure_content_ = true;
- SSLManager::NotifySSLInternalStateChanged(&GetController());
+ SSLManager::NotifySSLInternalStateChanged(
+ GetController().GetBrowserContext());
}
void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
@@ -2523,6 +2525,11 @@ void WebContentsImpl::DidBlock3DAPIs(const GURL& url,
DidBlock3DAPIs(url, requester));
}
+void WebContentsImpl::DidChangeVisibleSSLState() {
+ FOR_EACH_OBSERVER(WebContentsObserver, observers_,
+ DidChangeVisibleSSLState());
+}
+
// Notifies the RenderWidgetHost instance about the fact that the page is
// loading, or done loading and calls the base implementation.
void WebContentsImpl::SetIsLoading(bool is_loading,
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
index d8ab2a2..6101ff2 100644
--- a/content/browser/web_contents/web_contents_impl.h
+++ b/content/browser/web_contents/web_contents_impl.h
@@ -183,6 +183,9 @@ class CONTENT_EXPORT WebContentsImpl
void DidBlock3DAPIs(const GURL& url, ThreeDAPIType requester);
+ // Invoked when visible SSL state (as defined by SSLStatus) changes.
+ void DidChangeVisibleSSLState();
+
// WebContents ------------------------------------------------------
virtual WebContentsDelegate* GetDelegate() OVERRIDE;
virtual void SetDelegate(WebContentsDelegate* delegate) OVERRIDE;
diff --git a/content/public/browser/notification_types.h b/content/public/browser/notification_types.h
index 4c3bd71..cfaafd5 100644
--- a/content/public/browser/notification_types.h
+++ b/content/public/browser/notification_types.h
@@ -102,40 +102,6 @@ enum NotificationType {
// issued. Details in the form of a ResourceRedirectDetails are provided.
NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
- // SSL ---------------------------------------------------------------------
-
- // Updating the SSL security indicators (the lock icon and such) proceeds
- // in two phases:
- //
- // 1) The internal SSL state for a host or tab changes. When this happens,
- // the SSLManager broadcasts an SSL_INTERNAL_STATE_CHANGED notification.
- //
- // 2) The SSLManager for each tab receives this notification and might or
- // might not update the navigation entry for its tab, depending on
- // whether the change in state affects that tab. If the SSLManager does
- // change the navigation entry, then the SSLManager broadcasts an
- // SSL_VISIBLE_STATE_CHANGED notification to the user interface can
- // redraw properly.
-
- // The SSL state of a page has changed in some visible way. For example,
- // if an insecure resource is loaded on a secure page. Note that a
- // toplevel load commit will also update the SSL state (since the
- // NavigationEntry is new) and this message won't always be sent in that
- // case. Listen to this notification if you need to refresh SSL-related UI
- // elements.
- //
- // There is no source or details.
- NOTIFICATION_SSL_VISIBLE_STATE_CHANGED,
-
- // The SSL state of the browser has changed in some internal way. For
- // example, the user might have explicitly allowed some broken certificate
- // or a secure origin might have included some insecure content. Listen to
- // this notifiation if you need to keep track of our internal SSL state.
- //
- // The source will be the browser context. The details will be the navigation
- // controller associated with the state change.
- NOTIFICATION_SSL_INTERNAL_STATE_CHANGED,
-
// Devtools ------------------------------------------------------------------
// Indicates that a devtools agent has attached to a client. The source is
diff --git a/content/public/browser/web_contents_observer.h b/content/public/browser/web_contents_observer.h
index 62be7d1..f58f57d 100644
--- a/content/public/browser/web_contents_observer.h
+++ b/content/public/browser/web_contents_observer.h
@@ -249,6 +249,9 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener,
virtual void DidShowFullscreenWidget(int routing_id) {}
virtual void DidDestroyFullscreenWidget(int routing_id) {}
+ // Invoked when visible SSL state (as defined by SSLStatus) changes.
+ virtual void DidChangeVisibleSSLState() {}
+
// IPC::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;