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

Side by Side Diff: chrome/browser/net/chrome_url_request_context.cc

Issue 6201005: Initial support for partitioning cookies for isolated apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update cookie logic in test. Created 9 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
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() {
Matt Perry 2011/01/26 20:09:23 Any way we could unify this factory with the Facto
Charlie Reis 2011/03/01 21:33:11 I've refactored this to work with the new ProfileI
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);
willchan no longer on Chromium 2011/01/26 23:21:52 For an isolated app, we don't use a disk cache? On
Charlie Reis 2011/03/01 21:33:11 Oops, that was incorrectly copied from FactoryForO
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);
willchan no longer on Chromium 2011/01/26 23:21:52 Why are we hijacking the request context used for
Charlie Reis 2011/03/01 21:33:11 Sorry, just incorrectly copied that from FactoryFo
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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 ChromeURLRequestContextGetter::CreateOriginalForExtensions( 721 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
645 Profile* profile, const FilePath& cookie_store_path) { 722 Profile* profile, const FilePath& cookie_store_path) {
646 DCHECK(!profile->IsOffTheRecord()); 723 DCHECK(!profile->IsOffTheRecord());
647 return new ChromeURLRequestContextGetter( 724 return new ChromeURLRequestContextGetter(
648 profile, 725 profile,
649 new FactoryForExtensions(profile, cookie_store_path, false)); 726 new FactoryForExtensions(profile, cookie_store_path, false));
650 } 727 }
651 728
652 // static 729 // static
653 ChromeURLRequestContextGetter* 730 ChromeURLRequestContextGetter*
731 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(Profile* profile,
732 const Extension* app, const FilePath& cookie_store_path) {
733 DCHECK(!profile->IsOffTheRecord());
734 return new ChromeURLRequestContextGetter(
735 profile,
736 new FactoryForIsolatedApp(profile, app, cookie_store_path, false));
737 }
738
739 // static
740 ChromeURLRequestContextGetter*
654 ChromeURLRequestContextGetter::CreateOffTheRecord(Profile* profile) { 741 ChromeURLRequestContextGetter::CreateOffTheRecord(Profile* profile) {
655 DCHECK(profile->IsOffTheRecord()); 742 DCHECK(profile->IsOffTheRecord());
656 return new ChromeURLRequestContextGetter( 743 return new ChromeURLRequestContextGetter(
657 profile, new FactoryForOffTheRecord(profile)); 744 profile, new FactoryForOffTheRecord(profile));
658 } 745 }
659 746
660 // static 747 // static
661 ChromeURLRequestContextGetter* 748 ChromeURLRequestContextGetter*
662 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( 749 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(
663 Profile* profile) { 750 Profile* profile) {
664 DCHECK(profile->IsOffTheRecord()); 751 DCHECK(profile->IsOffTheRecord());
665 return new ChromeURLRequestContextGetter( 752 return new ChromeURLRequestContextGetter(
666 profile, new FactoryForExtensions(profile, FilePath(), true)); 753 profile, new FactoryForExtensions(profile, FilePath(), true));
667 } 754 }
668 755
756 // static
757 ChromeURLRequestContextGetter*
758 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp(
759 Profile* profile, const Extension* app) {
760 DCHECK(profile->IsOffTheRecord());
761 return new ChromeURLRequestContextGetter(
762 profile, new FactoryForIsolatedApp(profile, app, FilePath(), true));
763 }
764
669 void ChromeURLRequestContextGetter::CleanupOnUIThread() { 765 void ChromeURLRequestContextGetter::CleanupOnUIThread() {
670 CheckCurrentlyOnMainThread(); 766 CheckCurrentlyOnMainThread();
671 // Unregister for pref notifications. 767 // Unregister for pref notifications.
672 registrar_.RemoveAll(); 768 registrar_.RemoveAll();
673 } 769 }
674 770
675 // NotificationObserver implementation. 771 // NotificationObserver implementation.
676 void ChromeURLRequestContextGetter::Observe( 772 void ChromeURLRequestContextGetter::Observe(
677 NotificationType type, 773 NotificationType type,
678 const NotificationSource& source, 774 const NotificationSource& source,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 context->set_transport_security_state( 1004 context->set_transport_security_state(
909 transport_security_state_); 1005 transport_security_state_);
910 context->set_ssl_config_service(ssl_config_service_); 1006 context->set_ssl_config_service(ssl_config_service_);
911 context->set_appcache_service(appcache_service_); 1007 context->set_appcache_service(appcache_service_);
912 context->set_database_tracker(database_tracker_); 1008 context->set_database_tracker(database_tracker_);
913 context->set_blob_storage_context(blob_storage_context_); 1009 context->set_blob_storage_context(blob_storage_context_);
914 context->set_file_system_context(file_system_context_); 1010 context->set_file_system_context(file_system_context_);
915 context->set_extension_info_map(extension_info_map_); 1011 context->set_extension_info_map(extension_info_map_);
916 context->set_prerender_manager(prerender_manager_); 1012 context->set_prerender_manager(prerender_manager_);
917 } 1013 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698