Chromium Code Reviews| Index: Source/modules/serviceworkers/WaitUntilObserver.cpp |
| diff --git a/Source/modules/serviceworkers/WaitUntilObserver.cpp b/Source/modules/serviceworkers/WaitUntilObserver.cpp |
| index bf4ed4e459ed914644c38adc2f24df6041e8e076..740512d7b9e6b25473d9ac9447a1e92923a3eb86 100644 |
| --- a/Source/modules/serviceworkers/WaitUntilObserver.cpp |
| +++ b/Source/modules/serviceworkers/WaitUntilObserver.cpp |
| @@ -21,6 +21,16 @@ |
| namespace blink { |
| +namespace { |
| + |
| +unsigned& windowInteractionTimeout() |
| +{ |
| + DEFINE_STATIC_LOCAL(unsigned, windowInteractionTimeout, (ServiceWorkerGlobalScope::kWindowInteractionTimeout)); |
| + return windowInteractionTimeout; |
| +} |
| + |
| +} // anonymous namespace |
| + |
| class WaitUntilObserver::ThenFunction final : public ScriptFunction { |
| public: |
| enum ResolveType { |
| @@ -70,6 +80,14 @@ WaitUntilObserver* WaitUntilObserver::create(ExecutionContext* context, EventTyp |
| void WaitUntilObserver::willDispatchEvent() |
| { |
| + // When handling a notificationclick event, we want to allow one window to |
| + // be focused or opened. These calls are allowed between the call to |
| + // willDispatchEvent() and the last call to decrementPendingActivity(). If |
| + // waitUntil() isn't called, that means between willDispatchEvent() and |
| + // didDispatchEvent(). |
| + if (m_type == NotificationClick) |
| + executionContext()->allowWindowInteraction(); |
|
dominicc (has gone to gerrit)
2015/02/05 18:58:13
Does it make sense to assert that this has been re
mlamouri (slow - plz ping)
2015/02/05 20:23:12
Not really. The callers are not aware of the numbe
|
| + |
| incrementPendingActivity(); |
| } |
| @@ -92,13 +110,12 @@ void WaitUntilObserver::waitUntil(ScriptState* scriptState, const ScriptValue& v |
| return; |
| // When handling a notificationclick event, we want to allow one window to |
| - // be focused or opened. Regardless of whether such action happened, |
| - // |consumeWindowInteraction| will be called when all the pending activities |
| - // will be resolved or after a |
| - if (m_type == NotificationClick) { |
| - executionContext()->allowWindowInteraction(); |
| - m_consumeWindowInteractionTimer.startOneShot(ServiceWorkerGlobalScope::kWindowInteractionTimeout, FROM_HERE); |
| - } |
| + // be focused or opened. See comments in ::willDispatchEvent(). When |
| + // waitUntil() is being used, opening or closing a window must happen in a |
| + // timeframe specified by windowInteractionTimeout(), otherwise the calls |
| + // will fail. |
| + if (m_type == NotificationClick) |
| + m_consumeWindowInteractionTimer.startOneShot(windowInteractionTimeout(), FROM_HERE); |
| incrementPendingActivity(); |
| ScriptPromise::cast(scriptState, value).then( |
| @@ -164,6 +181,12 @@ void WaitUntilObserver::consumeWindowInteraction(Timer<WaitUntilObserver>*) |
| executionContext()->consumeWindowInteraction(); |
| } |
| +// static |
| +void WaitUntilObserver::overrideWindowInteractionTimeoutForTest(unsigned timeout) |
| +{ |
| + windowInteractionTimeout() = timeout; |
| +} |
| + |
| void WaitUntilObserver::trace(Visitor* visitor) |
| { |
| ContextLifecycleObserver::trace(visitor); |