diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-01-06 14:44:00 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-01-06 14:44:00 +0100 |
commit | 40736c5763bf61337c8c14e16d8587db021a87d4 (patch) | |
tree | b17a9c00042ad89cb1308e2484491799aa14e9f8 /Source/WebKit2/UIProcess/Notifications | |
download | qtwebkit-40736c5763bf61337c8c14e16d8587db021a87d4.tar.gz |
Imported WebKit commit 2ea9d364d0f6efa8fa64acf19f451504c59be0e4 (http://svn.webkit.org/repository/webkit/trunk@104285)
Diffstat (limited to 'Source/WebKit2/UIProcess/Notifications')
11 files changed, 783 insertions, 0 deletions
diff --git a/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.cpp b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.cpp new file mode 100644 index 000000000..25d37da4b --- /dev/null +++ b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "NotificationPermissionRequest.h" + +#include "NotificationPermissionRequestManagerProxy.h" + +namespace WebKit { + +PassRefPtr<NotificationPermissionRequest> NotificationPermissionRequest::create(WebKit::NotificationPermissionRequestManagerProxy *manager, uint64_t notificationID) +{ + return adoptRef(new NotificationPermissionRequest(manager, notificationID)); +} + +NotificationPermissionRequest::NotificationPermissionRequest(NotificationPermissionRequestManagerProxy* manager, uint64_t notificationID) + : m_manager(manager) + , m_notificationID(notificationID) +{ +} + +void NotificationPermissionRequest::allow() +{ + if (!m_manager) + return; + + m_manager->didReceiveNotificationPermissionDecision(m_notificationID, true); + m_manager = 0; +} + +void NotificationPermissionRequest::deny() +{ + if (!m_manager) + return; + + m_manager->didReceiveNotificationPermissionDecision(m_notificationID, false); + m_manager = 0; +} + +void NotificationPermissionRequest::invalidate() +{ + m_manager = 0; +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.h b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.h new file mode 100644 index 000000000..24db98b0c --- /dev/null +++ b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequest.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef NotificationPermissionRequest_h +#define NotificationPermissionRequest_h + +#include "APIObject.h" +#include <wtf/PassRefPtr.h> + +namespace WebKit { + +class NotificationPermissionRequestManagerProxy; + +class NotificationPermissionRequest : public APIObject { +public: + static const Type APIType = TypeNotificationPermissionRequest; + + static PassRefPtr<NotificationPermissionRequest> create(NotificationPermissionRequestManagerProxy*, uint64_t notificationID); + + void allow(); + void deny(); + + void invalidate(); + +private: + NotificationPermissionRequest(NotificationPermissionRequestManagerProxy*, uint64_t notificationID); + + virtual Type type() const { return APIType; } + + NotificationPermissionRequestManagerProxy* m_manager; + uint64_t m_notificationID; +}; + +} // namespace WebKit + +#endif // NotificationPermissionRequestProxy_h diff --git a/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequestManagerProxy.cpp b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequestManagerProxy.cpp new file mode 100644 index 000000000..07922985e --- /dev/null +++ b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequestManagerProxy.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "NotificationPermissionRequestManagerProxy.h" + +#include "NotificationPermissionRequest.h" +#include "WebPageMessages.h" +#include "WebPageProxy.h" +#include "WebProcessProxy.h" + +namespace WebKit { + +NotificationPermissionRequestManagerProxy::NotificationPermissionRequestManagerProxy(WebPageProxy* page) + : m_page(page) +{ +} + +void NotificationPermissionRequestManagerProxy::invalidateRequests() +{ + PendingRequestMap::const_iterator it = m_pendingRequests.begin(); + PendingRequestMap::const_iterator end = m_pendingRequests.end(); + for (; it != end; ++it) + it->second->invalidate(); + + m_pendingRequests.clear(); +} + +PassRefPtr<NotificationPermissionRequest> NotificationPermissionRequestManagerProxy::createRequest(uint64_t notificationID) +{ + RefPtr<NotificationPermissionRequest> request = NotificationPermissionRequest::create(this, notificationID); + m_pendingRequests.add(notificationID, request.get()); + return request.release(); +} + +void NotificationPermissionRequestManagerProxy::didReceiveNotificationPermissionDecision(uint64_t notificationID, bool allow) +{ + if (!m_page->isValid()) + return; + + RefPtr<NotificationPermissionRequest> request = m_pendingRequests.take(notificationID); + if (!request) + return; + + m_page->process()->send(Messages::WebPage::DidReceiveNotificationPermissionDecision(notificationID, allow), m_page->pageID()); +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequestManagerProxy.h b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequestManagerProxy.h new file mode 100644 index 000000000..f6228e72a --- /dev/null +++ b/Source/WebKit2/UIProcess/Notifications/NotificationPermissionRequestManagerProxy.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef NotificationPermissionRequestManagerProxy_h +#define NotificationPermissionRequestManagerProxy_h + +#include "NotificationPermissionRequest.h" +#include <wtf/HashMap.h> +#include <wtf/RefPtr.h> + +namespace WebKit { + +class GeolocationPermissionRequestProxy; +class WebPageProxy; + +class NotificationPermissionRequestManagerProxy { +public: + explicit NotificationPermissionRequestManagerProxy(WebPageProxy*); + + void invalidateRequests(); + + // Create a request to be presented to the user. + PassRefPtr<NotificationPermissionRequest> createRequest(uint64_t notificationID); + + // Called by NotificationPermissionRequest when a decision is made by the user. + void didReceiveNotificationPermissionDecision(uint64_t notificationID, bool allow); + +private: + typedef HashMap<uint64_t, RefPtr<NotificationPermissionRequest> > PendingRequestMap; + PendingRequestMap m_pendingRequests; + WebPageProxy* m_page; +}; + +} // namespace WebKit + + +#endif // NotificationPermissionRequestManagerProxy_h diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotification.cpp b/Source/WebKit2/UIProcess/Notifications/WebNotification.cpp new file mode 100644 index 000000000..7bb74432c --- /dev/null +++ b/Source/WebKit2/UIProcess/Notifications/WebNotification.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebNotification.h" + +#include "ArgumentCoders.h" +#include "ArgumentDecoder.h" +#include "ArgumentEncoder.h" +#include "Arguments.h" + +namespace WebKit { + +WebNotification::WebNotification(const String& title, const String& body, const String& originIdentifier, uint64_t notificationID) + : m_title(title) + , m_body(body) + , m_origin(WebSecurityOrigin::create(originIdentifier)) + , m_notificationID(notificationID) +{ +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotification.h b/Source/WebKit2/UIProcess/Notifications/WebNotification.h new file mode 100644 index 000000000..0b89a0aab --- /dev/null +++ b/Source/WebKit2/UIProcess/Notifications/WebNotification.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebNotification_h +#define WebNotification_h + +#include "APIObject.h" +#include "WebSecurityOrigin.h" +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> +#include <wtf/text/WTFString.h> + +namespace CoreIPC { + +class ArgumentDecoder; +class ArgumentEncoder; + +} // namespace CoreIPC + +namespace WebKit { + +class WebNotification : public APIObject { +public: + static const Type APIType = TypeNotification; + + static PassRefPtr<WebNotification> create(const String& title, const String& body, const String& originIdentifier, uint64_t notificationID) + { + return adoptRef(new WebNotification(title, body, originIdentifier, notificationID)); + } + + const String& title() const { return m_title; } + const String& body() const { return m_body; } + WebSecurityOrigin* origin() const { return m_origin.get(); } + + uint64_t notificationID() const { return m_notificationID; } + +private: + WebNotification(const String& title, const String& body, const String& originIdentifier, uint64_t notificationID); + + virtual Type type() const { return APIType; } + + String m_title; + String m_body; + RefPtr<WebSecurityOrigin> m_origin; + uint64_t m_notificationID; +}; + +inline bool isNotificationIDValid(uint64_t id) +{ + // This check makes sure that the ID is not equal to values needed by + // HashMap for bucketing. + return id && id != static_cast<uint64_t>(-1); +} + +} // namespace WebKit + +#endif // WebNotification_h diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.cpp b/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.cpp new file mode 100644 index 000000000..7d7c045db --- /dev/null +++ b/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebNotificationManagerProxy.h" + +#include "ImmutableArray.h" +#include "WebContext.h" +#include "WebNotification.h" +#include "WebNotificationManagerMessages.h" +#include "WebPageProxy.h" +#include "WebSecurityOrigin.h" +#include <WebCore/NotificationContents.h> + +using namespace WTF; +using namespace WebCore; + +namespace WebKit { + +PassRefPtr<WebNotificationManagerProxy> WebNotificationManagerProxy::create(WebContext* context) +{ + return adoptRef(new WebNotificationManagerProxy(context)); +} + +WebNotificationManagerProxy::WebNotificationManagerProxy(WebContext* context) + : m_context(context) +{ +} + +void WebNotificationManagerProxy::invalidate() +{ + m_provider.removeNotificationManager(this); +} + +void WebNotificationManagerProxy::initializeProvider(const WKNotificationProvider *provider) +{ + m_provider.initialize(provider); +} + +void WebNotificationManagerProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments) +{ + didReceiveWebNotificationManagerProxyMessage(connection, messageID, arguments); +} + +void WebNotificationManagerProxy::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, OwnPtr<CoreIPC::ArgumentEncoder>& reply) +{ + didReceiveSyncWebNotificationManagerProxyMessage(connection, messageID, arguments, reply); +} + +void WebNotificationManagerProxy::show(WebPageProxy* page, const String& title, const String& body, const String& originIdentifier, uint64_t notificationID) +{ + if (!isNotificationIDValid(notificationID)) + return; + + m_provider.addNotificationManager(this); + + RefPtr<WebNotification> notification = WebNotification::create(title, body, originIdentifier, notificationID); + m_notifications.set(notificationID, notification); + m_provider.show(page, notification.get()); +} + +void WebNotificationManagerProxy::cancel(uint64_t notificationID) +{ + if (!isNotificationIDValid(notificationID)) + return; + + RefPtr<WebNotification> notification = m_notifications.get(notificationID); + if (!notification) + return; + + m_provider.addNotificationManager(this); + m_provider.cancel(notification.get()); +} + +void WebNotificationManagerProxy::didDestroyNotification(uint64_t notificationID) +{ + if (!isNotificationIDValid(notificationID)) + return; + + RefPtr<WebNotification> notification = m_notifications.take(notificationID); + if (!notification) + return; + + m_provider.didDestroyNotification(notification.get()); +} + +void WebNotificationManagerProxy::notificationPermissionLevel(const String& originIdentifier, uint64_t& permissionLevel) +{ + RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::create(originIdentifier); + permissionLevel = m_provider.policyForNotificationPermissionAtOrigin(origin.get()); +} + +void WebNotificationManagerProxy::providerDidShowNotification(uint64_t notificationID) +{ + if (!m_context) + return; + + m_context->sendToAllProcesses(Messages::WebNotificationManager::DidShowNotification(notificationID)); +} + +void WebNotificationManagerProxy::providerDidClickNotification(uint64_t notificationID) +{ + if (!m_context) + return; + + m_context->sendToAllProcesses(Messages::WebNotificationManager::DidClickNotification(notificationID)); +} + + +void WebNotificationManagerProxy::providerDidCloseNotifications(ImmutableArray* notificationIDs) +{ + if (!m_context) + return; + + size_t size = notificationIDs->size(); + + Vector<uint64_t> vectorNotificationIDs; + vectorNotificationIDs.reserveInitialCapacity(size); + + for (size_t i = 0; i < size; ++i) { + uint64_t notificationID = notificationIDs->at<WebUInt64>(i)->value(); + vectorNotificationIDs.append(notificationID); + } + + if (vectorNotificationIDs.size()) + m_context->sendToAllProcesses(Messages::WebNotificationManager::DidCloseNotifications(vectorNotificationIDs)); +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.h b/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.h new file mode 100644 index 000000000..1705abcf4 --- /dev/null +++ b/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebNotificationManagerProxy_h +#define WebNotificationManagerProxy_h + +#include "APIObject.h" +#include "MessageID.h" +#include "WebNotificationProvider.h" +#include <wtf/HashMap.h> +#include <wtf/OwnPtr.h> +#include <wtf/PassRefPtr.h> + +namespace CoreIPC { +class ArgumentDecoder; +class ArgumentEncoder; +class Connection; +} + +namespace WebKit { + +class ImmutableArray; +class WebContext; +class WebPageProxy; + +class WebNotificationManagerProxy : public APIObject { +public: + static const Type APIType = TypeNotificationManager; + + static PassRefPtr<WebNotificationManagerProxy> create(WebContext*); + + void invalidate(); + void clearContext() { m_context = 0; } + + void initializeProvider(const WKNotificationProvider*); + + void show(WebPageProxy*, const WTF::String& title, const WTF::String& body, const WTF::String& originIdentifier, uint64_t notificationID); + + void providerDidShowNotification(uint64_t notificationID); + void providerDidClickNotification(uint64_t notificationID); + void providerDidCloseNotifications(ImmutableArray* notificationIDs); + + void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*); + void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&); + +private: + explicit WebNotificationManagerProxy(WebContext*); + + virtual Type type() const { return APIType; } + + void didReceiveWebNotificationManagerProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*); + void didReceiveSyncWebNotificationManagerProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&); + + // Message handlers + void cancel(uint64_t notificationID); + void didDestroyNotification(uint64_t notificationID); + void notificationPermissionLevel(const WTF::String& originIdentifier, uint64_t& permissionLevel); + + typedef HashMap<uint64_t, RefPtr<WebNotification> > WebNotificationMap; + + WebContext* m_context; + WebNotificationProvider m_provider; + WebNotificationMap m_notifications; +}; + +} // namespace WebKit + +#endif // WebNotificationManagerProxy_h diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.messages.in b/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.messages.in new file mode 100644 index 000000000..04d1a01b1 --- /dev/null +++ b/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.messages.in @@ -0,0 +1,28 @@ +# Copyright (C) 2011 Apple Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +messages -> WebNotificationManagerProxy { + Cancel(uint64_t notificationID); + DidDestroyNotification(uint64_t notificationID); + + NotificationPermissionLevel(WTF::String originIdentifier) -> (uint64_t policy) +} diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.cpp b/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.cpp new file mode 100644 index 000000000..080aea666 --- /dev/null +++ b/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebNotificationProvider.h" + +#include "WKAPICast.h" +#include "WebNotification.h" +#include "WebNotificationManagerProxy.h" +#include "WebSecurityOrigin.h" + +namespace WebKit { + +void WebNotificationProvider::show(WebPageProxy* page, WebNotification* notification) +{ + if (!m_client.show) + return; + + m_client.show(toAPI(page), toAPI(notification), m_client.clientInfo); +} + +void WebNotificationProvider::cancel(WebNotification* notification) +{ + if (!m_client.cancel) + return; + + m_client.cancel(toAPI(notification), m_client.clientInfo); +} + +void WebNotificationProvider::didDestroyNotification(WebNotification* notification) +{ + if (!m_client.didDestroyNotification) + return; + + m_client.didDestroyNotification(toAPI(notification), m_client.clientInfo); +} + +int WebNotificationProvider::policyForNotificationPermissionAtOrigin(WebSecurityOrigin* origin) +{ + if (!m_client.policyForNotificationPermissionAtOrigin) + return INT_MIN; + + return m_client.policyForNotificationPermissionAtOrigin(toAPI(origin), m_client.clientInfo); +} + +void WebNotificationProvider::addNotificationManager(WebNotificationManagerProxy* manager) +{ + if (!m_client.addNotificationManager) + return; + + m_client.addNotificationManager(toAPI(manager), m_client.clientInfo); +} + +void WebNotificationProvider::removeNotificationManager(WebNotificationManagerProxy* manager) +{ + if (!m_client.removeNotificationManager) + return; + + m_client.removeNotificationManager(toAPI(manager), m_client.clientInfo); +} + +} // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.h b/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.h new file mode 100644 index 000000000..43d963919 --- /dev/null +++ b/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebNotificationProvider_h +#define WebNotificationProvider_h + +#include "APIClient.h" +#include "WKNotificationProvider.h" +#include <wtf/Forward.h> + +namespace WebKit { + +class WebNotification; +class WebNotificationManagerProxy; +class WebPageProxy; +class WebSecurityOrigin; + +class WebNotificationProvider : public APIClient<WKNotificationProvider, kWKNotificationProviderCurrentVersion> { +public: + void show(WebPageProxy*, WebNotification*); + void cancel(WebNotification*); + void didDestroyNotification(WebNotification*); + int policyForNotificationPermissionAtOrigin(WebSecurityOrigin*); + + void addNotificationManager(WebNotificationManagerProxy*); + void removeNotificationManager(WebNotificationManagerProxy*); +}; + +} // namespace WebKit + +#endif // WebNotificationProvider_h |