Title: [288387] trunk/Source/WebKit
Revision
288387
Author
pvol...@apple.com
Date
2022-01-21 16:29:07 -0800 (Fri, 21 Jan 2022)

Log Message

Inject Launch Services database before NSApplication is initialized
https://bugs.webkit.org/show_bug.cgi?id=235186
<rdar://87468788>

Reviewed by Chris Dumez.

To avoid the main thread getting stuck, the Launch Services database should be injected before NSApplication
is initialized, since the initialization now depends on the database. To make sure also prewarmed WebContent
processes are receiving the Launch Services database, the WebsiteDataStore method
sendNetworkProcessXPCEndpointToProcess is moved to the class NetworkProcessProxy, since prewarmed processes
will not have a data store initially. This allows us to simplify the code, since we are no longer depending
on having a Website data store before sending the XPC endpoint.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didFinishLaunching):
* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::sendNetworkProcessXPCEndpointToProcess):
(WebKit::WebsiteDataStore::sendNetworkProcessXPCEndpointToProcess const): Deleted.
* UIProcess/WebsiteData/WebsiteDataStore.h:
* WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::platformDidReceiveLoadParameters):
* WebProcess/cocoa/LaunchServicesDatabaseManager.h:
* WebProcess/cocoa/LaunchServicesDatabaseManager.mm:
(WebKit::LaunchServicesDatabaseManager::waitForDatabaseUpdate):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (288386 => 288387)


--- trunk/Source/WebKit/ChangeLog	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/ChangeLog	2022-01-22 00:29:07 UTC (rev 288387)
@@ -1,5 +1,34 @@
 2022-01-21  Per Arne Vollan  <pvol...@apple.com>
 
+        Inject Launch Services database before NSApplication is initialized
+        https://bugs.webkit.org/show_bug.cgi?id=235186
+        <rdar://87468788>
+
+        Reviewed by Chris Dumez.
+
+        To avoid the main thread getting stuck, the Launch Services database should be injected before NSApplication
+        is initialized, since the initialization now depends on the database. To make sure also prewarmed WebContent
+        processes are receiving the Launch Services database, the WebsiteDataStore method
+        sendNetworkProcessXPCEndpointToProcess is moved to the class NetworkProcessProxy, since prewarmed processes
+        will not have a data store initially. This allows us to simplify the code, since we are no longer depending
+        on having a Website data store before sending the XPC endpoint.
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::didFinishLaunching):
+        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+        (WebKit::WebsiteDataStore::sendNetworkProcessXPCEndpointToProcess):
+        (WebKit::WebsiteDataStore::sendNetworkProcessXPCEndpointToProcess const): Deleted.
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+        (WebKit::WebPage::platformDidReceiveLoadParameters):
+        * WebProcess/cocoa/LaunchServicesDatabaseManager.h:
+        * WebProcess/cocoa/LaunchServicesDatabaseManager.mm:
+        (WebKit::LaunchServicesDatabaseManager::waitForDatabaseUpdate):
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
+2022-01-21  Per Arne Vollan  <pvol...@apple.com>
+
         [iOS][WP] Allow access to CFNetwork prefs
         https://bugs.webkit.org/show_bug.cgi?id=235457
         <rdar://87822314>

Modified: trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp (288386 => 288387)


--- trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp	2022-01-22 00:29:07 UTC (rev 288387)
@@ -441,15 +441,8 @@
 #endif
 
 #if PLATFORM(COCOA)
-    // Use any session ID to get any Website data store. It is OK to use any Website data store,
-    // since we are using it to access any Networking process, which all have the XPC endpoint.
-    // The XPC endpoint is used to receive the Launch Services database from the Network process.
-    if (m_sessionIDs.isEmpty())
-        return;
-    auto store = WebsiteDataStore::existingDataStoreForSessionID(*m_sessionIDs.begin());
-    if (!store)
-        return;
-    m_hasSentNetworkProcessXPCEndpoint = store->sendNetworkProcessXPCEndpointToProcess(*this);
+    if (auto networkProcess = NetworkProcessProxy::defaultNetworkProcess())
+        networkProcess->sendXPCEndpointToProcess(*this);
 #endif
 }
 
@@ -515,11 +508,6 @@
 
     send(Messages::GPUProcess::AddSession { store.sessionID(), gpuProcessSessionParameters(store) }, 0);
     m_sessionIDs.add(store.sessionID());
-
-#if PLATFORM(COCOA)
-    if (!m_hasSentNetworkProcessXPCEndpoint)
-        m_hasSentNetworkProcessXPCEndpoint = store.sendNetworkProcessXPCEndpointToProcess(*this);
-#endif
 }
 
 void GPUProcessProxy::removeSession(PAL::SessionID sessionID)

Modified: trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.h (288386 => 288387)


--- trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.h	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.h	2022-01-22 00:29:07 UTC (rev 288387)
@@ -151,7 +151,6 @@
     bool m_hasSentTCCDSandboxExtension { false };
     bool m_hasSentCameraSandboxExtension { false };
     bool m_hasSentMicrophoneSandboxExtension { false };
-    bool m_hasSentNetworkProcessXPCEndpoint { false };
 #endif
 
 #if ENABLE(MEDIA_SOURCE) && ENABLE(VP9)

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (288386 => 288387)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2022-01-22 00:29:07 UTC (rev 288387)
@@ -271,6 +271,7 @@
     API::CustomProtocolManagerClient& customProtocolManagerClient() { return m_customProtocolManagerClient.get(); }
 
 #if PLATFORM(COCOA)
+    bool sendXPCEndpointToProcess(AuxiliaryProcessProxy&);
     xpc_object_t xpcEndpointMessage() const { return m_endpointMessage.get(); }
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxyCocoa.mm (288386 => 288387)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxyCocoa.mm	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxyCocoa.mm	2022-01-22 00:29:07 UTC (rev 288387)
@@ -53,8 +53,14 @@
 
     if (messageName == LaunchServicesDatabaseXPCConstants::xpcLaunchServicesDatabaseXPCEndpointMessageName) {
         m_networkProcess->m_endpointMessage = event;
-        for (auto& dataStore : copyToVectorOf<Ref<WebsiteDataStore>>(m_networkProcess->m_websiteDataStores))
-            dataStore->sendNetworkProcessXPCEndpointToAllProcesses();
+        for (auto& processPool : WebProcessPool::allProcessPools()) {
+            for (auto& process : processPool->processes())
+                m_networkProcess->sendXPCEndpointToProcess(process);
+        }
+#if ENABLE(GPU_PROCESS)
+        if (auto gpuProcess = GPUProcessProxy::singletonIfCreated())
+            m_networkProcess->sendXPCEndpointToProcess(*gpuProcess);
+#endif
     }
 
     return true;
@@ -65,4 +71,18 @@
 {
 }
 
+bool NetworkProcessProxy::sendXPCEndpointToProcess(AuxiliaryProcessProxy& process)
+{
+    if (process.state() != AuxiliaryProcessProxy::State::Running)
+        return false;
+    auto* connection = process.connection();
+    if (!connection)
+        return false;
+    auto message = xpcEndpointMessage();
+    if (!message)
+        return false;
+    xpc_connection_send_message(connection->xpcConnection(), message);
+    return true;
 }
+
+}

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (288386 => 288387)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2022-01-22 00:29:07 UTC (rev 288387)
@@ -349,13 +349,6 @@
     ASSERT(!m_websiteDataStore);
     WEBPROCESSPROXY_RELEASE_LOG(Process, "setWebsiteDataStore() dataStore=%p, sessionID=%" PRIu64, &dataStore, dataStore.sessionID().toUInt64());
     m_websiteDataStore = &dataStore;
-#if PLATFORM(COCOA)
-    dataStore.sendNetworkProcessXPCEndpointToProcess(*this);
-#if ENABLE(GPU_PROCESS)
-    if (GPUProcessProxy::singletonIfCreated())
-        dataStore.sendNetworkProcessXPCEndpointToProcess(*GPUProcessProxy::singletonIfCreated());
-#endif
-#endif
     updateRegistrationWithDataStore();
     send(Messages::WebProcess::SetWebsiteDataStoreParameters(processPool().webProcessDataStoreParameters(*this, dataStore)), 0);
 
@@ -1055,8 +1048,8 @@
     }
 
 #if PLATFORM(COCOA)
-    if (m_websiteDataStore)
-        m_websiteDataStore->sendNetworkProcessXPCEndpointToProcess(*this);
+    if (auto networkProcess = NetworkProcessProxy::defaultNetworkProcess())
+        networkProcess->sendXPCEndpointToProcess(*this);
 #endif
 
     RELEASE_ASSERT(!m_webConnection);

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm (288386 => 288387)


--- trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2022-01-22 00:29:07 UTC (rev 288387)
@@ -616,28 +616,4 @@
     return WTF::hasEntitlement(networkProcess().connection()->xpcConnection(), entitlement.utf8().data());
 }
 
-bool WebsiteDataStore::sendNetworkProcessXPCEndpointToProcess(AuxiliaryProcessProxy& process) const
-{
-    if (process.state() != AuxiliaryProcessProxy::State::Running)
-        return false;
-    auto* connection = process.connection();
-    if (!connection)
-        return false;
-    auto message = networkProcess().xpcEndpointMessage();
-    if (!message)
-        return false;
-    xpc_connection_send_message(connection->xpcConnection(), message);
-    return true;
 }
-
-void WebsiteDataStore::sendNetworkProcessXPCEndpointToAllProcesses()
-{
-    for (auto& process : m_processes)
-        sendNetworkProcessXPCEndpointToProcess(process);
-#if ENABLE(GPU_PROCESS)
-    if (GPUProcessProxy::singletonIfCreated())
-        sendNetworkProcessXPCEndpointToProcess(*GPUProcessProxy::singletonIfCreated());
-#endif
-}
-
-}

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (288386 => 288387)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2022-01-22 00:29:07 UTC (rev 288387)
@@ -278,9 +278,6 @@
     void dispatchOnQueue(Function<void()>&&);
 
 #if PLATFORM(COCOA)
-    bool sendNetworkProcessXPCEndpointToProcess(AuxiliaryProcessProxy&) const;
-    void sendNetworkProcessXPCEndpointToAllProcesses();
-    
     static bool useNetworkLoader();
 #endif
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (288386 => 288387)


--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2022-01-22 00:29:07 UTC (rev 288387)
@@ -27,7 +27,6 @@
 #import "WebPage.h"
 
 #import "InsertTextOptions.h"
-#import "LaunchServicesDatabaseManager.h"
 #import "LoadParameters.h"
 #import "PluginView.h"
 #import "UserMediaCaptureManager.h"
@@ -77,21 +76,6 @@
 
 void WebPage::platformDidReceiveLoadParameters(const LoadParameters& parameters)
 {
-#if HAVE(LSDATABASECONTEXT)
-    static bool hasWaitedForLaunchServicesDatabase = false;
-    if (!hasWaitedForLaunchServicesDatabase) {
-        auto startTime = WallTime::now();
-        bool databaseUpdated = LaunchServicesDatabaseManager::singleton().waitForDatabaseUpdate(5_s);
-        auto elapsedTime = WallTime::now() - startTime;
-        if (elapsedTime.value() > 0.5)
-            RELEASE_LOG(Loading, "Waiting for Launch Services database update took %f seconds", elapsedTime.value());
-        ASSERT_UNUSED(databaseUpdated, databaseUpdated);
-        if (!databaseUpdated)
-            RELEASE_LOG_ERROR(Loading, "Timed out waiting for Launch Services database update.");
-        hasWaitedForLaunchServicesDatabase = true;
-    }
-#endif
-
     m_dataDetectionContext = parameters.dataDetectionContext;
 
     consumeNetworkExtensionSandboxExtensions(parameters.networkExtensionSandboxExtensionHandles);

Modified: trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.h (288386 => 288387)


--- trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.h	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.h	2022-01-22 00:29:07 UTC (rev 288387)
@@ -35,12 +35,14 @@
 public:
     static LaunchServicesDatabaseManager& singleton();
 
-    bool waitForDatabaseUpdate(Seconds);
+    void waitForDatabaseUpdate();
 
 private:
     void handleEvent(xpc_object_t) override;
     void didConnect() override;
 
+    bool waitForDatabaseUpdate(Seconds);
+
     std::atomic<bool> m_hasReceivedLaunchServicesDatabase { false };
     BinarySemaphore m_semaphore;
 };

Modified: trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.mm (288386 => 288387)


--- trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.mm	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.mm	2022-01-22 00:29:07 UTC (rev 288387)
@@ -27,6 +27,7 @@
 #import "LaunchServicesDatabaseManager.h"
 
 #import "LaunchServicesDatabaseXPCConstants.h"
+#import "Logging.h"
 #import "XPCEndpoint.h"
 #import <pal/spi/cocoa/LaunchServicesSPI.h>
 #import <wtf/cocoa/Entitlements.h>
@@ -81,4 +82,16 @@
     return m_semaphore.waitFor(timeout);
 }
 
+void LaunchServicesDatabaseManager::waitForDatabaseUpdate()
+{
+    auto startTime = MonotonicTime::now();
+    bool databaseUpdated = waitForDatabaseUpdate(5_s);
+    auto elapsedTime = MonotonicTime::now() - startTime;
+    if (elapsedTime > 0.5_s)
+        RELEASE_LOG_ERROR(Loading, "Waiting for Launch Services database update took %f seconds", elapsedTime.value());
+    ASSERT_UNUSED(databaseUpdated, databaseUpdated);
+    if (!databaseUpdated)
+        RELEASE_LOG_ERROR(Loading, "Timed out waiting for Launch Services database update.");
 }
+
+}

Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (288386 => 288387)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2022-01-22 00:21:53 UTC (rev 288386)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2022-01-22 00:29:07 UTC (rev 288387)
@@ -28,6 +28,7 @@
 
 #import "AccessibilitySupportSPI.h"
 #import "GPUProcessConnectionParameters.h"
+#import "LaunchServicesDatabaseManager.h"
 #import "LegacyCustomProtocolManager.h"
 #import "LogInitialization.h"
 #import "Logging.h"
@@ -328,6 +329,12 @@
     method_setImplementation(methodToPatch, (IMP)NSApplicationAccessibilityFocusedUIElement);
 #endif
 
+#if HAVE(LSDATABASECONTEXT)
+    // On Mac, this needs to be called before NSApplication is being initialized.
+    // The NSApplication initialization is being done in [NSApplication _accessibilityInitialize]
+    LaunchServicesDatabaseManager::singleton().waitForDatabaseUpdate();
+#endif
+
 #if PLATFORM(MAC) && ENABLE(WEBPROCESS_NSRUNLOOP)
     RefPtr<SandboxExtension> launchServicesExtension;
     if (parameters.launchServicesExtensionHandle) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to