Changeset 265139 in webkit


Ignore:
Timestamp:
Jul 31, 2020 7:03:35 AM (4 years ago)
Author:
pvollan@apple.com
Message:

[iOS] Issue a temporary extension to the MobileGestalt daemon when the MobileGestalt cache is invalid
https://bugs.webkit.org/show_bug.cgi?id=214965

Reviewed by Geoffrey Garen.

Source/WebCore/PAL:

Declare MobileGestalt queestion identifier.

  • pal/spi/ios/MobileGestaltSPI.h:

Source/WebKit:

When the MobileGestalt cache is invalid, some MG queries will fail in the WebContent process, since it has no access to the daemon.
This can be fixed by issuing a temporary extension to the daemon, and having the WebContent process query all relevant MG values
while holding the extension. This will bring the values into the in-memory cache, which will be valid after the extension to the
daemon has been revoked. We will still attempt to rebuild the MG cache if invalid, but since we now have a workaround for when the
cache is invalid, we can do this on a secondary thread to avoid blocking the main thread. We also only attempt to rebuild once now,
instead of every time a WebContent process is started. Additionally, add IOKit property read access to "platform-name", since that
is needed by a MG query.

No new tests, since testing this depends on having an invalid cache, which is rare, and non-trivial to enforce in the test
environment.

  • Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
  • Shared/WebProcessCreationParameters.cpp:

(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):

  • Shared/WebProcessCreationParameters.h:
  • UIProcess/Cocoa/WebProcessPoolCocoa.mm:

(WebKit::WebProcessPool::platformInitialize):
(WebKit::WebProcessPool::platformInitializeWebProcess):

  • WebProcess/cocoa/WebProcessCocoa.mm:

(WebKit::WebProcess::platformInitializeWebProcess):

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/PAL/ChangeLog

    r265115 r265139  
     12020-07-31  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [iOS] Issue a temporary extension to the MobileGestalt daemon when the MobileGestalt cache is invalid
     4        https://bugs.webkit.org/show_bug.cgi?id=214965
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Declare MobileGestalt queestion identifier.
     9
     10        * pal/spi/ios/MobileGestaltSPI.h:
     11
    1122020-07-30  Jer Noble  <jer.noble@apple.com>
    213
  • trunk/Source/WebCore/PAL/pal/spi/ios/MobileGestaltSPI.h

    r261584 r265139  
    4646static const CFStringRef kMGQDeviceClassNumber = CFSTR("DeviceClassNumber");
    4747static const CFStringRef kMGQHasExtendedColorDisplay = CFSTR("HasExtendedColorDisplay");
     48static const CFStringRef kMGQDeviceCornerRadius = CFSTR("DeviceCornerRadius");
    4849
    4950typedef enum {
  • trunk/Source/WebKit/ChangeLog

    r265138 r265139  
     12020-07-31  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [iOS] Issue a temporary extension to the MobileGestalt daemon when the MobileGestalt cache is invalid
     4        https://bugs.webkit.org/show_bug.cgi?id=214965
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        When the MobileGestalt cache is invalid, some MG queries will fail in the WebContent process, since it has no access to the daemon.
     9        This can be fixed by issuing a temporary extension to the daemon, and having the WebContent process query all relevant MG values
     10        while holding the extension. This will bring the values into the in-memory cache, which will be valid after the extension to the
     11        daemon has been revoked. We will still attempt to rebuild the MG cache if invalid, but since we now have a workaround for when the
     12        cache is invalid, we can do this on a secondary thread to avoid blocking the main thread. We also only attempt to rebuild once now,
     13        instead of every time a WebContent process is started. Additionally, add IOKit property read access to "platform-name", since that
     14        is needed by a MG query.
     15
     16        No new tests, since testing this depends on having an invalid cache, which is rare, and non-trivial to enforce in the test
     17        environment.
     18
     19        * Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
     20        * Shared/WebProcessCreationParameters.cpp:
     21        (WebKit::WebProcessCreationParameters::encode const):
     22        (WebKit::WebProcessCreationParameters::decode):
     23        * Shared/WebProcessCreationParameters.h:
     24        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
     25        (WebKit::WebProcessPool::platformInitialize):
     26        (WebKit::WebProcessPool::platformInitializeWebProcess):
     27        * WebProcess/cocoa/WebProcessCocoa.mm:
     28        (WebKit::WebProcess::platformInitializeWebProcess):
     29
    1302020-07-31  Carlos Garcia Campos  <cgarcia@igalia.com>
    231
  • trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb

    r264681 r265139  
    888888    (iokit-property "udid-version") ;; <rdar://problem/52903475>
    889889    (iokit-property "ui-pip") ;; <rdar://problem/48867037>
     890    (iokit-property "platform-name")
    890891)
    891892
     
    947948)
    948949
     950(deny mach-lookup (with telemetry-backtrace)
     951    (global-name "com.apple.mobilegestalt.xpc")
     952)
     953
    949954(allow mach-lookup
    950955    (require-all
     
    958963            "com.apple.lsd.mapdb"
    959964            "com.apple.mobileassetd.v2"
     965            "com.apple.mobilegestalt.xpc"
    960966            "com.apple.nehelper"
    961967            "com.apple.nesessionmanager.content-filter"
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp

    r265081 r265139  
    161161
    162162    encoder << containerManagerExtensionHandle;
    163    
     163    encoder << mobileGestaltExtensionHandle;
     164
    164165#if PLATFORM(IOS_FAMILY)
    165166    encoder << diagnosticsExtensionHandles;
     
    429430    parameters.containerManagerExtensionHandle = WTFMove(*containerManagerExtensionHandle);
    430431
     432    Optional<Optional<SandboxExtension::Handle>> mobileGestaltExtensionHandle;
     433    decoder >> mobileGestaltExtensionHandle;
     434    if (!mobileGestaltExtensionHandle)
     435        return false;
     436    parameters.mobileGestaltExtensionHandle = WTFMove(*mobileGestaltExtensionHandle);
     437
    431438#if PLATFORM(IOS_FAMILY)
    432439    Optional<SandboxExtension::HandleArray> diagnosticsExtensionHandles;
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.h

    r265081 r265139  
    205205
    206206    Optional<SandboxExtension::Handle> containerManagerExtensionHandle;
     207    Optional<SandboxExtension::Handle> mobileGestaltExtensionHandle;
    207208
    208209#if PLATFORM(IOS_FAMILY)
  • trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm

    r265081 r265139  
    166166
    167167    setLegacyCustomProtocolManagerClient(makeUnique<LegacyCustomProtocolManagerClient>());
     168
     169#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
     170    if (!_MGCacheValid()) {
     171        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
     172            [adoptNS([[objc_getClass("MobileGestaltHelperProxy") alloc] init]) proxyRebuildCache];
     173        });
     174    }
     175#endif
    168176}
    169177
     
    448456
    449457#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
    450     if (!_MGCacheValid())
    451         [adoptNS([[objc_getClass("MobileGestaltHelperProxy") alloc] init]) proxyRebuildCache];
     458    if (!_MGCacheValid()) {
     459        SandboxExtension::Handle handle;
     460        SandboxExtension::createHandleForMachLookup("com.apple.mobilegestalt.xpc"_s, WTF::nullopt, handle);
     461        parameters.mobileGestaltExtensionHandle = WTFMove(handle);
     462    }
    452463#endif
    453464
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r265087 r265139  
    110110#import <UIKit/UIAccessibility.h>
    111111#import <pal/spi/ios/GraphicsServicesSPI.h>
     112#import <pal/spi/ios/MobileGestaltSPI.h>
    112113#endif
    113114
     
    203204void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
    204205{
     206    if (parameters.mobileGestaltExtensionHandle) {
     207        if (auto extension = SandboxExtension::create(WTFMove(*parameters.mobileGestaltExtensionHandle))) {
     208            bool ok = extension->consume();
     209            ASSERT_UNUSED(ok, ok);
     210#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
     211            MGGetFloat32Answer(kMGQMainScreenScale, 0);
     212            MGGetSInt32Answer(kMGQMainScreenPitch, 0);
     213            MGGetSInt32Answer(kMGQMainScreenClass, MGScreenClassPad2);
     214            MGGetBoolAnswer(kMGQAppleInternalInstallCapability);
     215            MGGetBoolAnswer(kMGQiPadCapability);
     216            auto deviceName = adoptCF(MGCopyAnswer(kMGQDeviceName, nullptr));
     217            MGGetSInt32Answer(kMGQDeviceClassNumber, MGDeviceClassInvalid);
     218            MGGetBoolAnswer(kMGQHasExtendedColorDisplay);
     219            MGGetFloat32Answer(kMGQDeviceCornerRadius, 0);
     220#endif
     221            ok = extension->revoke();
     222            ASSERT_UNUSED(ok, ok);
     223        }
     224    }
     225
    205226#if HAVE(LSDATABASECONTEXT)
    206227    // FIXME: Remove this entire section when the selector observeDatabaseChange4WebKit is present
Note: See TracChangeset for help on using the changeset viewer.