Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 0e5ba8ab4eba52c95190e3315a9bcdde1aa374bc
      
https://github.com/WebKit/WebKit/commit/0e5ba8ab4eba52c95190e3315a9bcdde1aa374bc
  Author: Elijah Sawyers <[email protected]>
  Date:   2025-02-19 (Wed, 19 Feb 2025)

  Changed paths:
    M 
Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIEventCocoa.mm
    M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm
    M Source/WebKit/UIProcess/Extensions/WebExtensionContext.h
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPITest.mm

  Log Message:
  -----------
  rdar://145075545 (Queue messages sent with browser.test if we don't have any 
listeners setup)
https://bugs.webkit.org/show_bug.cgi?id=287899
rdar://145075545

Reviewed by Timothy Hatcher.

This patch makes it so that we queue all messages sent with 
browser.test.sendMessage are
queued if there aren't currently any event listeners. We flush these queued 
messages
whenever the first listener is added.

This is useful if an extension starts sending test messages as soon as it's 
loaded, but
the listener isn't set up until later (e.g. in a content script that's injected 
later).

* 
Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIEventCocoa.mm:
(WebKit::WebExtensionContext::addListener):
Increment the count of how many listeners we have for test messages. If it's 
the first
listener being added, flush the message queue.

(WebKit::WebExtensionContext::removeListener):
Decrement the count of how many listeners we have for test messages.

* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm:
(WebKit::WebExtensionContext::sendTestMessage):
If there aren't any test message listeners, queue the message.

(WebKit::WebExtensionContext::flushTestMessageQueueIfNeeded):
Send all of the queued test messages, if there are any.

* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h:
Introduce all of the private state that we need to keep track of a test message 
queue.

(WebKit::WebExtensionContext::hasTestMessageEventListeners):
Return whether or not the context has any test message event listeners.

* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPITest.mm:
(TestWebKitAPI::TEST(WKWebExtensionAPITest, SendMessageBeforeListenerAdded)):
Write a new test to ensure that this patch behaves as expected.

Canonical link: https://commits.webkit.org/290601@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to