summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-28 23:04:27 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-28 23:04:27 +0000
commit0ce3f598543d7023bbd72397edf57c25a169e80d (patch)
tree60b4cb50e412fce82c396aae6e2373430247758e /chrome
parent0e4e115bb7fd55308c8bb244f1d690bb30fc8f9e (diff)
downloadchromium_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')
-rw-r--r--chrome/browser/extensions/extensions_service.cc7
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc86
-rw-r--r--chrome/browser/net/chrome_url_request_context.h297
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc13
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h3
-rw-r--r--chrome/common/render_messages_internal.h5
-rw-r--r--chrome/renderer/notification_provider.cc14
-rw-r--r--chrome/renderer/notification_provider.h2
8 files changed, 241 insertions, 186 deletions
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index a62799f..08b9707 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -455,8 +455,11 @@ void ExtensionsService::NotifyExtensionLoaded(Extension* extension) {
context_getter,
&ChromeURLRequestContextGetter::OnNewExtensions,
extension->id(),
- extension->path(),
- extension->default_locale()));
+ new ChromeURLRequestContext::ExtensionInfo(
+ extension->path(),
+ extension->default_locale(),
+ extension->app_origins(),
+ extension->api_permissions())));
}
}
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 7294359..9e5286a 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -515,9 +515,8 @@ void ChromeURLRequestContextGetter::CleanupOnUIThread() {
void ChromeURLRequestContextGetter::OnNewExtensions(
const std::string& id,
- const FilePath& path,
- const std::string default_locale) {
- GetIOContext()->OnNewExtensions(id, path, default_locale);
+ ChromeURLRequestContext::ExtensionInfo* info) {
+ GetIOContext()->OnNewExtensions(id, info);
}
void ChromeURLRequestContextGetter::OnUnloadedExtension(
@@ -654,24 +653,53 @@ ChromeURLRequestContext::~ChromeURLRequestContext() {
}
FilePath ChromeURLRequestContext::GetPathForExtension(const std::string& id) {
- ExtensionPaths::iterator iter = extension_paths_.find(id);
- if (iter != extension_paths_.end()) {
- return iter->second;
- } else {
+ ExtensionInfoMap::iterator iter = extension_info_.find(id);
+ if (iter != extension_info_.end())
+ return iter->second->path;
+ else
return FilePath();
- }
}
std::string ChromeURLRequestContext::GetDefaultLocaleForExtension(
const std::string& id) {
- ExtensionDefaultLocales::iterator iter = extension_default_locales_.find(id);
+ ExtensionInfoMap::iterator iter = extension_info_.find(id);
std::string result;
- if (iter != extension_default_locales_.end())
- result = iter->second;
+ if (iter != extension_info_.end())
+ result = iter->second->default_locale;
return result;
}
+bool ChromeURLRequestContext::CheckURLAccessToExtensionPermission(
+ const GURL& url,
+ const std::string& application_id,
+ const char* permission_name) {
+ DCHECK(!application_id.empty());
+
+ // Get the information about the specified extension. If the extension isn't
+ // installed, then permission is not granted.
+ ExtensionInfoMap::iterator info = extension_info_.find(application_id);
+ if (info == extension_info_.end())
+ return false;
+
+ // Check that the extension declares the required permission.
+ std::vector<std::string>& permissions = info->second->api_permissions;
+ if (permissions.end() == std::find(permissions.begin(), permissions.end(),
+ permission_name)) {
+ return false;
+ }
+
+ // Check that the extension declares the source URL in its extent.
+ std::vector<GURL>& origins = info->second->web_origins;
+ for (std::vector<GURL>::iterator origin = origins.begin();
+ origin != origins.end(); ++origin) {
+ if (url.GetOrigin() == *origin)
+ return true;
+ }
+
+ return false;
+}
+
const std::string& ChromeURLRequestContext::GetUserAgent(
const GURL& url) const {
return webkit_glue::GetUserAgent(url);
@@ -715,26 +743,19 @@ const Blacklist* ChromeURLRequestContext::GetPrivacyBlacklist() const {
return privacy_blacklist_;
}
-void ChromeURLRequestContext::OnNewExtensions(
- const std::string& id,
- const FilePath& path,
- const std::string& default_locale) {
- if (!is_off_the_record_) {
- extension_paths_[id] = path;
- if (!default_locale.empty())
- extension_default_locales_[id] = default_locale;
- }
+void ChromeURLRequestContext::OnNewExtensions(const std::string& id,
+ ExtensionInfo* info) {
+ if (!is_off_the_record_)
+ extension_info_[id] = linked_ptr<ExtensionInfo>(info);
}
void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) {
CheckCurrentlyOnIOThread();
if (is_off_the_record_)
return;
- ExtensionPaths::iterator iter = extension_paths_.find(id);
- DCHECK(iter != extension_paths_.end());
- extension_paths_.erase(iter);
-
- extension_default_locales_.erase(id);
+ ExtensionInfoMap::iterator iter = extension_info_.find(id);
+ DCHECK(iter != extension_info_.end());
+ extension_info_.erase(iter);
}
ChromeURLRequestContext::ChromeURLRequestContext(
@@ -755,7 +776,7 @@ ChromeURLRequestContext::ChromeURLRequestContext(
referrer_charset_ = other->referrer_charset_;
// Set ChromeURLRequestContext members
- extension_paths_ = other->extension_paths_;
+ extension_info_ = other->extension_info_;
user_script_dir_path_ = other->user_script_dir_path_;
appcache_service_ = other->appcache_service_;
host_zoom_map_ = other->host_zoom_map_;
@@ -848,9 +869,13 @@ ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile)
profile->GetExtensionsService()->extensions();
for (ExtensionList::const_iterator iter = extensions->begin();
iter != extensions->end(); ++iter) {
- extension_paths_[(*iter)->id()] = (*iter)->path();
- if (!(*iter)->default_locale().empty())
- extension_default_locales_[(*iter)->id()] = (*iter)->default_locale();
+ extension_info_[(*iter)->id()] =
+ linked_ptr<ChromeURLRequestContext::ExtensionInfo>(
+ new ChromeURLRequestContext::ExtensionInfo(
+ (*iter)->path(),
+ (*iter)->default_locale(),
+ (*iter)->app_origins(),
+ (*iter)->api_permissions()));
}
}
@@ -876,8 +901,7 @@ void ChromeURLRequestContextFactory::ApplyProfileParametersToContext(
context->set_accept_charset(accept_charset_);
context->set_referrer_charset(referrer_charset_);
context->set_cookie_policy_type(cookie_policy_type_);
- context->set_extension_paths(extension_paths_);
- context->set_extension_default_locales(extension_default_locales_);
+ context->set_extension_info(extension_info_);
context->set_user_script_dir_path(user_script_dir_path_);
context->set_host_zoom_map(host_zoom_map_);
context->set_privacy_blacklist(privacy_blacklist_);
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_;
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 4313dbd..a83bdba 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -56,6 +56,7 @@
#include "net/http/http_cache.h"
#include "net/http/http_transaction_factory.h"
#include "net/url_request/url_request_context.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h"
#include "webkit/glue/plugins/plugin_list.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/webplugin.h"
@@ -768,8 +769,16 @@ void ResourceMessageFilter::OnClipboardReadHTML(Clipboard::Buffer buffer,
#endif
void ResourceMessageFilter::OnCheckNotificationPermission(
- const GURL& source_origin, int* result) {
- *result = notification_prefs_->HasPermission(source_origin);
+ const GURL& source_url, const std::string& application_id, int* result) {
+ ChromeURLRequestContext* context = GetRequestContextForURL(source_url);
+ if (!application_id.empty() &&
+ context->CheckURLAccessToExtensionPermission(
+ source_url, application_id, Extension::kNotificationPermission)) {
+ *result = WebKit::WebNotificationPresenter::PermissionAllowed;
+ return;
+ }
+
+ *result = notification_prefs_->HasPermission(source_url);
}
void ResourceMessageFilter::OnGetMimeTypeFromExtension(
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index 7cd1251..7cc55658 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -210,7 +210,8 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
void OnClipboardFindPboardWriteString(const string16& text);
#endif
- void OnCheckNotificationPermission(const GURL& origin,
+ void OnCheckNotificationPermission(const GURL& source_url,
+ const std::string& application_id,
int* permission_level);
#if !defined(OS_MACOSX)
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index d243a21..696e5e9 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -1800,8 +1800,9 @@ IPC_BEGIN_MESSAGES(ViewHost)
IPC_MESSAGE_ROUTED2(ViewHostMsg_RequestNotificationPermission,
GURL /* origin */,
int /* callback_context */)
- IPC_SYNC_MESSAGE_ROUTED1_1(ViewHostMsg_CheckNotificationPermission,
- GURL /* origin */,
+ IPC_SYNC_MESSAGE_ROUTED2_1(ViewHostMsg_CheckNotificationPermission,
+ GURL /* source page */,
+ std::string /* application id */,
int /* permission_result */)
// Sent if the worker object has sent a ViewHostMsg_CreateDedicatedWorker
diff --git a/chrome/renderer/notification_provider.cc b/chrome/renderer/notification_provider.cc
index 4489951..0234675 100644
--- a/chrome/renderer/notification_provider.cc
+++ b/chrome/renderer/notification_provider.cc
@@ -4,18 +4,23 @@
#include "chrome/renderer/notification_provider.h"
+#include "base/string_util.h"
#include "base/task.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
#include "chrome/renderer/render_thread.h"
#include "chrome/renderer/render_view.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPermissionCallback.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
+using WebKit::WebDocument;
using WebKit::WebNotification;
using WebKit::WebNotificationPresenter;
using WebKit::WebNotificationPermissionCallback;
using WebKit::WebString;
+using WebKit::WebURL;
NotificationProvider::NotificationProvider(RenderView* view)
: view_(view) {
@@ -47,10 +52,13 @@ void NotificationProvider::objectDestroyed(
}
WebNotificationPresenter::Permission NotificationProvider::checkPermission(
- const WebString& origin) {
+ const WebURL& url, WebDocument* document) {
int permission;
- Send(new ViewHostMsg_CheckNotificationPermission(view_->routing_id(),
- GURL(origin), &permission));
+ Send(new ViewHostMsg_CheckNotificationPermission(
+ view_->routing_id(),
+ url,
+ document ? UTF16ToASCII(document->applicationID()) : "",
+ &permission));
return static_cast<WebNotificationPresenter::Permission>(permission);
}
diff --git a/chrome/renderer/notification_provider.h b/chrome/renderer/notification_provider.h
index 7c5ca71..85cda25 100644
--- a/chrome/renderer/notification_provider.h
+++ b/chrome/renderer/notification_provider.h
@@ -29,7 +29,7 @@ class NotificationProvider : public WebKit::WebNotificationPresenter {
virtual void cancel(const WebKit::WebNotification& proxy);
virtual void objectDestroyed(const WebKit::WebNotification& proxy);
virtual WebKit::WebNotificationPresenter::Permission checkPermission(
- const WebKit::WebString& origin);
+ const WebKit::WebURL& url, WebKit::WebDocument* document);
virtual void requestPermission(const WebKit::WebString& origin,
WebKit::WebNotificationPermissionCallback* callback);