diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-28 23:04:27 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-28 23:04:27 +0000 |
commit | 0ce3f598543d7023bbd72397edf57c25a169e80d (patch) | |
tree | 60b4cb50e412fce82c396aae6e2373430247758e /chrome/browser/net/chrome_url_request_context.h | |
parent | 0e4e115bb7fd55308c8bb244f1d690bb30fc8f9e (diff) | |
download | chromium_src-0ce3f598543d7023bbd72397edf57c25a169e80d.zip chromium_src-0ce3f598543d7023bbd72397edf57c25a169e80d.tar.gz chromium_src-0ce3f598543d7023bbd72397edf57c25a169e80d.tar.bz2 |
Enable apps to request the HTML5 notification permission.
Note: the big change to chrome_url_request_context.h was mostly to swap the order of ChromeURLRequestContext and ChromeURLRequestContextGetter so that the latter could reference an inner struct of the former.
BUG=32361
Review URL: http://codereview.chromium.org/545149
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37456 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/chrome_url_request_context.h')
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.h | 297 |
1 files changed, 153 insertions, 144 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 55ec9cc..3a3c1bb 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ #include "base/file_path.h" +#include "base/linked_ptr.h" #include "chrome/browser/host_zoom_map.h" #include "chrome/browser/net/url_request_context_getter.h" #include "chrome/common/appcache/chrome_appcache_service.h" @@ -25,121 +26,6 @@ class ChromeURLRequestContext; class ChromeURLRequestContextFactory; class IOThread; -// TODO(eroman): Cleanup the declaration order in this file -- it is all -// wonky to try and minimize awkward deltas. - -// A URLRequestContextGetter subclass used by the browser. This returns a -// subclass of URLRequestContext which can be used to store extra information -// about requests. -// -// Most methods are expected to be called on the UI thread, except for -// the destructor and GetURLRequestContext(). -class ChromeURLRequestContextGetter : public URLRequestContextGetter, - public NotificationObserver { - public: - // Constructs a ChromeURLRequestContextGetter that will use |factory| to - // create the ChromeURLRequestContext. If |profile| is non-NULL, then the - // ChromeURLRequestContextGetter will additionally watch the preferences for - // changes to charset/language and CleanupOnUIThread() will need to be - // called to unregister. - ChromeURLRequestContextGetter(Profile* profile, - ChromeURLRequestContextFactory* factory); - - // Note that GetURLRequestContext() can only be called from the IO - // thread (it will assert otherwise). GetCookieStore() however can - // be called from any thread. - // - // URLRequestContextGetter implementation. - virtual URLRequestContext* GetURLRequestContext(); - virtual net::CookieStore* GetCookieStore(); - - // Convenience overload of GetURLRequestContext() that returns a - // ChromeURLRequestContext* rather than a URLRequestContext*. - ChromeURLRequestContext* GetIOContext() { - return reinterpret_cast<ChromeURLRequestContext*>(GetURLRequestContext()); - } - - // Create an instance for use with an 'original' (non-OTR) profile. This is - // expected to get called on the UI thread. - static ChromeURLRequestContextGetter* CreateOriginal( - Profile* profile, const FilePath& cookie_store_path, - const FilePath& disk_cache_path, int cache_size); - - // Create an instance for an original profile for media. This is expected to - // get called on UI thread. This method takes a profile and reuses the - // 'original' URLRequestContext for common files. - static ChromeURLRequestContextGetter* CreateOriginalForMedia( - Profile* profile, const FilePath& disk_cache_path, int cache_size); - - // Create an instance for an original profile for extensions. This is expected - // to get called on UI thread. - static ChromeURLRequestContextGetter* CreateOriginalForExtensions( - Profile* profile, const FilePath& cookie_store_path); - - // Create an instance for use with an OTR profile. This is expected to get - // called on the UI thread. - static ChromeURLRequestContextGetter* CreateOffTheRecord(Profile* profile); - - // Create an instance of request context for OTR profile for extensions. - static ChromeURLRequestContextGetter* CreateOffTheRecordForExtensions( - Profile* profile); - - // Clean up UI thread resources. This is expected to get called on the UI - // thread before the instance is deleted on the IO thread. - void CleanupOnUIThread(); - - // These methods simply forward to the corresponding methods on - // ChromeURLRequestContext. - void OnNewExtensions(const std::string& id, - const FilePath& path, - const std::string default_locale); - void OnUnloadedExtension(const std::string& id); - - // NotificationObserver implementation. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - private: - // Must be called on the IO thread. - virtual ~ChromeURLRequestContextGetter(); - - // Registers an observer on |profile|'s preferences which will be used - // to update the context when the default language and charset change. - void RegisterPrefsObserver(Profile* profile); - - // Creates a request context for media resources from a regular request - // context. This helper method is called from CreateOriginalForMedia and - // CreateOffTheRecordForMedia. - static ChromeURLRequestContextGetter* CreateRequestContextForMedia( - Profile* profile, const FilePath& disk_cache_path, int cache_size, - bool off_the_record); - - // These methods simply forward to the corresponding method on - // ChromeURLRequestContext. - void OnAcceptLanguageChange(const std::string& accept_language); - void OnCookiePolicyChange(net::CookiePolicy::Type type); - void OnDefaultCharsetChange(const std::string& default_charset); - - // Saves the cookie store to |result| and signals |completion|. - void GetCookieStoreAsyncHelper(base::WaitableEvent* completion, - net::CookieStore** result); - - // Access only from the UI thread. - PrefService* prefs_; - - // Deferred logic for creating a ChromeURLRequestContext. - // Access only from the IO thread. - scoped_ptr<ChromeURLRequestContextFactory> factory_; - - // NULL if not yet initialized. Otherwise, it is the URLRequestContext - // instance that was lazilly created by GetURLRequestContext. - // Access only from the IO thread. - scoped_refptr<URLRequestContext> url_request_context_; - - DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter); -}; - // Subclass of URLRequestContext which can be used to store extra information // for requests. // @@ -147,8 +33,25 @@ class ChromeURLRequestContextGetter : public URLRequestContextGetter, // including the constructor and destructor. class ChromeURLRequestContext : public URLRequestContext { public: - typedef std::map<std::string, FilePath> ExtensionPaths; - typedef std::map<std::string, std::string> ExtensionDefaultLocales; + // Maintains some extension-related state we need on the IO thread. + // TODO(aa): It would be cool if the Extension objects in ExtensionsService + // could be immutable and ref-counted so that we could use them directly from + // both threads. There is only a small amount of mutable state in Extension. + struct ExtensionInfo { + ExtensionInfo(const FilePath& path, const std::string& default_locale, + const std::vector<GURL>& web_origins, + const std::vector<std::string>& api_permissions) + : path(path), default_locale(default_locale), + web_origins(web_origins), api_permissions(api_permissions) { + } + FilePath path; + std::string default_locale; + std::vector<GURL> web_origins; + std::vector<std::string> api_permissions; + }; + + // Map of extension info by extension id. + typedef std::map<std::string, linked_ptr<ExtensionInfo> > ExtensionInfoMap; ChromeURLRequestContext(); @@ -159,6 +62,14 @@ class ChromeURLRequestContext : public URLRequestContext { // locale. std::string GetDefaultLocaleForExtension(const std::string& id); + // Determine whether a URL has access to the specified extension permission. + // TODO(aa): This will eventually have to take an additional parameter: the + // ID of a specific extension to check, since |url| could show up in multiple + // extensions. + bool CheckURLAccessToExtensionPermission(const GURL& url, + const std::string& application_id, + const char* permission_name); + // Gets the path to the directory user scripts are stored in. FilePath user_script_dir_path() const { return user_script_dir_path_; @@ -176,13 +87,6 @@ class ChromeURLRequestContext : public URLRequestContext { bool is_media() const { return is_media_; } - const ExtensionPaths& extension_paths() const { - return extension_paths_; - } - - const ExtensionDefaultLocales& extension_default_locales() const { - return extension_default_locales_; - } virtual const std::string& GetUserAgent(const GURL& url) const; @@ -199,10 +103,11 @@ class ChromeURLRequestContext : public URLRequestContext { // Gets the Privacy Blacklist, if any for this context. const Blacklist* GetPrivacyBlacklist() const; - // Callback for when new extensions are loaded. - void OnNewExtensions(const std::string& id, - const FilePath& path, - const std::string& default_locale); + // Callback for when new extensions are loaded. Takes ownership of + // |extension_info|. + void OnNewExtensions( + const std::string& id, + ChromeURLRequestContext::ExtensionInfo* extension_info); // Callback for when an extension is unloaded. void OnUnloadedExtension(const std::string& id); @@ -229,6 +134,10 @@ class ChromeURLRequestContext : public URLRequestContext { void set_cookie_policy_type(net::CookiePolicy::Type type) { cookie_policy_.set_type(type); } + void set_extension_info( + const ChromeURLRequestContext::ExtensionInfoMap& info) { + extension_info_ = info; + } void set_transport_security_state( net::TransportSecurityState* state) { transport_security_state_ = state; @@ -260,12 +169,6 @@ class ChromeURLRequestContext : public URLRequestContext { void set_is_media(bool is_media) { is_media_ = is_media; } - void set_extension_paths(const ExtensionPaths& paths) { - extension_paths_ = paths; - } - void set_extension_default_locales(const ExtensionDefaultLocales& locales) { - extension_default_locales_ = locales; - } void set_host_zoom_map(HostZoomMap* host_zoom_map) { host_zoom_map_ = host_zoom_map; } @@ -284,14 +187,7 @@ class ChromeURLRequestContext : public URLRequestContext { void OnDefaultCharsetChange(const std::string& default_charset); protected: - // Maps extension IDs to paths on disk. This is initialized in the - // constructor and updated when extensions changed. - ExtensionPaths extension_paths_; - - // Maps extension IDs to default locales. This is initialized in the - // constructor and updated when extensions change. Only extensions that - // have default_locale set are inserted. - ExtensionDefaultLocales extension_default_locales_; + ExtensionInfoMap extension_info_; // Path to the directory user scripts are stored in. FilePath user_script_dir_path_; @@ -318,6 +214,118 @@ class ChromeURLRequestContext : public URLRequestContext { DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContext); }; +// A URLRequestContextGetter subclass used by the browser. This returns a +// subclass of URLRequestContext which can be used to store extra information +// about requests. +// +// Most methods are expected to be called on the UI thread, except for +// the destructor and GetURLRequestContext(). +class ChromeURLRequestContextGetter : public URLRequestContextGetter, + public NotificationObserver { + public: + // Constructs a ChromeURLRequestContextGetter that will use |factory| to + // create the ChromeURLRequestContext. If |profile| is non-NULL, then the + // ChromeURLRequestContextGetter will additionally watch the preferences for + // changes to charset/language and CleanupOnUIThread() will need to be + // called to unregister. + ChromeURLRequestContextGetter(Profile* profile, + ChromeURLRequestContextFactory* factory); + + // Note that GetURLRequestContext() can only be called from the IO + // thread (it will assert otherwise). GetCookieStore() however can + // be called from any thread. + // + // URLRequestContextGetter implementation. + virtual URLRequestContext* GetURLRequestContext(); + virtual net::CookieStore* GetCookieStore(); + + // Convenience overload of GetURLRequestContext() that returns a + // ChromeURLRequestContext* rather than a URLRequestContext*. + ChromeURLRequestContext* GetIOContext() { + return reinterpret_cast<ChromeURLRequestContext*>(GetURLRequestContext()); + } + + // Create an instance for use with an 'original' (non-OTR) profile. This is + // expected to get called on the UI thread. + static ChromeURLRequestContextGetter* CreateOriginal( + Profile* profile, const FilePath& cookie_store_path, + const FilePath& disk_cache_path, int cache_size); + + // Create an instance for an original profile for media. This is expected to + // get called on UI thread. This method takes a profile and reuses the + // 'original' URLRequestContext for common files. + static ChromeURLRequestContextGetter* CreateOriginalForMedia( + Profile* profile, const FilePath& disk_cache_path, int cache_size); + + // Create an instance for an original profile for extensions. This is expected + // to get called on UI thread. + static ChromeURLRequestContextGetter* CreateOriginalForExtensions( + Profile* profile, const FilePath& cookie_store_path); + + // Create an instance for use with an OTR profile. This is expected to get + // called on the UI thread. + static ChromeURLRequestContextGetter* CreateOffTheRecord(Profile* profile); + + // Create an instance of request context for OTR profile for extensions. + static ChromeURLRequestContextGetter* CreateOffTheRecordForExtensions( + Profile* profile); + + // Clean up UI thread resources. This is expected to get called on the UI + // thread before the instance is deleted on the IO thread. + void CleanupOnUIThread(); + + // These methods simply forward to the corresponding methods on + // ChromeURLRequestContext. Takes ownership of |extension_info|. + void OnNewExtensions( + const std::string& extension_id, + ChromeURLRequestContext::ExtensionInfo* extension_info); + void OnUnloadedExtension(const std::string& id); + + // NotificationObserver implementation. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + private: + // Must be called on the IO thread. + virtual ~ChromeURLRequestContextGetter(); + + // Registers an observer on |profile|'s preferences which will be used + // to update the context when the default language and charset change. + void RegisterPrefsObserver(Profile* profile); + + // Creates a request context for media resources from a regular request + // context. This helper method is called from CreateOriginalForMedia and + // CreateOffTheRecordForMedia. + static ChromeURLRequestContextGetter* CreateRequestContextForMedia( + Profile* profile, const FilePath& disk_cache_path, int cache_size, + bool off_the_record); + + // These methods simply forward to the corresponding method on + // ChromeURLRequestContext. + void OnAcceptLanguageChange(const std::string& accept_language); + void OnCookiePolicyChange(net::CookiePolicy::Type type); + void OnDefaultCharsetChange(const std::string& default_charset); + + // Saves the cookie store to |result| and signals |completion|. + void GetCookieStoreAsyncHelper(base::WaitableEvent* completion, + net::CookieStore** result); + + // Access only from the UI thread. + PrefService* prefs_; + + // Deferred logic for creating a ChromeURLRequestContext. + // Access only from the IO thread. + scoped_ptr<ChromeURLRequestContextFactory> factory_; + + // NULL if not yet initialized. Otherwise, it is the URLRequestContext + // instance that was lazilly created by GetURLRequestContext. + // Access only from the IO thread. + scoped_refptr<URLRequestContext> url_request_context_; + + DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter); +}; + // Base class for a ChromeURLRequestContext factory. This includes // the shared functionality like extracting the default language/charset // from a profile. @@ -351,8 +359,9 @@ class ChromeURLRequestContextFactory { std::string accept_charset_; std::string referrer_charset_; net::CookiePolicy::Type cookie_policy_type_; - ChromeURLRequestContext::ExtensionPaths extension_paths_; - ChromeURLRequestContext::ExtensionDefaultLocales extension_default_locales_; + ChromeURLRequestContext::ExtensionInfoMap extension_info_; + // TODO(aa): I think this can go away now as we no longer support standalone + // user scripts. FilePath user_script_dir_path_; scoped_refptr<HostZoomMap> host_zoom_map_; const Blacklist* privacy_blacklist_; |