haikuwebkit/Source/WebCore/dom/BroadcastChannelRegistry.h

46 lines
2.0 KiB
C
Raw Permalink Normal View History

Add initial support for BroadcastChannel behind a runtime flag https://bugs.webkit.org/show_bug.cgi?id=227924 Reviewed by Sam Weinig. LayoutTests/imported/w3c: Rebaseline WPT tests now that more tests are running and we are passing more checks. * web-platform-tests/FileAPI/url/url-in-tags-revoke.window-expected.txt: * web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-BarProp.window-expected.txt: * web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-sizing.window-expected.txt: * web-platform-tests/html/browsers/the-window-object/window-open-noreferrer-expected.txt: * web-platform-tests/html/cross-origin-embedder-policy/report-only-require-corp.https-expected.txt: * web-platform-tests/html/cross-origin-embedder-policy/require-corp.https-expected.txt: * web-platform-tests/html/dom/idlharness.worker-expected.txt: * web-platform-tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/broadcastchannel-success.https-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-base-target-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-button-target-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-form-target-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-input-target-expected.txt: * web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/htmlanchorelement_noopener-expected.txt: * web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/target_blank_implicit_noopener-expected.txt: * web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/target_blank_implicit_noopener_base-expected.txt: * web-platform-tests/wasm/serialization/module/broadcastchannel-success-and-failure-expected.txt: * web-platform-tests/wasm/serialization/module/broadcastchannel-success-expected.txt: * web-platform-tests/webmessaging/MessageEvent-trusted.any-expected.txt: * web-platform-tests/webmessaging/MessageEvent-trusted.any.worker-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/basics-expected.txt: Removed. * web-platform-tests/webmessaging/broadcastchannel/basics.any-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/basics.any.worker-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/blobs-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/interface-expected.txt: Removed. * web-platform-tests/webmessaging/broadcastchannel/interface.any-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/interface.any.worker-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/sandbox-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/workers-expected.txt: Added. * web-platform-tests/webmessaging/multi-globals/broadcastchannel-current.sub-expected.txt: * web-platform-tests/webstorage/storage_session_window_noopener.window-expected.txt: * web-platform-tests/workers/semantics/interface-objects/001.worker-expected.txt: Source/WebCore: Add initial support for BroadcastChannel behind a runtime flag, off by default: - https://html.spec.whatwg.org/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts Both Firefox and Blink have been supporting BroadcastChannel for a long time. The implementation is complete and spec-compliant. It works both in Window and Worker environments, in WebKit1 and WebKit2. However, the feature is off-by-default because of privacy concerns that have not been addresssed yet: - https://github.com/whatwg/html/issues/5803 We should be able to add partioning to address the privacy concerns and ship this later on. In the mean time though, having a working BroadcastChannel implementation in the context of layout tests is already very useful because a lot of Web-Platform-Tests are relying on it to test other Web features. This means better test coverage for WebKit. Tests: - fast/html/broadcast-channel-between-different-sessions.html - Rebaselined WPT tests * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Headers.cmake: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * bindings/js/WebCoreBuiltinNames.h: * dom/BroadcastChannel.cpp: Added. (WebCore::channelToContextIdentifier): (WebCore::BroadcastChannel::BroadcastChannel): (WebCore::BroadcastChannel::~BroadcastChannel): (WebCore::BroadcastChannel::postMessage): (WebCore::BroadcastChannel::close): (WebCore::BroadcastChannel::dispatchMessageTo): (WebCore::BroadcastChannel::dispatchMessage): (WebCore::BroadcastChannel::ensureOnMainThread): (WebCore::BroadcastChannel::activeDOMObjectName const): (WebCore::BroadcastChannel::eventListenersDidChange): (WebCore::BroadcastChannel::virtualHasPendingActivity const): * dom/BroadcastChannel.h: Added. (WebCore::BroadcastChannel::create): (WebCore::BroadcastChannel::identifier const): (WebCore::BroadcastChannel::name const): * dom/BroadcastChannel.idl: Added. * dom/BroadcastChannelIdentifier.h: Added. * dom/BroadcastChannelRegistry.h: Added. (WebCore::BroadcastChannelRegistry::~BroadcastChannelRegistry): * dom/DeviceOrientationAndMotionAccessController.h: * dom/DeviceOrientationEvent.cpp: * dom/DeviceOrientationEvent.h: * dom/EventTargetFactory.in: * loader/EmptyClients.cpp: (WebCore::pageConfigurationWithEmptyClients): * page/Page.cpp: (WebCore::Page::Page): (WebCore::Page::setBroadcastChannelRegistry): * page/Page.h: (WebCore::Page::broadcastChannelRegistry): * page/PageConfiguration.cpp: (WebCore::PageConfiguration::PageConfiguration): * page/PageConfiguration.h: Source/WebKit: Add initial support for BroadcastChannel behind a runtime flag, off by default: - https://html.spec.whatwg.org/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts Both Firefox and Blink have been supporting BroadcastChannel for a long time. The implementation is complete and spec-compliant. It works both in Window and Worker environments, in WebKit1 and WebKit2. However, the feature is off-by-default because of privacy concerns that have not been addresssed yet: - https://github.com/whatwg/html/issues/5803 We should be able to add partioning to address the privacy concerns and ship this later on. In the mean time though, having a working BroadcastChannel implementation in the context of layout tests is already very useful because a lot of Web-Platform-Tests are relying on it to test other Web features. This means better test coverage for WebKit. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * NetworkProcess/Downloads/DownloadManager.cpp: * NetworkProcess/NetworkBroadcastChannelRegistry.cpp: Added. (WebKit::NetworkBroadcastChannelRegistry::registerChannel): (WebKit::NetworkBroadcastChannelRegistry::unregisterChannel): (WebKit::NetworkBroadcastChannelRegistry::postMessage): (WebKit::NetworkBroadcastChannelRegistry::removeConnection): * NetworkProcess/NetworkBroadcastChannelRegistry.h: Added. (WebKit::NetworkBroadcastChannelRegistry::GlobalBroadcastChannelIdentifier::operator== const): * NetworkProcess/NetworkBroadcastChannelRegistry.messages.in: Added. * NetworkProcess/NetworkConnectionToWebProcess.cpp: (WebKit::NetworkConnectionToWebProcess::didReceiveMessage): (WebKit::NetworkConnectionToWebProcess::didClose): * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::NetworkSession): * NetworkProcess/NetworkSession.h: (WebKit::NetworkSession::broadcastChannelRegistry): * Scripts/webkit/messages.py: (types_that_cannot_be_forward_declared): * Sources.txt: * WebKit.xcodeproj/project.pbxproj: * WebProcess/Network/NetworkProcessConnection.cpp: (WebKit::NetworkProcessConnection::didReceiveMessage): * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp: Added. (WebKit::networkProcessConnection): (WebKit::WebBroadcastChannelRegistry::registerChannel): (WebKit::WebBroadcastChannelRegistry::unregisterChannel): (WebKit::WebBroadcastChannelRegistry::postMessage): (WebKit::WebBroadcastChannelRegistry::postMessageToRemote): * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.h: Added. * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.messages.in: Added. * WebProcess/WebPage/WebPage.cpp: (WebKit::m_appHighlightsVisible): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::WebProcess): * WebProcess/WebProcess.h: (WebKit::WebProcess::broadcastChannelRegistry): Source/WebKitLegacy: Add BroadcastChannelRegistry implementation for WebKitLegacy. * Sources.txt: * WebCoreSupport/WebBroadcastChannelRegistry.cpp: Added. (WebBroadcastChannelRegistry::getOrCreate): (WebBroadcastChannelRegistry::registerChannel): (WebBroadcastChannelRegistry::unregisterChannel): (WebBroadcastChannelRegistry::postMessage): * WebCoreSupport/WebBroadcastChannelRegistry.h: Added. * WebKitLegacy.xcodeproj/project.pbxproj: Source/WebKitLegacy/mac: * WebView/WebView.mm: (-[WebView _commonInitializationWithFrameName:groupName:]): (-[WebView _preferencesChanged:]): Source/WebKitLegacy/win: * WebView.cpp: (WebView::initWithFrame): (WebView::notifyPreferencesChanged): Source/WTF: Add experimental feature flag for BroadcastChannel, off by default. * Scripts/Preferences/WebPreferencesExperimental.yaml: LayoutTests: * TestExpectations: * fast/html/broadcast-channel-between-different-sessions-expected.txt: Added. * fast/html/broadcast-channel-between-different-sessions.html: Added. * fast/html/resources/broadcast-channel-between-different-sessions-window.html: Added. Add layout test coverage to make sure that windows belonging to different session are unable to communicate via BroadcastChannel. * platform/ios-wk2/imported/w3c/web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-sizing.window-expected.txt: Copied from LayoutTests/imported/w3c/web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-sizing.window-expected.txt. * platform/ios-wk2/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/mac-wk1/TestExpectations: * platform/mac-wk1/imported/w3c/web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-BarProp.window-expected.txt: Added. * platform/mac-wk1/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/mac-wk1/imported/w3c/web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/htmlanchorelement_noopener-expected.txt: Added. * platform/mac-wk2/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/win/TestExpectations: * platform/wk2/TestExpectations: Update test expectations now that we support BroadcastChannel. Canonical link: https://commits.webkit.org/239714@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279971 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-07-16 00:36:39 +00:00
/*
* Copyright (C) 2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "BroadcastChannelIdentifier.h"
imported/w3c/web-platform-tests/webmessaging/broadcastchannel/blobs.html is a flaky failure since implementing BlobChannel https://bugs.webkit.org/show_bug.cgi?id=228168 <rdar://problem/80922502> Reviewed by Alex Christensen. Source/WebCore: The test was flaky because it is trying to send a Blob via BroadcastChannel.postMessage() without keeping the blob alive. When GC triggers, the Blob would go away and trying to decode the Blob upon receiving would fail. To address the issue, I introduced a Blob::Handle class that wraps the Blob's internal URL and keeps the Blob data alive as long as as someone is holding such handle. Previously, the Blob destructor would unregister the internal URL and the Blob data would go away. I then updated SerializedScriptValue to hold on to Blob::Handle objects instead of Blob URLs. This guarantees that when using postMessage() to send a message to a worker, the Blob data will stay alive until we dispatch the message event on the worker side and try and deserialized the SerializedScriptValue. For BroadcastChannel.postMessage() though, we end up going via the network process and the SerializedScriptValue ends up getting serialized/deserialized over IPC. I added a CompletionHandler to BroadcastChannelRegistry::postMessage() which only gets called once the message event has successfully been dispatched. I use this completion handler to make sure the SerializedScriptValue's Blob URLs stay valid until the the message has been dispatched by holding on to the Blob::Handles. No new tests, unskipped existing test. * Modules/indexeddb/IDBValue.cpp: (WebCore::IDBValue::IDBValue): * bindings/js/SerializedScriptValue.cpp: (WebCore::CloneSerializer::serialize): (WebCore::CloneSerializer::CloneSerializer): (WebCore::CloneSerializer::dumpIfTerminal): (WebCore::CloneSerializer::write): (WebCore::SerializedScriptValue::SerializedScriptValue): (WebCore::SerializedScriptValue::computeMemoryCost const): (WebCore::SerializedScriptValue::create): (WebCore::SerializedScriptValue::blobURLs const): (WebCore::SerializedScriptValue::writeBlobsToDiskForIndexedDB): * bindings/js/SerializedScriptValue.h: (WebCore::SerializedScriptValue::hasBlobURLs const): (WebCore::SerializedScriptValue::blobHandles const): (WebCore::SerializedScriptValue::SerializedScriptValue): * dom/BroadcastChannel.cpp: (WebCore::BroadcastChannel::postMessage): (WebCore::BroadcastChannel::dispatchMessageTo): * dom/BroadcastChannel.h: * dom/BroadcastChannelRegistry.h: * fileapi/Blob.cpp: (WebCore::BlobInternalURL::create): (WebCore::BlobInternalURL::~BlobInternalURL): (WebCore::BlobInternalURL::url const): (WebCore::BlobInternalURL::BlobInternalURL): (WebCore::Blob::Blob): (WebCore::Blob::~Blob): (WebCore::Blob::url const): (WebCore::Blob::slice const): (WebCore::Blob::size const): (WebCore::Blob::handle const): (WebCore::Blob::Handle::Handle): (WebCore::Blob::Handle::url const): * fileapi/Blob.h: * loader/EmptyClients.cpp: Source/WebKit: * NetworkProcess/NetworkBroadcastChannelRegistry.cpp: (WebKit::NetworkBroadcastChannelRegistry::postMessage): * NetworkProcess/NetworkBroadcastChannelRegistry.h: * NetworkProcess/NetworkBroadcastChannelRegistry.messages.in: * Platform/IPC/HandleMessage.h: (IPC::handleMessageAsyncWantsConnection): handleMessageAsyncWantsConnection() had gotten out of sync with handleMessageAsync(). This was causing IPC decoding failures when using both "Async" and "WantsConnection" for the IPC message. * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp: (WebKit::WebBroadcastChannelRegistry::postMessage): (WebKit::WebBroadcastChannelRegistry::postMessageToRemote): * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.h: * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.messages.in: Source/WebKitLegacy: * WebCoreSupport/WebBroadcastChannelRegistry.cpp: (WebBroadcastChannelRegistry::postMessage): * WebCoreSupport/WebBroadcastChannelRegistry.h: LayoutTests: Unskip test that is no longer flaky. * platform/ios-wk2/TestExpectations: * platform/mac/TestExpectations: Canonical link: https://commits.webkit.org/240174@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@280547 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-08-02 18:46:51 +00:00
#include <wtf/Forward.h>
Add initial support for BroadcastChannel behind a runtime flag https://bugs.webkit.org/show_bug.cgi?id=227924 Reviewed by Sam Weinig. LayoutTests/imported/w3c: Rebaseline WPT tests now that more tests are running and we are passing more checks. * web-platform-tests/FileAPI/url/url-in-tags-revoke.window-expected.txt: * web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-BarProp.window-expected.txt: * web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-sizing.window-expected.txt: * web-platform-tests/html/browsers/the-window-object/window-open-noreferrer-expected.txt: * web-platform-tests/html/cross-origin-embedder-policy/report-only-require-corp.https-expected.txt: * web-platform-tests/html/cross-origin-embedder-policy/require-corp.https-expected.txt: * web-platform-tests/html/dom/idlharness.worker-expected.txt: * web-platform-tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/broadcastchannel-success.https-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-base-target-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-button-target-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-form-target-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-input-target-expected.txt: * web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/htmlanchorelement_noopener-expected.txt: * web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/target_blank_implicit_noopener-expected.txt: * web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/target_blank_implicit_noopener_base-expected.txt: * web-platform-tests/wasm/serialization/module/broadcastchannel-success-and-failure-expected.txt: * web-platform-tests/wasm/serialization/module/broadcastchannel-success-expected.txt: * web-platform-tests/webmessaging/MessageEvent-trusted.any-expected.txt: * web-platform-tests/webmessaging/MessageEvent-trusted.any.worker-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/basics-expected.txt: Removed. * web-platform-tests/webmessaging/broadcastchannel/basics.any-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/basics.any.worker-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/blobs-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/interface-expected.txt: Removed. * web-platform-tests/webmessaging/broadcastchannel/interface.any-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/interface.any.worker-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/sandbox-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/workers-expected.txt: Added. * web-platform-tests/webmessaging/multi-globals/broadcastchannel-current.sub-expected.txt: * web-platform-tests/webstorage/storage_session_window_noopener.window-expected.txt: * web-platform-tests/workers/semantics/interface-objects/001.worker-expected.txt: Source/WebCore: Add initial support for BroadcastChannel behind a runtime flag, off by default: - https://html.spec.whatwg.org/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts Both Firefox and Blink have been supporting BroadcastChannel for a long time. The implementation is complete and spec-compliant. It works both in Window and Worker environments, in WebKit1 and WebKit2. However, the feature is off-by-default because of privacy concerns that have not been addresssed yet: - https://github.com/whatwg/html/issues/5803 We should be able to add partioning to address the privacy concerns and ship this later on. In the mean time though, having a working BroadcastChannel implementation in the context of layout tests is already very useful because a lot of Web-Platform-Tests are relying on it to test other Web features. This means better test coverage for WebKit. Tests: - fast/html/broadcast-channel-between-different-sessions.html - Rebaselined WPT tests * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Headers.cmake: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * bindings/js/WebCoreBuiltinNames.h: * dom/BroadcastChannel.cpp: Added. (WebCore::channelToContextIdentifier): (WebCore::BroadcastChannel::BroadcastChannel): (WebCore::BroadcastChannel::~BroadcastChannel): (WebCore::BroadcastChannel::postMessage): (WebCore::BroadcastChannel::close): (WebCore::BroadcastChannel::dispatchMessageTo): (WebCore::BroadcastChannel::dispatchMessage): (WebCore::BroadcastChannel::ensureOnMainThread): (WebCore::BroadcastChannel::activeDOMObjectName const): (WebCore::BroadcastChannel::eventListenersDidChange): (WebCore::BroadcastChannel::virtualHasPendingActivity const): * dom/BroadcastChannel.h: Added. (WebCore::BroadcastChannel::create): (WebCore::BroadcastChannel::identifier const): (WebCore::BroadcastChannel::name const): * dom/BroadcastChannel.idl: Added. * dom/BroadcastChannelIdentifier.h: Added. * dom/BroadcastChannelRegistry.h: Added. (WebCore::BroadcastChannelRegistry::~BroadcastChannelRegistry): * dom/DeviceOrientationAndMotionAccessController.h: * dom/DeviceOrientationEvent.cpp: * dom/DeviceOrientationEvent.h: * dom/EventTargetFactory.in: * loader/EmptyClients.cpp: (WebCore::pageConfigurationWithEmptyClients): * page/Page.cpp: (WebCore::Page::Page): (WebCore::Page::setBroadcastChannelRegistry): * page/Page.h: (WebCore::Page::broadcastChannelRegistry): * page/PageConfiguration.cpp: (WebCore::PageConfiguration::PageConfiguration): * page/PageConfiguration.h: Source/WebKit: Add initial support for BroadcastChannel behind a runtime flag, off by default: - https://html.spec.whatwg.org/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts Both Firefox and Blink have been supporting BroadcastChannel for a long time. The implementation is complete and spec-compliant. It works both in Window and Worker environments, in WebKit1 and WebKit2. However, the feature is off-by-default because of privacy concerns that have not been addresssed yet: - https://github.com/whatwg/html/issues/5803 We should be able to add partioning to address the privacy concerns and ship this later on. In the mean time though, having a working BroadcastChannel implementation in the context of layout tests is already very useful because a lot of Web-Platform-Tests are relying on it to test other Web features. This means better test coverage for WebKit. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * NetworkProcess/Downloads/DownloadManager.cpp: * NetworkProcess/NetworkBroadcastChannelRegistry.cpp: Added. (WebKit::NetworkBroadcastChannelRegistry::registerChannel): (WebKit::NetworkBroadcastChannelRegistry::unregisterChannel): (WebKit::NetworkBroadcastChannelRegistry::postMessage): (WebKit::NetworkBroadcastChannelRegistry::removeConnection): * NetworkProcess/NetworkBroadcastChannelRegistry.h: Added. (WebKit::NetworkBroadcastChannelRegistry::GlobalBroadcastChannelIdentifier::operator== const): * NetworkProcess/NetworkBroadcastChannelRegistry.messages.in: Added. * NetworkProcess/NetworkConnectionToWebProcess.cpp: (WebKit::NetworkConnectionToWebProcess::didReceiveMessage): (WebKit::NetworkConnectionToWebProcess::didClose): * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::NetworkSession): * NetworkProcess/NetworkSession.h: (WebKit::NetworkSession::broadcastChannelRegistry): * Scripts/webkit/messages.py: (types_that_cannot_be_forward_declared): * Sources.txt: * WebKit.xcodeproj/project.pbxproj: * WebProcess/Network/NetworkProcessConnection.cpp: (WebKit::NetworkProcessConnection::didReceiveMessage): * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp: Added. (WebKit::networkProcessConnection): (WebKit::WebBroadcastChannelRegistry::registerChannel): (WebKit::WebBroadcastChannelRegistry::unregisterChannel): (WebKit::WebBroadcastChannelRegistry::postMessage): (WebKit::WebBroadcastChannelRegistry::postMessageToRemote): * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.h: Added. * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.messages.in: Added. * WebProcess/WebPage/WebPage.cpp: (WebKit::m_appHighlightsVisible): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::WebProcess): * WebProcess/WebProcess.h: (WebKit::WebProcess::broadcastChannelRegistry): Source/WebKitLegacy: Add BroadcastChannelRegistry implementation for WebKitLegacy. * Sources.txt: * WebCoreSupport/WebBroadcastChannelRegistry.cpp: Added. (WebBroadcastChannelRegistry::getOrCreate): (WebBroadcastChannelRegistry::registerChannel): (WebBroadcastChannelRegistry::unregisterChannel): (WebBroadcastChannelRegistry::postMessage): * WebCoreSupport/WebBroadcastChannelRegistry.h: Added. * WebKitLegacy.xcodeproj/project.pbxproj: Source/WebKitLegacy/mac: * WebView/WebView.mm: (-[WebView _commonInitializationWithFrameName:groupName:]): (-[WebView _preferencesChanged:]): Source/WebKitLegacy/win: * WebView.cpp: (WebView::initWithFrame): (WebView::notifyPreferencesChanged): Source/WTF: Add experimental feature flag for BroadcastChannel, off by default. * Scripts/Preferences/WebPreferencesExperimental.yaml: LayoutTests: * TestExpectations: * fast/html/broadcast-channel-between-different-sessions-expected.txt: Added. * fast/html/broadcast-channel-between-different-sessions.html: Added. * fast/html/resources/broadcast-channel-between-different-sessions-window.html: Added. Add layout test coverage to make sure that windows belonging to different session are unable to communicate via BroadcastChannel. * platform/ios-wk2/imported/w3c/web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-sizing.window-expected.txt: Copied from LayoutTests/imported/w3c/web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-sizing.window-expected.txt. * platform/ios-wk2/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/mac-wk1/TestExpectations: * platform/mac-wk1/imported/w3c/web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-BarProp.window-expected.txt: Added. * platform/mac-wk1/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/mac-wk1/imported/w3c/web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/htmlanchorelement_noopener-expected.txt: Added. * platform/mac-wk2/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/win/TestExpectations: * platform/wk2/TestExpectations: Update test expectations now that we support BroadcastChannel. Canonical link: https://commits.webkit.org/239714@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279971 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-07-16 00:36:39 +00:00
#include <wtf/RefCounted.h>
namespace WebCore {
class SerializedScriptValue;
struct SecurityOriginData;
class BroadcastChannelRegistry : public RefCounted<BroadcastChannelRegistry> {
public:
virtual ~BroadcastChannelRegistry() { }
virtual void registerChannel(const SecurityOriginData&, const String& name, BroadcastChannelIdentifier) = 0;
virtual void unregisterChannel(const SecurityOriginData&, const String& name, BroadcastChannelIdentifier) = 0;
imported/w3c/web-platform-tests/webmessaging/broadcastchannel/blobs.html is a flaky failure since implementing BlobChannel https://bugs.webkit.org/show_bug.cgi?id=228168 <rdar://problem/80922502> Reviewed by Alex Christensen. Source/WebCore: The test was flaky because it is trying to send a Blob via BroadcastChannel.postMessage() without keeping the blob alive. When GC triggers, the Blob would go away and trying to decode the Blob upon receiving would fail. To address the issue, I introduced a Blob::Handle class that wraps the Blob's internal URL and keeps the Blob data alive as long as as someone is holding such handle. Previously, the Blob destructor would unregister the internal URL and the Blob data would go away. I then updated SerializedScriptValue to hold on to Blob::Handle objects instead of Blob URLs. This guarantees that when using postMessage() to send a message to a worker, the Blob data will stay alive until we dispatch the message event on the worker side and try and deserialized the SerializedScriptValue. For BroadcastChannel.postMessage() though, we end up going via the network process and the SerializedScriptValue ends up getting serialized/deserialized over IPC. I added a CompletionHandler to BroadcastChannelRegistry::postMessage() which only gets called once the message event has successfully been dispatched. I use this completion handler to make sure the SerializedScriptValue's Blob URLs stay valid until the the message has been dispatched by holding on to the Blob::Handles. No new tests, unskipped existing test. * Modules/indexeddb/IDBValue.cpp: (WebCore::IDBValue::IDBValue): * bindings/js/SerializedScriptValue.cpp: (WebCore::CloneSerializer::serialize): (WebCore::CloneSerializer::CloneSerializer): (WebCore::CloneSerializer::dumpIfTerminal): (WebCore::CloneSerializer::write): (WebCore::SerializedScriptValue::SerializedScriptValue): (WebCore::SerializedScriptValue::computeMemoryCost const): (WebCore::SerializedScriptValue::create): (WebCore::SerializedScriptValue::blobURLs const): (WebCore::SerializedScriptValue::writeBlobsToDiskForIndexedDB): * bindings/js/SerializedScriptValue.h: (WebCore::SerializedScriptValue::hasBlobURLs const): (WebCore::SerializedScriptValue::blobHandles const): (WebCore::SerializedScriptValue::SerializedScriptValue): * dom/BroadcastChannel.cpp: (WebCore::BroadcastChannel::postMessage): (WebCore::BroadcastChannel::dispatchMessageTo): * dom/BroadcastChannel.h: * dom/BroadcastChannelRegistry.h: * fileapi/Blob.cpp: (WebCore::BlobInternalURL::create): (WebCore::BlobInternalURL::~BlobInternalURL): (WebCore::BlobInternalURL::url const): (WebCore::BlobInternalURL::BlobInternalURL): (WebCore::Blob::Blob): (WebCore::Blob::~Blob): (WebCore::Blob::url const): (WebCore::Blob::slice const): (WebCore::Blob::size const): (WebCore::Blob::handle const): (WebCore::Blob::Handle::Handle): (WebCore::Blob::Handle::url const): * fileapi/Blob.h: * loader/EmptyClients.cpp: Source/WebKit: * NetworkProcess/NetworkBroadcastChannelRegistry.cpp: (WebKit::NetworkBroadcastChannelRegistry::postMessage): * NetworkProcess/NetworkBroadcastChannelRegistry.h: * NetworkProcess/NetworkBroadcastChannelRegistry.messages.in: * Platform/IPC/HandleMessage.h: (IPC::handleMessageAsyncWantsConnection): handleMessageAsyncWantsConnection() had gotten out of sync with handleMessageAsync(). This was causing IPC decoding failures when using both "Async" and "WantsConnection" for the IPC message. * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp: (WebKit::WebBroadcastChannelRegistry::postMessage): (WebKit::WebBroadcastChannelRegistry::postMessageToRemote): * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.h: * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.messages.in: Source/WebKitLegacy: * WebCoreSupport/WebBroadcastChannelRegistry.cpp: (WebBroadcastChannelRegistry::postMessage): * WebCoreSupport/WebBroadcastChannelRegistry.h: LayoutTests: Unskip test that is no longer flaky. * platform/ios-wk2/TestExpectations: * platform/mac/TestExpectations: Canonical link: https://commits.webkit.org/240174@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@280547 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-08-02 18:46:51 +00:00
virtual void postMessage(const SecurityOriginData&, const String& name, BroadcastChannelIdentifier source, Ref<SerializedScriptValue>&&, CompletionHandler<void()>&&) = 0;
Add initial support for BroadcastChannel behind a runtime flag https://bugs.webkit.org/show_bug.cgi?id=227924 Reviewed by Sam Weinig. LayoutTests/imported/w3c: Rebaseline WPT tests now that more tests are running and we are passing more checks. * web-platform-tests/FileAPI/url/url-in-tags-revoke.window-expected.txt: * web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-BarProp.window-expected.txt: * web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-sizing.window-expected.txt: * web-platform-tests/html/browsers/the-window-object/window-open-noreferrer-expected.txt: * web-platform-tests/html/cross-origin-embedder-policy/report-only-require-corp.https-expected.txt: * web-platform-tests/html/cross-origin-embedder-policy/require-corp.https-expected.txt: * web-platform-tests/html/dom/idlharness.worker-expected.txt: * web-platform-tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/broadcastchannel-success.https-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-base-target-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-button-target-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-form-target-expected.txt: * web-platform-tests/html/semantics/forms/form-submission-target/rel-input-target-expected.txt: * web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/htmlanchorelement_noopener-expected.txt: * web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/target_blank_implicit_noopener-expected.txt: * web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/target_blank_implicit_noopener_base-expected.txt: * web-platform-tests/wasm/serialization/module/broadcastchannel-success-and-failure-expected.txt: * web-platform-tests/wasm/serialization/module/broadcastchannel-success-expected.txt: * web-platform-tests/webmessaging/MessageEvent-trusted.any-expected.txt: * web-platform-tests/webmessaging/MessageEvent-trusted.any.worker-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/basics-expected.txt: Removed. * web-platform-tests/webmessaging/broadcastchannel/basics.any-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/basics.any.worker-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/blobs-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/interface-expected.txt: Removed. * web-platform-tests/webmessaging/broadcastchannel/interface.any-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/interface.any.worker-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/sandbox-expected.txt: * web-platform-tests/webmessaging/broadcastchannel/workers-expected.txt: Added. * web-platform-tests/webmessaging/multi-globals/broadcastchannel-current.sub-expected.txt: * web-platform-tests/webstorage/storage_session_window_noopener.window-expected.txt: * web-platform-tests/workers/semantics/interface-objects/001.worker-expected.txt: Source/WebCore: Add initial support for BroadcastChannel behind a runtime flag, off by default: - https://html.spec.whatwg.org/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts Both Firefox and Blink have been supporting BroadcastChannel for a long time. The implementation is complete and spec-compliant. It works both in Window and Worker environments, in WebKit1 and WebKit2. However, the feature is off-by-default because of privacy concerns that have not been addresssed yet: - https://github.com/whatwg/html/issues/5803 We should be able to add partioning to address the privacy concerns and ship this later on. In the mean time though, having a working BroadcastChannel implementation in the context of layout tests is already very useful because a lot of Web-Platform-Tests are relying on it to test other Web features. This means better test coverage for WebKit. Tests: - fast/html/broadcast-channel-between-different-sessions.html - Rebaselined WPT tests * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Headers.cmake: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * bindings/js/WebCoreBuiltinNames.h: * dom/BroadcastChannel.cpp: Added. (WebCore::channelToContextIdentifier): (WebCore::BroadcastChannel::BroadcastChannel): (WebCore::BroadcastChannel::~BroadcastChannel): (WebCore::BroadcastChannel::postMessage): (WebCore::BroadcastChannel::close): (WebCore::BroadcastChannel::dispatchMessageTo): (WebCore::BroadcastChannel::dispatchMessage): (WebCore::BroadcastChannel::ensureOnMainThread): (WebCore::BroadcastChannel::activeDOMObjectName const): (WebCore::BroadcastChannel::eventListenersDidChange): (WebCore::BroadcastChannel::virtualHasPendingActivity const): * dom/BroadcastChannel.h: Added. (WebCore::BroadcastChannel::create): (WebCore::BroadcastChannel::identifier const): (WebCore::BroadcastChannel::name const): * dom/BroadcastChannel.idl: Added. * dom/BroadcastChannelIdentifier.h: Added. * dom/BroadcastChannelRegistry.h: Added. (WebCore::BroadcastChannelRegistry::~BroadcastChannelRegistry): * dom/DeviceOrientationAndMotionAccessController.h: * dom/DeviceOrientationEvent.cpp: * dom/DeviceOrientationEvent.h: * dom/EventTargetFactory.in: * loader/EmptyClients.cpp: (WebCore::pageConfigurationWithEmptyClients): * page/Page.cpp: (WebCore::Page::Page): (WebCore::Page::setBroadcastChannelRegistry): * page/Page.h: (WebCore::Page::broadcastChannelRegistry): * page/PageConfiguration.cpp: (WebCore::PageConfiguration::PageConfiguration): * page/PageConfiguration.h: Source/WebKit: Add initial support for BroadcastChannel behind a runtime flag, off by default: - https://html.spec.whatwg.org/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts Both Firefox and Blink have been supporting BroadcastChannel for a long time. The implementation is complete and spec-compliant. It works both in Window and Worker environments, in WebKit1 and WebKit2. However, the feature is off-by-default because of privacy concerns that have not been addresssed yet: - https://github.com/whatwg/html/issues/5803 We should be able to add partioning to address the privacy concerns and ship this later on. In the mean time though, having a working BroadcastChannel implementation in the context of layout tests is already very useful because a lot of Web-Platform-Tests are relying on it to test other Web features. This means better test coverage for WebKit. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * NetworkProcess/Downloads/DownloadManager.cpp: * NetworkProcess/NetworkBroadcastChannelRegistry.cpp: Added. (WebKit::NetworkBroadcastChannelRegistry::registerChannel): (WebKit::NetworkBroadcastChannelRegistry::unregisterChannel): (WebKit::NetworkBroadcastChannelRegistry::postMessage): (WebKit::NetworkBroadcastChannelRegistry::removeConnection): * NetworkProcess/NetworkBroadcastChannelRegistry.h: Added. (WebKit::NetworkBroadcastChannelRegistry::GlobalBroadcastChannelIdentifier::operator== const): * NetworkProcess/NetworkBroadcastChannelRegistry.messages.in: Added. * NetworkProcess/NetworkConnectionToWebProcess.cpp: (WebKit::NetworkConnectionToWebProcess::didReceiveMessage): (WebKit::NetworkConnectionToWebProcess::didClose): * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::NetworkSession): * NetworkProcess/NetworkSession.h: (WebKit::NetworkSession::broadcastChannelRegistry): * Scripts/webkit/messages.py: (types_that_cannot_be_forward_declared): * Sources.txt: * WebKit.xcodeproj/project.pbxproj: * WebProcess/Network/NetworkProcessConnection.cpp: (WebKit::NetworkProcessConnection::didReceiveMessage): * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp: Added. (WebKit::networkProcessConnection): (WebKit::WebBroadcastChannelRegistry::registerChannel): (WebKit::WebBroadcastChannelRegistry::unregisterChannel): (WebKit::WebBroadcastChannelRegistry::postMessage): (WebKit::WebBroadcastChannelRegistry::postMessageToRemote): * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.h: Added. * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.messages.in: Added. * WebProcess/WebPage/WebPage.cpp: (WebKit::m_appHighlightsVisible): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::WebProcess): * WebProcess/WebProcess.h: (WebKit::WebProcess::broadcastChannelRegistry): Source/WebKitLegacy: Add BroadcastChannelRegistry implementation for WebKitLegacy. * Sources.txt: * WebCoreSupport/WebBroadcastChannelRegistry.cpp: Added. (WebBroadcastChannelRegistry::getOrCreate): (WebBroadcastChannelRegistry::registerChannel): (WebBroadcastChannelRegistry::unregisterChannel): (WebBroadcastChannelRegistry::postMessage): * WebCoreSupport/WebBroadcastChannelRegistry.h: Added. * WebKitLegacy.xcodeproj/project.pbxproj: Source/WebKitLegacy/mac: * WebView/WebView.mm: (-[WebView _commonInitializationWithFrameName:groupName:]): (-[WebView _preferencesChanged:]): Source/WebKitLegacy/win: * WebView.cpp: (WebView::initWithFrame): (WebView::notifyPreferencesChanged): Source/WTF: Add experimental feature flag for BroadcastChannel, off by default. * Scripts/Preferences/WebPreferencesExperimental.yaml: LayoutTests: * TestExpectations: * fast/html/broadcast-channel-between-different-sessions-expected.txt: Added. * fast/html/broadcast-channel-between-different-sessions.html: Added. * fast/html/resources/broadcast-channel-between-different-sessions-window.html: Added. Add layout test coverage to make sure that windows belonging to different session are unable to communicate via BroadcastChannel. * platform/ios-wk2/imported/w3c/web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-sizing.window-expected.txt: Copied from LayoutTests/imported/w3c/web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-sizing.window-expected.txt. * platform/ios-wk2/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/mac-wk1/TestExpectations: * platform/mac-wk1/imported/w3c/web-platform-tests/html/browsers/the-window-object/noopener-noreferrer-BarProp.window-expected.txt: Added. * platform/mac-wk1/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/mac-wk1/imported/w3c/web-platform-tests/html/semantics/links/links-created-by-a-and-area-elements/htmlanchorelement_noopener-expected.txt: Added. * platform/mac-wk2/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/win/TestExpectations: * platform/wk2/TestExpectations: Update test expectations now that we support BroadcastChannel. Canonical link: https://commits.webkit.org/239714@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279971 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-07-16 00:36:39 +00:00
};
} // namespace WebCore