Changeset 282377 in webkit
- Timestamp:
- Sep 13, 2021, 9:15:43 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
-
LayoutTests/imported/w3c/web-platform-tests/html/cross-origin-opener-policy/coop-navigated-history-popup.https-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/dom/BroadcastChannel.cpp (modified) (1 diff)
-
Source/WebCore/dom/ScriptExecutionContext.cpp (modified) (1 diff)
-
Source/WebCore/dom/ScriptExecutionContext.h (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/NetworkProcess/NetworkBroadcastChannelRegistry.cpp (modified) (4 diffs)
-
Source/WebKit/NetworkProcess/NetworkBroadcastChannelRegistry.h (modified) (1 diff)
-
Source/WebKit/NetworkProcess/NetworkBroadcastChannelRegistry.messages.in (modified) (1 diff)
-
Source/WebKit/WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp (modified) (2 diffs)
-
Source/WebKit/WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.h (modified) (2 diffs)
-
Source/WebKit/WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.messages.in (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/web-platform-tests/html/cross-origin-opener-policy/coop-navigated-history-popup.https-expected.txt
r280504 r282377 1 CONSOLE MESSAGE: Can't close the window since it was not opened by JavaScript 1 2 2 3 PASS Popup navigating to other origin with COOP: same-origin and back in history -
trunk/Source/WebCore/ChangeLog
r282374 r282377 1 2021-09-13 Chris Dumez <cdumez@apple.com> 2 3 [WK2] Reduce amount of IPC needed by BroadcastChannel 4 https://bugs.webkit.org/show_bug.cgi?id=230181 5 6 Reviewed by Alex Christensen. 7 8 Introduce ScriptExecutionContext::ensureOnContextThread() which is similar to 9 ScriptExecutionContext::postTaskTo() but doesn't call postTask() if we're already 10 on the ScriptExecutionContext's context thread. Use it in BroadcastChannel::dispatchMessageTo() 11 to avoid unnecessary thread hopping when the BroadcastChannel belongs to a Window 12 environment. 13 14 * dom/BroadcastChannel.cpp: 15 (WebCore::BroadcastChannel::dispatchMessageTo): 16 * dom/ScriptExecutionContext.cpp: 17 (WebCore::ScriptExecutionContext::ensureOnContextThread): 18 * dom/ScriptExecutionContext.h: 19 1 20 2021-09-13 Jean-Yves Avenard <jya@apple.com> 2 21 -
trunk/Source/WebCore/dom/BroadcastChannel.cpp
r282366 r282377 227 227 228 228 auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler)); 229 ScriptExecutionContext:: postTaskTo(contextIdentifier, [channelIdentifier, message = WTFMove(message), callbackAggregator = WTFMove(callbackAggregator)](auto&) mutable {229 ScriptExecutionContext::ensureOnContextThread(contextIdentifier, [channelIdentifier, message = WTFMove(message), callbackAggregator = WTFMove(callbackAggregator)](auto&) mutable { 230 230 RefPtr<BroadcastChannel> channel; 231 231 { -
trunk/Source/WebCore/dom/ScriptExecutionContext.cpp
r281879 r282377 651 651 } 652 652 653 bool ScriptExecutionContext::ensureOnContextThread(ScriptExecutionContextIdentifier identifier, Task&& task) 654 { 655 ScriptExecutionContext* context = nullptr; 656 { 657 Locker locker { allScriptExecutionContextsMapLock }; 658 context = allScriptExecutionContextsMap().get(identifier); 659 660 if (!context) 661 return false; 662 663 if (!context->isContextThread()) { 664 context->postTask(WTFMove(task)); 665 return true; 666 } 667 } 668 669 task.performTask(*context); 670 return true; 671 } 672 653 673 } // namespace WebCore -
trunk/Source/WebCore/dom/ScriptExecutionContext.h
r282222 r282377 282 282 #endif 283 283 WEBCORE_EXPORT static bool postTaskTo(ScriptExecutionContextIdentifier, Task&&); 284 WEBCORE_EXPORT static bool ensureOnContextThread(ScriptExecutionContextIdentifier, Task&&); 284 285 285 286 ScriptExecutionContextIdentifier contextIdentifier() const; -
trunk/Source/WebKit/ChangeLog
r282375 r282377 1 2021-09-13 Chris Dumez <cdumez@apple.com> 2 3 [WK2] Reduce amount of IPC needed by BroadcastChannel 4 https://bugs.webkit.org/show_bug.cgi?id=230181 5 6 Reviewed by Alex Christensen. 7 8 Reduce amount of IPC needed by BroadcastChannel for both registration / unregistration 9 and communication. Each WebBroadcastChannelRegistry in the WebProcess now maintains 10 a map of BroadcastChannels within the WebProcess. As a result, we are able to dispatch 11 messages to other BroadcastChannels within the same process without going via the 12 NetworkProcess. 13 14 Also, the NetworkBroadcastChannelRegistry on the NetworkProcess side no longer needs 15 to store individual BroadcastChannelIdentifiers. It merely needs to know which 16 WebProcesses have one or more BroadcastChannels for a given ClientOrigin / name. 17 When NetworkBroadcastChannelRegistry::postMessage() is called, we no longer send 18 IPC to the source process in case there are other BroadcastChannels than the source 19 with the given ClientOrigin / name in that process. Also, if there is more than 20 one BroadcastChannel for the given ClientOrigin / name within a given destination 21 WebProcess, we now send a single IPC message instead of sending one per BroadcastChannel. 22 23 * NetworkProcess/NetworkBroadcastChannelRegistry.cpp: 24 (WebKit::NetworkBroadcastChannelRegistry::registerChannel): 25 (WebKit::NetworkBroadcastChannelRegistry::unregisterChannel): 26 (WebKit::NetworkBroadcastChannelRegistry::postMessage): 27 (WebKit::NetworkBroadcastChannelRegistry::removeConnection): 28 * NetworkProcess/NetworkBroadcastChannelRegistry.h: 29 * NetworkProcess/NetworkBroadcastChannelRegistry.messages.in: 30 * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp: 31 (WebKit::WebBroadcastChannelRegistry::registerChannel): 32 (WebKit::WebBroadcastChannelRegistry::unregisterChannel): 33 (WebKit::WebBroadcastChannelRegistry::postMessage): 34 (WebKit::WebBroadcastChannelRegistry::postMessageLocally): 35 (WebKit::WebBroadcastChannelRegistry::postMessageToRemote): 36 * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.h: 37 * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.messages.in: 38 1 39 2021-09-13 Wenson Hsieh <wenson_hsieh@apple.com> 2 40 -
trunk/Source/WebKit/NetworkProcess/NetworkBroadcastChannelRegistry.cpp
r282105 r282377 35 35 NetworkBroadcastChannelRegistry::NetworkBroadcastChannelRegistry() = default; 36 36 37 void NetworkBroadcastChannelRegistry::registerChannel(IPC::Connection& connection, const WebCore::ClientOrigin& origin, const String& name , WebCore::BroadcastChannelIdentifier channelIdentifier)37 void NetworkBroadcastChannelRegistry::registerChannel(IPC::Connection& connection, const WebCore::ClientOrigin& origin, const String& name) 38 38 { 39 auto& channelsForOrigin = m_broadcastChannels.ensure(origin, [] { return NameToChannelIdentifiersMap { }; }).iterator->value; 40 auto& channelsForName = channelsForOrigin.ensure(name, [] { return Vector<GlobalBroadcastChannelIdentifier> { }; }).iterator->value; 41 GlobalBroadcastChannelIdentifier globalChannelIdentifier { connection.uniqueID(), channelIdentifier }; 42 ASSERT(!channelsForName.contains(globalChannelIdentifier)); 43 channelsForName.append(WTFMove(globalChannelIdentifier)); 39 auto& channelsForOrigin = m_broadcastChannels.ensure(origin, [] { return NameToConnectionIdentifiersMap { }; }).iterator->value; 40 auto& connectionIdentifiersForName = channelsForOrigin.ensure(name, [] { return Vector<IPC::Connection::UniqueID> { }; }).iterator->value; 41 ASSERT(!connectionIdentifiersForName.contains(connection.uniqueID())); 42 connectionIdentifiersForName.append(connection.uniqueID()); 44 43 } 45 44 46 void NetworkBroadcastChannelRegistry::unregisterChannel(IPC::Connection& connection, const WebCore::ClientOrigin& origin, const String& name , WebCore::BroadcastChannelIdentifier channelIdentifier)45 void NetworkBroadcastChannelRegistry::unregisterChannel(IPC::Connection& connection, const WebCore::ClientOrigin& origin, const String& name) 47 46 { 48 47 auto channelsForOriginIterator = m_broadcastChannels.find(origin); … … 50 49 if (channelsForOriginIterator == m_broadcastChannels.end()) 51 50 return; 52 auto c hannelsForNameIterator = channelsForOriginIterator->value.find(name);53 ASSERT(c hannelsForNameIterator != channelsForOriginIterator->value.end());54 if (c hannelsForNameIterator == channelsForOriginIterator->value.end())51 auto connectionIdentifiersForNameIterator = channelsForOriginIterator->value.find(name); 52 ASSERT(connectionIdentifiersForNameIterator != channelsForOriginIterator->value.end()); 53 if (connectionIdentifiersForNameIterator == channelsForOriginIterator->value.end()) 55 54 return; 56 55 57 GlobalBroadcastChannelIdentifier globalChannelIdentifier { connection.uniqueID(), channelIdentifier }; 58 ASSERT(channelsForNameIterator->value.contains(globalChannelIdentifier)); 59 channelsForNameIterator->value.removeFirst(globalChannelIdentifier); 56 ASSERT(connectionIdentifiersForNameIterator->value.contains(connection.uniqueID())); 57 connectionIdentifiersForNameIterator->value.removeFirst(connection.uniqueID()); 60 58 } 61 59 62 void NetworkBroadcastChannelRegistry::postMessage(IPC::Connection& connection, const WebCore::ClientOrigin& origin, const String& name, WebCore:: BroadcastChannelIdentifier source, WebCore::MessageWithMessagePorts&& message, CompletionHandler<void()>&& completionHandler)60 void NetworkBroadcastChannelRegistry::postMessage(IPC::Connection& connection, const WebCore::ClientOrigin& origin, const String& name, WebCore::MessageWithMessagePorts&& message, CompletionHandler<void()>&& completionHandler) 63 61 { 64 62 auto channelsForOriginIterator = m_broadcastChannels.find(origin); … … 66 64 if (channelsForOriginIterator == m_broadcastChannels.end()) 67 65 return completionHandler(); 68 auto c hannelsForNameIterator = channelsForOriginIterator->value.find(name);69 ASSERT(c hannelsForNameIterator != channelsForOriginIterator->value.end());70 if (c hannelsForNameIterator == channelsForOriginIterator->value.end())66 auto connectionIdentifiersForNameIterator = channelsForOriginIterator->value.find(name); 67 ASSERT(connectionIdentifiersForNameIterator != channelsForOriginIterator->value.end()); 68 if (connectionIdentifiersForNameIterator == channelsForOriginIterator->value.end()) 71 69 return completionHandler(); 72 70 73 71 auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler)); 74 GlobalBroadcastChannelIdentifier sourceGlobalChannelIdentifier { connection.uniqueID(), source };75 for (auto& globalIdentifier : channelsForNameIterator->value) {76 if ( globalIdentifier == sourceGlobalChannelIdentifier)72 for (auto& connectionID : connectionIdentifiersForNameIterator->value) { 73 // Only dispatch the post the messages to BroadcastChannels outside the source process. 74 if (connectionID == connection.uniqueID()) 77 75 continue; 78 76 79 RefPtr connection = IPC::Connection::connection( globalIdentifier.connectionIdentifier);77 RefPtr connection = IPC::Connection::connection(connectionID); 80 78 if (!connection) 81 79 continue; 82 80 83 connection->sendWithAsyncReply(Messages::WebBroadcastChannelRegistry::PostMessageToRemote( globalIdentifier.channelIndentifierInProcess, message), [callbackAggregator] { }, 0);81 connection->sendWithAsyncReply(Messages::WebBroadcastChannelRegistry::PostMessageToRemote(origin, name, message), [callbackAggregator] { }, 0); 84 82 } 85 83 } … … 91 89 Vector<String> namesToRemove; 92 90 for (auto& innerEntry : entry.value) { 93 innerEntry.value.removeAllMatching([connectionIdentifier = connection.uniqueID()](auto& globalIdentifier) { 94 return globalIdentifier.connectionIdentifier == connectionIdentifier; 95 }); 91 innerEntry.value.removeFirst(connection.uniqueID()); 96 92 if (innerEntry.value.isEmpty()) 97 93 namesToRemove.append(innerEntry.key); -
trunk/Source/WebKit/NetworkProcess/NetworkBroadcastChannelRegistry.h
r282105 r282377 46 46 void didReceiveMessage(IPC::Connection&, IPC::Decoder&); 47 47 48 void registerChannel(IPC::Connection&, const WebCore::ClientOrigin&, const String& name , WebCore::BroadcastChannelIdentifier);49 void unregisterChannel(IPC::Connection&, const WebCore::ClientOrigin&, const String& name , WebCore::BroadcastChannelIdentifier);50 void postMessage(IPC::Connection&, const WebCore::ClientOrigin&, const String& name, WebCore:: BroadcastChannelIdentifier source, WebCore::MessageWithMessagePorts&&, CompletionHandler<void()>&&);48 void registerChannel(IPC::Connection&, const WebCore::ClientOrigin&, const String& name); 49 void unregisterChannel(IPC::Connection&, const WebCore::ClientOrigin&, const String& name); 50 void postMessage(IPC::Connection&, const WebCore::ClientOrigin&, const String& name, WebCore::MessageWithMessagePorts&&, CompletionHandler<void()>&&); 51 51 52 52 private: 53 struct GlobalBroadcastChannelIdentifier { 54 IPC::Connection::UniqueID connectionIdentifier; 55 WebCore::BroadcastChannelIdentifier channelIndentifierInProcess; 56 57 bool operator==(const GlobalBroadcastChannelIdentifier& other) const 58 { 59 return connectionIdentifier == other.connectionIdentifier && channelIndentifierInProcess == other.channelIndentifierInProcess; 60 } 61 }; 62 63 using NameToChannelIdentifiersMap = HashMap<String, Vector<GlobalBroadcastChannelIdentifier>>; 64 HashMap<WebCore::ClientOrigin, NameToChannelIdentifiersMap> m_broadcastChannels; 53 using NameToConnectionIdentifiersMap = HashMap<String, Vector<IPC::Connection::UniqueID>>; 54 HashMap<WebCore::ClientOrigin, NameToConnectionIdentifiersMap> m_broadcastChannels; 65 55 }; 66 56 -
trunk/Source/WebKit/NetworkProcess/NetworkBroadcastChannelRegistry.messages.in
r282105 r282377 22 22 23 23 messages -> NetworkBroadcastChannelRegistry NotRefCounted { 24 RegisterChannel(struct WebCore::ClientOrigin origin, String name , WebCore::BroadcastChannelIdentifier channelIdentifier) WantsConnection25 UnregisterChannel(struct WebCore::ClientOrigin origin, String name , WebCore::BroadcastChannelIdentifier channelIdentifier) WantsConnection26 PostMessage(struct WebCore::ClientOrigin origin, String name, WebCore::BroadcastChannelIdentifier source,struct WebCore::MessageWithMessagePorts message) -> () Async WantsConnection24 RegisterChannel(struct WebCore::ClientOrigin origin, String name) WantsConnection 25 UnregisterChannel(struct WebCore::ClientOrigin origin, String name) WantsConnection 26 PostMessage(struct WebCore::ClientOrigin origin, String name, struct WebCore::MessageWithMessagePorts message) -> () Async WantsConnection 27 27 } -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp
r282105 r282377 32 32 #include <WebCore/BroadcastChannel.h> 33 33 #include <WebCore/MessageWithMessagePorts.h> 34 #include <wtf/CallbackAggregator.h> 34 35 35 36 namespace WebKit { … … 42 43 void WebBroadcastChannelRegistry::registerChannel(const WebCore::ClientOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier identifier) 43 44 { 44 networkProcessConnection().send(Messages::NetworkBroadcastChannelRegistry::RegisterChannel { origin, name, identifier }, 0); 45 auto& channelsForOrigin = m_channelsPerOrigin.ensure(origin, [] { return HashMap<String, Vector<WebCore::BroadcastChannelIdentifier>> { }; }).iterator->value; 46 auto& channelsForName = channelsForOrigin.ensure(name, [] { return Vector<WebCore::BroadcastChannelIdentifier> { }; }).iterator->value; 47 channelsForName.append(identifier); 48 49 if (channelsForName.size() == 1) 50 networkProcessConnection().send(Messages::NetworkBroadcastChannelRegistry::RegisterChannel { origin, name }, 0); 45 51 } 46 52 47 53 void WebBroadcastChannelRegistry::unregisterChannel(const WebCore::ClientOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier identifier) 48 54 { 49 networkProcessConnection().send(Messages::NetworkBroadcastChannelRegistry::UnregisterChannel { origin, name, identifier }, 0); 55 auto channelsPerOriginIterator = m_channelsPerOrigin.find(origin); 56 if (channelsPerOriginIterator == m_channelsPerOrigin.end()) 57 return; 58 59 auto& channelsForOrigin = channelsPerOriginIterator->value; 60 auto channelsForOriginIterator = channelsForOrigin.find(name); 61 if (channelsForOriginIterator == channelsForOrigin.end()) 62 return; 63 64 auto& channelIdentifiersForName = channelsForOriginIterator->value; 65 if (!channelIdentifiersForName.removeFirst(identifier)) 66 return; 67 if (!channelIdentifiersForName.isEmpty()) 68 return; 69 70 channelsForOrigin.remove(channelsForOriginIterator); 71 networkProcessConnection().send(Messages::NetworkBroadcastChannelRegistry::UnregisterChannel { origin, name }, 0); 72 73 if (channelsForOrigin.isEmpty()) 74 m_channelsPerOrigin.remove(channelsPerOriginIterator); 50 75 } 51 76 52 77 void WebBroadcastChannelRegistry::postMessage(const WebCore::ClientOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier source, Ref<WebCore::SerializedScriptValue>&& message, CompletionHandler<void()>&& completionHandler) 53 78 { 54 networkProcessConnection().sendWithAsyncReply(Messages::NetworkBroadcastChannelRegistry::PostMessage { origin, name, source, WebCore::MessageWithMessagePorts { WTFMove(message), { } } }, WTFMove(completionHandler), 0); 79 auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler)); 80 postMessageLocally(origin, name, source, message.copyRef(), callbackAggregator.copyRef()); 81 networkProcessConnection().sendWithAsyncReply(Messages::NetworkBroadcastChannelRegistry::PostMessage { origin, name, WebCore::MessageWithMessagePorts { WTFMove(message), { } } }, [callbackAggregator] { }, 0); 55 82 } 56 83 57 void WebBroadcastChannelRegistry::postMessage ToRemote(WebCore::BroadcastChannelIdentifier identifier, WebCore::MessageWithMessagePorts&& message, CompletionHandler<void()>&& completionHandler)84 void WebBroadcastChannelRegistry::postMessageLocally(const WebCore::ClientOrigin& origin, const String& name, std::optional<WebCore::BroadcastChannelIdentifier> sourceInProcess, Ref<WebCore::SerializedScriptValue>&& message, Ref<WTF::CallbackAggregator>&& callbackAggregator) 58 85 { 59 WebCore::BroadcastChannel::dispatchMessageTo(identifier, message.message.releaseNonNull(), WTFMove(completionHandler)); 86 auto channelsPerOriginIterator = m_channelsPerOrigin.find(origin); 87 if (channelsPerOriginIterator == m_channelsPerOrigin.end()) 88 return; 89 90 auto& channelsForOrigin = channelsPerOriginIterator->value; 91 auto channelsForOriginIterator = channelsForOrigin.find(name); 92 if (channelsForOriginIterator == channelsForOrigin.end()) 93 return; 94 95 auto channelIdentifiersForName = channelsForOriginIterator->value; 96 for (auto& channelIdentier : channelIdentifiersForName) { 97 if (channelIdentier == sourceInProcess) 98 continue; 99 WebCore::BroadcastChannel::dispatchMessageTo(channelIdentier, message.copyRef(), [callbackAggregator] { }); 100 } 101 } 102 103 void WebBroadcastChannelRegistry::postMessageToRemote(const WebCore::ClientOrigin& origin, const String& name, WebCore::MessageWithMessagePorts&& message, CompletionHandler<void()>&& completionHandler) 104 { 105 auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler)); 106 postMessageLocally(origin, name, std::nullopt, *message.message, callbackAggregator.copyRef()); 60 107 } 61 108 -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.h
r282105 r282377 28 28 #include "Connection.h" 29 29 #include <WebCore/BroadcastChannelRegistry.h> 30 #include <WebCore/ClientOrigin.h> 31 #include <wtf/HashMap.h> 32 #include <wtf/Vector.h> 33 34 namespace WTF { 35 class CallbackAggregator; 36 } 30 37 31 38 namespace WebCore { … … 51 58 WebBroadcastChannelRegistry() = default; 52 59 53 void postMessageToRemote(WebCore::BroadcastChannelIdentifier, WebCore::MessageWithMessagePorts&&, CompletionHandler<void()>&&); 60 void postMessageToRemote(const WebCore::ClientOrigin&, const String& name, WebCore::MessageWithMessagePorts&&, CompletionHandler<void()>&&); 61 void postMessageLocally(const WebCore::ClientOrigin&, const String& name, std::optional<WebCore::BroadcastChannelIdentifier> sourceInProcess, Ref<WebCore::SerializedScriptValue>&&, Ref<WTF::CallbackAggregator>&&); 62 63 HashMap<WebCore::ClientOrigin, HashMap<String, Vector<WebCore::BroadcastChannelIdentifier>>> m_channelsPerOrigin; 54 64 }; 55 65 -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.messages.in
r280547 r282377 22 22 23 23 messages -> WebBroadcastChannelRegistry { 24 PostMessageToRemote( WebCore::BroadcastChannelIdentifier destination, struct WebCore::MessageWithMessagePorts message) -> () Async24 PostMessageToRemote(struct WebCore::ClientOrigin origin, String name, struct WebCore::MessageWithMessagePorts message) -> () Async 25 25 }
Note:
See TracChangeset
for help on using the changeset viewer.