Title: [289292] branches/safari-613-branch/Source/WebKit
Revision
289292
Author
[email protected]
Date
2022-02-07 18:54:32 -0800 (Mon, 07 Feb 2022)

Log Message

Cherry-pick r288387. rdar://problem/87468788

    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):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288387 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-613-branch/Source/WebKit/ChangeLog (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/ChangeLog	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/ChangeLog	2022-02-08 02:54:32 UTC (rev 289292)
@@ -1,5 +1,68 @@
 2022-02-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r288387. rdar://problem/87468788
+
+    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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288387 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-21  Per Arne Vollan  <[email protected]>
+
+            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-02-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r288296. rdar://problem/88593227
 
     Disable fallback path to WebRTC platform sockets

Modified: branches/safari-613-branch/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp	2022-02-08 02:54:32 UTC (rev 289292)
@@ -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: branches/safari-613-branch/Source/WebKit/UIProcess/GPU/GPUProcessProxy.h (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/UIProcess/GPU/GPUProcessProxy.h	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/GPU/GPUProcessProxy.h	2022-02-08 02:54:32 UTC (rev 289292)
@@ -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: branches/safari-613-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2022-02-08 02:54:32 UTC (rev 289292)
@@ -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: branches/safari-613-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxyCocoa.mm (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxyCocoa.mm	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxyCocoa.mm	2022-02-08 02:54:32 UTC (rev 289292)
@@ -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: branches/safari-613-branch/Source/WebKit/UIProcess/WebProcessProxy.cpp (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/UIProcess/WebProcessProxy.cpp	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/WebProcessProxy.cpp	2022-02-08 02:54:32 UTC (rev 289292)
@@ -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: branches/safari-613-branch/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2022-02-08 02:54:32 UTC (rev 289292)
@@ -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: branches/safari-613-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2022-02-08 02:54:32 UTC (rev 289292)
@@ -278,9 +278,6 @@
     void dispatchOnQueue(Function<void()>&&);
 
 #if PLATFORM(COCOA)
-    bool sendNetworkProcessXPCEndpointToProcess(AuxiliaryProcessProxy&) const;
-    void sendNetworkProcessXPCEndpointToAllProcesses();
-    
     static bool useNetworkLoader();
 #endif
 

Modified: branches/safari-613-branch/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2022-02-08 02:54:32 UTC (rev 289292)
@@ -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: branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.h (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.h	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.h	2022-02-08 02:54:32 UTC (rev 289292)
@@ -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: branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.mm (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.mm	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.mm	2022-02-08 02:54:32 UTC (rev 289292)
@@ -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: branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (289291 => 289292)


--- branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2022-02-08 02:54:27 UTC (rev 289291)
+++ branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2022-02-08 02:54:32 UTC (rev 289292)
@@ -28,6 +28,7 @@
 
 #import "AccessibilitySupportSPI.h"
 #import "GPUProcessConnectionParameters.h"
+#import "LaunchServicesDatabaseManager.h"
 #import "LegacyCustomProtocolManager.h"
 #import "LogInitialization.h"
 #import "Logging.h"
@@ -326,6 +327,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
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to