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 "DRTDesktopNotificationPresenter.h"
34 #include "DumpRenderTree.h"
35 #include "LayoutTestController.h"
36 #include <JavaScriptCore/JSStringRef.h>
37 #include <JavaScriptCore/JSStringRefBSTR.h>
38 #include <WebCore/NotificationPresenter.h>
40 DRTDesktopNotificationPresenter::DRTDesktopNotificationPresenter()
43 HRESULT STDMETHODCALLTYPE DRTDesktopNotificationPresenter::QueryInterface(REFIID riid, void** ppvObject)
46 if (IsEqualGUID(riid, IID_IUnknown))
47 *ppvObject = static_cast<DRTDesktopNotificationPresenter*>(this);
48 else if (IsEqualGUID(riid, IID_IWebDesktopNotificationsDelegate))
49 *ppvObject = static_cast<DRTDesktopNotificationPresenter*>(this);
57 ULONG STDMETHODCALLTYPE DRTDesktopNotificationPresenter::AddRef()
62 ULONG STDMETHODCALLTYPE DRTDesktopNotificationPresenter::Release()
64 ULONG newRef = --m_refCount;
71 HRESULT STDMETHODCALLTYPE DRTDesktopNotificationPresenter::showDesktopNotification(
72 /* [in] */ IWebDesktopNotification* notification)
74 BSTR title, text, url;
77 if (!notification->isHTML(&html) && html) {
78 notification->contentsURL(&url);
79 printf("DESKTOP NOTIFICATION: contents at %S\n", url ? url : L"");
81 notification->iconURL(&url);
82 notification->title(&title);
83 notification->text(&text);
84 printf("DESKTOP NOTIFICATION: icon %S, title %S, text %S\n",
90 // In this stub implementation, the notification is displayed immediately;
91 // we dispatch the display event to mimic that.
92 notification->notifyDisplay();
97 HRESULT STDMETHODCALLTYPE DRTDesktopNotificationPresenter::cancelDesktopNotification(
98 /* [in] */ IWebDesktopNotification* notification)
102 notification->isHTML(&html);
104 notification->contentsURL(&identifier);
106 notification->title(&identifier);
108 printf("DESKTOP NOTIFICATION CLOSED: %S\n", identifier ? identifier : L"");
109 notification->notifyClose(false);
114 HRESULT STDMETHODCALLTYPE DRTDesktopNotificationPresenter::notificationDestroyed(
115 /* [in] */ IWebDesktopNotification* notification)
117 // Since in these tests events happen immediately, we don't hold on to
118 // Notification pointers. So there's no cleanup to do.
122 HRESULT STDMETHODCALLTYPE DRTDesktopNotificationPresenter::checkNotificationPermission(
123 /* [in] */ BSTR origin,
124 /* [out, retval] */ int* result)
126 #if ENABLE(NOTIFICATIONS)
127 JSStringRef jsOrigin = JSStringCreateWithBSTR(origin);
128 bool allowed = ::gLayoutTestController->checkDesktopNotificationPermission(jsOrigin);
131 *result = WebCore::NotificationPresenter::PermissionAllowed;
133 *result = WebCore::NotificationPresenter::PermissionDenied;
135 JSStringRelease(jsOrigin);
140 HRESULT STDMETHODCALLTYPE DRTDesktopNotificationPresenter::requestNotificationPermission(
141 /* [in] */ BSTR origin)
143 printf("DESKTOP NOTIFICATION PERMISSION REQUESTED: %S\n", origin ? origin : L"");