Title: [234668] trunk/Source/WebKit
Revision
234668
Author
[email protected]
Date
2018-08-07 14:04:43 -0700 (Tue, 07 Aug 2018)

Log Message

Add SPI for launching WebContent process with pre-linked injected bundle
https://bugs.webkit.org/show_bug.cgi?id=188367

Patch by Ben Richards <[email protected]> on 2018-08-07
Reviewed by Ryosuke Niwa.

Added SPI to allow applications to set a "customWebContentServiceBundleIdentifier" which will be launched instead of the default WebContent XPC service.
The "customWebContentServiceBundleIdentifier" should be the bundle identifier for an XPC service that calls [WKProcessPool _webContentProcessXPCMain].
The new XPC service should be hard linked to the application's injected bundle in order to receive the intended performance benefit.

* Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h:
* Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm:
(WebKit::XPCServiceMain):
(main):
* UIProcess/API/APIProcessPoolConfiguration.h:
* UIProcess/API/C/WKContext.cpp:
(WKContextSetCustomWebContentServiceBundleIdentifier):
* UIProcess/API/C/WKContext.h:
* UIProcess/API/Cocoa/WKProcessPool.mm:
(+[WKProcessPool _webContentProcessXPCMain]):
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
(-[_WKProcessPoolConfiguration customWebContentServiceBundleIdentifier]):
(-[_WKProcessPoolConfiguration setCustomWebContentServiceBundleIdentifier:]):
* UIProcess/Launcher/ProcessLauncher.h:
* UIProcess/Launcher/mac/ProcessLauncherMac.mm:
(WebKit::ProcessLauncher::launchProcess):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::setCustomWebContentServiceBundleIdentifier):
* UIProcess/WebProcessPool.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::getLaunchOptions):
* WebKit.xcodeproj/project.pbxproj:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (234667 => 234668)


--- trunk/Source/WebKit/ChangeLog	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/ChangeLog	2018-08-07 21:04:43 UTC (rev 234668)
@@ -1,3 +1,39 @@
+2018-08-07  Ben Richards  <[email protected]>
+
+        Add SPI for launching WebContent process with pre-linked injected bundle
+        https://bugs.webkit.org/show_bug.cgi?id=188367
+
+        Reviewed by Ryosuke Niwa.
+
+        Added SPI to allow applications to set a "customWebContentServiceBundleIdentifier" which will be launched instead of the default WebContent XPC service.
+        The "customWebContentServiceBundleIdentifier" should be the bundle identifier for an XPC service that calls [WKProcessPool _webContentProcessXPCMain].
+        The new XPC service should be hard linked to the application's injected bundle in order to receive the intended performance benefit.
+
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h:
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm:
+        (WebKit::XPCServiceMain):
+        (main):
+        * UIProcess/API/APIProcessPoolConfiguration.h:
+        * UIProcess/API/C/WKContext.cpp:
+        (WKContextSetCustomWebContentServiceBundleIdentifier):
+        * UIProcess/API/C/WKContext.h:
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (+[WKProcessPool _webContentProcessXPCMain]):
+        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
+        (-[_WKProcessPoolConfiguration customWebContentServiceBundleIdentifier]):
+        (-[_WKProcessPoolConfiguration setCustomWebContentServiceBundleIdentifier:]):
+        * UIProcess/Launcher/ProcessLauncher.h:
+        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+        (WebKit::ProcessLauncher::launchProcess):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::setCustomWebContentServiceBundleIdentifier):
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::getLaunchOptions):
+        * WebKit.xcodeproj/project.pbxproj:
+
 2018-08-07  Chris Dumez  <[email protected]>
 
         StorageManager should stop ref'ing IPC::Connections as this is leak-prone

Modified: trunk/Source/WebKit/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h (234667 => 234668)


--- trunk/Source/WebKit/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h	2018-08-07 21:04:43 UTC (rev 234668)
@@ -115,6 +115,8 @@
     XPCServiceType::singleton().initialize(parameters);
 }
 
+int XPCServiceMain();
+
 void XPCServiceExit(OSObjectPtr<xpc_object_t>&& priorityBoostMessage);
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm (234667 => 234668)


--- trunk/Source/WebKit/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm	2018-08-07 21:04:43 UTC (rev 234668)
@@ -25,6 +25,7 @@
 
 #import "config.h"
 #import "WebProcessCocoa.h"
+#import "XPCServiceEntryPoint.h"
 
 #import <CoreFoundation/CoreFoundation.h>
 #import <wtf/OSObjectPtr.h>
@@ -91,11 +92,7 @@
     xpc_connection_resume(peer);
 }
 
-} // namespace WebKit
-
-using namespace WebKit;
-
-int main(int argc, char** argv)
+int XPCServiceMain()
 {
 #if defined(__i386__)
     // FIXME: This should only be done for the 32-bit plug-in XPC service so we rely on the fact that
@@ -160,3 +157,10 @@
     xpc_main(XPCServiceEventHandler);
     return 0;
 }
+
+} // namespace WebKit
+
+int main(int argc, char** argv)
+{
+    return WebKit::XPCServiceMain();
+}

Modified: trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h	2018-08-07 21:04:43 UTC (rev 234668)
@@ -150,6 +150,9 @@
     bool processSwapsOnWindowOpenWithOpener() const { return m_processSwapsOnWindowOpenWithOpener; }
     void setProcessSwapsOnWindowOpenWithOpener(bool swaps) { m_processSwapsOnWindowOpenWithOpener = swaps; }
 
+    const WTF::String& customWebContentServiceBundleIdentifier() const { return m_customWebContentServiceBundleIdentifier; }
+    void setCustomWebContentServiceBundleIdentifier(const WTF::String& customWebContentServiceBundleIdentifier) { m_customWebContentServiceBundleIdentifier = customWebContentServiceBundleIdentifier; }
+
 #if ENABLE(WIFI_ASSERTIONS)
     unsigned wirelessContextIdentifier() const { return m_wirelessContextIdentifier; }
     void setWirelessContextIdentifier(unsigned wirelessContextIdentifier) { m_wirelessContextIdentifier = wirelessContextIdentifier; }
@@ -196,6 +199,7 @@
     bool m_processSwapsOnNavigation { false };
     bool m_alwaysKeepAndReuseSwappedProcesses { false };
     bool m_processSwapsOnWindowOpenWithOpener { false };
+    WTF::String m_customWebContentServiceBundleIdentifier;
 
 #if PLATFORM(IOS)
     WTF::String m_ctDataConnectionServiceType;

Modified: trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp	2018-08-07 21:04:43 UTC (rev 234668)
@@ -407,6 +407,11 @@
     toImpl(contextRef)->setMaximumNumberOfPrewarmedProcesses(value);
 }
 
+void WKContextSetCustomWebContentServiceBundleIdentifier(WKContextRef contextRef, WKStringRef name)
+{
+    toImpl(contextRef)->setCustomWebContentServiceBundleIdentifier(toImpl(name)->string());
+}
+
 void WKContextSetDiskCacheSpeculativeValidationEnabled(WKContextRef contextRef, bool value)
 {
     toImpl(contextRef)->configuration().setDiskCacheSpeculativeValidationEnabled(value);

Modified: trunk/Source/WebKit/UIProcess/API/C/WKContext.h (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/API/C/WKContext.h	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/API/C/WKContext.h	2018-08-07 21:04:43 UTC (rev 234668)
@@ -165,6 +165,8 @@
 WK_EXPORT void WKContextSetPlugInAutoStartOriginsFilteringOutEntriesAddedAfterTime(WKContextRef contextRef, WKDictionaryRef dictionaryRef, double time);
 WK_EXPORT void WKContextRefreshPlugIns(WKContextRef context);
 
+WK_EXPORT void WKContextSetCustomWebContentServiceBundleIdentifier(WKContextRef contextRef, WKStringRef name);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2018-08-07 21:04:43 UTC (rev 234668)
@@ -40,6 +40,7 @@
 #import "WebCookieManagerProxy.h"
 #import "WebProcessMessages.h"
 #import "WebProcessPool.h"
+#import "XPCServiceEntryPoint.h"
 #import "_WKAutomationDelegate.h"
 #import "_WKAutomationSessionInternal.h"
 #import "_WKDownloadDelegate.h"
@@ -181,6 +182,11 @@
     return [url URLByAppendingPathComponent:@"WebsiteData" isDirectory:YES];
 }
 
++ (int)_webContentProcessXPCMain
+{
+    return WebKit::XPCServiceMain();
+}
+
 - (void)_setAllowsSpecificHTTPSCertificate:(NSArray *)certificateChain forHost:(NSString *)host
 {
     _processPool->allowSpecificHTTPSCertificateForHost(WebKit::WebCertificateInfo::create(WebCore::CertificateInfo((__bridge CFArrayRef)certificateChain)).ptr(), host);

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2018-08-07 21:04:43 UTC (rev 234668)
@@ -79,6 +79,8 @@
 
 - (void)_registerURLSchemeAsCanDisplayOnlyIfCanRequest:(NSString *)scheme WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
++ (int)_webContentProcessXPCMain WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 // Test only. Should be called only while no web content processes are running.
 - (void)_terminateStorageProcess;
 - (void)_terminateNetworkProcess;

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h	2018-08-07 21:04:43 UTC (rev 234668)
@@ -36,6 +36,7 @@
 @property (nonatomic, copy) NSURL *injectedBundleURL;
 @property (nonatomic) NSUInteger maximumProcessCount;
 @property (nonatomic) NSUInteger maximumPrewarmedProcessCount WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, nullable, copy) NSString *customWebContentServiceBundleIdentifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @property (nonatomic) BOOL ignoreSynchronousMessagingTimeoutsForTesting WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 @property (nonatomic) BOOL attrStyleEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm	2018-08-07 21:04:43 UTC (rev 234668)
@@ -359,6 +359,16 @@
     return wrapper(_processPoolConfiguration->copy().leakRef());
 }
 
+- (NSString *)customWebContentServiceBundleIdentifier
+{
+    return _processPoolConfiguration->customWebContentServiceBundleIdentifier();
+}
+
+- (void)setCustomWebContentServiceBundleIdentifier:(NSString *)customWebContentServiceBundleIdentifier
+{
+    _processPoolConfiguration->setCustomWebContentServiceBundleIdentifier(customWebContentServiceBundleIdentifier);
+}
+
 #pragma mark WKObject protocol implementation
 
 - (API::Object&)_apiObject

Modified: trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h	2018-08-07 21:04:43 UTC (rev 234668)
@@ -66,6 +66,7 @@
         HashMap<String, String> extraInitializationData;
         bool nonValidInjectedCodeAllowed { false };
         bool shouldMakeProcessLaunchFailForTesting { false };
+        CString customWebContentServiceBundleIdentifier;
 
 #if ENABLE(DEVELOPER_MODE) && (PLATFORM(GTK) || PLATFORM(WPE))
         String processCmdPrefix;

Modified: trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2018-08-07 21:04:43 UTC (rev 234668)
@@ -101,8 +101,14 @@
 {
     ASSERT(!m_xpcConnection);
 
-    m_xpcConnection = adoptOSObject(xpc_connection_create(serviceName(m_launchOptions), dispatch_get_main_queue()));
+    const char* name;
+    if (!m_launchOptions.customWebContentServiceBundleIdentifier.isNull())
+        name = m_launchOptions.customWebContentServiceBundleIdentifier.data();
+    else
+        name = serviceName(m_launchOptions);
 
+    m_xpcConnection = adoptOSObject(xpc_connection_create(name, dispatch_get_main_queue()));
+
     uuid_t uuid;
     uuid_generate(uuid);
     xpc_connection_set_oneshot_instance(m_xpcConnection.get(), uuid);

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-08-07 21:04:43 UTC (rev 234668)
@@ -418,6 +418,15 @@
     m_configuration->setMaximumPrewarmedProcessCount(maximumNumberOfProcesses);
 }
 
+void WebProcessPool::setCustomWebContentServiceBundleIdentifier(const String& customWebContentServiceBundleIdentifier)
+{
+    // Guard against API misuse.
+    if (m_processes.size() || !customWebContentServiceBundleIdentifier.isAllASCII())
+        CRASH();
+
+    m_configuration->setCustomWebContentServiceBundleIdentifier(customWebContentServiceBundleIdentifier);
+}
+
 IPC::Connection* WebProcessPool::networkingProcessConnection()
 {
     return m_networkProcess->connection();

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2018-08-07 21:04:43 UTC (rev 234668)
@@ -159,6 +159,9 @@
     void setMaximumNumberOfPrewarmedProcesses(unsigned); // Can only be called when there are no processes running.
     unsigned maximumNumberOfPrewarmedProcesses() const { return m_configuration->maximumPrewarmedProcessCount(); }
 
+    void setCustomWebContentServiceBundleIdentifier(const String&);
+    const String& customWebContentServiceBundleIdentifier() { return m_configuration->customWebContentServiceBundleIdentifier(); }
+
     const Vector<RefPtr<WebProcessProxy>>& processes() const { return m_processes; }
 
     // WebProcess or NetworkProcess as approporiate for current process model. The connection must be non-null.

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (234667 => 234668)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2018-08-07 21:04:43 UTC (rev 234668)
@@ -162,6 +162,8 @@
 
     ChildProcessProxy::getLaunchOptions(launchOptions);
 
+    if (!m_processPool->customWebContentServiceBundleIdentifier().isNull())
+        launchOptions.customWebContentServiceBundleIdentifier = m_processPool->customWebContentServiceBundleIdentifier().ascii();
     if (WebKit::isInspectorProcessPool(processPool()))
         launchOptions.extraInitializationData.add("inspector-process"_s, "1"_s);
 

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (234667 => 234668)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2018-08-07 19:34:23 UTC (rev 234667)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2018-08-07 21:04:43 UTC (rev 234668)
@@ -957,6 +957,7 @@
 		414DEDD71F9EDDE50047C40D /* ServiceWorkerProcessProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 414DEDD51F9EDDDF0047C40D /* ServiceWorkerProcessProxy.h */; };
 		414DEDD81F9EDDE50047C40D /* ServiceWorkerProcessProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 414DEDD61F9EDDE00047C40D /* ServiceWorkerProcessProxy.cpp */; };
 		4157E4B020E2ECDF00A6C0D7 /* com.google.o1dbrowserplugin.sb in Copy Plug-in Sandbox Profiles */ = {isa = PBXBuildFile; fileRef = 4157E4AF20E2EC9800A6C0D7 /* com.google.o1dbrowserplugin.sb */; };
+		41639A89211933ED001CEF14 /* XPCServiceMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC82839616B47EC400A278FE /* XPCServiceMain.mm */; };
 		41897ECF1F415D620016FA42 /* WebCacheStorageConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41897ECE1F415D5C0016FA42 /* WebCacheStorageConnection.cpp */; };
 		41897ED01F415D650016FA42 /* WebCacheStorageProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41897ECC1F415D5C0016FA42 /* WebCacheStorageProvider.cpp */; };
 		41897ED11F415D680016FA42 /* WebCacheStorageConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 41897ECD1F415D5C0016FA42 /* WebCacheStorageConnection.h */; };
@@ -11770,6 +11771,7 @@
 				1AD60F5D18E20F4C0020C034 /* WKWindowFeatures.mm in Sources */,
 				1A7C0DF61B7D1F1000A9B848 /* WKWindowFeaturesRef.cpp in Sources */,
 				BCBECDE716B6416800047A1A /* XPCServiceEntryPoint.mm in Sources */,
+				41639A89211933ED001CEF14 /* XPCServiceMain.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to