2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "NotificationPresenterImpl.h"
34 #if ENABLE(NOTIFICATIONS)
37 #include "Notification.h"
38 #include "ScriptExecutionContext.h"
39 #include "SecurityOrigin.h"
41 #include "WebNotification.h"
42 #include "WebNotificationPermissionCallback.h"
43 #include "WebNotificationPresenter.h"
46 #include <wtf/PassRefPtr.h>
48 using namespace WebCore;
52 class VoidCallbackClient : public WebNotificationPermissionCallback {
54 VoidCallbackClient(PassRefPtr<VoidCallback> callback)
55 : m_callback(callback)
59 virtual void permissionRequestComplete()
62 m_callback->handleEvent();
67 virtual ~VoidCallbackClient() { }
69 RefPtr<VoidCallback> m_callback;
72 void NotificationPresenterImpl::initialize(WebNotificationPresenter* presenter)
74 m_presenter = presenter;
77 bool NotificationPresenterImpl::isInitialized()
82 bool NotificationPresenterImpl::show(Notification* notification)
84 return m_presenter->show(PassRefPtr<Notification>(notification));
87 void NotificationPresenterImpl::cancel(Notification* notification)
89 m_presenter->cancel(PassRefPtr<Notification>(notification));
92 void NotificationPresenterImpl::notificationObjectDestroyed(Notification* notification)
94 m_presenter->objectDestroyed(PassRefPtr<Notification>(notification));
97 NotificationPresenter::Permission NotificationPresenterImpl::checkPermission(ScriptExecutionContext* context)
99 int result = m_presenter->checkPermission(WebSecurityOrigin(context->securityOrigin()));
100 return static_cast<NotificationPresenter::Permission>(result);
103 void NotificationPresenterImpl::requestPermission(ScriptExecutionContext* context, PassRefPtr<VoidCallback> callback)
105 m_presenter->requestPermission(WebSecurityOrigin(context->securityOrigin()), new VoidCallbackClient(callback));
108 } // namespace WebKit
110 #endif // ENABLE(NOTIFICATIONS)