jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 1 | /* |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 2 | * Copyright (C) 2012 Apple Inc. All rights reserved. |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 3 | * |
| 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.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 14 | * 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.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 32 | |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 33 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 34 | #import "WebSecurityOriginInternal.h" |
| 35 | #import <WebCore/Notification.h> |
| 36 | #import <WebCore/ScriptExecutionContext.h> |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 37 | #import <wtf/RefPtr.h> |
| 38 | |
| 39 | using namespace WebCore; |
jonlee@apple.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 40 | #endif |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 41 | |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 42 | @interface WebNotificationPrivate : NSObject |
| 43 | { |
| 44 | @public |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 45 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | bb6499f | 2012-02-22 01:01:31 +0000 | [diff] [blame] | 46 | RefPtr<Notification> _internal; |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 47 | uint64_t _notificationID; |
jonlee@apple.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 48 | #endif |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 49 | } |
| 50 | @end |
| 51 | |
| 52 | @implementation WebNotificationPrivate |
| 53 | @end |
| 54 | |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 55 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 56 | @implementation WebNotification (WebNotificationInternal) |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 57 | |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 58 | Notification* core(WebNotification *notification) |
| 59 | { |
| 60 | if (!notification->_private) |
| 61 | return 0; |
jonlee@apple.com | bb6499f | 2012-02-22 01:01:31 +0000 | [diff] [blame] | 62 | return notification->_private->_internal.get(); |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 63 | } |
| 64 | |
ysuzuki@apple.com | 6fd9dd5 | 2020-01-09 01:42:38 +0000 | [diff] [blame] | 65 | - (id)initWithCoreNotification:(NakedPtr<Notification>)coreNotification notificationID:(uint64_t)notificationID |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 66 | { |
| 67 | if (!(self = [super init])) |
| 68 | return nil; |
ap@apple.com | 196373c | 2017-02-27 00:17:34 +0000 | [diff] [blame] | 69 | _private = [[WebNotificationPrivate alloc] init]; |
jonlee@apple.com | bb6499f | 2012-02-22 01:01:31 +0000 | [diff] [blame] | 70 | _private->_internal = coreNotification; |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 71 | _private->_notificationID = notificationID; |
| 72 | return self; |
| 73 | } |
| 74 | @end |
jonlee@apple.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 75 | #endif |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 76 | |
| 77 | @implementation WebNotification |
| 78 | - (id)init |
| 79 | { |
| 80 | return nil; |
| 81 | } |
| 82 | |
ap@apple.com | 196373c | 2017-02-27 00:17:34 +0000 | [diff] [blame] | 83 | - (void)dealloc |
| 84 | { |
| 85 | [_private release]; |
| 86 | [super dealloc]; |
| 87 | } |
| 88 | |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 89 | - (NSString *)title |
| 90 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 91 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | f2d234b | 2012-03-15 23:07:37 +0000 | [diff] [blame] | 92 | return core(self)->title(); |
jonlee@apple.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 93 | #else |
| 94 | return nil; |
| 95 | #endif |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | - (NSString *)body |
| 99 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 100 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | f2d234b | 2012-03-15 23:07:37 +0000 | [diff] [blame] | 101 | return core(self)->body(); |
jonlee@apple.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 102 | #else |
| 103 | return nil; |
| 104 | #endif |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 105 | } |
| 106 | |
jonlee@apple.com | 3448913 | 2012-04-01 23:15:44 +0000 | [diff] [blame] | 107 | - (NSString *)tag |
jonlee@apple.com | 296e2ab | 2012-03-05 18:34:14 +0000 | [diff] [blame] | 108 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 109 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | 3448913 | 2012-04-01 23:15:44 +0000 | [diff] [blame] | 110 | return core(self)->tag(); |
jonlee@apple.com | 296e2ab | 2012-03-05 18:34:14 +0000 | [diff] [blame] | 111 | #else |
| 112 | return nil; |
| 113 | #endif |
| 114 | } |
| 115 | |
jonlee@apple.com | b0256ff | 2012-08-29 17:12:28 +0000 | [diff] [blame] | 116 | - (NSString *)iconURL |
| 117 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 118 | #if ENABLE(NOTIFICATIONS) |
commit-queue@webkit.org | 39359f0 | 2020-04-25 21:28:45 +0000 | [diff] [blame] | 119 | return core(self)->icon().string(); |
jonlee@apple.com | b0256ff | 2012-08-29 17:12:28 +0000 | [diff] [blame] | 120 | #else |
| 121 | return nil; |
| 122 | #endif |
| 123 | } |
| 124 | |
jonlee@apple.com | 4178729 | 2012-09-10 22:12:52 +0000 | [diff] [blame] | 125 | - (NSString *)lang |
| 126 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 127 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | 4178729 | 2012-09-10 22:12:52 +0000 | [diff] [blame] | 128 | return core(self)->lang(); |
| 129 | #else |
| 130 | return nil; |
| 131 | #endif |
| 132 | } |
| 133 | |
| 134 | - (NSString *)dir |
| 135 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 136 | #if ENABLE(NOTIFICATIONS) |
commit-queue@webkit.org | a750e77 | 2017-05-17 03:22:38 +0000 | [diff] [blame] | 137 | 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.com | 4178729 | 2012-09-10 22:12:52 +0000 | [diff] [blame] | 145 | #else |
| 146 | return nil; |
| 147 | #endif |
| 148 | } |
| 149 | |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 150 | - (WebSecurityOrigin *)origin |
| 151 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 152 | #if ENABLE(NOTIFICATIONS) |
cdumez@apple.com | 459c89a | 2021-02-18 05:06:15 +0000 | [diff] [blame] | 153 | return adoptNS([[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:core(self)->scriptExecutionContext()->securityOrigin()]).autorelease(); |
jonlee@apple.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 154 | #else |
| 155 | return nil; |
| 156 | #endif |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | - (uint64_t)notificationID |
| 160 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 161 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 162 | return _private->_notificationID; |
jonlee@apple.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 163 | #else |
| 164 | return 0; |
| 165 | #endif |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | - (void)dispatchShowEvent |
| 169 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 170 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 171 | core(self)->dispatchShowEvent(); |
jonlee@apple.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 172 | #endif |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | - (void)dispatchCloseEvent |
| 176 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 177 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 178 | core(self)->dispatchCloseEvent(); |
jonlee@apple.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 179 | #endif |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | - (void)dispatchClickEvent |
| 183 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 184 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 185 | core(self)->dispatchClickEvent(); |
jonlee@apple.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 186 | #endif |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | - (void)dispatchErrorEvent |
| 190 | { |
weinig@apple.com | 1d7fe20 | 2017-05-11 00:29:37 +0000 | [diff] [blame] | 191 | #if ENABLE(NOTIFICATIONS) |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 192 | core(self)->dispatchErrorEvent(); |
jonlee@apple.com | c92fdea | 2012-02-22 02:35:55 +0000 | [diff] [blame] | 193 | #endif |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 194 | } |
| 195 | |
cdumez@apple.com | 2a7af38 | 2020-03-18 00:12:47 +0000 | [diff] [blame] | 196 | - (void)finalize |
| 197 | { |
| 198 | #if ENABLE(NOTIFICATIONS) |
| 199 | core(self)->finalize(); |
| 200 | #endif |
| 201 | } |
| 202 | |
jonlee@apple.com | 793d514 | 2012-02-22 00:00:59 +0000 | [diff] [blame] | 203 | @end |
jonlee@apple.com | bb6499f | 2012-02-22 01:01:31 +0000 | [diff] [blame] | 204 | |