diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-24 00:21:26 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-24 00:21:26 +0000 |
commit | 828912619a537bf7a33a36c2441d922a7639bc9b (patch) | |
tree | 6c49122fa2a1d04ba8b3b65705bd6fbf23b3d34e /chrome/browser/net | |
parent | ed1ff5e175dbc151aa7999e2c7b79a82c8ff7052 (diff) | |
download | chromium_src-828912619a537bf7a33a36c2441d922a7639bc9b.zip chromium_src-828912619a537bf7a33a36c2441d922a7639bc9b.tar.gz chromium_src-828912619a537bf7a33a36c2441d922a7639bc9b.tar.bz2 |
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
Diffstat (limited to 'chrome/browser/net')
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 58 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.h | 13 |
2 files changed, 62 insertions, 9 deletions
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<ExtensionList>(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_); diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index ab62e60..7cd95f1 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/file_path.h" #include "chrome/common/net/cookie_monster_sqlite.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_service.h" @@ -19,6 +20,8 @@ class Profile; class ChromeURLRequestContext : public URLRequestContext, public NotificationObserver { public: + typedef std::map<std::string, FilePath> ExtensionPaths; + // Create an instance for use with an 'original' (non-OTR) profile. This is // expected to get called on the UI thread. static ChromeURLRequestContext* CreateOriginal( @@ -33,6 +36,9 @@ class ChromeURLRequestContext : public URLRequestContext, // thread before the instance is deleted on the IO thread. void CleanupOnUIThread(); + // Gets the path to the directory for the specified extension. + FilePath GetPathForExtension(const std::string& id); + private: // Private constructor, use the static factory methods instead. This is // expected to be called on the UI thread. @@ -49,9 +55,16 @@ class ChromeURLRequestContext : public URLRequestContext, // Callback for when the cookie policy changes. void OnCookiePolicyChange(net::CookiePolicy::Type type); + // Callback for when new extensions are loaded. + void OnNewExtensions(ExtensionPaths* new_paths); + // Destructor. virtual ~ChromeURLRequestContext(); + // Maps extension IDs to paths on disk. This is initialized in the + // construtor and updated when extensions changed. + ExtensionPaths extension_paths_; + scoped_ptr<SQLitePersistentCookieStore> cookie_db_; PrefService* prefs_; bool is_off_the_record_; |