[Cocoa] Only set CF prefs direct mode for the WebContent process
authorpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Mar 2020 19:50:59 +0000 (19:50 +0000)
committerpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Mar 2020 19:50:59 +0000 (19:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=209091
<rdar://problem/60337842>

Reviewed by Brent Fulgham.

Currently, we enable CF prefs direct mode in XPCServiceMain. This is incorrect, it should only be enabled
for the WebContent process.

* Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
(WebKit::XPCServiceMain):

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

Source/WebKit/ChangeLog
Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm

index fa7c790..fb7b134 100644 (file)
@@ -1,3 +1,17 @@
+2020-03-16  Per Arne Vollan  <pvollan@apple.com>
+
+        [Cocoa] Only set CF prefs direct mode for the WebContent process
+        https://bugs.webkit.org/show_bug.cgi?id=209091
+        <rdar://problem/60337842>
+
+        Reviewed by Brent Fulgham.
+
+        Currently, we enable CF prefs direct mode in XPCServiceMain. This is incorrect, it should only be enabled
+        for the WebContent process.
+
+        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
+        (WebKit::XPCServiceMain):
+
 2020-03-16  David Kilzer  <ddkilzer@apple.com>
 
         WebPage::GetDataSelectionForPasteboard should validate its `size` variable
index 1f2e571..210efbb 100644 (file)
@@ -70,7 +70,6 @@ static void XPCServiceEventHandler(xpc_connection_t peer)
                 else
                     RELEASE_ASSERT_NOT_REACHED();
 
-                
                 typedef void (*InitializerFunction)(xpc_connection_t, xpc_object_t, xpc_object_t);
                 InitializerFunction initializerFunctionPtr = reinterpret_cast<InitializerFunction>(CFBundleGetFunctionPointerForName(webKitBundle, entryPointFunctionName));
                 if (!initializerFunctionPtr) {
@@ -106,8 +105,17 @@ static void XPCServiceEventHandler(xpc_connection_t peer)
     xpc_connection_resume(peer);
 }
 
-int XPCServiceMain(int, const char**)
+int XPCServiceMain(int argc, const char** argv)
 {
+    ASSERT(argc >= 1);
+    ASSERT(argv[0]);
+#if ENABLE(CFPREFS_DIRECT_MODE)
+    if (argc >= 1 && argv[0] && strstr(argv[0], "com.apple.WebKit.WebContent")) {
+        // Enable CFPrefs direct mode to avoid unsuccessfully attempting to connect to the daemon and getting blocked by the sandbox.
+        _CFPrefsSetDirectModeEnabled(YES);
+    }
+#endif
+
     auto bootstrap = adoptOSObject(xpc_copy_bootstrap());
 #if PLATFORM(IOS_FAMILY)
     auto containerEnvironmentVariables = xpc_dictionary_get_value(bootstrap.get(), "ContainerEnvironmentVariables");
@@ -117,11 +125,6 @@ int XPCServiceMain(int, const char**)
     });
 #endif
 
-#if ENABLE(CFPREFS_DIRECT_MODE)
-    // Enable CF prefs direct mode to avoid connecting to the CF prefs daemon.
-    _CFPrefsSetDirectModeEnabled(YES);
-#endif
-
     if (bootstrap) {
 #if PLATFORM(MAC)
         if (const char* webKitBundleVersion = xpc_dictionary_get_string(bootstrap.get(), "WebKitBundleVersion")) {