| 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 net::SetURLRequestContextForOCSP(context); | 318 net::SetURLRequestContextForOCSP(context); |
| 319 #endif | 319 #endif |
| 320 | 320 |
| 321 context->set_net_log(io_thread_globals->net_log.get()); | 321 context->set_net_log(io_thread_globals->net_log.get()); |
| 322 return context; | 322 return context; |
| 323 } | 323 } |
| 324 | 324 |
| 325 // Factory that creates the ChromeURLRequestContext for extensions. | 325 // Factory that creates the ChromeURLRequestContext for extensions. |
| 326 class FactoryForExtensions : public ChromeURLRequestContextFactory { | 326 class FactoryForExtensions : public ChromeURLRequestContextFactory { |
| 327 public: | 327 public: |
| 328 FactoryForExtensions(Profile* profile, const FilePath& cookie_store_path) | 328 FactoryForExtensions(Profile* profile, const FilePath& cookie_store_path, |
| 329 bool incognito) |
| 329 : ChromeURLRequestContextFactory(profile), | 330 : ChromeURLRequestContextFactory(profile), |
| 330 cookie_store_path_(cookie_store_path) { | 331 cookie_store_path_(cookie_store_path), |
| 332 incognito_(incognito) { |
| 331 } | 333 } |
| 332 | 334 |
| 333 virtual ChromeURLRequestContext* Create(); | 335 virtual ChromeURLRequestContext* Create(); |
| 334 | 336 |
| 335 private: | 337 private: |
| 336 FilePath cookie_store_path_; | 338 FilePath cookie_store_path_; |
| 339 bool incognito_; |
| 337 }; | 340 }; |
| 338 | 341 |
| 339 ChromeURLRequestContext* FactoryForExtensions::Create() { | 342 ChromeURLRequestContext* FactoryForExtensions::Create() { |
| 340 ChromeURLRequestContext* context = new ChromeURLRequestContext; | 343 ChromeURLRequestContext* context = new ChromeURLRequestContext; |
| 341 ApplyProfileParametersToContext(context); | 344 ApplyProfileParametersToContext(context); |
| 342 | 345 |
| 343 IOThread::Globals* io_thread_globals = io_thread()->globals(); | 346 IOThread::Globals* io_thread_globals = io_thread()->globals(); |
| 344 | 347 |
| 345 // All we care about for extensions is the cookie store. | 348 // All we care about for extensions is the cookie store. For incognito, we |
| 346 DCHECK(!cookie_store_path_.empty()); | 349 // use a non-persistent cookie store. |
| 350 scoped_refptr<SQLitePersistentCookieStore> cookie_db = NULL; |
| 351 if (!incognito_) { |
| 352 DCHECK(!cookie_store_path_.empty()); |
| 353 cookie_db = new SQLitePersistentCookieStore(cookie_store_path_); |
| 354 } |
| 347 | 355 |
| 348 scoped_refptr<SQLitePersistentCookieStore> cookie_db = | |
| 349 new SQLitePersistentCookieStore(cookie_store_path_); | |
| 350 net::CookieMonster* cookie_monster = | 356 net::CookieMonster* cookie_monster = |
| 351 new net::CookieMonster(cookie_db.get(), NULL); | 357 new net::CookieMonster(cookie_db.get(), NULL); |
| 352 | 358 |
| 353 // Enable cookies for extension URLs only. | 359 // Enable cookies for extension URLs only. |
| 354 const char* schemes[] = {chrome::kExtensionScheme}; | 360 const char* schemes[] = {chrome::kExtensionScheme}; |
| 355 cookie_monster->SetCookieableSchemes(schemes, 1); | 361 cookie_monster->SetCookieableSchemes(schemes, 1); |
| 356 context->set_cookie_store(cookie_monster); | 362 context->set_cookie_store(cookie_monster); |
| 357 // TODO(cbentzel): How should extensions handle HTTP Authentication? | 363 // TODO(cbentzel): How should extensions handle HTTP Authentication? |
| 358 context->set_http_auth_handler_factory( | 364 context->set_http_auth_handler_factory( |
| 359 io_thread_globals->http_auth_handler_factory.get()); | 365 io_thread_globals->http_auth_handler_factory.get()); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 false); | 623 false); |
| 618 } | 624 } |
| 619 | 625 |
| 620 // static | 626 // static |
| 621 ChromeURLRequestContextGetter* | 627 ChromeURLRequestContextGetter* |
| 622 ChromeURLRequestContextGetter::CreateOriginalForExtensions( | 628 ChromeURLRequestContextGetter::CreateOriginalForExtensions( |
| 623 Profile* profile, const FilePath& cookie_store_path) { | 629 Profile* profile, const FilePath& cookie_store_path) { |
| 624 DCHECK(!profile->IsOffTheRecord()); | 630 DCHECK(!profile->IsOffTheRecord()); |
| 625 return new ChromeURLRequestContextGetter( | 631 return new ChromeURLRequestContextGetter( |
| 626 profile, | 632 profile, |
| 627 new FactoryForExtensions(profile, cookie_store_path)); | 633 new FactoryForExtensions(profile, cookie_store_path, false)); |
| 628 } | 634 } |
| 629 | 635 |
| 630 // static | 636 // static |
| 631 ChromeURLRequestContextGetter* | 637 ChromeURLRequestContextGetter* |
| 632 ChromeURLRequestContextGetter::CreateOffTheRecord(Profile* profile) { | 638 ChromeURLRequestContextGetter::CreateOffTheRecord(Profile* profile) { |
| 633 DCHECK(profile->IsOffTheRecord()); | 639 DCHECK(profile->IsOffTheRecord()); |
| 634 return new ChromeURLRequestContextGetter( | 640 return new ChromeURLRequestContextGetter( |
| 635 profile, new FactoryForOffTheRecord(profile)); | 641 profile, new FactoryForOffTheRecord(profile)); |
| 636 } | 642 } |
| 637 | 643 |
| 644 // static |
| 645 ChromeURLRequestContextGetter* |
| 646 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( |
| 647 Profile* profile) { |
| 648 DCHECK(profile->IsOffTheRecord()); |
| 649 return new ChromeURLRequestContextGetter( |
| 650 profile, new FactoryForExtensions(profile, FilePath(), true)); |
| 651 } |
| 652 |
| 638 void ChromeURLRequestContextGetter::CleanupOnUIThread() { | 653 void ChromeURLRequestContextGetter::CleanupOnUIThread() { |
| 639 CheckCurrentlyOnMainThread(); | 654 CheckCurrentlyOnMainThread(); |
| 640 | 655 |
| 641 if (prefs_) { | 656 if (prefs_) { |
| 642 // Unregister for pref notifications. | 657 // Unregister for pref notifications. |
| 643 prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this); | 658 prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this); |
| 644 prefs_->RemovePrefObserver(prefs::kDefaultCharset, this); | 659 prefs_->RemovePrefObserver(prefs::kDefaultCharset, this); |
| 645 prefs_ = NULL; | 660 prefs_ = NULL; |
| 646 } | 661 } |
| 647 } | 662 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 return iter->second->path; | 806 return iter->second->path; |
| 792 else | 807 else |
| 793 return FilePath(); | 808 return FilePath(); |
| 794 } | 809 } |
| 795 | 810 |
| 796 bool ChromeURLRequestContext::ExtensionHasWebExtent(const std::string& id) { | 811 bool ChromeURLRequestContext::ExtensionHasWebExtent(const std::string& id) { |
| 797 ExtensionInfoMap::iterator iter = extension_info_.find(id); | 812 ExtensionInfoMap::iterator iter = extension_info_.find(id); |
| 798 return iter != extension_info_.end() && !iter->second->extent.is_empty(); | 813 return iter != extension_info_.end() && !iter->second->extent.is_empty(); |
| 799 } | 814 } |
| 800 | 815 |
| 816 bool ChromeURLRequestContext::ExtensionCanLoadInIncognito( |
| 817 const std::string& id) { |
| 818 ExtensionInfoMap::iterator iter = extension_info_.find(id); |
| 819 // Only split-mode extensions can load in incognito profiles. |
| 820 return iter != extension_info_.end() && iter->second->incognito_split_mode; |
| 821 } |
| 822 |
| 801 std::string ChromeURLRequestContext::GetDefaultLocaleForExtension( | 823 std::string ChromeURLRequestContext::GetDefaultLocaleForExtension( |
| 802 const std::string& id) { | 824 const std::string& id) { |
| 803 ExtensionInfoMap::iterator iter = extension_info_.find(id); | 825 ExtensionInfoMap::iterator iter = extension_info_.find(id); |
| 804 std::string result; | 826 std::string result; |
| 805 if (iter != extension_info_.end()) | 827 if (iter != extension_info_.end()) |
| 806 result = iter->second->default_locale; | 828 result = iter->second->default_locale; |
| 807 | 829 |
| 808 return result; | 830 return result; |
| 809 } | 831 } |
| 810 | 832 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 permission_name) != api_permissions.end(); | 867 permission_name) != api_permissions.end(); |
| 846 } | 868 } |
| 847 | 869 |
| 848 const std::string& ChromeURLRequestContext::GetUserAgent( | 870 const std::string& ChromeURLRequestContext::GetUserAgent( |
| 849 const GURL& url) const { | 871 const GURL& url) const { |
| 850 return webkit_glue::GetUserAgent(url); | 872 return webkit_glue::GetUserAgent(url); |
| 851 } | 873 } |
| 852 | 874 |
| 853 void ChromeURLRequestContext::OnNewExtensions(const std::string& id, | 875 void ChromeURLRequestContext::OnNewExtensions(const std::string& id, |
| 854 ExtensionInfo* info) { | 876 ExtensionInfo* info) { |
| 855 if (!is_off_the_record_) | 877 extension_info_[id] = linked_ptr<ExtensionInfo>(info); |
| 856 extension_info_[id] = linked_ptr<ExtensionInfo>(info); | |
| 857 } | 878 } |
| 858 | 879 |
| 859 void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) { | 880 void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) { |
| 860 CheckCurrentlyOnIOThread(); | 881 CheckCurrentlyOnIOThread(); |
| 861 if (is_off_the_record_) | |
| 862 return; | |
| 863 ExtensionInfoMap::iterator iter = extension_info_.find(id); | 882 ExtensionInfoMap::iterator iter = extension_info_.find(id); |
| 864 if (iter != extension_info_.end()) { | 883 if (iter != extension_info_.end()) { |
| 865 extension_info_.erase(iter); | 884 extension_info_.erase(iter); |
| 866 } else { | 885 } else { |
| 867 // NOTE: This can currently happen if we receive multiple unload | 886 // NOTE: This can currently happen if we receive multiple unload |
| 868 // notifications, e.g. setting incognito-enabled state for a | 887 // notifications, e.g. setting incognito-enabled state for a |
| 869 // disabled extension (e.g., via sync). See | 888 // disabled extension (e.g., via sync). See |
| 870 // http://code.google.com/p/chromium/issues/detail?id=50582 . | 889 // http://code.google.com/p/chromium/issues/detail?id=50582 . |
| 871 NOTREACHED() << id; | 890 NOTREACHED() << id; |
| 872 } | 891 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 const ExtensionList* extensions = | 988 const ExtensionList* extensions = |
| 970 profile->GetExtensionsService()->extensions(); | 989 profile->GetExtensionsService()->extensions(); |
| 971 for (ExtensionList::const_iterator iter = extensions->begin(); | 990 for (ExtensionList::const_iterator iter = extensions->begin(); |
| 972 iter != extensions->end(); ++iter) { | 991 iter != extensions->end(); ++iter) { |
| 973 extension_info_[(*iter)->id()] = | 992 extension_info_[(*iter)->id()] = |
| 974 linked_ptr<ChromeURLRequestContext::ExtensionInfo>( | 993 linked_ptr<ChromeURLRequestContext::ExtensionInfo>( |
| 975 new ChromeURLRequestContext::ExtensionInfo( | 994 new ChromeURLRequestContext::ExtensionInfo( |
| 976 (*iter)->name(), | 995 (*iter)->name(), |
| 977 (*iter)->path(), | 996 (*iter)->path(), |
| 978 (*iter)->default_locale(), | 997 (*iter)->default_locale(), |
| 998 (*iter)->incognito_split_mode(), |
| 979 (*iter)->web_extent(), | 999 (*iter)->web_extent(), |
| 980 (*iter)->GetEffectiveHostPermissions(), | 1000 (*iter)->GetEffectiveHostPermissions(), |
| 981 (*iter)->api_permissions())); | 1001 (*iter)->api_permissions())); |
| 982 } | 1002 } |
| 983 } | 1003 } |
| 984 | 1004 |
| 985 if (profile->GetUserScriptMaster()) | 1005 if (profile->GetUserScriptMaster()) |
| 986 user_script_dir_path_ = profile->GetUserScriptMaster()->user_script_dir(); | 1006 user_script_dir_path_ = profile->GetUserScriptMaster()->user_script_dir(); |
| 987 | 1007 |
| 988 ssl_config_service_ = profile->GetSSLConfigService(); | 1008 ssl_config_service_ = profile->GetSSLConfigService(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 prefs::kProxyAutoDetect)); | 1083 prefs::kProxyAutoDetect)); |
| 1064 | 1084 |
| 1065 if (pref_service->HasPrefPath(prefs::kProxyBypassList)) { | 1085 if (pref_service->HasPrefPath(prefs::kProxyBypassList)) { |
| 1066 std::string proxy_bypass = | 1086 std::string proxy_bypass = |
| 1067 pref_service->GetString(prefs::kProxyBypassList); | 1087 pref_service->GetString(prefs::kProxyBypassList); |
| 1068 proxy_config->proxy_rules().bypass_rules.ParseFromString(proxy_bypass); | 1088 proxy_config->proxy_rules().bypass_rules.ParseFromString(proxy_bypass); |
| 1069 } | 1089 } |
| 1070 | 1090 |
| 1071 return proxy_config; | 1091 return proxy_config; |
| 1072 } | 1092 } |
| OLD | NEW |