OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 166 } |
167 | 167 |
168 void Notification::close() | 168 void Notification::close() |
169 { | 169 { |
170 if (m_state != State::Showing) | 170 if (m_state != State::Showing) |
171 return; | 171 return; |
172 | 172 |
173 // Schedule the "close" event to be fired for non-persistent notifications. | 173 // Schedule the "close" event to be fired for non-persistent notifications. |
174 // Persistent notifications won't get such events for programmatic closes. | 174 // Persistent notifications won't get such events for programmatic closes. |
175 if (m_type == Type::NonPersistent) { | 175 if (m_type == Type::NonPersistent) { |
176 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&N
otification::dispatchCloseEvent, wrapPersistent(this))); | 176 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&N
otification::didCloseNotification, wrapPersistent(this))); |
177 m_state = State::Closing; | 177 m_state = State::Closing; |
178 | 178 } else { |
179 notificationManager()->close(this); | 179 m_state = State::Closed; |
180 return; | |
181 } | 180 } |
182 | 181 |
183 m_state = State::Closed; | 182 DCHECK(!m_notificationId.isEmpty()); |
184 | 183 |
185 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); | 184 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); |
186 DCHECK(origin); | 185 DCHECK(origin); |
187 | 186 |
188 notificationManager()->closePersistent(WebSecurityOrigin(origin), m_data.tag
, m_notificationId); | 187 notificationManager()->close(WebSecurityOrigin(origin), m_data.tag, m_notifi
cationId); |
189 } | 188 } |
190 | 189 |
191 void Notification::dispatchShowEvent() | 190 void Notification::didShowNotification(const WebString& notificationId) |
192 { | 191 { |
| 192 DCHECK(m_notificationId.isEmpty()); |
| 193 m_notificationId = notificationId; |
| 194 |
193 dispatchEvent(Event::create(EventTypeNames::show)); | 195 dispatchEvent(Event::create(EventTypeNames::show)); |
194 } | 196 } |
195 | 197 |
196 void Notification::dispatchClickEvent() | 198 void Notification::didClickNotification() |
197 { | 199 { |
198 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | 200 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); |
199 ScopedWindowFocusAllowedIndicator windowFocusAllowed(getExecutionContext()); | 201 ScopedWindowFocusAllowedIndicator windowFocusAllowed(getExecutionContext()); |
200 dispatchEvent(Event::create(EventTypeNames::click)); | 202 dispatchEvent(Event::create(EventTypeNames::click)); |
201 } | 203 } |
202 | 204 |
203 void Notification::dispatchErrorEvent() | 205 void Notification::didCloseNotification() |
204 { | |
205 dispatchEvent(Event::create(EventTypeNames::error)); | |
206 } | |
207 | |
208 void Notification::dispatchCloseEvent() | |
209 { | 206 { |
210 // The notification will be showing when the user initiated the close, or it
will be | 207 // The notification will be showing when the user initiated the close, or it
will be |
211 // closing if the developer initiated the close. | 208 // closing if the developer initiated the close. |
212 if (m_state != State::Showing && m_state != State::Closing) | 209 if (m_state != State::Showing && m_state != State::Closing) |
213 return; | 210 return; |
214 | 211 |
215 m_state = State::Closed; | 212 m_state = State::Closed; |
216 dispatchEvent(Event::create(EventTypeNames::close)); | 213 dispatchEvent(Event::create(EventTypeNames::close)); |
217 } | 214 } |
218 | 215 |
| 216 void Notification::dispatchErrorEvent() |
| 217 { |
| 218 dispatchEvent(Event::create(EventTypeNames::error)); |
| 219 } |
| 220 |
219 String Notification::title() const | 221 String Notification::title() const |
220 { | 222 { |
221 return m_data.title; | 223 return m_data.title; |
222 } | 224 } |
223 | 225 |
224 String Notification::dir() const | 226 String Notification::dir() const |
225 { | 227 { |
226 switch (m_data.direction) { | 228 switch (m_data.direction) { |
227 case WebNotificationData::DirectionLeftToRight: | 229 case WebNotificationData::DirectionLeftToRight: |
228 return "ltr"; | 230 return "ltr"; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 402 |
401 DEFINE_TRACE(Notification) | 403 DEFINE_TRACE(Notification) |
402 { | 404 { |
403 visitor->trace(m_prepareShowMethodRunner); | 405 visitor->trace(m_prepareShowMethodRunner); |
404 visitor->trace(m_loader); | 406 visitor->trace(m_loader); |
405 EventTargetWithInlineData::trace(visitor); | 407 EventTargetWithInlineData::trace(visitor); |
406 ActiveDOMObject::trace(visitor); | 408 ActiveDOMObject::trace(visitor); |
407 } | 409 } |
408 | 410 |
409 } // namespace blink | 411 } // namespace blink |
OLD | NEW |