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

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

Issue 113391: Refactor the inner classes from SSLManager to their own files to reduce the c... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 7 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/ssl/ssl_manager.h" 5 #include "chrome/browser/ssl/ssl_manager.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/load_from_memory_cache_details.h" 12 #include "chrome/browser/load_from_memory_cache_details.h"
13 #include "chrome/browser/renderer_host/render_view_host.h" 13 #include "chrome/browser/renderer_host/render_view_host.h"
14 #include "chrome/browser/renderer_host/resource_request_details.h" 14 #include "chrome/browser/renderer_host/resource_request_details.h"
15 #include "chrome/browser/ssl/ssl_cert_error_handler.h"
15 #include "chrome/browser/ssl/ssl_error_info.h" 16 #include "chrome/browser/ssl/ssl_error_info.h"
17 #include "chrome/browser/ssl/ssl_error_handler.h"
16 #include "chrome/browser/ssl/ssl_host_state.h" 18 #include "chrome/browser/ssl/ssl_host_state.h"
19 #include "chrome/browser/ssl/ssl_mixed_content_handler.h"
17 #include "chrome/browser/ssl/ssl_policy.h" 20 #include "chrome/browser/ssl/ssl_policy.h"
21 #include "chrome/browser/ssl/ssl_request_info.h"
18 #include "chrome/browser/tab_contents/infobar_delegate.h" 22 #include "chrome/browser/tab_contents/infobar_delegate.h"
19 #include "chrome/browser/tab_contents/navigation_controller.h" 23 #include "chrome/browser/tab_contents/navigation_controller.h"
20 #include "chrome/browser/tab_contents/navigation_entry.h" 24 #include "chrome/browser/tab_contents/navigation_entry.h"
21 #include "chrome/browser/tab_contents/provisional_load_details.h" 25 #include "chrome/browser/tab_contents/provisional_load_details.h"
22 #include "chrome/browser/tab_contents/tab_contents.h" 26 #include "chrome/browser/tab_contents/tab_contents.h"
23 #include "chrome/browser/tab_contents/tab_util.h" 27 #include "chrome/browser/tab_contents/tab_util.h"
24 #include "chrome/common/notification_service.h" 28 #include "chrome/common/notification_service.h"
25 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
26 #include "chrome/common/pref_service.h" 30 #include "chrome/common/pref_service.h"
27 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Labels for the InfoBar's message and button. 87 // Labels for the InfoBar's message and button.
84 std::wstring message_; 88 std::wstring message_;
85 std::wstring button_label_; 89 std::wstring button_label_;
86 90
87 // A task to run when the InfoBar is accepted. 91 // A task to run when the InfoBar is accepted.
88 scoped_ptr<Task> task_; 92 scoped_ptr<Task> task_;
89 93
90 DISALLOW_COPY_AND_ASSIGN(SSLInfoBarDelegate); 94 DISALLOW_COPY_AND_ASSIGN(SSLInfoBarDelegate);
91 }; 95 };
92 96
93 ////////////////////////////////////////////////////////////////////////////////
94 // SSLManager
95
96 // static 97 // static
97 void SSLManager::RegisterUserPrefs(PrefService* prefs) { 98 void SSLManager::RegisterUserPrefs(PrefService* prefs) {
98 prefs->RegisterIntegerPref(prefs::kMixedContentFiltering, 99 prefs->RegisterIntegerPref(prefs::kMixedContentFiltering,
99 FilterPolicy::DONT_FILTER); 100 FilterPolicy::DONT_FILTER);
100 } 101 }
101 102
102 SSLManager::SSLManager(NavigationController* controller, Delegate* delegate) 103 SSLManager::SSLManager(NavigationController* controller, Delegate* delegate)
103 : delegate_(delegate), 104 : delegate_(delegate),
104 controller_(controller), 105 controller_(controller),
105 ssl_host_state_(controller->profile()->GetSSLHostState()) { 106 ssl_host_state_(controller->profile()->GetSSLHostState()) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 bool SSLManager::ProcessedSSLErrorFromRequest() const { 225 bool SSLManager::ProcessedSSLErrorFromRequest() const {
225 NavigationEntry* entry = controller_->GetActiveEntry(); 226 NavigationEntry* entry = controller_->GetActiveEntry();
226 if (!entry) { 227 if (!entry) {
227 NOTREACHED(); 228 NOTREACHED();
228 return false; 229 return false;
229 } 230 }
230 231
231 return net::IsCertStatusError(entry->ssl().cert_status()); 232 return net::IsCertStatusError(entry->ssl().cert_status());
232 } 233 }
233 234
234 ////////////////////////////////////////////////////////////////////////////////
235 // ErrorHandler
236
237 SSLManager::ErrorHandler::ErrorHandler(ResourceDispatcherHost* rdh,
238 URLRequest* request,
239 ResourceType::Type resource_type,
240 const std::string& frame_origin,
241 const std::string& main_frame_origin,
242 MessageLoop* ui_loop)
243 : ui_loop_(ui_loop),
244 io_loop_(MessageLoop::current()),
245 manager_(NULL),
246 request_id_(0, 0),
247 resource_dispatcher_host_(rdh),
248 request_url_(request->url()),
249 resource_type_(resource_type),
250 frame_origin_(frame_origin),
251 main_frame_origin_(main_frame_origin),
252 request_has_been_notified_(false) {
253 DCHECK(MessageLoop::current() != ui_loop);
254
255 ResourceDispatcherHost::ExtraRequestInfo* info =
256 ResourceDispatcherHost::ExtraInfoForRequest(request);
257 request_id_.process_id = info->process_id;
258 request_id_.request_id = info->request_id;
259
260 if (!tab_util::GetTabContentsID(request,
261 &render_process_host_id_,
262 &tab_contents_id_))
263 NOTREACHED();
264
265 // This makes sure we don't disappear on the IO thread until we've given an
266 // answer to the URLRequest.
267 //
268 // Release in CompleteCancelRequest, CompleteContinueRequest,
269 // CompleteStartRequest or CompleteTakeNoAction.
270 AddRef();
271 }
272
273 void SSLManager::ErrorHandler::Dispatch() {
274 DCHECK(MessageLoop::current() == ui_loop_);
275
276 TabContents* tab_contents =
277 tab_util::GetTabContentsByID(render_process_host_id_, tab_contents_id_);
278
279 if (!tab_contents) {
280 // We arrived on the UI thread, but the tab we're looking for is no longer
281 // here.
282 OnDispatchFailed();
283 return;
284 }
285
286 // Hand ourselves off to the SSLManager.
287 manager_ = tab_contents->controller().ssl_manager();
288 OnDispatched();
289 }
290
291 TabContents* SSLManager::ErrorHandler::GetTabContents() {
292 return tab_util::GetTabContentsByID(render_process_host_id_,
293 tab_contents_id_);
294 }
295
296 void SSLManager::ErrorHandler::CancelRequest() {
297 DCHECK(MessageLoop::current() == ui_loop_);
298
299 // We need to complete this task on the IO thread.
300 io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
301 this, &SSLManager::ErrorHandler::CompleteCancelRequest,
302 net::ERR_ABORTED));
303 }
304
305 void SSLManager::ErrorHandler::DenyRequest() {
306 DCHECK(MessageLoop::current() == ui_loop_);
307
308 // We need to complete this task on the IO thread.
309 io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
310 this, &SSLManager::ErrorHandler::CompleteCancelRequest,
311 net::ERR_INSECURE_RESPONSE));
312 }
313
314 void SSLManager::ErrorHandler::ContinueRequest() {
315 DCHECK(MessageLoop::current() == ui_loop_);
316
317 // We need to complete this task on the IO thread.
318 io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
319 this, &SSLManager::ErrorHandler::CompleteContinueRequest));
320 }
321
322 void SSLManager::ErrorHandler::StartRequest(FilterPolicy::Type filter_policy) {
323 DCHECK(MessageLoop::current() == ui_loop_);
324
325 // We need to complete this task on the IO thread.
326 io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
327 this, &SSLManager::ErrorHandler::CompleteStartRequest, filter_policy));
328 }
329
330 void SSLManager::ErrorHandler::TakeNoAction() {
331 DCHECK(MessageLoop::current() == ui_loop_);
332
333 // We need to complete this task on the IO thread.
334 io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
335 this, &SSLManager::ErrorHandler::CompleteTakeNoAction));
336 }
337
338 void SSLManager::ErrorHandler::CompleteCancelRequest(int error) {
339 DCHECK(MessageLoop::current() == io_loop_);
340
341 // It is important that we notify the URLRequest only once. If we try to
342 // notify the request twice, it may no longer exist and |this| might have
343 // already have been deleted.
344 DCHECK(!request_has_been_notified_);
345
346 if (!request_has_been_notified_) {
347 URLRequest* request = resource_dispatcher_host_->GetURLRequest(request_id_);
348 if (request) {
349 // The request can be NULL if it was cancelled by the renderer (as the
350 // result of the user navigating to a new page from the location bar).
351 DLOG(INFO) << "CompleteCancelRequest() url: " << request->url().spec();
352 SSLManager::CertError* cert_error = AsCertError();
353 if (cert_error)
354 request->SimulateSSLError(error, cert_error->ssl_info());
355 else
356 request->SimulateError(error);
357 }
358 request_has_been_notified_ = true;
359
360 // We're done with this object on the IO thread.
361 Release();
362 }
363 }
364
365 void SSLManager::ErrorHandler::CompleteContinueRequest() {
366 DCHECK(MessageLoop::current() == io_loop_);
367
368 // It is important that we notify the URLRequest only once. If we try to
369 // notify the request twice, it may no longer exist and |this| might have
370 // already have been deleted.
371 DCHECK(!request_has_been_notified_);
372
373 if (!request_has_been_notified_) {
374 URLRequest* request = resource_dispatcher_host_->GetURLRequest(request_id_);
375 if (request) {
376 // The request can be NULL if it was cancelled by the renderer (as the
377 // result of the user navigating to a new page from the location bar).
378 DLOG(INFO) << "CompleteContinueRequest() url: " << request->url().spec();
379 request->ContinueDespiteLastError();
380 }
381 request_has_been_notified_ = true;
382
383 // We're done with this object on the IO thread.
384 Release();
385 }
386 }
387
388 void SSLManager::ErrorHandler::CompleteStartRequest(
389 FilterPolicy::Type filter_policy) {
390 DCHECK(MessageLoop::current() == io_loop_);
391
392 // It is important that we notify the URLRequest only once. If we try to
393 // notify the request twice, it may no longer exist and |this| might have
394 // already have been deleted.
395 DCHECK(!request_has_been_notified_);
396
397 if (request_has_been_notified_)
398 return;
399
400 URLRequest* request = resource_dispatcher_host_->GetURLRequest(request_id_);
401 if (request) {
402 // The request can be NULL if it was cancelled by the renderer (as the
403 // result of the user navigating to a new page from the location bar).
404 DLOG(INFO) << "CompleteStartRequest() url: " << request->url().spec();
405 // The request should not have been started (SUCCESS is the initial state).
406 DCHECK(request->status().status() == URLRequestStatus::SUCCESS);
407 ResourceDispatcherHost::ExtraRequestInfo* info =
408 ResourceDispatcherHost::ExtraInfoForRequest(request);
409 info->filter_policy = filter_policy;
410 request->Start();
411 }
412 request_has_been_notified_ = true;
413
414 // We're done with this object on the IO thread.
415 Release();
416 }
417
418 void SSLManager::ErrorHandler::CompleteTakeNoAction() {
419 DCHECK(MessageLoop::current() == io_loop_);
420
421 // It is important that we notify the URLRequest only once. If we try to
422 // notify the request twice, it may no longer exist and |this| might have
423 // already have been deleted.
424 DCHECK(!request_has_been_notified_);
425
426 if (!request_has_been_notified_) {
427 request_has_been_notified_ = true;
428
429 // We're done with this object on the IO thread.
430 Release();
431 }
432 }
433
434
435 ////////////////////////////////////////////////////////////////////////////////
436 // CertError
437
438 SSLManager::CertError::CertError(
439 ResourceDispatcherHost* rdh,
440 URLRequest* request,
441 ResourceType::Type resource_type,
442 const std::string& frame_origin,
443 const std::string& main_frame_origin,
444 int cert_error,
445 net::X509Certificate* cert,
446 MessageLoop* ui_loop)
447 : ErrorHandler(rdh, request, resource_type, frame_origin,
448 main_frame_origin, ui_loop),
449 cert_error_(cert_error) {
450 DCHECK(request == resource_dispatcher_host_->GetURLRequest(request_id_));
451
452 // We cannot use the request->ssl_info(), it's not been initialized yet, so
453 // we have to set the fields manually.
454 ssl_info_.cert = cert;
455 ssl_info_.SetCertError(cert_error);
456 }
457
458 // static 235 // static
459 void SSLManager::OnSSLCertificateError(ResourceDispatcherHost* rdh, 236 void SSLManager::OnSSLCertificateError(ResourceDispatcherHost* rdh,
460 URLRequest* request, 237 URLRequest* request,
461 int cert_error, 238 int cert_error,
462 net::X509Certificate* cert, 239 net::X509Certificate* cert,
463 MessageLoop* ui_loop) { 240 MessageLoop* ui_loop) {
464 DLOG(INFO) << "OnSSLCertificateError() cert_error: " << cert_error << 241 DLOG(INFO) << "OnSSLCertificateError() cert_error: " << cert_error <<
465 " url: " << request->url().spec(); 242 " url: " << request->url().spec();
466 243
467 ResourceDispatcherHost::ExtraRequestInfo* info = 244 ResourceDispatcherHost::ExtraRequestInfo* info =
468 ResourceDispatcherHost::ExtraInfoForRequest(request); 245 ResourceDispatcherHost::ExtraInfoForRequest(request);
469 DCHECK(info); 246 DCHECK(info);
470 247
471 // A certificate error occurred. Construct a CertError object and hand it 248 // A certificate error occurred. Construct a SSLCertErrorHandler object and
472 // over to the UI thread for processing. 249 // hand it over to the UI thread for processing.
473 ui_loop->PostTask(FROM_HERE, 250 ui_loop->PostTask(FROM_HERE,
474 NewRunnableMethod(new CertError(rdh, 251 NewRunnableMethod(new SSLCertErrorHandler(rdh,
475 request, 252 request,
476 info->resource_type, 253 info->resource_type,
477 info->frame_origin, 254 info->frame_origin,
478 info->main_frame_origin, 255 info->main_frame_origin,
479 cert_error, 256 cert_error,
480 cert, 257 cert,
481 ui_loop), 258 ui_loop),
482 &CertError::Dispatch)); 259 &SSLCertErrorHandler::Dispatch));
483 } 260 }
484 261
485 // static 262 // static
486 bool SSLManager::ShouldStartRequest(ResourceDispatcherHost* rdh, 263 bool SSLManager::ShouldStartRequest(ResourceDispatcherHost* rdh,
487 URLRequest* request, 264 URLRequest* request,
488 MessageLoop* ui_loop) { 265 MessageLoop* ui_loop) {
489 ResourceDispatcherHost::ExtraRequestInfo* info = 266 ResourceDispatcherHost::ExtraRequestInfo* info =
490 ResourceDispatcherHost::ExtraInfoForRequest(request); 267 ResourceDispatcherHost::ExtraInfoForRequest(request);
491 DCHECK(info); 268 DCHECK(info);
492 269
493 // We cheat here and talk to the SSLPolicy on the IO thread because we need 270 // We cheat here and talk to the SSLPolicy on the IO thread because we need
494 // to respond synchronously to avoid delaying all network requests... 271 // to respond synchronously to avoid delaying all network requests...
495 if (!SSLPolicy::IsMixedContent(request->url(), 272 if (!SSLPolicy::IsMixedContent(request->url(),
496 info->resource_type, 273 info->resource_type,
497 info->filter_policy, 274 info->filter_policy,
498 info->frame_origin)) 275 info->frame_origin))
499 return true; 276 return true;
500 277
501 278
502 ui_loop->PostTask(FROM_HERE, 279 ui_loop->PostTask(FROM_HERE,
503 NewRunnableMethod(new MixedContentHandler(rdh, request, 280 NewRunnableMethod(new SSLMixedContentHandler(rdh,
504 info->resource_type, 281 request,
505 info->frame_origin, 282 info->resource_type,
506 info->main_frame_origin, 283 info->frame_origin,
507 info->process_id, 284 info->main_frame_origin,
508 ui_loop), 285 info->process_id,
509 &MixedContentHandler::Dispatch)); 286 ui_loop),
287 &SSLMixedContentHandler::Dispatch));
510 return false; 288 return false;
511 } 289 }
512 290
513 void SSLManager::OnCertError(CertError* error) { 291 void SSLManager::OnCertError(SSLCertErrorHandler* handler) {
514 delegate()->OnCertError(error); 292 delegate()->OnCertError(handler);
515 } 293 }
516 294
517 void SSLManager::OnMixedContent(MixedContentHandler* handler) { 295 void SSLManager::OnMixedContent(SSLMixedContentHandler* handler) {
518 delegate()->OnMixedContent(handler); 296 delegate()->OnMixedContent(handler);
519 } 297 }
520 298
521 void SSLManager::Observe(NotificationType type, 299 void SSLManager::Observe(NotificationType type,
522 const NotificationSource& source, 300 const NotificationSource& source,
523 const NotificationDetails& details) { 301 const NotificationDetails& details) {
524 // Dispatch by type. 302 // Dispatch by type.
525 switch (type.value) { 303 switch (type.value) {
526 case NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR: 304 case NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR:
527 DidFailProvisionalLoadWithError( 305 DidFailProvisionalLoadWithError(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 } 353 }
576 354
577 void SSLManager::DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details) { 355 void SSLManager::DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details) {
578 DCHECK(details); 356 DCHECK(details);
579 357
580 // Simulate loading this resource through the usual path. 358 // Simulate loading this resource through the usual path.
581 // Note that we specify SUB_RESOURCE as the resource type as WebCore only 359 // Note that we specify SUB_RESOURCE as the resource type as WebCore only
582 // caches sub-resources. 360 // caches sub-resources.
583 // This resource must have been loaded with FilterPolicy::DONT_FILTER because 361 // This resource must have been loaded with FilterPolicy::DONT_FILTER because
584 // filtered resouces aren't cachable. 362 // filtered resouces aren't cachable.
585 scoped_refptr<RequestInfo> info = new RequestInfo( 363 scoped_refptr<SSLRequestInfo> info = new SSLRequestInfo(
586 this, 364 this,
587 details->url(), 365 details->url(),
588 ResourceType::SUB_RESOURCE, 366 ResourceType::SUB_RESOURCE,
589 details->frame_origin(), 367 details->frame_origin(),
590 details->main_frame_origin(), 368 details->main_frame_origin(),
591 FilterPolicy::DONT_FILTER, 369 FilterPolicy::DONT_FILTER,
592 details->pid(), 370 details->pid(),
593 details->ssl_cert_id(), 371 details->ssl_cert_id(),
594 details->ssl_cert_status()); 372 details->ssl_cert_status());
595 373
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 if (details->in_page_navigation()) 417 if (details->in_page_navigation())
640 return; 418 return;
641 419
642 if (details->main_frame()) 420 if (details->main_frame())
643 ClearPendingMessages(); 421 ClearPendingMessages();
644 } 422 }
645 423
646 void SSLManager::DidStartResourceResponse(ResourceRequestDetails* details) { 424 void SSLManager::DidStartResourceResponse(ResourceRequestDetails* details) {
647 DCHECK(details); 425 DCHECK(details);
648 426
649 scoped_refptr<RequestInfo> info = new RequestInfo( 427 scoped_refptr<SSLRequestInfo> info = new SSLRequestInfo(
650 this, 428 this,
651 details->url(), 429 details->url(),
652 details->resource_type(), 430 details->resource_type(),
653 details->frame_origin(), 431 details->frame_origin(),
654 details->main_frame_origin(), 432 details->main_frame_origin(),
655 details->filter_policy(), 433 details->filter_policy(),
656 details->origin_pid(), 434 details->origin_pid(),
657 details->ssl_cert_id(), 435 details->ssl_cert_id(),
658 details->ssl_cert_status()); 436 details->ssl_cert_status());
659 437
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 } 519 }
742 520
743 if (ca_name) { 521 if (ca_name) {
744 // TODO(wtc): should we show the root CA's name instead? 522 // TODO(wtc): should we show the root CA's name instead?
745 *ca_name = l10n_util::GetStringF( 523 *ca_name = l10n_util::GetStringF(
746 IDS_SECURE_CONNECTION_EV_CA, 524 IDS_SECURE_CONNECTION_EV_CA,
747 UTF8ToWide(cert.issuer().organization_names[0])); 525 UTF8ToWide(cert.issuer().organization_names[0]));
748 } 526 }
749 return true; 527 return true;
750 } 528 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698