summaryrefslogtreecommitdiff
path: root/Source/WebKit2/WebProcess/Notifications
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/WebProcess/Notifications')
-rw-r--r--Source/WebKit2/WebProcess/Notifications/NotificationPermissionRequestManager.cpp16
-rw-r--r--Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp45
-rw-r--r--Source/WebKit2/WebProcess/Notifications/WebNotificationManager.h12
-rw-r--r--Source/WebKit2/WebProcess/Notifications/WebNotificationManager.messages.in2
4 files changed, 66 insertions, 9 deletions
diff --git a/Source/WebKit2/WebProcess/Notifications/NotificationPermissionRequestManager.cpp b/Source/WebKit2/WebProcess/Notifications/NotificationPermissionRequestManager.cpp
index 3eeaa5022..7d662f12d 100644
--- a/Source/WebKit2/WebProcess/Notifications/NotificationPermissionRequestManager.cpp
+++ b/Source/WebKit2/WebProcess/Notifications/NotificationPermissionRequestManager.cpp
@@ -32,8 +32,10 @@
#include "WebPageProxyMessages.h"
#include "WebProcess.h"
#include <WebCore/Notification.h>
+#include <WebCore/Page.h>
#include <WebCore/ScriptExecutionContext.h>
#include <WebCore/SecurityOrigin.h>
+#include <WebCore/Settings.h>
using namespace WebCore;
@@ -60,11 +62,14 @@ NotificationPermissionRequestManager::NotificationPermissionRequestManager(WebPa
void NotificationPermissionRequestManager::startRequest(SecurityOrigin* origin, PassRefPtr<VoidCallback> callback)
{
#if ENABLE(NOTIFICATIONS)
+ if (permissionLevel(origin) != NotificationPresenter::PermissionNotAllowed)
+ return;
+
uint64_t requestID = generateRequestID();
m_originToIDMap.set(origin, requestID);
m_idToOriginMap.set(requestID, origin);
m_idToCallbackMap.set(requestID, callback);
- m_page->send(Messages::WebPageProxy::RequestNotificationPermission(requestID, origin->databaseIdentifier()));
+ m_page->send(Messages::WebPageProxy::RequestNotificationPermission(requestID, origin->toString()));
#else
UNUSED_PARAM(origin);
UNUSED_PARAM(callback);
@@ -88,11 +93,10 @@ void NotificationPermissionRequestManager::cancelRequest(SecurityOrigin* origin)
NotificationPresenter::Permission NotificationPermissionRequestManager::permissionLevel(SecurityOrigin* securityOrigin)
{
#if ENABLE(NOTIFICATIONS)
- uint64_t permissionLevel;
- WebProcess::shared().connection()->sendSync(Messages::WebNotificationManagerProxy::NotificationPermissionLevel(securityOrigin->databaseIdentifier()),
- Messages::WebNotificationManagerProxy::NotificationPermissionLevel::Reply(permissionLevel),
- 0);
- return static_cast<NotificationPresenter::Permission>(permissionLevel);
+ if (!m_page->corePage()->settings()->notificationsEnabled())
+ return NotificationPresenter::PermissionDenied;
+
+ return WebProcess::shared().notificationManager().policyForOrigin(securityOrigin);
#else
UNUSED_PARAM(securityOrigin);
return NotificationPresenter::PermissionDenied;
diff --git a/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp b/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp
index dfc30f5f3..0c865292d 100644
--- a/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp
+++ b/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp
@@ -34,8 +34,10 @@
#include "WebNotificationManagerProxyMessages.h"
#include "WebPageProxyMessages.h"
#include <WebCore/Notification.h>
+#include <WebCore/Page.h>
#include <WebCore/ScriptExecutionContext.h>
#include <WebCore/SecurityOrigin.h>
+#include <WebCore/Settings.h>
#endif
using namespace WebCore;
@@ -64,17 +66,54 @@ void WebNotificationManager::didReceiveMessage(CoreIPC::Connection* connection,
didReceiveWebNotificationManagerMessage(connection, messageID, arguments);
}
+void WebNotificationManager::initialize(const HashMap<String, bool>& permissions)
+{
+#if ENABLE(NOTIFICATIONS)
+ m_permissionsMap = permissions;
+#endif
+}
+
+void WebNotificationManager::didUpdateNotificationDecision(const String& originString, bool allowed)
+{
+#if ENABLE(NOTIFICATIONS)
+ m_permissionsMap.set(originString, allowed);
+#endif
+}
+
+void WebNotificationManager::didRemoveNotificationDecisions(const Vector<String>& originStrings)
+{
+#if ENABLE(NOTIFICATIONS)
+ size_t count = originStrings.size();
+ for (size_t i = 0; i < count; ++i)
+ m_permissionsMap.remove(originStrings[i]);
+#endif
+}
+
+NotificationPresenter::Permission WebNotificationManager::policyForOrigin(WebCore::SecurityOrigin *origin) const
+{
+#if ENABLE(NOTIFICATIONS)
+ if (!origin)
+ return NotificationPresenter::PermissionNotAllowed;
+
+ HashMap<String, bool>::const_iterator it = m_permissionsMap.find(origin->toString());
+ if (it != m_permissionsMap.end())
+ return it->second ? NotificationPresenter::PermissionAllowed : NotificationPresenter::PermissionDenied;
+#endif
+
+ return NotificationPresenter::PermissionNotAllowed;
+}
+
bool WebNotificationManager::show(Notification* notification, WebPage* page)
{
#if ENABLE(NOTIFICATIONS)
- if (!notification)
+ if (!notification || !page->corePage()->settings()->notificationsEnabled())
return true;
uint64_t notificationID = generateNotificationID();
m_notificationMap.set(notification, notificationID);
m_notificationIDMap.set(notificationID, notification);
- m_process->connection()->send(Messages::WebPageProxy::ShowNotification(notification->contents().title, notification->contents().body, notification->scriptExecutionContext()->securityOrigin()->databaseIdentifier(), notificationID), page->pageID());
+ m_process->connection()->send(Messages::WebPageProxy::ShowNotification(notification->contents().title, notification->contents().body, notification->scriptExecutionContext()->securityOrigin()->toString(), notificationID), page->pageID());
#endif
return true;
}
@@ -82,7 +121,7 @@ bool WebNotificationManager::show(Notification* notification, WebPage* page)
void WebNotificationManager::cancel(Notification* notification, WebPage* page)
{
#if ENABLE(NOTIFICATIONS)
- if (!notification)
+ if (!notification || !page->corePage()->settings()->notificationsEnabled())
return;
uint64_t notificationID = m_notificationMap.get(notification);
diff --git a/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.h b/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.h
index 3b32f0ade..61507394c 100644
--- a/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.h
+++ b/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.h
@@ -27,10 +27,12 @@
#define WebNotificationManager_h
#include "MessageID.h"
+#include <WebCore/NotificationPresenter.h>
#include <wtf/HashMap.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
+#include <wtf/text/StringHash.h>
namespace CoreIPC {
class ArgumentDecoder;
@@ -39,6 +41,7 @@ class Connection;
namespace WebCore {
class Notification;
+class SecurityOrigin;
}
namespace WebKit {
@@ -52,12 +55,17 @@ public:
explicit WebNotificationManager(WebProcess*);
~WebNotificationManager();
+ void initialize(const HashMap<String, bool>& permissions);
+
bool show(WebCore::Notification*, WebPage*);
void cancel(WebCore::Notification*, WebPage*);
// This callback comes from WebCore, not messaged from the UI process.
void didDestroyNotification(WebCore::Notification*, WebPage*);
void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
+
+ // Looks in local cache for permission. If not found, returns DefaultDenied.
+ WebCore::NotificationPresenter::Permission policyForOrigin(WebCore::SecurityOrigin*) const;
private:
// Implemented in generated WebNotificationManagerMessageReceiver.cpp
@@ -66,6 +74,8 @@ private:
void didShowNotification(uint64_t notificationID);
void didClickNotification(uint64_t notificationID);
void didCloseNotifications(const Vector<uint64_t>& notificationIDs);
+ void didUpdateNotificationDecision(const String& originString, bool allowed);
+ void didRemoveNotificationDecisions(const Vector<String>& originStrings);
WebProcess* m_process;
@@ -75,6 +85,8 @@ private:
typedef HashMap<uint64_t, RefPtr<WebCore::Notification> > NotificationIDMap;
NotificationIDMap m_notificationIDMap;
+
+ HashMap<String, bool> m_permissionsMap;
#endif
};
diff --git a/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.messages.in b/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.messages.in
index 13d97ff7a..b88f26c9e 100644
--- a/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.messages.in
+++ b/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.messages.in
@@ -24,4 +24,6 @@ messages -> WebNotificationManager {
DidShowNotification(uint64_t notificationID);
DidClickNotification(uint64_t notificationID);
DidCloseNotifications(Vector<uint64_t> notificationIDs);
+ DidUpdateNotificationDecision(WTF::String originString, bool allowed);
+ DidRemoveNotificationDecisions(Vector<WTF::String> originStrings);
}