| 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(getExecutionContext(), |
| 152 bind<NotificationResourcesLoader*>(&Notification::didLoadResources, |
| 153 WeakPersistentThisPointer<Notification>(this))); |
| 154 m_loader->start(m_data); |
| 155 } |
| 156 |
| 157 void Notification::didLoadResources(NotificationResourcesLoader* loader) |
| 158 { |
| 159 DCHECK_EQ(loader, m_loader.get()); |
| 160 |
| 149 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); | 161 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); |
| 150 ASSERT(origin); | 162 ASSERT(origin); |
| 151 | 163 |
| 152 notificationManager()->show(WebSecurityOrigin(origin), m_data, this); | 164 notificationManager()->show(WebSecurityOrigin(origin), m_data, loader->getRe
sources(), this); |
| 165 m_loader.clear(); |
| 153 | 166 |
| 154 m_state = NotificationStateShowing; | 167 m_state = NotificationStateShowing; |
| 155 } | 168 } |
| 156 | 169 |
| 157 void Notification::close() | 170 void Notification::close() |
| 158 { | 171 { |
| 159 if (m_state != NotificationStateShowing) | 172 if (m_state != NotificationStateShowing) |
| 160 return; | 173 return; |
| 161 | 174 |
| 162 if (m_persistentId == kInvalidPersistentId) { | 175 if (m_persistentId == kInvalidPersistentId) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 { | 392 { |
| 380 return EventTargetNames::Notification; | 393 return EventTargetNames::Notification; |
| 381 } | 394 } |
| 382 | 395 |
| 383 void Notification::stop() | 396 void Notification::stop() |
| 384 { | 397 { |
| 385 notificationManager()->notifyDelegateDestroyed(this); | 398 notificationManager()->notifyDelegateDestroyed(this); |
| 386 | 399 |
| 387 m_state = NotificationStateClosed; | 400 m_state = NotificationStateClosed; |
| 388 | 401 |
| 389 m_asyncRunner->stop(); | 402 m_prepareShowMethodRunner->stop(); |
| 403 |
| 404 // If |m_loader| is active it will stop itself. |
| 390 } | 405 } |
| 391 | 406 |
| 392 bool Notification::hasPendingActivity() const | 407 bool Notification::hasPendingActivity() const |
| 393 { | 408 { |
| 394 return m_state == NotificationStateShowing || m_asyncRunner->isActive(); | 409 return m_state == NotificationStateShowing || m_prepareShowMethodRunner->isA
ctive() || m_loader; |
| 395 } | 410 } |
| 396 | 411 |
| 397 DEFINE_TRACE(Notification) | 412 DEFINE_TRACE(Notification) |
| 398 { | 413 { |
| 399 visitor->trace(m_asyncRunner); | 414 visitor->trace(m_prepareShowMethodRunner); |
| 415 visitor->trace(m_loader); |
| 400 EventTargetWithInlineData::trace(visitor); | 416 EventTargetWithInlineData::trace(visitor); |
| 401 ActiveDOMObject::trace(visitor); | 417 ActiveDOMObject::trace(visitor); |
| 402 } | 418 } |
| 403 | 419 |
| 404 } // namespace blink | 420 } // namespace blink |
| OLD | NEW |