OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
3 * Copyright (C) 2011, 2012 Apple Inc. 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 are | |
7 * met: | |
8 * | |
9 * * Redistributions of source code must retain the above copyright | |
10 * notice, this list of conditions and the following disclaimer. | |
11 * * Redistributions in binary form must reproduce the above | |
12 * copyright notice, this list of conditions and the following disclaimer | |
13 * in the documentation and/or other materials provided with the | |
14 * distribution. | |
15 * * Neither the name of Google Inc. nor the names of its | |
16 * contributors may be used to endorse or promote products derived from | |
17 * this software without specific prior written permission. | |
18 * | |
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
30 */ | |
31 | |
32 #ifndef NotificationCenter_h | |
33 #define NotificationCenter_h | |
34 | |
35 #if ENABLE(LEGACY_NOTIFICATIONS) | |
36 | |
37 #include "bindings/v8/ExceptionState.h" | |
38 #include "bindings/v8/ScriptWrappable.h" | |
39 #include "core/dom/ExceptionCode.h" | |
40 #include "core/dom/ExecutionContext.h" | |
41 #include "core/html/VoidCallback.h" | |
42 #include "heap/Handle.h" | |
43 #include "modules/notifications/WebKitNotification.h" | |
44 #include "platform/Supplementable.h" | |
45 #include "platform/Timer.h" | |
46 #include "wtf/OwnPtr.h" | |
47 #include "wtf/PassRefPtr.h" | |
48 #include "wtf/RefCounted.h" | |
49 #include "wtf/RefPtr.h" | |
50 | |
51 namespace WebCore { | |
52 | |
53 class NotificationClient; | |
54 class VoidCallback; | |
55 | |
56 // FIXME: oilpan: Change this to GarbageCollectedFinalized once we move ActiveDO
MObject to oilpan. | |
57 class NotificationCenter FINAL : public RefCountedWillBeGarbageCollectedFinalize
d<NotificationCenter>, public ScriptWrappable, public ActiveDOMObject { | |
58 public: | |
59 static PassRefPtrWillBeRawPtr<NotificationCenter> create(ExecutionContext*,
NotificationClient*); | |
60 | |
61 PassRefPtrWillBeRawPtr<WebKitNotification> createNotification(const String&
iconUrl, const String& title, const String& body, ExceptionState& exceptionState
) | |
62 { | |
63 if (!client()) { | |
64 exceptionState.throwDOMException(InvalidStateError, "The notificatio
n client is null."); | |
65 return nullptr; | |
66 } | |
67 return WebKitNotification::create(title, body, iconUrl, executionContext
(), exceptionState, this); | |
68 } | |
69 | |
70 NotificationClient* client() const { return m_client; } | |
71 | |
72 int checkPermission(); | |
73 void requestPermission(PassOwnPtr<VoidCallback> = nullptr); | |
74 | |
75 virtual void stop() OVERRIDE; | |
76 | |
77 void trace(Visitor*); | |
78 | |
79 private: | |
80 NotificationCenter(ExecutionContext*, NotificationClient*); | |
81 | |
82 class NotificationRequestCallback : public RefCountedWillBeGarbageCollectedF
inalized<NotificationRequestCallback> { | |
83 public: | |
84 static PassRefPtrWillBeRawPtr<NotificationRequestCallback> createAndStar
tTimer(NotificationCenter*, PassOwnPtr<VoidCallback>); | |
85 void startTimer(); | |
86 void timerFired(Timer<NotificationRequestCallback>*); | |
87 | |
88 void trace(Visitor*); | |
89 | |
90 private: | |
91 NotificationRequestCallback(NotificationCenter*, PassOwnPtr<VoidCallback
>); | |
92 | |
93 RefPtrWillBeMember<NotificationCenter> m_notificationCenter; | |
94 Timer<NotificationRequestCallback> m_timer; | |
95 OwnPtr<VoidCallback> m_callback; | |
96 }; | |
97 | |
98 void requestTimedOut(NotificationRequestCallback*); | |
99 | |
100 NotificationClient* m_client; | |
101 WillBeHeapHashSet<RefPtrWillBeMember<NotificationRequestCallback> > m_callba
cks; | |
102 }; | |
103 | |
104 // FIXME: oilpan: Move this to ThreadState.h. | |
105 template<> struct ThreadingTrait<NotificationCenter::NotificationRequestCallback
> { | |
106 static const ThreadAffinity Affinity = AnyThread; | |
107 }; | |
108 | |
109 } // namespace WebCore | |
110 | |
111 #endif // ENABLE(LEGACY_NOTIFICATIONS) | |
112 | |
113 #endif // NotificationCenter_h | |
OLD | NEW |