[webkit-changes] [WebKit/WebKit] 617326: [WebPrivacy] Reduce code duplication in helper cla...

Wenson Hsieh noreply at github.com
Tue Sep 10 23:20:59 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 617326575536554ba7faf2a1f95788f6714f38c1
      https://github.com/WebKit/WebKit/commit/617326575536554ba7faf2a1f95788f6714f38c1
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2024-09-10 (Tue, 10 Sep 2024)

  Changed paths:
    M Source/WebKit/Platform/cocoa/WebPrivacyHelpers.h
    M Source/WebKit/Platform/cocoa/WebPrivacyHelpers.mm
    M Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
    M Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
    M Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
    M Source/WebKit/UIProcess/WebPageProxy.cpp
    M Source/WebKit/UIProcess/WebPageProxy.h
    M Source/WebKit/UIProcess/WebProcessPool.cpp
    M Source/WebKit/UIProcess/WebProcessPool.h
    M Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

  Log Message:
  -----------
  [WebPrivacy] Reduce code duplication in helper classes used to manage remotely updatable lists
https://bugs.webkit.org/show_bug.cgi?id=279469

Reviewed by Charlie Wolfe and Abrar Rahman Protyasha.

Ahead of making further changes in this area, clean up the following helper classes to consolidate
(currently) duplicated code underneath common base classes. See below for more details.

No change in behavior.

* Source/WebKit/Platform/cocoa/WebPrivacyHelpers.h:
(WebKit::ListDataObserver::create):
(WebKit::ListDataObserver::ListDataObserver):

We currently have 3 nearly-identical classes, that all fulfill the same purpose of wrapping a
callback in a weakly-held C++ object:

- LinkDecorationFilteringDataObserver
- StorageAccessPromptQuirkObserver
- StorageAccessUserAgentStringQuirkObserver

Simply consolidate these three into a single class: `WebKit::ListDataObserver`.

(WebKit::ListDataController::shared):
(WebKit::ListDataController::setCachedListDataForTesting):
(WebKit::ListDataController::cachedListData const):
(WebKit::ListDataController::setCachedListData):
(WebKit::ListDataController::didUpdateCachedListData):

Add two helper classes:

1.  `ListDataControllerBase`, a virtual, non-templated class which implements `observeUpdates()` and
    `initialize()`.

2.  `ListDataController<S, T>`, a templated class which derives from `ListDataControllerBase` and
    exposes getters and setters for the backing `T m_cachedListData`.

This split between non-templated and templated classes allows us to keep the implementations of
`observeUpdates` and `initialize` in the C++ source (rather than an inline header), which is
necessary since the implementation of `observeUpdates` calls into ObjC code but this header is
included in C++ sources.

(WebKit::LinkDecorationFilteringController::cachedListData const):
(WebKit::LinkDecorationFilteringDataObserver::create): Deleted.
(WebKit::LinkDecorationFilteringDataObserver::invokeCallback): Deleted.
(WebKit::LinkDecorationFilteringDataObserver::LinkDecorationFilteringDataObserver): Deleted.
(WebKit::LinkDecorationFilteringController::cachedStrings const): Deleted.
(WebKit::StorageAccessPromptQuirkObserver::create): Deleted.
(WebKit::StorageAccessPromptQuirkObserver::invokeCallback): Deleted.
(WebKit::StorageAccessPromptQuirkObserver::StorageAccessPromptQuirkObserver): Deleted.
(WebKit::StorageAccessUserAgentStringQuirkObserver::create): Deleted.
(WebKit::StorageAccessUserAgentStringQuirkObserver::invokeCallback): Deleted.
(WebKit::StorageAccessUserAgentStringQuirkObserver::StorageAccessUserAgentStringQuirkObserver): Deleted.
(WebKit::StorageAccessPromptQuirkController::cachedQuirks const): Deleted.
(WebKit::StorageAccessUserAgentStringQuirkController::cachedQuirks const): Deleted.
* Source/WebKit/Platform/cocoa/WebPrivacyHelpers.mm:
(-[WKWebPrivacyNotificationListener initWithType:callback:]):
(-[WKWebPrivacyNotificationListener dealloc]):
(-[WKWebPrivacyNotificationListener didUpdate:]):

Refactor `WKWebPrivacyNotificationListener` so that it takes a single callback block and resource
type, and only calls the callback if the notification's resource type matches. This is much cleaner
than enumerating every single list type as a member, but only using a single member for any given
listener instance.

(WebKit::ListDataControllerBase::observeUpdates):
(WebKit::ListDataControllerBase::initialize):
(WebKit::LinkDecorationFilteringController::resourceType const):
(WebKit::LinkDecorationFilteringController::updateList):
(WebKit::requestLinkDecorationFilteringData):
(WebKit::StorageAccessPromptQuirkController::resourceType const):
(WebKit::StorageAccessPromptQuirkController::didUpdateCachedListData):
(WebKit::StorageAccessPromptQuirkController::updateList):
(WebKit::StorageAccessUserAgentStringQuirkController::resourceType const):
(WebKit::StorageAccessUserAgentStringQuirkController::updateList):
(WebKit::RestrictedOpenerDomainsController::RestrictedOpenerDomainsController):
(WebKit::RestrictedOpenerDomainsController::update):
(WebKit::TrackerAddressLookupInfo::populateIfNeeded):
(WebKit::TrackerDomainLookupInfo::populateIfNeeded):
(WebKit::canUseWebPrivacyFramework): Deleted.
(WebKit::resourceDataChangedNotificationName): Deleted.
(WebKit::notificationUserInfoResourceTypeKey): Deleted.

Remove several workarounds that are no longer necessary, since we dropped support for macOS Monterey
on trunk.

(-[WKWebPrivacyNotificationListener init]): Deleted.
(-[WKWebPrivacyNotificationListener listenForLinkFilteringDataChanges:]): Deleted.
(-[WKWebPrivacyNotificationListener listenForStorageAccessPromptQuirkChanges:]): Deleted.
(-[WKWebPrivacyNotificationListener listenForStorageAccessUserAgentStringQuirkChanges:]): Deleted.
(-[WKWebPrivacyNotificationListener listenForRestrictedOpenerDomainsChanges:]): Deleted.
(WebKit::LinkDecorationFilteringController::shared): Deleted.
(WebKit::LinkDecorationFilteringController::observeUpdates): Deleted.
(WebKit::LinkDecorationFilteringController::setCachedStrings): Deleted.
(WebKit::LinkDecorationFilteringController::updateStrings): Deleted.
(WebKit::StorageAccessPromptQuirkController::shared): Deleted.
(WebKit::StorageAccessPromptQuirkController::observeUpdates): Deleted.
(WebKit::StorageAccessPromptQuirkController::setCachedQuirks): Deleted.
(WebKit::StorageAccessPromptQuirkController::setCachedQuirksForTesting): Deleted.
(WebKit::StorageAccessPromptQuirkController::initialize): Deleted.
(WebKit::StorageAccessPromptQuirkController::updateQuirks): Deleted.
(WebKit::StorageAccessUserAgentStringQuirkController::shared): Deleted.
(WebKit::StorageAccessUserAgentStringQuirkController::observeUpdates): Deleted.
(WebKit::StorageAccessUserAgentStringQuirkController::setCachedQuirks): Deleted.
(WebKit::StorageAccessUserAgentStringQuirkController::setCachedQuirksForTesting): Deleted.
(WebKit::StorageAccessUserAgentStringQuirkController::initialize): Deleted.
(WebKit::StorageAccessUserAgentStringQuirkController::updateQuirks): Deleted.
* Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeWebProcess):
(WebKit::WebProcessPool::platformInitializeNetworkProcess):
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::sendCreationParametersToNewProcess):
(WebKit::NetworkProcessProxy::NetworkProcessProxy):
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::initializeWebPage):
(WebKit::WebPageProxy::decidePolicyForNavigationAction):
(WebKit::WebPageProxy::createNewPage):
(WebKit::WebPageProxy::creationParameters):
(WebKit::WebPageProxy::sendCachedLinkDecorationFilteringData):
(WebKit::WebPageProxy::waitForInitialLinkDecorationFilteringData):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/WebProcessPool.cpp:
* Source/WebKit/UIProcess/WebProcessPool.h:
* Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::setStorageAccessPromptQuirkForTesting):
(WebKit::WebsiteDataStore::setUserAgentStringQuirkForTesting):

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



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list