| 1 | /* | 
|---|
| 2 | * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. | 
|---|
| 3 | * | 
|---|
| 4 | * Redistribution and use in source and binary forms, with or without | 
|---|
| 5 | * modification, are permitted provided that the following conditions | 
|---|
| 6 | * are met: | 
|---|
| 7 | * 1. Redistributions of source code must retain the above copyright | 
|---|
| 8 | *    notice, this list of conditions and the following disclaimer. | 
|---|
| 9 | * 2. Redistributions in binary form must reproduce the above copyright | 
|---|
| 10 | *    notice, this list of conditions and the following disclaimer in the | 
|---|
| 11 | *    documentation and/or other materials provided with the distribution. | 
|---|
| 12 | * | 
|---|
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | 
|---|
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | 
|---|
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 
|---|
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | 
|---|
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 
|---|
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 
|---|
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 
|---|
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 
|---|
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 
|---|
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 
|---|
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. | 
|---|
| 24 | */ | 
|---|
| 25 |  | 
|---|
| 26 | #pragma once | 
|---|
| 27 |  | 
|---|
| 28 | #include "APIObject.h" | 
|---|
| 29 | #include "MessageReceiver.h" | 
|---|
| 30 | #include "WebContextSupplement.h" | 
|---|
| 31 | #include <WebCore/NotificationClient.h> | 
|---|
| 32 | #include <wtf/HashMap.h> | 
|---|
| 33 | #include <wtf/text/StringHash.h> | 
|---|
| 34 |  | 
|---|
| 35 | namespace WebCore { | 
|---|
| 36 | enum class NotificationDirection : uint8_t; | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | namespace API { | 
|---|
| 40 | class Array; | 
|---|
| 41 | class NotificationProvider; | 
|---|
| 42 | class SecurityOrigin; | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | namespace WebKit { | 
|---|
| 46 |  | 
|---|
| 47 | class WebNotification; | 
|---|
| 48 | class WebPageProxy; | 
|---|
| 49 | class WebProcessPool; | 
|---|
| 50 |  | 
|---|
| 51 | class WebNotificationManagerProxy : public API::ObjectImpl<API::Object::Type::NotificationManager>, public WebContextSupplement { | 
|---|
| 52 | public: | 
|---|
| 53 |  | 
|---|
| 54 | static const char* supplementName(); | 
|---|
| 55 |  | 
|---|
| 56 | static Ref<WebNotificationManagerProxy> create(WebProcessPool*); | 
|---|
| 57 |  | 
|---|
| 58 | void setProvider(std::unique_ptr<API::NotificationProvider>&&); | 
|---|
| 59 | HashMap<String, bool> notificationPermissions(); | 
|---|
| 60 |  | 
|---|
| 61 | void show(WebPageProxy*, const String& title, const String& body, const String& iconURL, const String& tag, const String& lang, WebCore::NotificationDirection, const String& originString, uint64_t pageNotificationID); | 
|---|
| 62 | void cancel(WebPageProxy*, uint64_t pageNotificationID); | 
|---|
| 63 | void clearNotifications(WebPageProxy*); | 
|---|
| 64 | void clearNotifications(WebPageProxy*, const Vector<uint64_t>& pageNotificationIDs); | 
|---|
| 65 | void didDestroyNotification(WebPageProxy*, uint64_t pageNotificationID); | 
|---|
| 66 |  | 
|---|
| 67 | void providerDidShowNotification(uint64_t notificationID); | 
|---|
| 68 | void providerDidClickNotification(uint64_t notificationID); | 
|---|
| 69 | void providerDidCloseNotifications(API::Array* notificationIDs); | 
|---|
| 70 | void providerDidUpdateNotificationPolicy(const API::SecurityOrigin*, bool allowed); | 
|---|
| 71 | void providerDidRemoveNotificationPolicies(API::Array* origins); | 
|---|
| 72 |  | 
|---|
| 73 | uint64_t notificationLocalIDForTesting(WebNotification*); | 
|---|
| 74 |  | 
|---|
| 75 | using API::Object::ref; | 
|---|
| 76 | using API::Object::deref; | 
|---|
| 77 |  | 
|---|
| 78 | private: | 
|---|
| 79 | explicit WebNotificationManagerProxy(WebProcessPool*); | 
|---|
| 80 |  | 
|---|
| 81 | typedef bool (*NotificationFilterFunction)(uint64_t pageID, uint64_t pageNotificationID, uint64_t desiredPageID, const Vector<uint64_t>& desiredPageNotificationIDs); | 
|---|
| 82 | void clearNotifications(WebPageProxy*, const Vector<uint64_t>& pageNotificationIDs, NotificationFilterFunction); | 
|---|
| 83 |  | 
|---|
| 84 | // WebContextSupplement | 
|---|
| 85 | void processPoolDestroyed() override; | 
|---|
| 86 | void refWebContextSupplement() override; | 
|---|
| 87 | void derefWebContextSupplement() override; | 
|---|
| 88 |  | 
|---|
| 89 | std::unique_ptr<API::NotificationProvider> m_provider; | 
|---|
| 90 | // Pair comprised of web page ID and the web process's notification ID | 
|---|
| 91 | HashMap<uint64_t, std::pair<uint64_t, uint64_t>> m_globalNotificationMap; | 
|---|
| 92 | // Key pair comprised of web page ID and the web process's notification ID; value pair comprised of global notification ID, and notification object | 
|---|
| 93 | HashMap<std::pair<uint64_t, uint64_t>, std::pair<uint64_t, RefPtr<WebNotification>>> m_notifications; | 
|---|
| 94 | }; | 
|---|
| 95 |  | 
|---|
| 96 | } // namespace WebKit | 
|---|
| 97 |  | 
|---|