WebKit icon indicating copy to clipboard operation
WebKit copied to clipboard

Web Extension ports can not receive messages in content scripts.

Open xeenon opened this issue 5 months ago โ€ข 1 comments

50b064ec1bf042c14a93c5d6588134cc6db3f929

Web Extension ports can not receive messages in content scripts.
https://webkit.org/b/278817
rdar://133501214

Reviewed by NOBODY (OOPS!).

When sending the queued message we were sending them to the wrong process,
since `fireQueuedPortMessageEventsIfNeeded()` was being passed in a process
and not using the same delivery logic as `portPostMessage()`.

Factor the code to send the message event out of `portPostMessage()` into a new
`firePortMessageEventsIfNeeded()` method and use that in both places. We also need
call it for both target and source world types, since messages can queue for both.

This impacted content script or web page externally connectable, since the worlds
are different, as compared to main world to main world connections.

* Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIPortCocoa.mm:
(WebKit::WebExtensionContext::portPostMessage): Use firePortMessageEventsIfNeeded.
(WebKit::WebExtensionContext::firePortMessageEventsIfNeeded): Added.
(WebKit::WebExtensionContext::fireQueuedPortMessageEventsIfNeeded): Use firePortMessageEventsIfNeeded.
(WebKit::WebExtensionContext::clearQueuedPortMessages): Added logging.
* Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIRuntimeCocoa.mm:
(WebKit::WebExtensionContext::runtimeConnect): Call fireQueuedPortMessageEventsIfNeeded and
clearQueuedPortMessages for both worlds.
(WebKit::WebExtensionContext::runtimeWebPageConnect): Ditto.
* Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPITabsCocoa.mm:
(WebKit::WebExtensionContext::tabsConnect): Ditto.
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIRuntime.mm:
(TestWebKitAPI::TEST(WKWebExtensionAPIRuntime, ConnectFromContentScriptWithImmediateMessage)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPIRuntime, ConnectFromWebPageWithImmediateMessage)): Added.

https://github.com/WebKit/WebKit/commit/50b064ec1bf042c14a93c5d6588134cc6db3f929

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
โœ… ๐Ÿงช style โœ… ๐Ÿ›  ios โœ… ๐Ÿ›  mac โœ… ๐Ÿ›  wpe โœ… ๐Ÿ›  wincairo
โœ… ๐Ÿงช bindings โœ… ๐Ÿ›  ios-sim โœ… ๐Ÿ›  mac-AS-debug โœ… ๐Ÿงช wpe-wk2 โœ… ๐Ÿงช wincairo-tests
โœ… ๐Ÿงช webkitperl โœ… ๐Ÿงช ios-wk2 โœ… ๐Ÿงช api-mac โœ… ๐Ÿงช api-wpe
โœ… ๐Ÿงช ios-wk2-wpt โœ… ๐Ÿงช mac-wk1 โœ… ๐Ÿ›  wpe-cairo
โœ… ๐Ÿงช api-ios โœ… ๐Ÿงช mac-wk2 โœ… ๐Ÿ›  gtk
โœ… ๐Ÿ›  vision โœ… ๐Ÿงช mac-AS-debug-wk2 โœ… ๐Ÿงช gtk-wk2
โœ… ๐Ÿ›  vision-sim โœ… ๐Ÿงช mac-wk2-stress โœ… ๐Ÿงช api-gtk
โœ… ๐Ÿงช vision-wk2 โœ… ๐Ÿงช mac-intel-wk2
โœ… ๐Ÿ›  tv
โœ… ๐Ÿ›  tv-sim
โœ… ๐Ÿ›  watch
โœ… ๐Ÿ›  watch-sim

xeenon avatar Aug 28 '24 21:08 xeenon