blob: 26b112ebfa01826155a40f11048b461ab4a2645d [file] [log] [blame]
jonlee@apple.com793d5142012-02-22 00:00:59 +00001/*
mjs@apple.com92047332014-03-15 04:08:27 +00002 * Copyright (C) 2012 Apple Inc. All rights reserved.
jonlee@apple.com793d5142012-02-22 00:00:59 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
mjs@apple.com92047332014-03-15 04:08:27 +000013 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
jonlee@apple.com793d5142012-02-22 00:00:59 +000014 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#import "WebNotification.h"
30
31#import "WebNotificationInternal.h"
jonlee@apple.comc92fdea2012-02-22 02:35:55 +000032
weinig@apple.com1d7fe202017-05-11 00:29:37 +000033#if ENABLE(NOTIFICATIONS)
jonlee@apple.com793d5142012-02-22 00:00:59 +000034#import "WebSecurityOriginInternal.h"
35#import <WebCore/Notification.h>
36#import <WebCore/ScriptExecutionContext.h>
jonlee@apple.com793d5142012-02-22 00:00:59 +000037#import <wtf/RefPtr.h>
38
39using namespace WebCore;
jonlee@apple.comc92fdea2012-02-22 02:35:55 +000040#endif
jonlee@apple.com793d5142012-02-22 00:00:59 +000041
jonlee@apple.com793d5142012-02-22 00:00:59 +000042@interface WebNotificationPrivate : NSObject
43{
44@public
weinig@apple.com1d7fe202017-05-11 00:29:37 +000045#if ENABLE(NOTIFICATIONS)
jonlee@apple.combb6499f2012-02-22 01:01:31 +000046 RefPtr<Notification> _internal;
jonlee@apple.com793d5142012-02-22 00:00:59 +000047 uint64_t _notificationID;
jonlee@apple.comc92fdea2012-02-22 02:35:55 +000048#endif
jonlee@apple.com793d5142012-02-22 00:00:59 +000049}
50@end
51
52@implementation WebNotificationPrivate
53@end
54
weinig@apple.com1d7fe202017-05-11 00:29:37 +000055#if ENABLE(NOTIFICATIONS)
jonlee@apple.com793d5142012-02-22 00:00:59 +000056@implementation WebNotification (WebNotificationInternal)
weinig@apple.com1d7fe202017-05-11 00:29:37 +000057
jonlee@apple.com793d5142012-02-22 00:00:59 +000058Notification* core(WebNotification *notification)
59{
60 if (!notification->_private)
61 return 0;
jonlee@apple.combb6499f2012-02-22 01:01:31 +000062 return notification->_private->_internal.get();
jonlee@apple.com793d5142012-02-22 00:00:59 +000063}
64
ysuzuki@apple.com6fd9dd52020-01-09 01:42:38 +000065- (id)initWithCoreNotification:(NakedPtr<Notification>)coreNotification notificationID:(uint64_t)notificationID
jonlee@apple.com793d5142012-02-22 00:00:59 +000066{
67 if (!(self = [super init]))
68 return nil;
ap@apple.com196373c2017-02-27 00:17:34 +000069 _private = [[WebNotificationPrivate alloc] init];
jonlee@apple.combb6499f2012-02-22 01:01:31 +000070 _private->_internal = coreNotification;
jonlee@apple.com793d5142012-02-22 00:00:59 +000071 _private->_notificationID = notificationID;
72 return self;
73}
74@end
jonlee@apple.comc92fdea2012-02-22 02:35:55 +000075#endif
jonlee@apple.com793d5142012-02-22 00:00:59 +000076
77@implementation WebNotification
78- (id)init
79{
80 return nil;
81}
82
ap@apple.com196373c2017-02-27 00:17:34 +000083- (void)dealloc
84{
85 [_private release];
86 [super dealloc];
87}
88
jonlee@apple.com793d5142012-02-22 00:00:59 +000089- (NSString *)title
90{
weinig@apple.com1d7fe202017-05-11 00:29:37 +000091#if ENABLE(NOTIFICATIONS)
jonlee@apple.comf2d234b2012-03-15 23:07:37 +000092 return core(self)->title();
jonlee@apple.comc92fdea2012-02-22 02:35:55 +000093#else
94 return nil;
95#endif
jonlee@apple.com793d5142012-02-22 00:00:59 +000096}
97
98- (NSString *)body
99{
weinig@apple.com1d7fe202017-05-11 00:29:37 +0000100#if ENABLE(NOTIFICATIONS)
jonlee@apple.comf2d234b2012-03-15 23:07:37 +0000101 return core(self)->body();
jonlee@apple.comc92fdea2012-02-22 02:35:55 +0000102#else
103 return nil;
104#endif
jonlee@apple.com793d5142012-02-22 00:00:59 +0000105}
106
jonlee@apple.com34489132012-04-01 23:15:44 +0000107- (NSString *)tag
jonlee@apple.com296e2ab2012-03-05 18:34:14 +0000108{
weinig@apple.com1d7fe202017-05-11 00:29:37 +0000109#if ENABLE(NOTIFICATIONS)
jonlee@apple.com34489132012-04-01 23:15:44 +0000110 return core(self)->tag();
jonlee@apple.com296e2ab2012-03-05 18:34:14 +0000111#else
112 return nil;
113#endif
114}
115
jonlee@apple.comb0256ff2012-08-29 17:12:28 +0000116- (NSString *)iconURL
117{
weinig@apple.com1d7fe202017-05-11 00:29:37 +0000118#if ENABLE(NOTIFICATIONS)
commit-queue@webkit.org39359f02020-04-25 21:28:45 +0000119 return core(self)->icon().string();
jonlee@apple.comb0256ff2012-08-29 17:12:28 +0000120#else
121 return nil;
122#endif
123}
124
jonlee@apple.com41787292012-09-10 22:12:52 +0000125- (NSString *)lang
126{
weinig@apple.com1d7fe202017-05-11 00:29:37 +0000127#if ENABLE(NOTIFICATIONS)
jonlee@apple.com41787292012-09-10 22:12:52 +0000128 return core(self)->lang();
129#else
130 return nil;
131#endif
132}
133
134- (NSString *)dir
135{
weinig@apple.com1d7fe202017-05-11 00:29:37 +0000136#if ENABLE(NOTIFICATIONS)
commit-queue@webkit.orga750e772017-05-17 03:22:38 +0000137 switch (core(self)->dir()) {
138 case Notification::Direction::Auto:
139 return @"auto";
140 case Notification::Direction::Ltr:
141 return @"ltr";
142 case Notification::Direction::Rtl:
143 return @"rtl";
144 }
jonlee@apple.com41787292012-09-10 22:12:52 +0000145#else
146 return nil;
147#endif
148}
149
jonlee@apple.com793d5142012-02-22 00:00:59 +0000150- (WebSecurityOrigin *)origin
151{
weinig@apple.com1d7fe202017-05-11 00:29:37 +0000152#if ENABLE(NOTIFICATIONS)
cdumez@apple.com459c89a2021-02-18 05:06:15 +0000153 return adoptNS([[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:core(self)->scriptExecutionContext()->securityOrigin()]).autorelease();
jonlee@apple.comc92fdea2012-02-22 02:35:55 +0000154#else
155 return nil;
156#endif
jonlee@apple.com793d5142012-02-22 00:00:59 +0000157}
158
159- (uint64_t)notificationID
160{
weinig@apple.com1d7fe202017-05-11 00:29:37 +0000161#if ENABLE(NOTIFICATIONS)
jonlee@apple.com793d5142012-02-22 00:00:59 +0000162 return _private->_notificationID;
jonlee@apple.comc92fdea2012-02-22 02:35:55 +0000163#else
164 return 0;
165#endif
jonlee@apple.com793d5142012-02-22 00:00:59 +0000166}
167
168- (void)dispatchShowEvent
169{
weinig@apple.com1d7fe202017-05-11 00:29:37 +0000170#if ENABLE(NOTIFICATIONS)
jonlee@apple.com793d5142012-02-22 00:00:59 +0000171 core(self)->dispatchShowEvent();
jonlee@apple.comc92fdea2012-02-22 02:35:55 +0000172#endif
jonlee@apple.com793d5142012-02-22 00:00:59 +0000173}
174
175- (void)dispatchCloseEvent
176{
weinig@apple.com1d7fe202017-05-11 00:29:37 +0000177#if ENABLE(NOTIFICATIONS)
jonlee@apple.com793d5142012-02-22 00:00:59 +0000178 core(self)->dispatchCloseEvent();
jonlee@apple.comc92fdea2012-02-22 02:35:55 +0000179#endif
jonlee@apple.com793d5142012-02-22 00:00:59 +0000180}
181
182- (void)dispatchClickEvent
183{
weinig@apple.com1d7fe202017-05-11 00:29:37 +0000184#if ENABLE(NOTIFICATIONS)
jonlee@apple.com793d5142012-02-22 00:00:59 +0000185 core(self)->dispatchClickEvent();
jonlee@apple.comc92fdea2012-02-22 02:35:55 +0000186#endif
jonlee@apple.com793d5142012-02-22 00:00:59 +0000187}
188
189- (void)dispatchErrorEvent
190{
weinig@apple.com1d7fe202017-05-11 00:29:37 +0000191#if ENABLE(NOTIFICATIONS)
jonlee@apple.com793d5142012-02-22 00:00:59 +0000192 core(self)->dispatchErrorEvent();
jonlee@apple.comc92fdea2012-02-22 02:35:55 +0000193#endif
jonlee@apple.com793d5142012-02-22 00:00:59 +0000194}
195
cdumez@apple.com2a7af382020-03-18 00:12:47 +0000196- (void)finalize
197{
198#if ENABLE(NOTIFICATIONS)
199 core(self)->finalize();
200#endif
201}
202
jonlee@apple.com793d5142012-02-22 00:00:59 +0000203@end
jonlee@apple.combb6499f2012-02-22 01:01:31 +0000204