From 828912619a537bf7a33a36c2441d922a7639bc9b Mon Sep 17 00:00:00 2001 From: "aa@chromium.org" Date: Wed, 24 Dec 2008 00:21:26 +0000 Subject: Implement extension:// protocol. Review URL: http://codereview.chromium.org/15010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7462 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/net/chrome_url_request_context.cc | 58 ++++++++++++++++++++---- 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'chrome/browser/net/chrome_url_request_context.cc') diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index d5ce7fb..f68c2c1 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -8,6 +8,7 @@ #include "base/string_util.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_thread.h" +#include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/profile.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -72,15 +73,15 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( // static ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( Profile* profile) { - DCHECK(profile->IsOffTheRecord()); - ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); - - // Share the same proxy service as the original profile. This proxy - // service's lifespan is dependent on the lifespan of the original profile, - // which we reference (see above). - context->proxy_service_ = - profile->GetOriginalProfile()->GetRequestContext()->proxy_service(); - + DCHECK(profile->IsOffTheRecord()); + ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); + + // Share the same proxy service as the original profile. This proxy + // service's lifespan is dependent on the lifespan of the original profile, + // which we reference (see above). + context->proxy_service_ = + profile->GetOriginalProfile()->GetRequestContext()->proxy_service(); + context->http_transaction_factory_ = new net::HttpCache(context->proxy_service_, 0); context->cookie_store_ = new net::CookieMonster; @@ -103,8 +104,18 @@ ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) cookie_policy_.SetType(net::CookiePolicy::FromInt( prefs_->GetInteger(prefs::kCookieBehavior))); + const ExtensionList* extensions = + profile->GetExtensionsService()->extensions(); + for (ExtensionList::const_iterator iter = extensions->begin(); + iter != extensions->end(); ++iter) { + extension_paths_[(*iter)->id()] = (*iter)->path(); + } + prefs_->AddPrefObserver(prefs::kAcceptLanguages, this); prefs_->AddPrefObserver(prefs::kCookieBehavior, this); + + NotificationService::current()->AddObserver( + this, NOTIFY_EXTENSIONS_LOADED, NotificationService::AllSources()); } // NotificationObserver implementation. @@ -130,6 +141,18 @@ void ChromeURLRequestContext::Observe(NotificationType type, &ChromeURLRequestContext::OnCookiePolicyChange, type)); } + } else if (NOTIFY_EXTENSIONS_LOADED == type) { + ExtensionPaths* new_paths = new ExtensionPaths; + ExtensionList* extensions = Details(details).ptr(); + DCHECK(extensions); + for (ExtensionList::const_iterator iter = extensions->begin(); + iter != extensions->end(); ++iter) { + new_paths->insert(ExtensionPaths::value_type((*iter)->id(), + (*iter)->path())); + } + g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(this, &ChromeURLRequestContext::OnNewExtensions, + new_paths)); } else { NOTREACHED(); } @@ -140,6 +163,18 @@ void ChromeURLRequestContext::CleanupOnUIThread() { prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this); prefs_->RemovePrefObserver(prefs::kCookieBehavior, this); prefs_ = NULL; + + NotificationService::current()->RemoveObserver( + this, NOTIFY_EXTENSIONS_LOADED, NotificationService::AllSources()); +} + +FilePath ChromeURLRequestContext::GetPathForExtension(const std::string& id) { + ExtensionPaths::iterator iter = extension_paths_.find(id); + if (iter != extension_paths_.end()) { + return iter->second; + } else { + return FilePath(); + } } void ChromeURLRequestContext::OnAcceptLanguageChange(std::string accept_language) { @@ -154,6 +189,11 @@ void ChromeURLRequestContext::OnCookiePolicyChange(net::CookiePolicy::Type type) cookie_policy_.SetType(type); } +void ChromeURLRequestContext::OnNewExtensions(ExtensionPaths* new_paths) { + extension_paths_.insert(new_paths->begin(), new_paths->end()); + delete new_paths; +} + ChromeURLRequestContext::~ChromeURLRequestContext() { DCHECK(NULL == prefs_); -- cgit v1.1