1 | /* |
2 | * Copyright (C) 2011, 2012, 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 "MessageReceiver.h" |
29 | #include "WebProcessSupplement.h" |
30 | #include <WebCore/NotificationClient.h> |
31 | #include <wtf/HashMap.h> |
32 | #include <wtf/Noncopyable.h> |
33 | #include <wtf/RefPtr.h> |
34 | #include <wtf/Vector.h> |
35 | #include <wtf/text/StringHash.h> |
36 | |
37 | namespace WebCore { |
38 | class Notification; |
39 | class SecurityOrigin; |
40 | } |
41 | |
42 | namespace WebKit { |
43 | |
44 | class WebPage; |
45 | class WebProcess; |
46 | |
47 | class WebNotificationManager : public WebProcessSupplement, public IPC::MessageReceiver { |
48 | WTF_MAKE_NONCOPYABLE(WebNotificationManager); |
49 | public: |
50 | explicit WebNotificationManager(WebProcess&); |
51 | ~WebNotificationManager(); |
52 | |
53 | static const char* supplementName(); |
54 | |
55 | bool show(WebCore::Notification*, WebPage*); |
56 | void cancel(WebCore::Notification*, WebPage*); |
57 | void clearNotifications(WebCore::ScriptExecutionContext*, WebPage*); |
58 | // This callback comes from WebCore, not messaged from the UI process. |
59 | void didDestroyNotification(WebCore::Notification*, WebPage*); |
60 | |
61 | void didUpdateNotificationDecision(const String& originString, bool allowed); |
62 | |
63 | // Looks in local cache for permission. If not found, returns DefaultDenied. |
64 | WebCore::NotificationClient::Permission policyForOrigin(WebCore::SecurityOrigin*) const; |
65 | |
66 | void removeAllPermissionsForTesting(); |
67 | uint64_t notificationIDForTesting(WebCore::Notification*); |
68 | |
69 | private: |
70 | // WebProcessSupplement |
71 | void initialize(const WebProcessCreationParameters&) override; |
72 | |
73 | // IPC::MessageReceiver |
74 | // Implemented in generated WebNotificationManagerMessageReceiver.cpp |
75 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
76 | |
77 | void didShowNotification(uint64_t notificationID); |
78 | void didClickNotification(uint64_t notificationID); |
79 | void didCloseNotifications(const Vector<uint64_t>& notificationIDs); |
80 | void didRemoveNotificationDecisions(const Vector<String>& originStrings); |
81 | |
82 | #if ENABLE(NOTIFICATIONS) |
83 | void removeNotificationFromContextMap(uint64_t notificationID, WebCore::Notification*); |
84 | #endif |
85 | |
86 | WebProcess& m_process; |
87 | |
88 | #if ENABLE(NOTIFICATIONS) |
89 | typedef HashMap<RefPtr<WebCore::Notification>, uint64_t> NotificationMap; |
90 | NotificationMap m_notificationMap; |
91 | |
92 | typedef HashMap<uint64_t, RefPtr<WebCore::Notification>> NotificationIDMap; |
93 | NotificationIDMap m_notificationIDMap; |
94 | |
95 | typedef HashMap<RefPtr<WebCore::ScriptExecutionContext>, Vector<uint64_t>> NotificationContextMap; |
96 | NotificationContextMap m_notificationContextMap; |
97 | |
98 | HashMap<String, bool> m_permissionsMap; |
99 | #endif |
100 | }; |
101 | |
102 | } // namespace WebKit |
103 | |