| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 { | 133 { |
| 134 ASSERT(m_state == NotificationStateIdle); | 134 ASSERT(m_state == NotificationStateIdle); |
| 135 ASSERT(!m_asyncRunner->isActive()); | 135 ASSERT(!m_asyncRunner->isActive()); |
| 136 | 136 |
| 137 m_asyncRunner->runAsync(); | 137 m_asyncRunner->runAsync(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void Notification::show() | 140 void Notification::show() |
| 141 { | 141 { |
| 142 ASSERT(m_state == NotificationStateIdle); | 142 ASSERT(m_state == NotificationStateIdle); |
| 143 if (Notification::checkPermission(executionContext()) != WebNotificationPerm
issionAllowed) { | 143 if (Notification::checkPermission(getExecutionContext()) != WebNotificationP
ermissionAllowed) { |
| 144 dispatchErrorEvent(); | 144 dispatchErrorEvent(); |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 | 147 |
| 148 SecurityOrigin* origin = executionContext()->securityOrigin(); | 148 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); |
| 149 ASSERT(origin); | 149 ASSERT(origin); |
| 150 | 150 |
| 151 notificationManager()->show(WebSecurityOrigin(origin), m_data, this); | 151 notificationManager()->show(WebSecurityOrigin(origin), m_data, this); |
| 152 | 152 |
| 153 m_state = NotificationStateShowing; | 153 m_state = NotificationStateShowing; |
| 154 } | 154 } |
| 155 | 155 |
| 156 void Notification::close() | 156 void Notification::close() |
| 157 { | 157 { |
| 158 if (m_state != NotificationStateShowing) | 158 if (m_state != NotificationStateShowing) |
| 159 return; | 159 return; |
| 160 | 160 |
| 161 if (m_persistentId == kInvalidPersistentId) { | 161 if (m_persistentId == kInvalidPersistentId) { |
| 162 // Fire the close event asynchronously. | 162 // Fire the close event asynchronously. |
| 163 executionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&Noti
fication::dispatchCloseEvent, this)); | 163 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&N
otification::dispatchCloseEvent, this)); |
| 164 | 164 |
| 165 m_state = NotificationStateClosing; | 165 m_state = NotificationStateClosing; |
| 166 notificationManager()->close(this); | 166 notificationManager()->close(this); |
| 167 } else { | 167 } else { |
| 168 m_state = NotificationStateClosed; | 168 m_state = NotificationStateClosed; |
| 169 | 169 |
| 170 SecurityOrigin* origin = executionContext()->securityOrigin(); | 170 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); |
| 171 ASSERT(origin); | 171 ASSERT(origin); |
| 172 | 172 |
| 173 notificationManager()->closePersistent(WebSecurityOrigin(origin), m_pers
istentId); | 173 notificationManager()->closePersistent(WebSecurityOrigin(origin), m_pers
istentId); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 void Notification::dispatchShowEvent() | 177 void Notification::dispatchShowEvent() |
| 178 { | 178 { |
| 179 dispatchEvent(Event::create(EventTypeNames::show)); | 179 dispatchEvent(Event::create(EventTypeNames::show)); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void Notification::dispatchClickEvent() | 182 void Notification::dispatchClickEvent() |
| 183 { | 183 { |
| 184 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | 184 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); |
| 185 ScopedWindowFocusAllowedIndicator windowFocusAllowed(executionContext()); | 185 ScopedWindowFocusAllowedIndicator windowFocusAllowed(getExecutionContext()); |
| 186 dispatchEvent(Event::create(EventTypeNames::click)); | 186 dispatchEvent(Event::create(EventTypeNames::click)); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void Notification::dispatchErrorEvent() | 189 void Notification::dispatchErrorEvent() |
| 190 { | 190 { |
| 191 dispatchEvent(Event::create(EventTypeNames::error)); | 191 dispatchEvent(Event::create(EventTypeNames::error)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void Notification::dispatchCloseEvent() | 194 void Notification::dispatchCloseEvent() |
| 195 { | 195 { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 return "denied"; | 319 return "denied"; |
| 320 } | 320 } |
| 321 | 321 |
| 322 String Notification::permission(ExecutionContext* context) | 322 String Notification::permission(ExecutionContext* context) |
| 323 { | 323 { |
| 324 return permissionString(checkPermission(context)); | 324 return permissionString(checkPermission(context)); |
| 325 } | 325 } |
| 326 | 326 |
| 327 WebNotificationPermission Notification::checkPermission(ExecutionContext* contex
t) | 327 WebNotificationPermission Notification::checkPermission(ExecutionContext* contex
t) |
| 328 { | 328 { |
| 329 SecurityOrigin* origin = context->securityOrigin(); | 329 SecurityOrigin* origin = context->getSecurityOrigin(); |
| 330 ASSERT(origin); | 330 ASSERT(origin); |
| 331 | 331 |
| 332 return notificationManager()->checkPermission(WebSecurityOrigin(origin)); | 332 return notificationManager()->checkPermission(WebSecurityOrigin(origin)); |
| 333 } | 333 } |
| 334 | 334 |
| 335 ScriptPromise Notification::requestPermission(ScriptState* scriptState, Notifica
tionPermissionCallback* deprecatedCallback) | 335 ScriptPromise Notification::requestPermission(ScriptState* scriptState, Notifica
tionPermissionCallback* deprecatedCallback) |
| 336 { | 336 { |
| 337 ExecutionContext* context = scriptState->executionContext(); | 337 ExecutionContext* context = scriptState->getExecutionContext(); |
| 338 if (NotificationPermissionClient* permissionClient = NotificationPermissionC
lient::from(context)) | 338 if (NotificationPermissionClient* permissionClient = NotificationPermissionC
lient::from(context)) |
| 339 return permissionClient->requestPermission(scriptState, deprecatedCallba
ck); | 339 return permissionClient->requestPermission(scriptState, deprecatedCallba
ck); |
| 340 | 340 |
| 341 // The context has been detached. Return a promise that will never settle. | 341 // The context has been detached. Return a promise that will never settle. |
| 342 ASSERT(context->activeDOMObjectsAreStopped()); | 342 ASSERT(context->activeDOMObjectsAreStopped()); |
| 343 return ScriptPromise(); | 343 return ScriptPromise(); |
| 344 } | 344 } |
| 345 | 345 |
| 346 size_t Notification::maxActions() | 346 size_t Notification::maxActions() |
| 347 { | 347 { |
| 348 // Returns a fixed number for unit tests, which run without the availability
of the Platform object. | 348 // Returns a fixed number for unit tests, which run without the availability
of the Platform object. |
| 349 if (!notificationManager()) | 349 if (!notificationManager()) |
| 350 return 2; | 350 return 2; |
| 351 | 351 |
| 352 return notificationManager()->maxActions(); | 352 return notificationManager()->maxActions(); |
| 353 } | 353 } |
| 354 | 354 |
| 355 DispatchEventResult Notification::dispatchEventInternal(PassRefPtrWillBeRawPtr<E
vent> event) | 355 DispatchEventResult Notification::dispatchEventInternal(PassRefPtrWillBeRawPtr<E
vent> event) |
| 356 { | 356 { |
| 357 ASSERT(executionContext()->isContextThread()); | 357 ASSERT(getExecutionContext()->isContextThread()); |
| 358 return EventTarget::dispatchEventInternal(event); | 358 return EventTarget::dispatchEventInternal(event); |
| 359 } | 359 } |
| 360 | 360 |
| 361 const AtomicString& Notification::interfaceName() const | 361 const AtomicString& Notification::interfaceName() const |
| 362 { | 362 { |
| 363 return EventTargetNames::Notification; | 363 return EventTargetNames::Notification; |
| 364 } | 364 } |
| 365 | 365 |
| 366 void Notification::stop() | 366 void Notification::stop() |
| 367 { | 367 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 378 } | 378 } |
| 379 | 379 |
| 380 DEFINE_TRACE(Notification) | 380 DEFINE_TRACE(Notification) |
| 381 { | 381 { |
| 382 visitor->trace(m_asyncRunner); | 382 visitor->trace(m_asyncRunner); |
| 383 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); | 383 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); |
| 384 ActiveDOMObject::trace(visitor); | 384 ActiveDOMObject::trace(visitor); |
| 385 } | 385 } |
| 386 | 386 |
| 387 } // namespace blink | 387 } // namespace blink |
| OLD | NEW |