Changeset 241223 in webkit


Ignore:
Timestamp:
Feb 8, 2019 5:17:41 PM (5 years ago)
Author:
achristensen@apple.com
Message:

Add SPI to use networking daemon instead of XPC service
https://bugs.webkit.org/show_bug.cgi?id=194427

Source/WebKit:

Reviewed by Geoffrey Garen.

There is still work to be done, but with the proper plist it starts and loads webpages!

  • NetworkProcess/EntryPoint/Cocoa/Daemon/DaemonEntryPoint.mm:

(WebKit::DaemonMain):

  • Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.h:
  • Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:

(WebKit::XPCEventHandler):
(WebKit::XPCInitializationHandler):
(WebKit::XPCServiceMain):
(WebKit::XPCServiceEventHandler): Deleted.

  • UIProcess/API/APIProcessPoolConfiguration.h:
  • UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
  • UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:

(-[_WKProcessPoolConfiguration usesNetworkingDaemon]):
(-[_WKProcessPoolConfiguration setUsesNetworkingDaemon:]):

  • UIProcess/AuxiliaryProcessProxy.cpp:

(WebKit::AuxiliaryProcessProxy::getLaunchOptions):

  • UIProcess/Launcher/ProcessLauncher.h:
  • UIProcess/Launcher/mac/ProcessLauncherMac.mm:

(WebKit::serviceName):
(WebKit::ProcessLauncher::launchProcess):

  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::getLaunchOptions):

  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::usesNetworkingDaemon const):

  • UIProcess/WebProcessPool.h:

Source/WTF:

Reviewed by Geoffrey Garen.

  • wtf/spi/darwin/XPCSPI.h:

Instead of using XPC bootstrap SPI, we just send a separate message.
xpc_copy_bootstrap does not seem to work in daemons.

Tools:

Reviewed by Geoffrey Garen

  • MiniBrowser/MiniBrowser.entitlements:
Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r241205 r241223  
     12019-02-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add SPI to use networking daemon instead of XPC service
     4        https://bugs.webkit.org/show_bug.cgi?id=194427
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * wtf/spi/darwin/XPCSPI.h:
     9        Instead of using XPC bootstrap SPI, we just send a separate message.
     10        xpc_copy_bootstrap does not seem to work in  daemons.
     11
    1122019-02-08  Truitt Savell  <tsavell@apple.com>
    213
  • trunk/Source/WTF/wtf/spi/darwin/XPCSPI.h

    r241205 r241223  
    7070
    7171#define XPC_ARRAY_APPEND ((size_t)(-1))
     72#define XPC_CONNECTION_MACH_SERVICE_LISTENER (1 << 0)
    7273#define XPC_ERROR_CONNECTION_INVALID XPC_GLOBAL_OBJECT(_xpc_error_connection_invalid)
     74#define XPC_ERROR_KEY_DESCRIPTION _xpc_error_key_description
    7375#define XPC_ERROR_TERMINATION_IMMINENT XPC_GLOBAL_OBJECT(_xpc_error_termination_imminent)
    7476#define XPC_TYPE_ARRAY (&_xpc_type_array)
     
    7981#define XPC_TYPE_ERROR (&_xpc_type_error)
    8082#define XPC_TYPE_STRING (&_xpc_type_string)
     83
     84extern const char * const _xpc_error_key_description;
    8185
    8286#endif // PLATFORM(MAC) || USE(APPLE_INTERNAL_SDK)
     
    153157void xpc_dictionary_set_mach_send(xpc_object_t, const char*, mach_port_t);
    154158
    155 void xpc_connection_set_bootstrap(xpc_connection_t, xpc_object_t bootstrap);
    156 xpc_object_t xpc_copy_bootstrap(void);
    157159void xpc_connection_set_oneshot_instance(xpc_connection_t, uuid_t instance);
    158160
  • trunk/Source/WebKit/ChangeLog

    r241205 r241223  
     12019-02-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add SPI to use networking daemon instead of XPC service
     4        https://bugs.webkit.org/show_bug.cgi?id=194427
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        There is still work to be done, but with the proper plist it starts and loads webpages!
     9
     10        * NetworkProcess/EntryPoint/Cocoa/Daemon/DaemonEntryPoint.mm:
     11        (WebKit::DaemonMain):
     12        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.h:
     13        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
     14        (WebKit::XPCEventHandler):
     15        (WebKit::XPCInitializationHandler):
     16        (WebKit::XPCServiceMain):
     17        (WebKit::XPCServiceEventHandler): Deleted.
     18        * UIProcess/API/APIProcessPoolConfiguration.h:
     19        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
     20        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
     21        (-[_WKProcessPoolConfiguration usesNetworkingDaemon]):
     22        (-[_WKProcessPoolConfiguration setUsesNetworkingDaemon:]):
     23        * UIProcess/AuxiliaryProcessProxy.cpp:
     24        (WebKit::AuxiliaryProcessProxy::getLaunchOptions):
     25        * UIProcess/Launcher/ProcessLauncher.h:
     26        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
     27        (WebKit::serviceName):
     28        (WebKit::ProcessLauncher::launchProcess):
     29        * UIProcess/Network/NetworkProcessProxy.cpp:
     30        (WebKit::NetworkProcessProxy::getLaunchOptions):
     31        * UIProcess/WebProcessPool.cpp:
     32        (WebKit::WebProcessPool::usesNetworkingDaemon const):
     33        * UIProcess/WebProcessPool.h:
     34
    1352019-02-08  Truitt Savell  <tsavell@apple.com>
    236
  • trunk/Source/WebKit/NetworkProcess/EntryPoint/Cocoa/Daemon/DaemonEntryPoint.mm

    r241205 r241223  
    2727#import "DaemonEntryPoint.h"
    2828
     29#import "XPCServiceEntryPoint.h"
     30#import <wtf/spi/darwin/XPCSPI.h>
     31
    2932namespace WebKit {
     33   
     34int DaemonMain(int argc, const char** argv)
     35{
     36    if (argc < 2 || strcmp(argv[1], "WebKitNetworkingDaemon")) {
     37        WTFLogAlways("Unexpected daemon parameters");
     38        return EXIT_FAILURE;
     39    }
    3040
    31 int DaemonMain(int, const char**)
    32 {
    33     return 0;
     41    xpc_connection_t listener = xpc_connection_create_mach_service("com.apple.WebKit.NetworkingDaemon", dispatch_get_main_queue(), XPC_CONNECTION_MACH_SERVICE_LISTENER);
     42   
     43    xpc_connection_set_event_handler(listener, ^(xpc_object_t peer) {
     44        if (!peer || xpc_get_type(peer) != XPC_TYPE_CONNECTION) {
     45            WTFLogAlways("Unexpected XPC object");
     46            return;
     47        }
     48
     49        XPCEventHandler(peer, AuxiliaryProcessType::Daemon);
     50    });
     51
     52    xpc_connection_resume(listener);
     53    CFRunLoopRun();
     54
     55    return EXIT_SUCCESS;
    3456}
    3557
  • trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.h

    r241205 r241223  
    131131int XPCServiceMain(int, const char**);
    132132
     133enum class AuxiliaryProcessType { Daemon, XPCService };
     134void XPCEventHandler(xpc_connection_t, AuxiliaryProcessType);
     135
    133136void XPCServiceExit(OSObjectPtr<xpc_object_t>&& priorityBoostMessage);
    134137
  • trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm

    r241205 r241223  
    3939namespace WebKit {
    4040
    41 static void XPCServiceEventHandler(xpc_connection_t peer)
     41void XPCInitializationHandler(xpc_object_t);
     42
     43void XPCEventHandler(xpc_connection_t peer, AuxiliaryProcessType processType)
    4244{
    4345    static xpc_object_t priorityBoostMessage = nullptr;
     
    4850        if (type == XPC_TYPE_ERROR) {
    4951            if (event == XPC_ERROR_CONNECTION_INVALID || event == XPC_ERROR_TERMINATION_IMMINENT) {
    50                 // FIXME: Handle this case more gracefully.
    51                 exit(EXIT_FAILURE);
     52                if (processType == AuxiliaryProcessType::XPCService) {
     53                    // FIXME: Handle this case more gracefully.
     54                    exit(EXIT_FAILURE);
     55                } else {
     56                    // FIXME: Deref the NetworkProcess object associated with this xpc connection
     57                    // once we have a container for such objects.
     58                }
    5259            }
    5360        } else {
     
    5562
    5663            if (!strcmp(xpc_dictionary_get_string(event, "message-name"), "bootstrap")) {
     64                XPCInitializationHandler(xpc_dictionary_get_value(event, "initialization-message"));
     65               
    5766                CFBundleRef webKitBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebKit"));
    5867                CFStringRef entryPointFunctionName = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), CFSTR("WebKitEntryPoint"));
     
    93102}
    94103
    95 int XPCServiceMain(int, const char**)
     104void XPCInitializationHandler(xpc_object_t event)
    96105{
    97 #if defined(__i386__)
    98     // FIXME: This should only be done for the 32-bit plug-in XPC service so we rely on the fact that
    99     // it's the only of the XPC services that are 32-bit. We should come up with a more targeted #if check.
    100     @autoreleasepool {
    101         // We must set the state of AppleMagnifiedMode before NSApplication initialization so that the value will be in
    102         // place before Cocoa startup logic runs and caches the value.
    103         [[NSUserDefaults standardUserDefaults] registerDefaults:@{ @"AppleMagnifiedMode" : @YES }];
    104     }
     106    ASSERT(event);
     107    ASSERT(xpc_get_type(event) == XPC_TYPE_DICTIONARY);
     108
     109    static std::once_flag once;
     110    std::call_once(once, [event] {
     111#if PLATFORM(MAC)
     112        // Don't allow Apple Events in WebKit processes. This can be removed when <rdar://problem/14012823> is fixed.
     113        setenv("__APPLEEVENTSSERVICENAME", "", 1);
     114
     115#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
     116        // We don't need to talk to the dock.
     117        if (Class nsApplicationClass = NSClassFromString(@"NSApplication")) {
     118            if ([nsApplicationClass respondsToSelector:@selector(_preventDockConnections)])
     119                [nsApplicationClass _preventDockConnections];
     120        }
     121#endif
    105122#endif
    106123
    107     auto bootstrap = adoptOSObject(xpc_copy_bootstrap());
    108 #if PLATFORM(IOS_FAMILY)
    109     auto containerEnvironmentVariables = xpc_dictionary_get_value(bootstrap.get(), "ContainerEnvironmentVariables");
    110     xpc_dictionary_apply(containerEnvironmentVariables, ^(const char *key, xpc_object_t value) {
    111         setenv(key, xpc_string_get_string_ptr(value), 1);
    112         return true;
    113     });
     124#if defined(__i386__)
     125        // FIXME: This should only be done for the 32-bit plug-in XPC service so we rely on the fact that
     126        // it's the only of the XPC services that are 32-bit. We should come up with a more targeted #if check.
     127        @autoreleasepool {
     128            // We must set the state of AppleMagnifiedMode before NSApplication initialization so that the value will be in
     129            // place before Cocoa startup logic runs and caches the value.
     130            [[NSUserDefaults standardUserDefaults] registerDefaults:@{ @"AppleMagnifiedMode" : @YES }];
     131        }
    114132#endif
    115133
    116     if (bootstrap) {
     134#if PLATFORM(IOS_FAMILY)
     135        auto containerEnvironmentVariables = xpc_dictionary_get_value(event, "ContainerEnvironmentVariables");
     136        xpc_dictionary_apply(containerEnvironmentVariables, ^(const char *key, xpc_object_t value) {
     137            setenv(key, xpc_string_get_string_ptr(value), 1);
     138            return true;
     139        });
     140#endif
     141
    117142#if PLATFORM(MAC)
    118         if (const char* webKitBundleVersion = xpc_dictionary_get_string(bootstrap.get(), "WebKitBundleVersion")) {
     143        if (const char* webKitBundleVersion = xpc_dictionary_get_string(event, "WebKitBundleVersion")) {
    119144            CFBundleRef webKitBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebKit"));
    120145            NSString *expectedBundleVersion = (NSString *)CFBundleGetValueForInfoDictionaryKey(webKitBundle, kCFBundleVersionKey);
     
    127152#endif
    128153
    129         if (xpc_object_t languages = xpc_dictionary_get_value(bootstrap.get(), "OverrideLanguages")) {
     154        if (xpc_object_t languages = xpc_dictionary_get_value(event, "OverrideLanguages")) {
    130155            @autoreleasepool {
    131156                NSDictionary *existingArguments = [[NSUserDefaults standardUserDefaults] volatileDomainForName:NSArgumentDomain];
     
    140165            }
    141166        }
    142     }
     167    });
     168}
    143169
    144 #if PLATFORM(MAC)
    145     // Don't allow Apple Events in WebKit processes. This can be removed when <rdar://problem/14012823> is fixed.
    146     setenv("__APPLEEVENTSSERVICENAME", "", 1);
    147 
    148 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
    149     // We don't need to talk to the dock.
    150     if (Class nsApplicationClass = NSClassFromString(@"NSApplication")) {
    151         if ([nsApplicationClass respondsToSelector:@selector(_preventDockConnections)])
    152             [nsApplicationClass _preventDockConnections];
    153     }
    154 #endif
    155 #endif
    156 
    157     xpc_main(XPCServiceEventHandler);
     170int XPCServiceMain(int, const char**)
     171{
     172    xpc_main([] (xpc_connection_t peer) {
     173        XPCEventHandler(peer, AuxiliaryProcessType::XPCService);
     174    });
    158175    return 0;
    159176}
  • trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h

    r241205 r241223  
    183183    bool suppressesConnectionTerminationOnSystemChange() const { return m_suppressesConnectionTerminationOnSystemChange; }
    184184    void setSuppressesConnectionTerminationOnSystemChange(bool suppressesConnectionTerminationOnSystemChange) { m_suppressesConnectionTerminationOnSystemChange = suppressesConnectionTerminationOnSystemChange; }
     185
     186    bool usesNetworkingDaemon() const { return m_usesNetworkingDaemon; }
     187    void setUsesNetworkingDaemon(bool usesNetworkingDaemon) { m_usesNetworkingDaemon = usesNetworkingDaemon; }
    185188#endif
    186189
     
    236239#if PLATFORM(COCOA)
    237240    bool m_suppressesConnectionTerminationOnSystemChange { false };
     241    bool m_usesNetworkingDaemon { false };
    238242#endif
    239243};
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h

    r241205 r241223  
    7171@property (nonatomic) BOOL suppressesConnectionTerminationOnSystemChange WK_API_AVAILABLE(macosx(10.14), ios(12.0));
    7272@property (nonatomic, getter=isJITEnabled) BOOL JITEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     73@property (nonatomic) BOOL usesNetworkingDaemon WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    7374
    7475@end
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm

    r241205 r241223  
    317317}
    318318
     319- (BOOL)usesNetworkingDaemon
     320{
     321    return _processPoolConfiguration->usesNetworkingDaemon();
     322}
     323
     324- (void)setUsesNetworkingDaemon:(BOOL)enabled
     325{
     326    _processPoolConfiguration->setUsesNetworkingDaemon(enabled);
     327}
     328
     329
    319330- (void)setSuppressesConnectionTerminationOnSystemChange:(BOOL)suppressesConnectionTerminationOnSystemChange
    320331{
  • trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp

    r241205 r241223  
    7373        varname = "NETWORK_PROCESS_CMD_PREFIX";
    7474        break;
     75    case ProcessLauncher::ProcessType::NetworkDaemon:
     76        ASSERT_NOT_REACHED();
     77        break;
    7578    }
    7679    const char* processCmdPrefix = getenv(varname);
  • trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h

    r241205 r241223  
    6666#endif
    6767        Network,
     68        NetworkDaemon
    6869    };
    6970
  • trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm

    r241205 r241223  
    5757    case ProcessLauncher::ProcessType::Network:
    5858        return "com.apple.WebKit.Networking";
     59    case ProcessLauncher::ProcessType::NetworkDaemon:
     60        ASSERT_NOT_REACHED();
     61        return nullptr;
    5962#if ENABLE(NETSCAPE_PLUGIN_API)
    6063    case ProcessLauncher::ProcessType::Plugin32:
     
    9699    ASSERT(!m_xpcConnection);
    97100
    98     const char* name;
    99     if (!m_launchOptions.customWebContentServiceBundleIdentifier.isNull())
    100         name = m_launchOptions.customWebContentServiceBundleIdentifier.data();
    101     else
    102         name = serviceName(m_launchOptions);
    103 
    104     m_xpcConnection = adoptOSObject(xpc_connection_create(name, nullptr));
    105 
    106     uuid_t uuid;
    107     uuid_generate(uuid);
    108     xpc_connection_set_oneshot_instance(m_xpcConnection.get(), uuid);
     101    if (m_launchOptions.processType == ProcessLauncher::ProcessType::NetworkDaemon)
     102        m_xpcConnection = adoptOSObject(xpc_connection_create_mach_service("com.apple.WebKit.NetworkingDaemon", dispatch_get_main_queue(), 0));
     103    else {
     104        const char* name = m_launchOptions.customWebContentServiceBundleIdentifier.isNull() ? serviceName(m_launchOptions) : m_launchOptions.customWebContentServiceBundleIdentifier.data();
     105        m_xpcConnection = adoptOSObject(xpc_connection_create(name, nullptr));
     106
     107        uuid_t uuid;
     108        uuid_generate(uuid);
     109        xpc_connection_set_oneshot_instance(m_xpcConnection.get(), uuid);
     110    }
    109111
    110112    // Inherit UI process localization. It can be different from child process default localization:
     
    137139    xpc_dictionary_set_string(initializationMessage.get(), "WebKitBundleVersion", [[NSBundle bundleWithIdentifier:@"com.apple.WebKit"].infoDictionary[(__bridge NSString *)kCFBundleVersionKey] UTF8String]);
    138140#endif
    139     xpc_connection_set_bootstrap(m_xpcConnection.get(), initializationMessage.get());
    140141
    141142    if (shouldLeakBoost(m_launchOptions)) {
     
    172173        clientIdentifier = [[NSBundle mainBundle] bundleIdentifier];
    173174
    174     // FIXME: Switch to xpc_connection_set_bootstrap once it's available everywhere we need.
    175175    auto bootstrapMessage = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
     176
     177    xpc_dictionary_set_value(bootstrapMessage.get(), "initialization-message", initializationMessage.get());
    176178   
    177179    if (m_client && !m_client->isJITEnabled())
     
    201203    auto errorHandlerImpl = [weakProcessLauncher = makeWeakPtr(*this), listeningPort] (xpc_object_t event) {
    202204        ASSERT(!event || xpc_get_type(event) == XPC_TYPE_ERROR);
     205
     206        if (event)
     207            LOG_ERROR("Error launching auxiliary process: %s", xpc_dictionary_get_string(event, XPC_ERROR_KEY_DESCRIPTION));
    203208
    204209        auto processLauncher = weakProcessLauncher.get();
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r241205 r241223  
    103103void NetworkProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions)
    104104{
    105     launchOptions.processType = ProcessLauncher::ProcessType::Network;
     105    launchOptions.processType = m_processPool.usesNetworkingDaemon() ? ProcessLauncher::ProcessType::NetworkDaemon : ProcessLauncher::ProcessType::Network;
    106106    AuxiliaryProcessProxy::getLaunchOptions(launchOptions);
    107107
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r241205 r241223  
    15081508}
    15091509
     1510bool WebProcessPool::usesNetworkingDaemon() const
     1511{
     1512#if PLATFORM(COCOA)
     1513    return m_configuration->usesNetworkingDaemon();
     1514#else
     1515    return false;
     1516#endif
     1517}
     1518   
    15101519void WebProcessPool::setCacheModel(CacheModel cacheModel)
    15111520{
  • trunk/Source/WebKit/UIProcess/WebProcessPool.h

    r241205 r241223  
    256256    API::DownloadClient& downloadClient() { return *m_downloadClient; }
    257257
     258    bool usesNetworkingDaemon() const;
     259   
    258260    API::LegacyContextHistoryClient& historyClient() { return *m_historyClient; }
    259261    WebContextClient& client() { return m_client; }
  • trunk/Tools/ChangeLog

    r241221 r241223  
     12019-02-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add SPI to use networking daemon instead of XPC service
     4        https://bugs.webkit.org/show_bug.cgi?id=194427
     5
     6        Reviewed by Geoffrey Garen
     7
     8        * MiniBrowser/MiniBrowser.entitlements:
     9
    1102019-02-08  Aakash Jain  <aakash_jain@apple.com>
    211
  • trunk/Tools/MiniBrowser/MiniBrowser.entitlements

    r240805 r241223  
    88        <array>
    99                <string>com.apple.Safari.SafeBrowsing.Service</string>
     10                <string>com.apple.WebKit.NetworkingDaemon</string>
    1011        </array>
    1112        <key>com.apple.security.app-sandbox</key>
Note: See TracChangeset for help on using the changeset viewer.