Skip to content

Commit

Permalink
LegacyCustomProtocolManager is incorrectly using the NetworkProcess o…
Browse files Browse the repository at this point in the history
…bject off the main thread

https://bugs.webkit.org/show_bug.cgi?id=266787

Reviewed by Alex Christensen.

LegacyCustomProtocolManager is incorrectly using the NetworkProcess object off the
main thread. NetworkProcess is only safe to use on the main thread.

Found this the hardware when I tried adding a threading assertion in 272402@main.

This patch fixes the bug and re-lands the threading assertion.

* Source/WebKit/NetworkProcess/CustomProtocols/Cocoa/LegacyCustomProtocolManagerCocoa.mm:
(-[WKCustomProtocol startLoading]):
(-[WKCustomProtocol stopLoading]):
* Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.cpp:
(WebKit::LegacyCustomProtocolManager::protectedNetworkProcess const):

Canonical link: https://commits.webkit.org/272437@main
  • Loading branch information
cdumez committed Dec 22, 2023
1 parent b5ceef7 commit ca9aa80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,20 @@ - (CFRunLoopRef)initializationRunLoop

- (void)startLoading
{
if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>())
customProtocolManager->startLoading(self.customProtocolID, [self request]);
ensureOnMainRunLoop([customProtocolID = self.customProtocolID, request = retainPtr([self request])] {
if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>())
customProtocolManager->startLoading(customProtocolID, request.get());
});
}

- (void)stopLoading
{
if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>()) {
customProtocolManager->stopLoading(self.customProtocolID);
customProtocolManager->removeCustomProtocol(self.customProtocolID);
}
ensureOnMainRunLoop([customProtocolID = self.customProtocolID] {
if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>()) {
customProtocolManager->stopLoading(customProtocolID);
customProtocolManager->removeCustomProtocol(customProtocolID);
}
});
}

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ LegacyCustomProtocolManager::LegacyCustomProtocolManager(NetworkProcess& network

Ref<NetworkProcess> LegacyCustomProtocolManager::protectedNetworkProcess() const
{
ASSERT(RunLoop::isMain());
return m_networkProcess.get();
}

Expand Down

0 comments on commit ca9aa80

Please sign in to comment.