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

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

Issue 12249003: content: convert SSL notifications to observer usage (take 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/ssl/ssl_manager.h ('k') | content/browser/ssl/ssl_policy_backend.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/supports_user_data.h"
8 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
9 #include "content/browser/loader/resource_dispatcher_host_impl.h" 12 #include "content/browser/loader/resource_dispatcher_host_impl.h"
10 #include "content/browser/loader/resource_request_info_impl.h" 13 #include "content/browser/loader/resource_request_info_impl.h"
11 #include "content/browser/ssl/ssl_cert_error_handler.h" 14 #include "content/browser/ssl/ssl_cert_error_handler.h"
12 #include "content/browser/ssl/ssl_policy.h" 15 #include "content/browser/ssl/ssl_policy.h"
13 #include "content/browser/ssl/ssl_request_info.h" 16 #include "content/browser/ssl/ssl_request_info.h"
14 #include "content/browser/web_contents/navigation_entry_impl.h" 17 #include "content/browser/web_contents/navigation_entry_impl.h"
15 #include "content/browser/web_contents/web_contents_impl.h" 18 #include "content/browser/web_contents/web_contents_impl.h"
16 #include "content/common/ssl_status_serialization.h" 19 #include "content/common/ssl_status_serialization.h"
20 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/load_from_memory_cache_details.h" 22 #include "content/public/browser/load_from_memory_cache_details.h"
19 #include "content/public/browser/navigation_details.h" 23 #include "content/public/browser/navigation_details.h"
20 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/notification_source.h" 25 #include "content/public/browser/notification_source.h"
22 #include "content/public/browser/resource_request_details.h" 26 #include "content/public/browser/resource_request_details.h"
23 #include "content/public/common/ssl_status.h" 27 #include "content/public/common/ssl_status.h"
24 #include "net/url_request/url_request.h" 28 #include "net/url_request/url_request.h"
25 29
26 namespace content { 30 namespace content {
27 31
32 namespace {
33
34 const char kSSLManagerKeyName[] = "content_ssl_manager";
35
36 class SSLManagerSet : public base::SupportsUserData::Data {
37 public:
38 SSLManagerSet() {
39 }
40
41 std::set<SSLManager*>& get() { return set_; }
42
43 private:
44 std::set<SSLManager*> set_;
45
46 DISALLOW_COPY_AND_ASSIGN(SSLManagerSet);
47 };
48
49 } // namespace
50
28 // static 51 // static
29 void SSLManager::OnSSLCertificateError( 52 void SSLManager::OnSSLCertificateError(
30 const base::WeakPtr<SSLErrorHandler::Delegate>& delegate, 53 const base::WeakPtr<SSLErrorHandler::Delegate>& delegate,
31 const GlobalRequestID& id, 54 const GlobalRequestID& id,
32 const ResourceType::Type resource_type, 55 const ResourceType::Type resource_type,
33 const GURL& url, 56 const GURL& url,
34 int render_process_id, 57 int render_process_id,
35 int render_view_id, 58 int render_view_id,
36 const net::SSLInfo& ssl_info, 59 const net::SSLInfo& ssl_info,
37 bool fatal) { 60 bool fatal) {
(...skipping 16 matching lines...) Expand all
54 id, 77 id,
55 resource_type, 78 resource_type,
56 url, 79 url,
57 render_process_id, 80 render_process_id,
58 render_view_id, 81 render_view_id,
59 ssl_info, 82 ssl_info,
60 fatal))); 83 fatal)));
61 } 84 }
62 85
63 // static 86 // static
64 void SSLManager::NotifySSLInternalStateChanged( 87 void SSLManager::NotifySSLInternalStateChanged(BrowserContext* context) {
65 NavigationControllerImpl* controller) { 88 SSLManagerSet* managers = static_cast<SSLManagerSet*>(
66 NotificationService::current()->Notify( 89 context->GetUserData(kSSLManagerKeyName));
67 NOTIFICATION_SSL_INTERNAL_STATE_CHANGED, 90
68 Source<BrowserContext>(controller->GetBrowserContext()), 91 for (std::set<SSLManager*>::iterator i = managers->get().begin();
69 NotificationService::NoDetails()); 92 i != managers->get().end(); ++i) {
93 (*i)->UpdateEntry(NavigationEntryImpl::FromNavigationEntry(
94 (*i)->controller()->GetActiveEntry()));
95 }
70 } 96 }
71 97
72 SSLManager::SSLManager(NavigationControllerImpl* controller) 98 SSLManager::SSLManager(NavigationControllerImpl* controller)
73 : backend_(controller), 99 : backend_(controller),
74 policy_(new SSLPolicy(&backend_)), 100 policy_(new SSLPolicy(&backend_)),
75 controller_(controller) { 101 controller_(controller) {
76 DCHECK(controller_); 102 DCHECK(controller_);
77 103
78 // Subscribe to various notifications. 104 // Subscribe to various notifications.
79 registrar_.Add( 105 registrar_.Add(
80 this, NOTIFICATION_RESOURCE_RESPONSE_STARTED, 106 this, NOTIFICATION_RESOURCE_RESPONSE_STARTED,
81 Source<WebContents>(controller_->web_contents())); 107 Source<WebContents>(controller_->web_contents()));
82 registrar_.Add( 108 registrar_.Add(
83 this, NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, 109 this, NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
84 Source<WebContents>(controller_->web_contents())); 110 Source<WebContents>(controller_->web_contents()));
85 registrar_.Add( 111 registrar_.Add(
86 this, NOTIFICATION_LOAD_FROM_MEMORY_CACHE, 112 this, NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
87 Source<NavigationController>(controller_)); 113 Source<NavigationController>(controller_));
88 registrar_.Add( 114
89 this, NOTIFICATION_SSL_INTERNAL_STATE_CHANGED, 115 SSLManagerSet* managers = static_cast<SSLManagerSet*>(
90 Source<BrowserContext>( 116 controller_->GetBrowserContext()->GetUserData(kSSLManagerKeyName));
91 controller_->GetBrowserContext())); 117 if (!managers) {
118 managers = new SSLManagerSet;
119 controller_->GetBrowserContext()->SetUserData(kSSLManagerKeyName, managers);
120 }
121 managers->get().insert(this);
92 } 122 }
93 123
94 SSLManager::~SSLManager() { 124 SSLManager::~SSLManager() {
125 SSLManagerSet* managers = static_cast<SSLManagerSet*>(
126 controller_->GetBrowserContext()->GetUserData(kSSLManagerKeyName));
127 managers->get().erase(this);
95 } 128 }
96 129
97 void SSLManager::DidCommitProvisionalLoad( 130 void SSLManager::DidCommitProvisionalLoad(
98 const NotificationDetails& in_details) { 131 const NotificationDetails& in_details) {
99 LoadCommittedDetails* details = 132 LoadCommittedDetails* details =
100 Details<LoadCommittedDetails>(in_details).ptr(); 133 Details<LoadCommittedDetails>(in_details).ptr();
101 134
102 NavigationEntryImpl* entry = 135 NavigationEntryImpl* entry =
103 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry()); 136 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry());
104 137
(...skipping 16 matching lines...) Expand all
121 entry->GetSSL().cert_id = ssl_cert_id; 154 entry->GetSSL().cert_id = ssl_cert_id;
122 entry->GetSSL().cert_status = ssl_cert_status; 155 entry->GetSSL().cert_status = ssl_cert_status;
123 entry->GetSSL().security_bits = ssl_security_bits; 156 entry->GetSSL().security_bits = ssl_security_bits;
124 entry->GetSSL().connection_status = ssl_connection_status; 157 entry->GetSSL().connection_status = ssl_connection_status;
125 } 158 }
126 } 159 }
127 160
128 UpdateEntry(entry); 161 UpdateEntry(entry);
129 } 162 }
130 163
164 void SSLManager::DidDisplayInsecureContent() {
165 UpdateEntry(
166 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry()));
167 }
168
131 void SSLManager::DidRunInsecureContent(const std::string& security_origin) { 169 void SSLManager::DidRunInsecureContent(const std::string& security_origin) {
132 policy()->DidRunInsecureContent( 170 NavigationEntryImpl* navigation_entry =
133 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry()), 171 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry());
134 security_origin); 172 policy()->DidRunInsecureContent(navigation_entry, security_origin);
173 UpdateEntry(navigation_entry);
135 } 174 }
136 175
137 void SSLManager::Observe(int type, 176 void SSLManager::Observe(int type,
138 const NotificationSource& source, 177 const NotificationSource& source,
139 const NotificationDetails& details) { 178 const NotificationDetails& details) {
140 // Dispatch by type. 179 // Dispatch by type.
141 switch (type) { 180 switch (type) {
142 case NOTIFICATION_RESOURCE_RESPONSE_STARTED: 181 case NOTIFICATION_RESOURCE_RESPONSE_STARTED:
143 DidStartResourceResponse( 182 DidStartResourceResponse(
144 Details<ResourceRequestDetails>(details).ptr()); 183 Details<ResourceRequestDetails>(details).ptr());
145 break; 184 break;
146 case NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: 185 case NOTIFICATION_RESOURCE_RECEIVED_REDIRECT:
147 DidReceiveResourceRedirect( 186 DidReceiveResourceRedirect(
148 Details<ResourceRedirectDetails>(details).ptr()); 187 Details<ResourceRedirectDetails>(details).ptr());
149 break; 188 break;
150 case NOTIFICATION_LOAD_FROM_MEMORY_CACHE: 189 case NOTIFICATION_LOAD_FROM_MEMORY_CACHE:
151 DidLoadFromMemoryCache( 190 DidLoadFromMemoryCache(
152 Details<LoadFromMemoryCacheDetails>(details).ptr()); 191 Details<LoadFromMemoryCacheDetails>(details).ptr());
153 break; 192 break;
154 case NOTIFICATION_SSL_INTERNAL_STATE_CHANGED:
155 DidChangeSSLInternalState();
156 break;
157 default: 193 default:
158 NOTREACHED() << "The SSLManager received an unexpected notification."; 194 NOTREACHED() << "The SSLManager received an unexpected notification.";
159 } 195 }
160 } 196 }
161 197
162 void SSLManager::DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details) { 198 void SSLManager::DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details) {
163 // Simulate loading this resource through the usual path. 199 // Simulate loading this resource through the usual path.
164 // Note that we specify SUB_RESOURCE as the resource type as WebCore only 200 // Note that we specify SUB_RESOURCE as the resource type as WebCore only
165 // caches sub-resources. 201 // caches sub-resources.
166 // This resource must have been loaded with no filtering because filtered 202 // This resource must have been loaded with no filtering because filtered
(...skipping 24 matching lines...) Expand all
191 } 227 }
192 228
193 void SSLManager::DidReceiveResourceRedirect(ResourceRedirectDetails* details) { 229 void SSLManager::DidReceiveResourceRedirect(ResourceRedirectDetails* details) {
194 // TODO(abarth): Make sure our redirect behavior is correct. If we ever see a 230 // TODO(abarth): Make sure our redirect behavior is correct. If we ever see a
195 // non-HTTPS resource in the redirect chain, we want to trigger 231 // non-HTTPS resource in the redirect chain, we want to trigger
196 // insecure content, even if the redirect chain goes back to 232 // insecure content, even if the redirect chain goes back to
197 // HTTPS. This is because the network attacker can redirect the 233 // HTTPS. This is because the network attacker can redirect the
198 // HTTP request to https://attacker.com/payload.js. 234 // HTTP request to https://attacker.com/payload.js.
199 } 235 }
200 236
201 void SSLManager::DidChangeSSLInternalState() {
202 UpdateEntry(
203 NavigationEntryImpl::FromNavigationEntry(controller_->GetActiveEntry()));
204 }
205
206 void SSLManager::UpdateEntry(NavigationEntryImpl* entry) { 237 void SSLManager::UpdateEntry(NavigationEntryImpl* entry) {
207 // We don't always have a navigation entry to update, for example in the 238 // We don't always have a navigation entry to update, for example in the
208 // case of the Web Inspector. 239 // case of the Web Inspector.
209 if (!entry) 240 if (!entry)
210 return; 241 return;
211 242
212 SSLStatus original_ssl_status = entry->GetSSL(); // Copy! 243 SSLStatus original_ssl_status = entry->GetSSL(); // Copy!
213 244
214 policy()->UpdateEntry(entry, controller_->web_contents()); 245 policy()->UpdateEntry(entry, controller_->web_contents());
215 246
216 if (!entry->GetSSL().Equals(original_ssl_status)) { 247 if (!entry->GetSSL().Equals(original_ssl_status))
217 NotificationService::current()->Notify( 248 controller_->web_contents()->DidChangeVisibleSSLState();
218 NOTIFICATION_SSL_VISIBLE_STATE_CHANGED,
219 Source<NavigationController>(controller_),
220 NotificationService::NoDetails());
221 }
222 } 249 }
223 250
224 } // namespace content 251 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/ssl/ssl_manager.h ('k') | content/browser/ssl/ssl_policy_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698