Skip to content

Commit

Permalink
Cherry-pick 546db34. rdar://114288616
Browse files Browse the repository at this point in the history
    [iOS 17+, Sonoma] REGRESSION (267051@main): Safari no longer responds to WebPrivacy list changes
    https://bugs.webkit.org/show_bug.cgi?id=260569
    rdar://114288616

    Reviewed by Aditya Keerthi.

    Several API tests in `TestWebKitAPI.AdvancedPrivacyProtections` began to fail after the changes in
    267051@main; in particular, they're failing because I changed the `SOFT_LINK_CONSTANT_FOR_HEADER`
    around `WPNotificationUserInfoResourceTypeKey` to `SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER`, the
    latter of which never attempts to load will return `nil` unless we call
    `PAL::canLoad_WebPrivacy_WPResourceDataChangedNotificationName()` first (the full macro expands to
    the following):

    ```
    namespace PAL {

    static NSNotificationName constantWebPrivacyWPResourceDataChangedNotificationName;

    bool init_WebPrivacy_WPResourceDataChangedNotificationName();
    bool init_WebPrivacy_WPResourceDataChangedNotificationName()
    {
        void* constant = dlsym(WebPrivacyLibrary(), "WPResourceDataChangedNotificationName");
        if (!constant)
            return false;
        constantWebPrivacyWPResourceDataChangedNotificationName = *static_cast<NSNotificationName const *>(constant);
        return true;
    }

    PAL_EXPORT bool canLoad_WebPrivacy_WPResourceDataChangedNotificationName();
    bool canLoad_WebPrivacy_WPResourceDataChangedNotificationName()
    {
        static bool loaded = init_WebPrivacy_WPResourceDataChangedNotificationName();
        return loaded;
    }

    PAL_EXPORT NSNotificationName get_WebPrivacy_WPResourceDataChangedNotificationName();
    NSNotificationName get_WebPrivacy_WPResourceDataChangedNotificationName()
    {
        return constantWebPrivacyWPResourceDataChangedNotificationName;
    }

    }
    ```

    ...in contrast, the original macro `SOFT_LINK_CONSTANT_FOR_HEADER` expands to:

    ```
    namespace PAL {

    PAL_EXPORT NSNotificationName get_WebPrivacy_WPResourceDataChangedNotificationName();
    NSNotificationName get_WebPrivacy_WPResourceDataChangedNotificationName()
    {
        static NSNotificationName constantWebPrivacyWPResourceDataChangedNotificationName;
        static dispatch_once_t once;
        dispatch_once(&once, ^{
            void* constant = dlsym(WebPrivacyLibrary(), "WPResourceDataChangedNotificationName");
            RELEASE_ASSERT_WITH_MESSAGE(constant, "%s", dlerror());
            constantWebPrivacyWPResourceDataChangedNotificationName = *static_cast<NSNotificationName const *>(constant);
        });
        return constantWebPrivacyWPResourceDataChangedNotificationName;
    }

    }
    ```

    This exposes a real bug caused by 267051@main, where we no longer listen for the resource data
    changed notification from WebPrivacy in WebKit since the soft-linking helper now always returns
    `nil`. Fix this by reverting to the original `SOFT_LINK_CONSTANT_FOR_HEADER` for these two symbols,
    which should be fine (i.e. not `RELEASE_ASSERT`) as long as we only ever call them from inside a
    `canUseWebPrivacyFramework()` check.

    * Source/WebCore/PAL/pal/cocoa/WebPrivacySoftLink.h:
    * Source/WebCore/PAL/pal/cocoa/WebPrivacySoftLink.mm:

    Canonical link: https://commits.webkit.org/267181@main

Identifier: 265870.484@safari-7616-branch
  • Loading branch information
whsieh authored and MyahCobbs committed Aug 31, 2023
1 parent 0b3c33c commit 7fc573b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Source/WebCore/PAL/pal/cocoa/WebPrivacySoftLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SOFT_LINK_FRAMEWORK_FOR_HEADER(PAL, WebPrivacy)
SOFT_LINK_CLASS_FOR_HEADER(PAL, WPResourceRequestOptions)
SOFT_LINK_CLASS_FOR_HEADER(PAL, WPResources)
SOFT_LINK_CLASS_FOR_HEADER(PAL, WPLinkFilteringData)
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, WebPrivacy, WPNotificationUserInfoResourceTypeKey, NSString *)
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, WebPrivacy, WPResourceDataChangedNotificationName, NSNotificationName)
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, WebPrivacy, WPNotificationUserInfoResourceTypeKey, NSString *)
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, WebPrivacy, WPResourceDataChangedNotificationName, NSNotificationName)

#endif // ENABLE(ADVANCED_PRIVACY_PROTECTIONS)
4 changes: 2 additions & 2 deletions Source/WebCore/PAL/pal/cocoa/WebPrivacySoftLink.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
SOFT_LINK_CLASS_FOR_SOURCE_OPTIONAL_WITH_EXPORT(PAL, WebPrivacy, WPResourceRequestOptions, PAL_EXPORT)
SOFT_LINK_CLASS_FOR_SOURCE_OPTIONAL_WITH_EXPORT(PAL, WebPrivacy, WPResources, PAL_EXPORT)
SOFT_LINK_CLASS_FOR_SOURCE_OPTIONAL_WITH_EXPORT(PAL, WebPrivacy, WPLinkFilteringData, PAL_EXPORT)
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, WebPrivacy, WPNotificationUserInfoResourceTypeKey, NSString *, PAL_EXPORT)
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, WebPrivacy, WPResourceDataChangedNotificationName, NSNotificationName, PAL_EXPORT)
SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, WebPrivacy, WPNotificationUserInfoResourceTypeKey, NSString *, PAL_EXPORT)
SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, WebPrivacy, WPResourceDataChangedNotificationName, NSNotificationName, PAL_EXPORT)

#endif // ENABLE(ADVANCED_PRIVACY_PROTECTIONS)

0 comments on commit 7fc573b

Please sign in to comment.