| 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(); | 178 if (m_asyncRunner) |
| 179 m_asyncRunner->stop(); |
| 175 | 180 |
| 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; | 181 m_state = Closed; |
| 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 } | 182 } |
| 197 | 183 |
| 198 void Notification::dispatchShowEvent() | 184 void Notification::dispatchShowEvent() |
| 199 { | 185 { |
| 200 #if ENABLE(LEGACY_NOTIFICATIONS) | 186 #if ENABLE(LEGACY_NOTIFICATIONS) |
| 201 dispatchEvent(Event::create(EventTypeNames::display)); | 187 dispatchEvent(Event::create(EventTypeNames::display)); |
| 202 #endif | 188 #endif |
| 203 dispatchEvent(Event::create(EventTypeNames::show)); | 189 dispatchEvent(Event::create(EventTypeNames::show)); |
| 204 } | 190 } |
| 205 | 191 |
| 206 void Notification::dispatchClickEvent() | 192 void Notification::dispatchClickEvent() |
| 207 { | 193 { |
| 208 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | 194 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); |
| 209 WindowFocusAllowedIndicator windowFocusAllowed; | 195 WindowFocusAllowedIndicator windowFocusAllowed; |
| 210 dispatchEvent(Event::create(EventTypeNames::click)); | 196 dispatchEvent(Event::create(EventTypeNames::click)); |
| 211 } | 197 } |
| 212 | 198 |
| 213 void Notification::dispatchCloseEvent() | 199 void Notification::dispatchCloseEvent() |
| 214 { | 200 { |
| 215 dispatchEvent(Event::create(EventTypeNames::close)); | 201 dispatchEvent(Event::create(EventTypeNames::close)); |
| 216 finalize(); | 202 m_state = Closed; |
| 217 } | 203 } |
| 218 | 204 |
| 219 void Notification::dispatchErrorEvent() | 205 void Notification::dispatchErrorEvent() |
| 220 { | 206 { |
| 221 dispatchEvent(Event::create(EventTypeNames::error)); | 207 dispatchEvent(Event::create(EventTypeNames::error)); |
| 222 } | 208 } |
| 223 | 209 |
| 224 void Notification::showSoon() | 210 void Notification::showSoon() |
| 225 { | 211 { |
| 226 ASSERT(executionContext()->isDocument()); | 212 ASSERT(executionContext()->isDocument()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 return deniedPermission; | 247 return deniedPermission; |
| 262 } | 248 } |
| 263 | 249 |
| 264 void Notification::requestPermission(ExecutionContext* context, PassRefPtr<Notif
icationPermissionCallback> callback) | 250 void Notification::requestPermission(ExecutionContext* context, PassRefPtr<Notif
icationPermissionCallback> callback) |
| 265 { | 251 { |
| 266 ASSERT(toDocument(context)->page()); | 252 ASSERT(toDocument(context)->page()); |
| 267 NotificationController::from(toDocument(context)->page())->client()->request
Permission(context, callback); | 253 NotificationController::from(toDocument(context)->page())->client()->request
Permission(context, callback); |
| 268 } | 254 } |
| 269 | 255 |
| 270 } // namespace WebCore | 256 } // namespace WebCore |
| OLD | NEW |