NotificationManager.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifndef NotificationManager_h
  27. #define NotificationManager_h
  28. #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
  29. #include "Notification.h"
  30. #include "NotificationClient.h"
  31. #include "NotificationPermissionCallback.h"
  32. #include "ScriptExecutionContext.h"
  33. #include "SecurityOrigin.h"
  34. #include "VoidCallback.h"
  35. #include <wtf/HashMap.h>
  36. #include <wtf/RefPtr.h>
  37. #include <wtf/Vector.h>
  38. namespace BlackBerry {
  39. namespace WebKit {
  40. class WebPagePrivate;
  41. class NotificationManager {
  42. public:
  43. NotificationManager(WebPagePrivate*);
  44. ~NotificationManager();
  45. bool show(WebCore::Notification*);
  46. void cancel(WebCore::Notification*);
  47. void clearNotifications(WebCore::ScriptExecutionContext*);
  48. void notificationObjectDestroyed(WebCore::Notification*);
  49. #if ENABLE(LEGACY_NOTIFICATIONS)
  50. void requestPermission(WebCore::ScriptExecutionContext*, PassRefPtr<WebCore::VoidCallback>);
  51. #endif
  52. #if ENABLE(NOTIFICATIONS)
  53. void requestPermission(WebCore::ScriptExecutionContext*, PassRefPtr<WebCore::NotificationPermissionCallback>);
  54. #endif
  55. void cancelRequestsForPermission(WebCore::ScriptExecutionContext*);
  56. WebCore::NotificationClient::Permission checkPermission(WebCore::ScriptExecutionContext*);
  57. void updatePermission(const String& requestID, bool allowed);
  58. void notificationClicked(const String& notificationID);
  59. void notificationClosed(const String& notificationID);
  60. void notificationError(const String& notificationID);
  61. void notificationShown(const String& notificationID);
  62. private:
  63. void removeNotificationFromContextMap(const String& notificationID, WebCore::Notification*);
  64. WebPagePrivate* m_webPagePrivate;
  65. typedef HashMap<RefPtr<WebCore::Notification>, String> NotificationMap;
  66. NotificationMap m_notificationMap;
  67. typedef HashMap<String, RefPtr<WebCore::Notification> > NotificationIdMap;
  68. NotificationIdMap m_notificationIDMap;
  69. typedef HashMap<RefPtr<WebCore::ScriptExecutionContext>, Vector<String> > NotificationContextMap;
  70. NotificationContextMap m_notificationContextMap;
  71. #if ENABLE(NOTIFICATIONS)
  72. typedef HashMap<String, RefPtr<WebCore::NotificationPermissionCallback> > PermissionCallbackMap;
  73. PermissionCallbackMap m_idToCallbackMap;
  74. #endif
  75. #if ENABLE(LEGACY_NOTIFICATIONS)
  76. typedef HashMap<String, RefPtr<WebCore::VoidCallback> > VoidCallbackMap;
  77. VoidCallbackMap m_idToVoidCallbackMap;
  78. #endif
  79. typedef HashMap<RefPtr<WebCore::SecurityOrigin>, String> OriginMap;
  80. OriginMap m_originToIDMap;
  81. typedef HashMap<String, RefPtr<WebCore::SecurityOrigin> > OriginIdMap;
  82. OriginIdMap m_idToOriginMap;
  83. };
  84. }
  85. }
  86. #endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
  87. #endif // NotificationManager_h