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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 es.throwDOMException(SyntaxError, ExceptionMessages::failedToExecute("cr
eateNotification", "NotificationCenter", "'" + iconURI + "' is not a valid icon
URL.")); | 80 es.throwDOMException(SyntaxError, ExceptionMessages::failedToExecute("cr
eateNotification", "NotificationCenter", "'" + iconURI + "' is not a valid icon
URL.")); |
81 return; | 81 return; |
82 } | 82 } |
83 } | 83 } |
84 #endif | 84 #endif |
85 | 85 |
86 Notification::Notification(ExecutionContext* context, const String& title) | 86 Notification::Notification(ExecutionContext* context, const String& title) |
87 : ActiveDOMObject(context) | 87 : ActiveDOMObject(context) |
88 , m_title(title) | 88 , m_title(title) |
89 , m_state(Idle) | 89 , m_state(Idle) |
90 , m_taskTimer(adoptPtr(new Timer<Notification>(this, &Notification::taskTime
rFired))) | 90 , m_asyncRunner(adoptPtr(new AsyncMethodRunner<Notification>(this, &Notifica
tion::showSoon))) |
91 { | 91 { |
92 ScriptWrappable::init(this); | 92 ScriptWrappable::init(this); |
93 | 93 |
94 m_notificationClient = NotificationController::clientFrom(toDocument(context
)->page()); | 94 m_notificationClient = NotificationController::clientFrom(toDocument(context
)->page()); |
95 ASSERT(m_notificationClient); | 95 ASSERT(m_notificationClient); |
96 | 96 |
97 m_taskTimer->startOneShot(0); | 97 m_asyncRunner->runAsync(); |
98 } | 98 } |
99 | 99 |
100 Notification::~Notification() | 100 Notification::~Notification() |
101 { | 101 { |
102 } | 102 } |
103 | 103 |
104 #if ENABLE(LEGACY_NOTIFICATIONS) | 104 #if ENABLE(LEGACY_NOTIFICATIONS) |
105 PassRefPtr<Notification> Notification::create(const String& title, const String&
body, const String& iconURI, ExecutionContext* context, ExceptionState& es, Pas
sRefPtr<NotificationCenter> provider) | 105 PassRefPtr<Notification> Notification::create(const String& title, const String&
body, const String& iconURI, ExecutionContext* context, ExceptionState& es, Pas
sRefPtr<NotificationCenter> provider) |
106 { | 106 { |
107 RefPtr<Notification> notification(adoptRef(new Notification(title, body, ico
nURI, context, es, provider))); | 107 RefPtr<Notification> notification(adoptRef(new Notification(title, body, ico
nURI, context, es, provider))); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 { | 200 { |
201 dispatchEvent(Event::create(EventTypeNames::close)); | 201 dispatchEvent(Event::create(EventTypeNames::close)); |
202 finalize(); | 202 finalize(); |
203 } | 203 } |
204 | 204 |
205 void Notification::dispatchErrorEvent() | 205 void Notification::dispatchErrorEvent() |
206 { | 206 { |
207 dispatchEvent(Event::create(EventTypeNames::error)); | 207 dispatchEvent(Event::create(EventTypeNames::error)); |
208 } | 208 } |
209 | 209 |
210 void Notification::taskTimerFired(Timer<Notification>* timer) | 210 void Notification::showSoon() |
211 { | 211 { |
212 ASSERT(executionContext()->isDocument()); | 212 ASSERT(executionContext()->isDocument()); |
213 ASSERT_UNUSED(timer, timer == m_taskTimer.get()); | |
214 show(); | 213 show(); |
215 } | 214 } |
216 | 215 |
217 bool Notification::dispatchEvent(PassRefPtr<Event> event) | 216 bool Notification::dispatchEvent(PassRefPtr<Event> event) |
218 { | 217 { |
219 // Do not dispatch if the context is gone. | 218 // Do not dispatch if the context is gone. |
220 if (!executionContext()) | 219 if (!executionContext()) |
221 return false; | 220 return false; |
222 | 221 |
223 return EventTarget::dispatchEvent(event); | 222 return EventTarget::dispatchEvent(event); |
(...skipping 24 matching lines...) Expand all Loading... |
248 return deniedPermission; | 247 return deniedPermission; |
249 } | 248 } |
250 | 249 |
251 void Notification::requestPermission(ExecutionContext* context, PassRefPtr<Notif
icationPermissionCallback> callback) | 250 void Notification::requestPermission(ExecutionContext* context, PassRefPtr<Notif
icationPermissionCallback> callback) |
252 { | 251 { |
253 ASSERT(toDocument(context)->page()); | 252 ASSERT(toDocument(context)->page()); |
254 NotificationController::from(toDocument(context)->page())->client()->request
Permission(context, callback); | 253 NotificationController::from(toDocument(context)->page())->client()->request
Permission(context, callback); |
255 } | 254 } |
256 | 255 |
257 } // namespace WebCore | 256 } // namespace WebCore |
OLD | NEW |