OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/net/chrome_url_request_context.h" | 5 #include "chrome/browser/net/chrome_url_request_context.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 chrome::kExtensionScheme}; | 368 chrome::kExtensionScheme}; |
369 cookie_monster->SetCookieableSchemes(schemes, 2); | 369 cookie_monster->SetCookieableSchemes(schemes, 2); |
370 context->set_cookie_store(cookie_monster); | 370 context->set_cookie_store(cookie_monster); |
371 // TODO(cbentzel): How should extensions handle HTTP Authentication? | 371 // TODO(cbentzel): How should extensions handle HTTP Authentication? |
372 context->set_http_auth_handler_factory( | 372 context->set_http_auth_handler_factory( |
373 io_thread_globals->http_auth_handler_factory.get()); | 373 io_thread_globals->http_auth_handler_factory.get()); |
374 | 374 |
375 return context; | 375 return context; |
376 } | 376 } |
377 | 377 |
| 378 // Factory that creates the ChromeURLRequestContext for a given isolated app. |
| 379 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { |
| 380 public: |
| 381 FactoryForIsolatedApp(Profile* profile, const Extension* app, |
| 382 const FilePath& cookie_store_path, bool incognito) |
| 383 : ChromeURLRequestContextFactory(profile), |
| 384 cookie_store_path_(cookie_store_path), |
| 385 incognito_(incognito), |
| 386 original_context_getter_( |
| 387 static_cast<ChromeURLRequestContextGetter*>( |
| 388 profile->GetOriginalProfile()->GetRequestContext())) { |
| 389 } |
| 390 |
| 391 virtual ChromeURLRequestContext* Create(); |
| 392 |
| 393 private: |
| 394 scoped_refptr<const Extension> app_; |
| 395 FilePath cookie_store_path_; |
| 396 bool incognito_; |
| 397 scoped_refptr<ChromeURLRequestContextGetter> original_context_getter_; |
| 398 }; |
| 399 |
| 400 ChromeURLRequestContext* FactoryForIsolatedApp::Create() { |
| 401 ChromeURLRequestContext* context = new ChromeURLRequestContext; |
| 402 ApplyProfileParametersToContext(context); |
| 403 |
| 404 ChromeURLRequestContext* original_context = |
| 405 original_context_getter_->GetIOContext(); |
| 406 |
| 407 IOThread::Globals* io_thread_globals = io_thread()->globals(); |
| 408 |
| 409 // Share the same proxy service, host resolver, cert verifier, |
| 410 // and http_auth_handler_factory as the original profile. |
| 411 context->set_host_resolver(original_context->host_resolver()); |
| 412 context->set_cert_verifier(original_context->cert_verifier()); |
| 413 context->set_proxy_service(original_context->proxy_service()); |
| 414 context->set_http_auth_handler_factory( |
| 415 original_context->http_auth_handler_factory()); |
| 416 |
| 417 net::HttpCache::BackendFactory* backend = |
| 418 net::HttpCache::DefaultBackend::InMemory(0); |
| 419 |
| 420 net::HttpCache* cache = |
| 421 new net::HttpCache(context->host_resolver(), |
| 422 context->cert_verifier(), |
| 423 context->dnsrr_resolver(), |
| 424 NULL /* dns_cert_checker */, |
| 425 context->proxy_service(), |
| 426 context->ssl_config_service(), |
| 427 context->http_auth_handler_factory(), |
| 428 &io_thread_globals->network_delegate, |
| 429 io_thread()->net_log(), |
| 430 backend); |
| 431 |
| 432 // TODO(creis): We care about the rest of storage as well, not just cookies. |
| 433 scoped_refptr<SQLitePersistentCookieStore> cookie_db = NULL; |
| 434 if (!incognito_) { |
| 435 DCHECK(!cookie_store_path_.empty()); |
| 436 cookie_db = new SQLitePersistentCookieStore(cookie_store_path_); |
| 437 } |
| 438 net::CookieMonster* cookie_monster = |
| 439 new net::CookieMonster(cookie_db.get(), cookie_monster_delegate_); |
| 440 context->set_cookie_store(cookie_monster); |
| 441 context->set_cookie_policy( |
| 442 new ChromeCookiePolicy(host_content_settings_map_)); |
| 443 |
| 444 context->set_http_transaction_factory(cache); |
| 445 |
| 446 context->set_ftp_transaction_factory( |
| 447 new net::FtpNetworkLayer(context->host_resolver())); |
| 448 |
| 449 appcache_service_->set_request_context(context); |
| 450 |
| 451 context->set_net_log(io_thread()->net_log()); |
| 452 return context; |
| 453 } |
| 454 |
378 // Factory that creates the ChromeURLRequestContext for incognito profile. | 455 // Factory that creates the ChromeURLRequestContext for incognito profile. |
379 class FactoryForOffTheRecord : public ChromeURLRequestContextFactory { | 456 class FactoryForOffTheRecord : public ChromeURLRequestContextFactory { |
380 public: | 457 public: |
381 explicit FactoryForOffTheRecord(Profile* profile) | 458 explicit FactoryForOffTheRecord(Profile* profile) |
382 : ChromeURLRequestContextFactory(profile), | 459 : ChromeURLRequestContextFactory(profile), |
383 original_context_getter_( | 460 original_context_getter_( |
384 static_cast<ChromeURLRequestContextGetter*>( | 461 static_cast<ChromeURLRequestContextGetter*>( |
385 profile->GetOriginalProfile()->GetRequestContext())) { | 462 profile->GetOriginalProfile()->GetRequestContext())) { |
386 } | 463 } |
387 | 464 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 ChromeURLRequestContextGetter::CreateOriginalForExtensions( | 720 ChromeURLRequestContextGetter::CreateOriginalForExtensions( |
644 Profile* profile, const FilePath& cookie_store_path) { | 721 Profile* profile, const FilePath& cookie_store_path) { |
645 DCHECK(!profile->IsOffTheRecord()); | 722 DCHECK(!profile->IsOffTheRecord()); |
646 return new ChromeURLRequestContextGetter( | 723 return new ChromeURLRequestContextGetter( |
647 profile, | 724 profile, |
648 new FactoryForExtensions(profile, cookie_store_path, false)); | 725 new FactoryForExtensions(profile, cookie_store_path, false)); |
649 } | 726 } |
650 | 727 |
651 // static | 728 // static |
652 ChromeURLRequestContextGetter* | 729 ChromeURLRequestContextGetter* |
| 730 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(Profile* profile, |
| 731 const Extension* app, const FilePath& cookie_store_path) { |
| 732 DCHECK(!profile->IsOffTheRecord()); |
| 733 return new ChromeURLRequestContextGetter( |
| 734 profile, |
| 735 new FactoryForIsolatedApp(profile, app, cookie_store_path, false)); |
| 736 } |
| 737 |
| 738 // static |
| 739 ChromeURLRequestContextGetter* |
653 ChromeURLRequestContextGetter::CreateOffTheRecord(Profile* profile) { | 740 ChromeURLRequestContextGetter::CreateOffTheRecord(Profile* profile) { |
654 DCHECK(profile->IsOffTheRecord()); | 741 DCHECK(profile->IsOffTheRecord()); |
655 return new ChromeURLRequestContextGetter( | 742 return new ChromeURLRequestContextGetter( |
656 profile, new FactoryForOffTheRecord(profile)); | 743 profile, new FactoryForOffTheRecord(profile)); |
657 } | 744 } |
658 | 745 |
659 // static | 746 // static |
660 ChromeURLRequestContextGetter* | 747 ChromeURLRequestContextGetter* |
661 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( | 748 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( |
662 Profile* profile) { | 749 Profile* profile) { |
663 DCHECK(profile->IsOffTheRecord()); | 750 DCHECK(profile->IsOffTheRecord()); |
664 return new ChromeURLRequestContextGetter( | 751 return new ChromeURLRequestContextGetter( |
665 profile, new FactoryForExtensions(profile, FilePath(), true)); | 752 profile, new FactoryForExtensions(profile, FilePath(), true)); |
666 } | 753 } |
667 | 754 |
| 755 // static |
| 756 ChromeURLRequestContextGetter* |
| 757 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( |
| 758 Profile* profile, const Extension* app) { |
| 759 DCHECK(profile->IsOffTheRecord()); |
| 760 return new ChromeURLRequestContextGetter( |
| 761 profile, new FactoryForIsolatedApp(profile, app, FilePath(), true)); |
| 762 } |
| 763 |
668 void ChromeURLRequestContextGetter::CleanupOnUIThread() { | 764 void ChromeURLRequestContextGetter::CleanupOnUIThread() { |
669 CheckCurrentlyOnMainThread(); | 765 CheckCurrentlyOnMainThread(); |
670 // Unregister for pref notifications. | 766 // Unregister for pref notifications. |
671 registrar_.RemoveAll(); | 767 registrar_.RemoveAll(); |
672 } | 768 } |
673 | 769 |
674 // NotificationObserver implementation. | 770 // NotificationObserver implementation. |
675 void ChromeURLRequestContextGetter::Observe( | 771 void ChromeURLRequestContextGetter::Observe( |
676 NotificationType type, | 772 NotificationType type, |
677 const NotificationSource& source, | 773 const NotificationSource& source, |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 context->set_host_zoom_map(host_zoom_map_); | 1001 context->set_host_zoom_map(host_zoom_map_); |
906 context->set_transport_security_state( | 1002 context->set_transport_security_state( |
907 transport_security_state_); | 1003 transport_security_state_); |
908 context->set_ssl_config_service(ssl_config_service_); | 1004 context->set_ssl_config_service(ssl_config_service_); |
909 context->set_appcache_service(appcache_service_); | 1005 context->set_appcache_service(appcache_service_); |
910 context->set_database_tracker(database_tracker_); | 1006 context->set_database_tracker(database_tracker_); |
911 context->set_blob_storage_context(blob_storage_context_); | 1007 context->set_blob_storage_context(blob_storage_context_); |
912 context->set_file_system_context(file_system_context_); | 1008 context->set_file_system_context(file_system_context_); |
913 context->set_extension_info_map(extension_info_map_); | 1009 context->set_extension_info_map(extension_info_map_); |
914 } | 1010 } |
OLD | NEW |