| Index: Source/modules/serviceworkers/WaitUntilObserver.cpp
|
| diff --git a/Source/modules/serviceworkers/WaitUntilObserver.cpp b/Source/modules/serviceworkers/WaitUntilObserver.cpp
|
| index 4fd5e62241179f89c777ca9f1a73c9f3a48043d1..be1f85301aa89aa2504f96189168e8d0d16ce5ab 100644
|
| --- a/Source/modules/serviceworkers/WaitUntilObserver.cpp
|
| +++ b/Source/modules/serviceworkers/WaitUntilObserver.cpp
|
| @@ -12,6 +12,7 @@
|
| #include "core/dom/ExceptionCode.h"
|
| #include "core/dom/ExecutionContext.h"
|
| #include "modules/serviceworkers/ServiceWorkerGlobalScope.h"
|
| +#include "platform/LayoutTestSupport.h"
|
| #include "platform/NotImplemented.h"
|
| #include "public/platform/WebServiceWorkerEventResult.h"
|
| #include "wtf/Assertions.h"
|
| @@ -21,6 +22,21 @@
|
|
|
| namespace blink {
|
|
|
| +namespace {
|
| +
|
| +// Timeout before a service worker that was given window interaction
|
| +// permission loses them. The unit is seconds.
|
| +const unsigned kWindowInteractionTimeout = 10;
|
| +const unsigned kWindowInteractionTimeoutForTest = 1;
|
| +
|
| +unsigned windowInteractionTimeout()
|
| +{
|
| + return LayoutTestSupport::isRunningLayoutTest()
|
| + ? kWindowInteractionTimeoutForTest : kWindowInteractionTimeout;
|
| +}
|
| +
|
| +} // anonymous namespace
|
| +
|
| class WaitUntilObserver::ThenFunction final : public ScriptFunction {
|
| public:
|
| enum ResolveType {
|
| @@ -70,6 +86,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();
|
| +
|
| incrementPendingActivity();
|
| }
|
|
|
| @@ -92,13 +116,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(
|
|
|