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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 // prevent double-showing | 140 // prevent double-showing |
141 if (m_state == Idle) { | 141 if (m_state == Idle) { |
142 if (!toDocument(executionContext())->page()) | 142 if (!toDocument(executionContext())->page()) |
143 return; | 143 return; |
144 if (NotificationController::from(toDocument(executionContext())->page()) ->client()->checkPermission(executionContext()) != NotificationClient::Permissio nAllowed) { | 144 if (NotificationController::from(toDocument(executionContext())->page()) ->client()->checkPermission(executionContext()) != NotificationClient::Permissio nAllowed) { |
145 dispatchErrorEvent(); | 145 dispatchErrorEvent(); |
146 return; | 146 return; |
147 } | 147 } |
148 if (m_notificationClient->show(this)) { | 148 if (m_notificationClient->show(this)) { |
149 m_state = Showing; | 149 m_state = Showing; |
150 setPendingActivity(this); | |
151 } | 150 } |
152 } | 151 } |
153 } | 152 } |
154 | 153 |
155 void Notification::close() | 154 void Notification::close() |
156 { | 155 { |
157 switch (m_state) { | 156 switch (m_state) { |
158 case Idle: | 157 case Idle: |
159 break; | 158 break; |
160 case Showing: | 159 case Showing: |
161 m_notificationClient->cancel(this); | 160 m_notificationClient->cancel(this); |
162 break; | 161 break; |
163 case Closed: | 162 case Closed: |
164 break; | 163 break; |
165 } | 164 } |
166 } | 165 } |
167 | 166 |
167 bool Notification::hasPendingActivity() const | |
168 { | |
169 return m_state == Showing || (m_asyncRunner && m_asyncRunner->isActive()); | |
170 } | |
171 | |
168 void Notification::stop() | 172 void Notification::stop() |
169 { | 173 { |
170 if (m_notificationClient) | 174 if (m_notificationClient) |
171 m_notificationClient->notificationObjectDestroyed(this); | 175 m_notificationClient->notificationObjectDestroyed(this); |
172 m_notificationClient = 0; | 176 m_notificationClient = 0; |
173 | 177 |
174 finalize(); | |
175 | |
176 // Ensure m_notificationClient == 0 only when in Closed state. | |
177 ASSERT(m_state == Closed); | |
178 } | |
179 | |
180 void Notification::finalize() | |
181 { | |
182 if (m_state == Closed) | |
183 return; | |
184 | |
185 // To call unsetPendingActivity() at the end. | |
186 NotificationState lastState = m_state; | |
187 m_state = Closed; | 178 m_state = Closed; |
abarth-chromium
2013/11/15 16:02:55
Do we need to tell the m_asyncRunner to stop, or d
tyoshino (SeeGerritForStatus)
2013/11/18 10:53:13
Good catch. Since
- if m_state is set to non Idle,
| |
188 | |
189 // setPendingActivity() is called only when show() was successful, and only | |
190 // in that case, m_state is set to Showing. So, if it's not Showing, do | |
191 // nothing here. | |
192 if (lastState != Showing) | |
193 return; | |
194 | |
195 unsetPendingActivity(this); | |
196 } | 179 } |
197 | 180 |
198 void Notification::dispatchShowEvent() | 181 void Notification::dispatchShowEvent() |
199 { | 182 { |
200 #if ENABLE(LEGACY_NOTIFICATIONS) | 183 #if ENABLE(LEGACY_NOTIFICATIONS) |
201 dispatchEvent(Event::create(EventTypeNames::display)); | 184 dispatchEvent(Event::create(EventTypeNames::display)); |
202 #endif | 185 #endif |
203 dispatchEvent(Event::create(EventTypeNames::show)); | 186 dispatchEvent(Event::create(EventTypeNames::show)); |
204 } | 187 } |
205 | 188 |
206 void Notification::dispatchClickEvent() | 189 void Notification::dispatchClickEvent() |
207 { | 190 { |
208 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | 191 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); |
209 WindowFocusAllowedIndicator windowFocusAllowed; | 192 WindowFocusAllowedIndicator windowFocusAllowed; |
210 dispatchEvent(Event::create(EventTypeNames::click)); | 193 dispatchEvent(Event::create(EventTypeNames::click)); |
211 } | 194 } |
212 | 195 |
213 void Notification::dispatchCloseEvent() | 196 void Notification::dispatchCloseEvent() |
214 { | 197 { |
215 dispatchEvent(Event::create(EventTypeNames::close)); | 198 dispatchEvent(Event::create(EventTypeNames::close)); |
216 finalize(); | 199 m_state = Closed; |
217 } | 200 } |
218 | 201 |
219 void Notification::dispatchErrorEvent() | 202 void Notification::dispatchErrorEvent() |
220 { | 203 { |
221 dispatchEvent(Event::create(EventTypeNames::error)); | 204 dispatchEvent(Event::create(EventTypeNames::error)); |
222 } | 205 } |
223 | 206 |
224 void Notification::showSoon() | 207 void Notification::showSoon() |
225 { | 208 { |
226 ASSERT(executionContext()->isDocument()); | 209 ASSERT(executionContext()->isDocument()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 return deniedPermission; | 244 return deniedPermission; |
262 } | 245 } |
263 | 246 |
264 void Notification::requestPermission(ExecutionContext* context, PassRefPtr<Notif icationPermissionCallback> callback) | 247 void Notification::requestPermission(ExecutionContext* context, PassRefPtr<Notif icationPermissionCallback> callback) |
265 { | 248 { |
266 ASSERT(toDocument(context)->page()); | 249 ASSERT(toDocument(context)->page()); |
267 NotificationController::from(toDocument(context)->page())->client()->request Permission(context, callback); | 250 NotificationController::from(toDocument(context)->page())->client()->request Permission(context, callback); |
268 } | 251 } |
269 | 252 |
270 } // namespace WebCore | 253 } // namespace WebCore |
OLD | NEW |