OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 Google 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 are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "NotificationPresenterImpl.h" | |
33 | |
34 #if ENABLE(NOTIFICATIONS) | |
35 | |
36 #include "Notification.h" | |
37 #include "SecurityOrigin.h" | |
38 | |
39 #include "WebNotification.h" | |
40 #include "WebNotificationPermissionCallback.h" | |
41 #include "WebNotificationPresenter.h" | |
42 | |
43 #include <wtf/PassRefPtr.h> | |
44 | |
45 using namespace WebCore; | |
46 | |
47 namespace WebKit { | |
48 | |
49 class VoidCallbackClient : public WebNotificationPermissionCallback { | |
50 public: | |
51 VoidCallbackClient(PassRefPtr<VoidCallback> callback) | |
52 : m_callback(callback) | |
53 { | |
54 } | |
55 | |
56 virtual void permissionRequestComplete() | |
57 { | |
58 if (m_callback) | |
59 m_callback->handleEvent(); | |
60 delete this; | |
61 } | |
62 | |
63 private: | |
64 RefPtr<VoidCallback> m_callback; | |
65 }; | |
66 | |
67 void NotificationPresenterImpl::initialize(WebNotificationPresenter* presenter) | |
68 { | |
69 m_presenter = presenter; | |
70 } | |
71 | |
72 bool NotificationPresenterImpl::isInitialized() | |
73 { | |
74 return !!m_presenter; | |
75 } | |
76 | |
77 bool NotificationPresenterImpl::show(Notification* notification) | |
78 { | |
79 return m_presenter->show(PassRefPtr<Notification>(notification)); | |
80 } | |
81 | |
82 void NotificationPresenterImpl::cancel(Notification* notification) | |
83 { | |
84 m_presenter->cancel(PassRefPtr<Notification>(notification)); | |
85 } | |
86 | |
87 void NotificationPresenterImpl::notificationObjectDestroyed(Notification* notification) | |
88 { | |
89 m_presenter->objectDestroyed(PassRefPtr<Notification>(notification)); | |
90 } | |
91 | |
92 NotificationPresenter::Permission NotificationPresenterImpl::checkPermission(SecurityOrigin* origin) | |
93 { | |
94 int result = m_presenter->checkPermission(origin->toString()); | |
95 return static_cast<NotificationPresenter::Permission>(result); | |
96 } | |
97 | |
98 void NotificationPresenterImpl::requestPermission(SecurityOrigin* origin, PassRefPtr<VoidCallback> callback) | |
99 { | |
100 m_presenter->requestPermission(origin->toString(), new VoidCallbackClient(callback)); | |
101 } | |
102 | |
103 } // namespace WebKit | |
104 | |
105 #endif // ENABLE(NOTIFICATIONS) | |
OLD | NEW |