• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "web/NotificationPresenterImpl.h"
33 
34 #include "core/dom/ExecutionContext.h"
35 #include "modules/notifications/Notification.h"
36 #include "platform/weborigin/SecurityOrigin.h"
37 #include "public/web/WebNotification.h"
38 #include "public/web/WebNotificationPermissionCallback.h"
39 #include "public/web/WebNotificationPresenter.h"
40 #include "public/web/WebSecurityOrigin.h"
41 
42 using namespace WebCore;
43 
44 namespace blink {
45 
46 class NotificationPermissionCallbackClient : public WebNotificationPermissionCallback {
47 public:
NotificationPermissionCallbackClient(WebNotificationPresenter * presenter,PassRefPtr<SecurityOrigin> securityOrigin,PassOwnPtr<NotificationPermissionCallback> callback)48     NotificationPermissionCallbackClient(WebNotificationPresenter* presenter, PassRefPtr<SecurityOrigin> securityOrigin, PassOwnPtr<NotificationPermissionCallback> callback)
49         : m_presenter(presenter)
50         , m_securityOrigin(securityOrigin)
51         , m_callback(callback)
52     {
53     }
54 
permissionRequestComplete()55     virtual void permissionRequestComplete()
56     {
57         if (m_callback)
58             m_callback->handleEvent(Notification::permissionString(static_cast<NotificationClient::Permission>(m_presenter->checkPermission(WebSecurityOrigin(m_securityOrigin)))));
59         delete this;
60     }
61 
62 private:
~NotificationPermissionCallbackClient()63     virtual ~NotificationPermissionCallbackClient() { }
64 
65     WebNotificationPresenter* m_presenter;
66     RefPtr<SecurityOrigin> m_securityOrigin;
67     OwnPtr<NotificationPermissionCallback> m_callback;
68 };
69 
initialize(WebNotificationPresenter * presenter)70 void NotificationPresenterImpl::initialize(WebNotificationPresenter* presenter)
71 {
72     m_presenter = presenter;
73 }
74 
isInitialized()75 bool NotificationPresenterImpl::isInitialized()
76 {
77     return !!m_presenter;
78 }
79 
show(Notification * notification)80 bool NotificationPresenterImpl::show(Notification* notification)
81 {
82     return m_presenter->show(notification);
83 }
84 
close(Notification * notification)85 void NotificationPresenterImpl::close(Notification* notification)
86 {
87     m_presenter->close(notification);
88 
89     // FIXME: Remove the duplicated call to cancel() when Chromium updated to override close() instead.
90     m_presenter->cancel(notification);
91 }
92 
notificationObjectDestroyed(Notification * notification)93 void NotificationPresenterImpl::notificationObjectDestroyed(Notification* notification)
94 {
95     m_presenter->objectDestroyed(notification);
96 }
97 
checkPermission(ExecutionContext * context)98 NotificationClient::Permission NotificationPresenterImpl::checkPermission(ExecutionContext* context)
99 {
100     int result = m_presenter->checkPermission(WebSecurityOrigin(context->securityOrigin()));
101     return static_cast<NotificationClient::Permission>(result);
102 }
103 
requestPermission(ExecutionContext * context,WTF::PassOwnPtr<NotificationPermissionCallback> callback)104 void NotificationPresenterImpl::requestPermission(ExecutionContext* context, WTF::PassOwnPtr<NotificationPermissionCallback> callback)
105 {
106     m_presenter->requestPermission(WebSecurityOrigin(context->securityOrigin()), new NotificationPermissionCallbackClient(m_presenter, context->securityOrigin(), callback));
107 }
108 
109 } // namespace blink
110