| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 #if ENABLE(NOTIFICATIONS) | 108 #if ENABLE(NOTIFICATIONS) |
| 109 Notification::Notification(ScriptExecutionContext* context, const String& title) | 109 Notification::Notification(ScriptExecutionContext* context, const String& title) |
| 110 : ActiveDOMObject(context) | 110 : ActiveDOMObject(context) |
| 111 , m_isHTML(false) | 111 , m_isHTML(false) |
| 112 , m_title(title) | 112 , m_title(title) |
| 113 , m_state(Idle) | 113 , m_state(Idle) |
| 114 , m_taskTimer(adoptPtr(new Timer<Notification>(this, &Notification::taskTime
rFired))) | 114 , m_taskTimer(adoptPtr(new Timer<Notification>(this, &Notification::taskTime
rFired))) |
| 115 { | 115 { |
| 116 ScriptWrappable::init(this); | 116 ScriptWrappable::init(this); |
| 117 m_notificationCenter = DOMWindowNotifications::webkitNotifications(toDocumen
t(context)->domWindow()); | 117 m_notificationCenter = DOMWindowNotifications::webkitNotifications(toDocumen
t(context)->domWindow()); |
| 118 | 118 |
| 119 ASSERT(m_notificationCenter->client()); | 119 ASSERT(m_notificationCenter->client()); |
| 120 m_taskTimer->startOneShot(0); | 120 m_taskTimer->startOneShot(0); |
| 121 } | 121 } |
| 122 #endif | 122 #endif |
| 123 | 123 |
| 124 Notification::~Notification() | 124 Notification::~Notification() |
| 125 { | 125 { |
| 126 } | 126 } |
| 127 | 127 |
| 128 #if ENABLE(LEGACY_NOTIFICATIONS) | 128 #if ENABLE(LEGACY_NOTIFICATIONS) |
| 129 PassRefPtr<Notification> Notification::create(const KURL& url, ScriptExecutionCo
ntext* context, ExceptionState& es, PassRefPtr<NotificationCenter> provider) | 129 PassRefPtr<Notification> Notification::create(const KURL& url, ScriptExecutionCo
ntext* context, ExceptionState& es, PassRefPtr<NotificationCenter> provider) |
| 130 { | 130 { |
| 131 RefPtr<Notification> notification(adoptRef(new Notification(url, context, es
, provider))); | 131 RefPtr<Notification> notification(adoptRef(new Notification(url, context, es
, provider))); |
| 132 notification->suspendIfNeeded(); | 132 notification->suspendIfNeeded(); |
| 133 return notification.release(); | 133 return notification.release(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 PassRefPtr<Notification> Notification::create(const String& title, const String&
body, const String& iconURI, ScriptExecutionContext* context, ExceptionState& e
s, PassRefPtr<NotificationCenter> provider) | 136 PassRefPtr<Notification> Notification::create(const String& title, const String&
body, const String& iconURI, ScriptExecutionContext* context, ExceptionState& e
s, PassRefPtr<NotificationCenter> provider) |
| 137 { | 137 { |
| 138 RefPtr<Notification> notification(adoptRef(new Notification(title, body, ico
nURI, context, es, provider))); | 138 RefPtr<Notification> notification(adoptRef(new Notification(title, body, ico
nURI, context, es, provider))); |
| 139 notification->suspendIfNeeded(); | 139 notification->suspendIfNeeded(); |
| 140 return notification.release(); | 140 return notification.release(); |
| 141 } | 141 } |
| 142 #endif | 142 #endif |
| 143 | 143 |
| 144 #if ENABLE(NOTIFICATIONS) | 144 #if ENABLE(NOTIFICATIONS) |
| 145 PassRefPtr<Notification> Notification::create(ScriptExecutionContext* context, c
onst String& title, const Dictionary& options) | 145 PassRefPtr<Notification> Notification::create(ScriptExecutionContext* context, c
onst String& title, const Dictionary& options) |
| 146 { | 146 { |
| 147 RefPtr<Notification> notification(adoptRef(new Notification(context, title))
); | 147 RefPtr<Notification> notification(adoptRef(new Notification(context, title))
); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 163 notification->suspendIfNeeded(); | 163 notification->suspendIfNeeded(); |
| 164 return notification.release(); | 164 return notification.release(); |
| 165 } | 165 } |
| 166 #endif | 166 #endif |
| 167 | 167 |
| 168 const AtomicString& Notification::interfaceName() const | 168 const AtomicString& Notification::interfaceName() const |
| 169 { | 169 { |
| 170 return eventNames().interfaceForNotification; | 170 return eventNames().interfaceForNotification; |
| 171 } | 171 } |
| 172 | 172 |
| 173 void Notification::show() | 173 void Notification::show() |
| 174 { | 174 { |
| 175 // prevent double-showing | 175 // prevent double-showing |
| 176 if (m_state == Idle && m_notificationCenter->client()) { | 176 if (m_state == Idle && m_notificationCenter->client()) { |
| 177 #if ENABLE(NOTIFICATIONS) | 177 #if ENABLE(NOTIFICATIONS) |
| 178 if (!toDocument(scriptExecutionContext())->page()) | 178 if (!toDocument(scriptExecutionContext())->page()) |
| 179 return; | 179 return; |
| 180 if (NotificationController::from(toDocument(scriptExecutionContext())->p
age())->client()->checkPermission(scriptExecutionContext()) != NotificationClien
t::PermissionAllowed) { | 180 if (NotificationController::from(toDocument(scriptExecutionContext())->p
age())->client()->checkPermission(scriptExecutionContext()) != NotificationClien
t::PermissionAllowed) { |
| 181 dispatchErrorEvent(); | 181 dispatchErrorEvent(); |
| 182 return; | 182 return; |
| 183 } | 183 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 DEFINE_STATIC_LOCAL(const String, defaultPermission, (ASCIILiteral("default"
))); | 274 DEFINE_STATIC_LOCAL(const String, defaultPermission, (ASCIILiteral("default"
))); |
| 275 | 275 |
| 276 switch (permission) { | 276 switch (permission) { |
| 277 case NotificationClient::PermissionAllowed: | 277 case NotificationClient::PermissionAllowed: |
| 278 return allowedPermission; | 278 return allowedPermission; |
| 279 case NotificationClient::PermissionDenied: | 279 case NotificationClient::PermissionDenied: |
| 280 return deniedPermission; | 280 return deniedPermission; |
| 281 case NotificationClient::PermissionNotAllowed: | 281 case NotificationClient::PermissionNotAllowed: |
| 282 return defaultPermission; | 282 return defaultPermission; |
| 283 } | 283 } |
| 284 | 284 |
| 285 ASSERT_NOT_REACHED(); | 285 ASSERT_NOT_REACHED(); |
| 286 return deniedPermission; | 286 return deniedPermission; |
| 287 } | 287 } |
| 288 | 288 |
| 289 void Notification::requestPermission(ScriptExecutionContext* context, PassRefPtr
<NotificationPermissionCallback> callback) | 289 void Notification::requestPermission(ScriptExecutionContext* context, PassRefPtr
<NotificationPermissionCallback> callback) |
| 290 { | 290 { |
| 291 ASSERT(toDocument(context)->page()); | 291 ASSERT(toDocument(context)->page()); |
| 292 NotificationController::from(toDocument(context)->page())->client()->request
Permission(context, callback); | 292 NotificationController::from(toDocument(context)->page())->client()->request
Permission(context, callback); |
| 293 } | 293 } |
| 294 #endif | 294 #endif |
| 295 | 295 |
| 296 } // namespace WebCore | 296 } // namespace WebCore |
| 297 | 297 |
| 298 #endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) | 298 #endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) |
| OLD | NEW |