Title: [288019] trunk/Source/WebKit
Revision
288019
Author
[email protected]
Date
2022-01-14 09:10:44 -0800 (Fri, 14 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 and Simon Fraser.

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.

* 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 (288018 => 288019)


--- trunk/Source/WebKit/ChangeLog	2022-01-14 16:40:31 UTC (rev 288018)
+++ trunk/Source/WebKit/ChangeLog	2022-01-14 17:10:44 UTC (rev 288019)
@@ -1,3 +1,22 @@
+2022-01-14  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 and Simon Fraser.
+
+        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.
+
+        * 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-14  J Pascoe  <[email protected]>
 
         Expose way to encode CTAP commands with only the hash of ClientDataJSON

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


--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2022-01-14 16:40:31 UTC (rev 288018)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2022-01-14 17:10:44 UTC (rev 288019)
@@ -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 (288018 => 288019)


--- trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.h	2022-01-14 16:40:31 UTC (rev 288018)
+++ trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.h	2022-01-14 17:10:44 UTC (rev 288019)
@@ -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 (288018 => 288019)


--- trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.mm	2022-01-14 16:40:31 UTC (rev 288018)
+++ trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.mm	2022-01-14 17:10:44 UTC (rev 288019)
@@ -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 (288018 => 288019)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2022-01-14 16:40:31 UTC (rev 288018)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2022-01-14 17:10:44 UTC (rev 288019)
@@ -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