ServiceWorkers API should reject promises when calling objects inside detached frames
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Dec 2017 18:40:05 +0000 (18:40 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Dec 2017 18:40:05 +0000 (18:40 +0000)
commit4da87c5d3dbe65a81762b9daf7c8ac5a84494cf6
tree70fb92eaaf8d496495ecf4e6493d1cb8b007e0c4
parent3fd7737547506cc69551726b478417cf7d293609
ServiceWorkers API should reject promises when calling objects inside detached frames
https://bugs.webkit.org/show_bug.cgi?id=180444

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

Rebaseline test now that it is passing some checks.

* web-platform-tests/service-workers/service-worker/detached-context.https-expected.txt:
* web-platform-tests/service-workers/service-worker/register-closed-window.https-expected.txt:

Source/WebCore:

ServiceWorkers API should reject promises when calling objects inside detached frames.

No new tests, rebaselined existing test.

* bindings/js/JSDOMPromiseDeferred.h:
(WebCore::callPromiseFunction):
Use the caller's globalObject instead of the lexicalGlobalObject when constructing the
deferred promise. The bug became visible when working on this service worker bug since
rejecting the promise when the frame is detached did not actually work. The issue is
that since the promise was created with the detached frame's globalObject, then it was
suspended and would not run script.

* bindings/js/JSDOMWindowBase.cpp:
(WebCore::callerGlobalObject):
(WebCore::incumbentDOMWindow):
* bindings/js/JSDOMWindowBase.h:
Add convenience function to get the caller's globalObject. It was carved out of
incumbentDOMWindow().

* workers/service/ServiceWorker.cpp:
(WebCore::ServiceWorker::postMessage):
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::addRegistration):
(WebCore::ServiceWorkerContainer::getRegistration):
(WebCore::ServiceWorkerContainer::getRegistrations):
* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::update):
(WebCore::ServiceWorkerRegistration::unregister):
Reject the promise when m_isStopped flag is set (i.e. ActiveDOMObject::stop()
has been called).

LayoutTests:

* TestExpectations:
Unskip test that no longer times out and starts passing a few checks.

* fast/dom/navigator-detached-no-crash-expected.txt:
Rebaseline test now that promise is rejected.

* http/tests/media/media-stream/disconnected-frame-permission-denied-expected.txt:
* http/tests/media/media-stream/disconnected-frame-permission-denied.html:
Update and rebaseline test now that the promise is rejected. I verified that this
behavior is consistent with Chrome.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225577 268f45cc-cd09-0410-ab3c-d52691b4dbfc
24 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/dom/navigator-detached-no-crash-expected.txt
LayoutTests/http/tests/media/media-stream/disconnected-frame-expected.txt
LayoutTests/http/tests/media/media-stream/disconnected-frame-permission-denied-expected.txt
LayoutTests/http/tests/media/media-stream/disconnected-frame-permission-denied.html
LayoutTests/http/tests/media/media-stream/disconnected-frame.html
LayoutTests/http/tests/media/media-stream/resources/disconnected-frame-inner.html
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/detached-context.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ready.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-closed-window.https-expected.txt
LayoutTests/platform/gtk/fast/dom/navigator-detached-no-crash-expected.txt
LayoutTests/platform/mac-elcapitan-wk2/fast/dom/navigator-detached-no-crash-expected.txt
LayoutTests/platform/mac-wk1/fast/dom/navigator-detached-no-crash-expected.txt
LayoutTests/platform/win/fast/dom/navigator-detached-no-crash-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
Source/WebCore/bindings/js/JSDOMGlobalObject.h
Source/WebCore/bindings/js/JSDOMPromiseDeferred.h
Source/WebCore/bindings/js/JSDOMWindowBase.cpp
Source/WebCore/workers/service/ServiceWorker.cpp
Source/WebCore/workers/service/ServiceWorkerContainer.cpp
Source/WebCore/workers/service/ServiceWorkerRegistration.cpp