1/* 2 * Copyright (C) 2012 Apple 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 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. 13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of 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" 32 33#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 34#import "WebSecurityOriginInternal.h" 35#import <WebCore/Notification.h> 36#import <WebCore/ScriptExecutionContext.h> 37#import <wtf/RefPtr.h> 38 39using namespace WebCore; 40#endif 41 42OBJC_CLASS WebNotificationInternal; 43 44@interface WebNotificationPrivate : NSObject 45{ 46@public 47#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 48 RefPtr<Notification> _internal; 49 uint64_t _notificationID; 50#endif 51} 52@end 53 54@implementation WebNotificationPrivate 55@end 56 57#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 58@implementation WebNotification (WebNotificationInternal) 59Notification* core(WebNotification *notification) 60{ 61 if (!notification->_private) 62 return 0; 63 return notification->_private->_internal.get(); 64} 65 66- (id)initWithCoreNotification:(Notification*)coreNotification notificationID:(uint64_t)notificationID 67{ 68 if (!(self = [super init])) 69 return nil; 70 _private = [[WebNotificationPrivate alloc] init]; 71 _private->_internal = coreNotification; 72 _private->_notificationID = notificationID; 73 return self; 74} 75@end 76#endif 77 78@implementation WebNotification 79- (id)init 80{ 81 return nil; 82} 83 84- (NSString *)title 85{ 86#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 87 return core(self)->title(); 88#else 89 return nil; 90#endif 91} 92 93- (NSString *)body 94{ 95#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 96 return core(self)->body(); 97#else 98 return nil; 99#endif 100} 101 102- (NSString *)tag 103{ 104#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 105 return core(self)->tag(); 106#else 107 return nil; 108#endif 109} 110 111- (NSString *)iconURL 112{ 113#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 114 return core(self)->iconURL(); 115#else 116 return nil; 117#endif 118} 119 120- (NSString *)lang 121{ 122#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 123 return core(self)->lang(); 124#else 125 return nil; 126#endif 127} 128 129- (NSString *)dir 130{ 131#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 132 return core(self)->dir(); 133#else 134 return nil; 135#endif 136} 137 138- (WebSecurityOrigin *)origin 139{ 140#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 141 return [[[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:core(self)->scriptExecutionContext()->securityOrigin()] autorelease]; 142#else 143 return nil; 144#endif 145} 146 147- (uint64_t)notificationID 148{ 149#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 150 return _private->_notificationID; 151#else 152 return 0; 153#endif 154} 155 156- (void)dispatchShowEvent 157{ 158#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 159 core(self)->dispatchShowEvent(); 160#endif 161} 162 163- (void)dispatchCloseEvent 164{ 165#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 166 core(self)->dispatchCloseEvent(); 167#endif 168} 169 170- (void)dispatchClickEvent 171{ 172#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 173 core(self)->dispatchClickEvent(); 174#endif 175} 176 177- (void)dispatchErrorEvent 178{ 179#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) 180 core(self)->dispatchErrorEvent(); 181#endif 182} 183 184@end 185 186