WebKit
WebKit copied to clipboard
Web Extension ports can not receive messages in content scripts.
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