1/* 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 24 * THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#ifndef NotificationManager_h 28#define NotificationManager_h 29 30#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 31#include "Notification.h" 32#include "NotificationClient.h" 33#include "NotificationPermissionCallback.h" 34#include "ScriptExecutionContext.h" 35#include "SecurityOrigin.h" 36#include "VoidCallback.h" 37#include <wtf/HashMap.h> 38#include <wtf/RefPtr.h> 39#include <wtf/Vector.h> 40 41namespace BlackBerry { 42namespace WebKit { 43class WebPagePrivate; 44 45class NotificationManager { 46public: 47 NotificationManager(WebPagePrivate*); 48 ~NotificationManager(); 49 50 bool show(WebCore::Notification*); 51 void cancel(WebCore::Notification*); 52 void clearNotifications(WebCore::ScriptExecutionContext*); 53 void notificationObjectDestroyed(WebCore::Notification*); 54#if ENABLE(LEGACY_NOTIFICATIONS) 55 void requestPermission(WebCore::ScriptExecutionContext*, PassRefPtr<WebCore::VoidCallback>); 56#endif 57#if ENABLE(NOTIFICATIONS) 58 void requestPermission(WebCore::ScriptExecutionContext*, PassRefPtr<WebCore::NotificationPermissionCallback>); 59#endif 60 void cancelRequestsForPermission(WebCore::ScriptExecutionContext*); 61 WebCore::NotificationClient::Permission checkPermission(WebCore::ScriptExecutionContext*); 62 63 void updatePermission(const String& requestID, bool allowed); 64 65 void notificationClicked(const String& notificationID); 66 void notificationClosed(const String& notificationID); 67 void notificationError(const String& notificationID); 68 void notificationShown(const String& notificationID); 69 70private: 71 void removeNotificationFromContextMap(const String& notificationID, WebCore::Notification*); 72 73 WebPagePrivate* m_webPagePrivate; 74 typedef HashMap<RefPtr<WebCore::Notification>, String> NotificationMap; 75 NotificationMap m_notificationMap; 76 77 typedef HashMap<String, RefPtr<WebCore::Notification> > NotificationIdMap; 78 NotificationIdMap m_notificationIDMap; 79 80 typedef HashMap<RefPtr<WebCore::ScriptExecutionContext>, Vector<String> > NotificationContextMap; 81 NotificationContextMap m_notificationContextMap; 82 83#if ENABLE(NOTIFICATIONS) 84 typedef HashMap<String, RefPtr<WebCore::NotificationPermissionCallback> > PermissionCallbackMap; 85 PermissionCallbackMap m_idToCallbackMap; 86#endif 87#if ENABLE(LEGACY_NOTIFICATIONS) 88 typedef HashMap<String, RefPtr<WebCore::VoidCallback> > VoidCallbackMap; 89 VoidCallbackMap m_idToVoidCallbackMap; 90#endif 91 typedef HashMap<RefPtr<WebCore::SecurityOrigin>, String> OriginMap; 92 OriginMap m_originToIDMap; 93 94 typedef HashMap<String, RefPtr<WebCore::SecurityOrigin> > OriginIdMap; 95 OriginIdMap m_idToOriginMap; 96}; 97 98} 99} 100 101#endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 102#endif // NotificationManager_h 103