| 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 25 matching lines...) Expand all Loading... |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/dom/ExecutionContext.h" | 37 #include "core/dom/ExecutionContext.h" |
| 38 #include "core/dom/ExecutionContextTask.h" | 38 #include "core/dom/ExecutionContextTask.h" |
| 39 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" | 39 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" |
| 40 #include "core/events/Event.h" | 40 #include "core/events/Event.h" |
| 41 #include "core/frame/UseCounter.h" | 41 #include "core/frame/UseCounter.h" |
| 42 #include "modules/notifications/NotificationAction.h" | 42 #include "modules/notifications/NotificationAction.h" |
| 43 #include "modules/notifications/NotificationData.h" | 43 #include "modules/notifications/NotificationData.h" |
| 44 #include "modules/notifications/NotificationOptions.h" | 44 #include "modules/notifications/NotificationOptions.h" |
| 45 #include "modules/notifications/NotificationPermissionClient.h" | 45 #include "modules/notifications/NotificationPermissionClient.h" |
| 46 #include "modules/notifications/NotificationResourcesLoader.h" |
| 46 #include "platform/RuntimeEnabledFeatures.h" | 47 #include "platform/RuntimeEnabledFeatures.h" |
| 47 #include "platform/UserGestureIndicator.h" | 48 #include "platform/UserGestureIndicator.h" |
| 48 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
| 49 #include "public/platform/WebSecurityOrigin.h" | 50 #include "public/platform/WebSecurityOrigin.h" |
| 50 #include "public/platform/WebString.h" | 51 #include "public/platform/WebString.h" |
| 51 #include "public/platform/modules/notifications/WebNotificationAction.h" | 52 #include "public/platform/modules/notifications/WebNotificationAction.h" |
| 52 #include "public/platform/modules/notifications/WebNotificationManager.h" | 53 #include "public/platform/modules/notifications/WebNotificationManager.h" |
| 54 #include "wtf/Functional.h" |
| 53 | 55 |
| 54 namespace blink { | 56 namespace blink { |
| 55 namespace { | 57 namespace { |
| 56 | 58 |
| 57 const int64_t kInvalidPersistentId = -1; | 59 const int64_t kInvalidPersistentId = -1; |
| 58 | 60 |
| 59 WebNotificationManager* notificationManager() | 61 WebNotificationManager* notificationManager() |
| 60 { | 62 { |
| 61 return Platform::current()->notificationManager(); | 63 return Platform::current()->notificationManager(); |
| 62 } | 64 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 92 UseCounter::count(context, UseCounter::NotificationInsecureOrigin); | 94 UseCounter::count(context, UseCounter::NotificationInsecureOrigin); |
| 93 if (context->isDocument()) | 95 if (context->isDocument()) |
| 94 UseCounter::countCrossOriginIframe(*toDocument(context), UseCounter
::NotificationAPIInsecureOriginIframe); | 96 UseCounter::countCrossOriginIframe(*toDocument(context), UseCounter
::NotificationAPIInsecureOriginIframe); |
| 95 } | 97 } |
| 96 | 98 |
| 97 WebNotificationData data = createWebNotificationData(context, title, options
, exceptionState); | 99 WebNotificationData data = createWebNotificationData(context, title, options
, exceptionState); |
| 98 if (exceptionState.hadException()) | 100 if (exceptionState.hadException()) |
| 99 return nullptr; | 101 return nullptr; |
| 100 | 102 |
| 101 Notification* notification = new Notification(context, data); | 103 Notification* notification = new Notification(context, data); |
| 102 notification->scheduleShow(); | 104 notification->schedulePrepareShow(); |
| 103 notification->suspendIfNeeded(); | 105 notification->suspendIfNeeded(); |
| 104 | 106 |
| 105 return notification; | 107 return notification; |
| 106 } | 108 } |
| 107 | 109 |
| 108 Notification* Notification::create(ExecutionContext* context, int64_t persistent
Id, const WebNotificationData& data, bool showing) | 110 Notification* Notification::create(ExecutionContext* context, int64_t persistent
Id, const WebNotificationData& data, bool showing) |
| 109 { | 111 { |
| 110 Notification* notification = new Notification(context, data); | 112 Notification* notification = new Notification(context, data); |
| 111 notification->setPersistentId(persistentId); | 113 notification->setPersistentId(persistentId); |
| 112 notification->setState(showing ? NotificationStateShowing : NotificationStat
eClosed); | 114 notification->setState(showing ? NotificationStateShowing : NotificationStat
eClosed); |
| 113 notification->suspendIfNeeded(); | 115 notification->suspendIfNeeded(); |
| 114 | 116 |
| 115 return notification; | 117 return notification; |
| 116 } | 118 } |
| 117 | 119 |
| 118 Notification::Notification(ExecutionContext* context, const WebNotificationData&
data) | 120 Notification::Notification(ExecutionContext* context, const WebNotificationData&
data) |
| 119 : ActiveScriptWrappable(this) | 121 : ActiveScriptWrappable(this) |
| 120 , ActiveDOMObject(context) | 122 , ActiveDOMObject(context) |
| 121 , m_data(data) | 123 , m_data(data) |
| 122 , m_persistentId(kInvalidPersistentId) | 124 , m_persistentId(kInvalidPersistentId) |
| 123 , m_state(NotificationStateIdle) | 125 , m_state(NotificationStateIdle) |
| 124 , m_asyncRunner(AsyncMethodRunner<Notification>::create(this, &Notification:
:show)) | 126 , m_prepareShowMethodRunner(AsyncMethodRunner<Notification>::create(this, &N
otification::prepareShow)) |
| 125 { | 127 { |
| 126 ASSERT(notificationManager()); | 128 ASSERT(notificationManager()); |
| 127 } | 129 } |
| 128 | 130 |
| 129 Notification::~Notification() | 131 Notification::~Notification() |
| 130 { | 132 { |
| 131 } | 133 } |
| 132 | 134 |
| 133 void Notification::scheduleShow() | 135 void Notification::schedulePrepareShow() |
| 134 { | 136 { |
| 135 ASSERT(m_state == NotificationStateIdle); | 137 ASSERT(m_state == NotificationStateIdle); |
| 136 ASSERT(!m_asyncRunner->isActive()); | 138 ASSERT(!m_prepareShowMethodRunner->isActive()); |
| 137 | 139 |
| 138 m_asyncRunner->runAsync(); | 140 m_prepareShowMethodRunner->runAsync(); |
| 139 } | 141 } |
| 140 | 142 |
| 141 void Notification::show() | 143 void Notification::prepareShow() |
| 142 { | 144 { |
| 143 ASSERT(m_state == NotificationStateIdle); | 145 ASSERT(m_state == NotificationStateIdle); |
| 144 if (Notification::checkPermission(getExecutionContext()) != WebNotificationP
ermissionAllowed) { | 146 if (Notification::checkPermission(getExecutionContext()) != WebNotificationP
ermissionAllowed) { |
| 145 dispatchErrorEvent(); | 147 dispatchErrorEvent(); |
| 146 return; | 148 return; |
| 147 } | 149 } |
| 148 | 150 |
| 151 m_loader = new NotificationResourcesLoader(bind<NotificationResourcesLoader*
>(&Notification::didLoadResources, WeakPersistentThisPointer<Notification>(this)
)); |
| 152 m_loader->start(getExecutionContext(), m_data); |
| 153 } |
| 154 |
| 155 void Notification::didLoadResources(NotificationResourcesLoader* loader) |
| 156 { |
| 157 DCHECK_EQ(loader, m_loader.get()); |
| 158 |
| 149 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); | 159 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); |
| 150 ASSERT(origin); | 160 ASSERT(origin); |
| 151 | 161 |
| 152 notificationManager()->show(WebSecurityOrigin(origin), m_data, this); | 162 notificationManager()->show(WebSecurityOrigin(origin), m_data, loader->getRe
sources(), this); |
| 163 m_loader.clear(); |
| 153 | 164 |
| 154 m_state = NotificationStateShowing; | 165 m_state = NotificationStateShowing; |
| 155 } | 166 } |
| 156 | 167 |
| 157 void Notification::close() | 168 void Notification::close() |
| 158 { | 169 { |
| 159 if (m_state != NotificationStateShowing) | 170 if (m_state != NotificationStateShowing) |
| 160 return; | 171 return; |
| 161 | 172 |
| 162 if (m_persistentId == kInvalidPersistentId) { | 173 if (m_persistentId == kInvalidPersistentId) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 { | 390 { |
| 380 return EventTargetNames::Notification; | 391 return EventTargetNames::Notification; |
| 381 } | 392 } |
| 382 | 393 |
| 383 void Notification::stop() | 394 void Notification::stop() |
| 384 { | 395 { |
| 385 notificationManager()->notifyDelegateDestroyed(this); | 396 notificationManager()->notifyDelegateDestroyed(this); |
| 386 | 397 |
| 387 m_state = NotificationStateClosed; | 398 m_state = NotificationStateClosed; |
| 388 | 399 |
| 389 m_asyncRunner->stop(); | 400 m_prepareShowMethodRunner->stop(); |
| 401 |
| 402 if (m_loader) |
| 403 m_loader->stop(); |
| 390 } | 404 } |
| 391 | 405 |
| 392 bool Notification::hasPendingActivity() const | 406 bool Notification::hasPendingActivity() const |
| 393 { | 407 { |
| 394 return m_state == NotificationStateShowing || m_asyncRunner->isActive(); | 408 return m_state == NotificationStateShowing || m_prepareShowMethodRunner->isA
ctive() || m_loader; |
| 395 } | 409 } |
| 396 | 410 |
| 397 DEFINE_TRACE(Notification) | 411 DEFINE_TRACE(Notification) |
| 398 { | 412 { |
| 399 visitor->trace(m_asyncRunner); | 413 visitor->trace(m_prepareShowMethodRunner); |
| 414 visitor->trace(m_loader); |
| 400 EventTargetWithInlineData::trace(visitor); | 415 EventTargetWithInlineData::trace(visitor); |
| 401 ActiveDOMObject::trace(visitor); | 416 ActiveDOMObject::trace(visitor); |
| 402 } | 417 } |
| 403 | 418 |
| 404 } // namespace blink | 419 } // namespace blink |
| OLD | NEW |