⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286640 in webkit


Ignore:
Timestamp:
Dec 7, 2021, 8:24:38 PM (5 years ago)
Author:
Wenson Hsieh
Message:

Add support for navigator.requestCookieConsent() behind a disabled feature flag
https://bugs.webkit.org/show_bug.cgi?id=233890
rdar://86117718

Reviewed by Darin Adler.

Source/WebCore:

Add plumbing to support a new (internal-for-the-time-being) navigator API, requestCookieConsent(). This
returns a promise indicating whether or not the user (or the UA, on behalf of the user) consents to usage of
cookies that are not strictly necessary for page performance.

Paired with this web-facing API, we also introduce corresponding private WKUIDelegate methods that are invoked
as a result of calling navigator.requestCookieConsent();, which a WebKit embedder may implement in order to
present UI or otherwise respond appropriately to the request. See WebKit ChangeLog for more details.

Tests: CookieConsent.BasicDecisionHandler

CookieConsent.NotEnabled
CookieConsent.ThrowsExceptionWithoutDelegate

  • CMakeLists.txt:
  • DerivedSources-input.xcfilelist:
  • DerivedSources-output.xcfilelist:
  • DerivedSources.make:
  • Headers.cmake:
  • Modules/cookie-consent/CookieConsentDecisionResult.h: Added.
  • Modules/cookie-consent/Navigator+CookieConsent.idl: Added.
  • Modules/cookie-consent/NavigatorCookieConsent.cpp: Added.

Add a new partial interface on Navigator that implements the new API by calling into the chrome client hook (see
WebKit changes for more details). Note that in the case where the consent delegate method is not implemented by
the client, we will reject the promise with a NotSupportedError.

(WebCore::NavigatorCookieConsent::requestCookieConsent):
(WebCore::NavigatorCookieConsent::from):

  • Modules/cookie-consent/NavigatorCookieConsent.h: Added.

(WebCore::RequestCookieConsentOptions::RequestCookieConsentOptions):

  • Modules/cookie-consent/RequestCookieConsentOptions.h: Added.
  • Modules/cookie-consent/RequestCookieConsentOptions.idl: Added.
  • Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
  • Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:

Add some missing includes to fix the unified source build on Windows.

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • loader/EmptyClients.cpp:

(WebCore::EmptyChromeClient::requestCookieConsent):

  • loader/EmptyClients.h:
  • page/ChromeClient.h:

Source/WebKit:

Add plumbing for an async requestCookieConsent() method on ChromeClient that plumbs through the WebKit2 client
layer, into a new private (for the time being) UI delegate method. If the new delegate method is not implemented
(or there is no UI delegate at all), we immediately invoke the decision handler with a result of NotSupported,
allowing us to reject the promise with a NotSupportedError.

See WebCore ChangeLog for more details.

  • UIProcess/API/APIUIClient.h:

(API::UIClient::requestCookieConsent):

  • UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
  • UIProcess/Cocoa/UIDelegate.h:
  • UIProcess/Cocoa/UIDelegate.mm:

(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::requestCookieConsent):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::requestCookieConsent):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::requestCookieConsent):

  • WebProcess/WebCoreSupport/WebChromeClient.h:

Source/WebKitLegacy/mac:

Add an implementation stub for the new chrome client hook, requestCookieConsent().

  • WebCoreSupport/WebChromeClient.h:
  • WebCoreSupport/WebChromeClient.mm:

(WebChromeClient::requestCookieConsent):

Source/WebKitLegacy/win:

Add an implementation stub for the new chrome client hook, requestCookieConsent().

  • WebCoreSupport/WebChromeClient.cpp:

(WebChromeClient::requestCookieConsent):

  • WebCoreSupport/WebChromeClient.h:

Source/WTF:

Add the new feature flag (off by default). Note that this is also only an internal feature flag for the time
being (rather than an experimental feature flag), such that it cannot (yet) be turned on by non-Apple internal
users.

  • Scripts/Preferences/WebPreferencesInternal.yaml:

Tools:

Add several new API tests that enable the feature flag and exercise the API.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit/CookieConsent.mm: Added.

(-[CookieConsentDelegate _webView:requestCookieConsentWithMoreInfoHandler:decisionHandler:]):
(TestWebKitAPI::createWebViewForTestingCookieConsent):
(TestWebKitAPI::checkForString):
(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKit/cookie-consent-basic.html: Added.
Location:
trunk
Files:
9 added
33 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r286601 r286640  
     12021-12-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for `navigator.requestCookieConsent()` behind a disabled feature flag
     4        https://bugs.webkit.org/show_bug.cgi?id=233890
     5        rdar://86117718
     6
     7        Reviewed by Darin Adler.
     8
     9        Add the new feature flag (off by default). Note that this is also only an internal feature flag for the time
     10        being (rather than an experimental feature flag), such that it cannot (yet) be turned on by non-Apple internal
     11        users.
     12
     13        * Scripts/Preferences/WebPreferencesInternal.yaml:
     14
    1152021-12-07  Sihui Liu  <sihui_liu@apple.com>
    216
  • trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml

    r286554 r286640  
    177177      default: false
    178178
     179CookieConsentAPIEnabled:
     180  type: bool
     181  humanReadableName: "Cookie Consent API"
     182  humanReadableDescription: "Enable cookie consent API"
     183  exposed: [ WebKit ]
     184  defaultValue:
     185    WebCore:
     186      default: false
     187    WebKitLegacy:
     188      default: false
     189    WebKit:
     190      default: false
     191
    179192DOMPasteAccessRequestsEnabled:
    180193  type: bool
  • trunk/Source/WebCore/CMakeLists.txt

    r286555 r286640  
    2828    "${WEBCORE_DIR}/Modules/cache"
    2929    "${WEBCORE_DIR}/Modules/contact-picker"
     30    "${WEBCORE_DIR}/Modules/cookie-consent"
    3031    "${WEBCORE_DIR}/Modules/credentialmanagement"
    3132    "${WEBCORE_DIR}/Modules/encryptedmedia"
     
    257258    Modules/contact-picker/Navigator+Contacts.idl
    258259
     260    Modules/cookie-consent/Navigator+CookieConsent.idl
     261    Modules/cookie-consent/RequestCookieConsentOptions.idl
     262
    259263    Modules/credentialmanagement/BasicCredential.idl
    260264    Modules/credentialmanagement/CredentialCreationOptions.idl
  • trunk/Source/WebCore/ChangeLog

    r286637 r286640  
     12021-12-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for `navigator.requestCookieConsent()` behind a disabled feature flag
     4        https://bugs.webkit.org/show_bug.cgi?id=233890
     5        rdar://86117718
     6
     7        Reviewed by Darin Adler.
     8
     9        Add plumbing to support a new (internal-for-the-time-being) navigator API, `requestCookieConsent()`. This
     10        returns a promise indicating whether or not the user (or the UA, on behalf of the user) consents to usage of
     11        cookies that are not strictly necessary for page performance.
     12
     13        Paired with this web-facing API, we also introduce corresponding private WKUIDelegate methods that are invoked
     14        as a result of calling `navigator.requestCookieConsent();`, which a WebKit embedder may implement in order to
     15        present UI or otherwise respond appropriately to the request. See WebKit ChangeLog for more details.
     16
     17        Tests:  CookieConsent.BasicDecisionHandler
     18                CookieConsent.NotEnabled
     19                CookieConsent.ThrowsExceptionWithoutDelegate
     20
     21        * CMakeLists.txt:
     22        * DerivedSources-input.xcfilelist:
     23        * DerivedSources-output.xcfilelist:
     24        * DerivedSources.make:
     25        * Headers.cmake:
     26        * Modules/cookie-consent/CookieConsentDecisionResult.h: Added.
     27        * Modules/cookie-consent/Navigator+CookieConsent.idl: Added.
     28        * Modules/cookie-consent/NavigatorCookieConsent.cpp: Added.
     29
     30        Add a new partial interface on Navigator that implements the new API by calling into the chrome client hook (see
     31        WebKit changes for more details). Note that in the case where the consent delegate method is not implemented by
     32        the client, we will reject the promise with a `NotSupportedError`.
     33
     34        (WebCore::NavigatorCookieConsent::requestCookieConsent):
     35        (WebCore::NavigatorCookieConsent::from):
     36        * Modules/cookie-consent/NavigatorCookieConsent.h: Added.
     37        (WebCore::RequestCookieConsentOptions::RequestCookieConsentOptions):
     38        * Modules/cookie-consent/RequestCookieConsentOptions.h: Added.
     39        * Modules/cookie-consent/RequestCookieConsentOptions.idl: Added.
     40        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
     41        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:
     42
     43        Add some missing includes to fix the unified source build on Windows.
     44
     45        * Sources.txt:
     46        * WebCore.xcodeproj/project.pbxproj:
     47        * loader/EmptyClients.cpp:
     48        (WebCore::EmptyChromeClient::requestCookieConsent):
     49        * loader/EmptyClients.h:
     50        * page/ChromeClient.h:
     51
    1522021-12-07  Cameron McCormack  <heycam@apple.com>
    253
  • trunk/Source/WebCore/DerivedSources-input.xcfilelist

    r286555 r286640  
    233233$(PROJECT_DIR)/Modules/contact-picker/ContactsSelectOptions.idl
    234234$(PROJECT_DIR)/Modules/contact-picker/Navigator+Contacts.idl
     235$(PROJECT_DIR)/Modules/cookie-consent/Navigator+CookieConsent.idl
     236$(PROJECT_DIR)/Modules/cookie-consent/RequestCookieConsentOptions.idl
    235237$(PROJECT_DIR)/Modules/credentialmanagement/BasicCredential.idl
    236238$(PROJECT_DIR)/Modules/credentialmanagement/CredentialCreationOptions.idl
  • trunk/Source/WebCore/DerivedSources-output.xcfilelist

    r286555 r286640  
    16481648$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSNavigator+Contacts.cpp
    16491649$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSNavigator+Contacts.h
     1650$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSNavigator+CookieConsent.cpp
     1651$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSNavigator+CookieConsent.h
    16501652$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSNavigator+Credentials.cpp
    16511653$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSNavigator+Credentials.h
     
    20902092$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRequestAnimationFrameCallback.cpp
    20912093$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRequestAnimationFrameCallback.h
     2094$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRequestCookieConsentOptions.cpp
     2095$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRequestCookieConsentOptions.h
    20922096$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSResizeObserver.cpp
    20932097$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSResizeObserver.h
  • trunk/Source/WebCore/DerivedSources.make

    r286555 r286640  
    255255    $(WebCore)/Modules/contact-picker/ContactsSelectOptions.idl \
    256256    $(WebCore)/Modules/contact-picker/Navigator+Contacts.idl \
     257    $(WebCore)/Modules/cookie-consent/Navigator+CookieConsent.idl \
     258    $(WebCore)/Modules/cookie-consent/RequestCookieConsentOptions.idl \
    257259    $(WebCore)/Modules/credentialmanagement/BasicCredential.idl \
    258260    $(WebCore)/Modules/credentialmanagement/CredentialCreationOptions.idl \
  • trunk/Source/WebCore/Headers.cmake

    r286596 r286640  
    153153    Modules/contact-picker/ContactProperty.h
    154154    Modules/contact-picker/ContactsRequestData.h
     155
     156    Modules/cookie-consent/CookieConsentDecisionResult.h
    155157
    156158    Modules/encryptedmedia/CDMClient.h
  • trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp

    r286414 r286640  
    2727#include "WorkerFileSystemStorageConnection.h"
    2828
     29#include "FileSystemSyncAccessHandle.h"
    2930#include "WorkerGlobalScope.h"
    3031#include "WorkerLoaderProxy.h"
  • trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h

    r286414 r286640  
    3333namespace WebCore {
    3434
     35class FileSystemSyncAccessHandle;
    3536class WorkerGlobalScope;
    3637class WorkerThread;
  • trunk/Source/WebCore/Sources.txt

    r286630 r286640  
    6969Modules/contact-picker/ContactsManager.cpp
    7070Modules/contact-picker/NavigatorContacts.cpp
     71Modules/cookie-consent/NavigatorCookieConsent.cpp
    7172Modules/credentialmanagement/BasicCredential.cpp
    7273Modules/credentialmanagement/CredentialsContainer.cpp
     
    36743675JSRemotePlaybackAvailabilityCallback.cpp
    36753676JSRequestAnimationFrameCallback.cpp
     3677JSRequestCookieConsentOptions.cpp
    36763678JSResizeObserver.cpp
    36773679JSResizeObserverBoxOptions.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r286630 r286640  
    54515451                F3ABFE0C130E9DA000E7F7D1 /* InstrumentingAgents.h in Headers */ = {isa = PBXBuildFile; fileRef = F3ABFE0B130E9DA000E7F7D1 /* InstrumentingAgents.h */; };
    54525452                F3D461491161D53200CA0D09 /* JSErrorHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = F3D461471161D53200CA0D09 /* JSErrorHandler.h */; };
     5453                F4034F9D275C4789003A81F8 /* CookieConsentDecisionResult.h in Headers */ = {isa = PBXBuildFile; fileRef = F4034F9C275C4783003A81F8 /* CookieConsentDecisionResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
     5454                F4034FAC275EAD6E003A81F8 /* RequestCookieConsentOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = F4034F8F275C1686003A81F8 /* RequestCookieConsentOptions.h */; };
     5455                F4034FAE275EAD76003A81F8 /* NavigatorCookieConsent.h in Headers */ = {isa = PBXBuildFile; fileRef = F4034F8D275C087B003A81F8 /* NavigatorCookieConsent.h */; };
    54535456                F403E7872363B58C00044550 /* EnterKeyHint.h in Headers */ = {isa = PBXBuildFile; fileRef = F403E7852363B58C00044550 /* EnterKeyHint.h */; settings = {ATTRIBUTES = (Private, ); }; };
    54545457                F40DAAEC25D9F25E0011B4FA /* PasteboardContext.h in Headers */ = {isa = PBXBuildFile; fileRef = F40DAAEB25D9F25E0011B4FA /* PasteboardContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1759617599                F3D461461161D53200CA0D09 /* JSErrorHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSErrorHandler.cpp; sourceTree = "<group>"; };
    1759717600                F3D461471161D53200CA0D09 /* JSErrorHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSErrorHandler.h; sourceTree = "<group>"; };
     17601                F4034F8C275C087B003A81F8 /* NavigatorCookieConsent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NavigatorCookieConsent.cpp; path = "cookie-consent/NavigatorCookieConsent.cpp"; sourceTree = "<group>"; };
     17602                F4034F8D275C087B003A81F8 /* NavigatorCookieConsent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NavigatorCookieConsent.h; path = "cookie-consent/NavigatorCookieConsent.h"; sourceTree = "<group>"; };
     17603                F4034F8E275C087C003A81F8 /* Navigator+CookieConsent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "Navigator+CookieConsent.idl"; path = "cookie-consent/Navigator+CookieConsent.idl"; sourceTree = "<group>"; };
     17604                F4034F8F275C1686003A81F8 /* RequestCookieConsentOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RequestCookieConsentOptions.h; path = "cookie-consent/RequestCookieConsentOptions.h"; sourceTree = "<group>"; };
     17605                F4034F91275C1686003A81F8 /* RequestCookieConsentOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; name = RequestCookieConsentOptions.idl; path = "cookie-consent/RequestCookieConsentOptions.idl"; sourceTree = "<group>"; };
     17606                F4034F9C275C4783003A81F8 /* CookieConsentDecisionResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CookieConsentDecisionResult.h; path = "cookie-consent/CookieConsentDecisionResult.h"; sourceTree = "<group>"; };
    1759817607                F403E7852363B58C00044550 /* EnterKeyHint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EnterKeyHint.h; sourceTree = "<group>"; };
    1759917608                F403E7862363B58C00044550 /* EnterKeyHint.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = EnterKeyHint.cpp; sourceTree = "<group>"; };
     
    2581125820                                41380C1E1F34366000155FDA /* cache */,
    2581225821                                E596DD23251902D600C275A7 /* contact-picker */,
     25822                                F4034F8B275C0867003A81F8 /* cookie-consent */,
    2581325823                                57C7A6881E56946D00C67D71 /* credentialmanagement */,
    2581425824                                CDA98DBD16014E0800FEA3B1 /* encryptedmedia */,
     
    3121631226                        );
    3121731227                        path = mac;
     31228                        sourceTree = "<group>";
     31229                };
     31230                F4034F8B275C0867003A81F8 /* cookie-consent */ = {
     31231                        isa = PBXGroup;
     31232                        children = (
     31233                                F4034F9C275C4783003A81F8 /* CookieConsentDecisionResult.h */,
     31234                                F4034F8E275C087C003A81F8 /* Navigator+CookieConsent.idl */,
     31235                                F4034F8C275C087B003A81F8 /* NavigatorCookieConsent.cpp */,
     31236                                F4034F8D275C087B003A81F8 /* NavigatorCookieConsent.h */,
     31237                                F4034F8F275C1686003A81F8 /* RequestCookieConsentOptions.h */,
     31238                                F4034F91275C1686003A81F8 /* RequestCookieConsentOptions.idl */,
     31239                        );
     31240                        name = "cookie-consent";
    3121831241                        sourceTree = "<group>";
    3121931242                };
     
    3305433077                        buildActionMask = 2147483647;
    3305533078                        files = (
    33056                                 7B582DD82716F55B004B92D0 /* (null) in Headers */,
    3305733079                                7CD0E2B81F80A4820016A4CE /* AbortController.h in Headers */,
    3305833080                                7CD0E2BF1F80A56E0016A4CE /* AbortSignal.h in Headers */,
     
    3360533627                                83F28C0024DB1DE1005BA6F6 /* ConvolverOptions.h in Headers */,
    3360633628                                D8B6152F1032495100C8554A /* Cookie.h in Headers */,
     33629                                F4034F9D275C4789003A81F8 /* CookieConsentDecisionResult.h in Headers */,
    3360733630                                E1424C94164B52C800F32D40 /* CookieJar.h in Headers */,
    3360833631                                7A5699702086C619000E0433 /* CookieRequestHeaderFieldProxy.h in Headers */,
     
    3603936062                                F440E77A233D94D70063F9AB /* NavigatorClipboard.h in Headers */,
    3604036063                                E596DD29251903D200C275A7 /* NavigatorContacts.h in Headers */,
     36064                                F4034FAE275EAD76003A81F8 /* NavigatorCookieConsent.h in Headers */,
    3604136065                                372D3E57216578AE00C5E021 /* NavigatorCredentials.h in Headers */,
    3604236066                                9711460414EF009A00674FD9 /* NavigatorGeolocation.h in Headers */,
     
    3661336637                                46DD6E1F26E7DBE7008C1F4C /* ReportingEndpointsCache.h in Headers */,
    3661436638                                4998AEC613F9D0EA0090B1AA /* RequestAnimationFrameCallback.h in Headers */,
     36639                                F4034FAC275EAD6E003A81F8 /* RequestCookieConsentOptions.h in Headers */,
    3661536640                                F55B3DD01251F12D003EF269 /* ResetInputType.h in Headers */,
    3661636641                                58B2F9F42232D45300938D63 /* ResizeObservation.h in Headers */,
  • trunk/Source/WebCore/loader/EmptyClients.cpp

    r286632 r286640  
    3636#include "ColorChooser.h"
    3737#include "ContextMenuClient.h"
     38#include "CookieConsentDecisionResult.h"
    3839#include "CookieJar.h"
    3940#include "DOMPasteAccess.h"
     
    585586}
    586587
     588void EmptyChromeClient::requestCookieConsent(CompletionHandler<void(CookieConsentDecisionResult)>&& completion)
     589{
     590    completion(CookieConsentDecisionResult::NotSupported);
     591}
     592
    587593void EmptyFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(const NavigationAction&, const ResourceRequest&, FormState*, const String&, PolicyCheckIdentifier, FramePolicyFunction&&)
    588594{
  • trunk/Source/WebCore/loader/EmptyClients.h

    r286019 r286640  
    219219
    220220    RefPtr<Icon> createIconForFiles(const Vector<String>& /* filenames */) final { return nullptr; }
     221
     222    void requestCookieConsent(CompletionHandler<void(CookieConsentDecisionResult)>&&) final;
    221223};
    222224
  • trunk/Source/WebCore/page/ChromeClient.h

    r286459 r286640  
    143143struct WindowFeatures;
    144144
     145enum class CookieConsentDecisionResult : uint8_t;
    145146enum class RouteSharingPolicy : uint8_t;
    146147
     
    620621#endif
    621622
     623    virtual void requestCookieConsent(CompletionHandler<void(CookieConsentDecisionResult)>&&) = 0;
     624
    622625protected:
    623626    virtual ~ChromeClient() = default;
  • trunk/Source/WebKit/ChangeLog

    r286632 r286640  
     12021-12-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for `navigator.requestCookieConsent()` behind a disabled feature flag
     4        https://bugs.webkit.org/show_bug.cgi?id=233890
     5        rdar://86117718
     6
     7        Reviewed by Darin Adler.
     8
     9        Add plumbing for an async `requestCookieConsent()` method on ChromeClient that plumbs through the WebKit2 client
     10        layer, into a new private (for the time being) UI delegate method. If the new delegate method is not implemented
     11        (or there is no UI delegate at all), we immediately invoke the decision handler with a result of `NotSupported`,
     12        allowing us to reject the promise with a `NotSupportedError`.
     13
     14        See WebCore ChangeLog for more details.
     15
     16        * UIProcess/API/APIUIClient.h:
     17        (API::UIClient::requestCookieConsent):
     18        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
     19        * UIProcess/Cocoa/UIDelegate.h:
     20        * UIProcess/Cocoa/UIDelegate.mm:
     21        (WebKit::UIDelegate::setDelegate):
     22        (WebKit::UIDelegate::UIClient::requestCookieConsent):
     23        * UIProcess/WebPageProxy.cpp:
     24        (WebKit::WebPageProxy::requestCookieConsent):
     25        * UIProcess/WebPageProxy.h:
     26        * UIProcess/WebPageProxy.messages.in:
     27        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     28        (WebKit::WebChromeClient::requestCookieConsent):
     29        * WebProcess/WebCoreSupport/WebChromeClient.h:
     30
    1312021-12-07  Devin Rousso  <drousso@apple.com>
    232
  • trunk/Source/WebKit/UIProcess/API/APIUIClient.h

    r286318 r286640  
    3131#include "WebHitTestResultData.h"
    3232#include "WebPageProxy.h"
     33#include <WebCore/CookieConsentDecisionResult.h>
    3334#include <WebCore/FloatRect.h>
    3435#include <wtf/CompletionHandler.h>
     
    145146    virtual void decidePolicyForNotificationPermissionRequest(WebKit::WebPageProxy&, SecurityOrigin&, CompletionHandler<void(bool allowed)>&& completionHandler) { completionHandler(false); }
    146147    virtual void requestStorageAccessConfirm(WebKit::WebPageProxy&, WebKit::WebFrameProxy*, const WebCore::RegistrableDomain& requestingDomain, const WebCore::RegistrableDomain& currentDomain, CompletionHandler<void(bool)>&& completionHandler) { completionHandler(true); }
     148    virtual void requestCookieConsent(CompletionHandler<void(WebCore::CookieConsentDecisionResult)>&& completionHandler) { completionHandler(WebCore::CookieConsentDecisionResult::NotSupported); }
    147149
    148150    // Printing.
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r286318 r286640  
    177177- (void)_webView:(WKWebView *)webView startXRSessionWithCompletionHandler:(void (^)(id))completionHandler WK_API_AVAILABLE(macos(12.0), ios(15.0));
    178178- (void)_webView:(WKWebView *)webView requestNotificationPermissionForSecurityOrigin:(WKSecurityOrigin *)securityOrigin decisionHandler:(void (^)(BOOL))decisionHandler WK_API_AVAILABLE(macos(10.13.4), ios(WK_IOS_TBA));
     179
     180- (void)_webView:(WKWebView *)webView requestCookieConsentWithMoreInfoHandler:(void (^)(void))moreInfoHandler decisionHandler:(void (^)(BOOL))decisionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    179181
    180182#if TARGET_OS_IPHONE
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h

    r286318 r286640  
    107107        void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
    108108        void decidePolicyForNotificationPermissionRequest(WebPageProxy&, API::SecurityOrigin&, CompletionHandler<void(bool allowed)>&&) final;
     109        void requestCookieConsent(CompletionHandler<void(WebCore::CookieConsentDecisionResult)>&&) final;
    109110
    110111#if PLATFORM(MAC)
     
    271272#endif
    272273        bool webViewRequestNotificationPermissionForSecurityOriginDecisionHandler : 1;
     274        bool webViewRequestCookieConsentWithMoreInfoHandlerDecisionHandler : 1;
    273275    } m_delegateMethods;
    274276};
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm

    r286318 r286640  
    198198#endif
    199199    m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:)];
     200    m_delegateMethods.webViewRequestCookieConsentWithMoreInfoHandlerDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestCookieConsentWithMoreInfoHandler:decisionHandler:)];
    200201}
    201202
     
    642643}
    643644
     645void UIDelegate::UIClient::requestCookieConsent(CompletionHandler<void(WebCore::CookieConsentDecisionResult)>&& completion)
     646{
     647    if (!m_uiDelegate)
     648        return completion(WebCore::CookieConsentDecisionResult::NotSupported);
     649
     650    if (!m_uiDelegate->m_delegateMethods.webViewRequestCookieConsentWithMoreInfoHandlerDecisionHandler)
     651        return completion(WebCore::CookieConsentDecisionResult::NotSupported);
     652
     653    auto delegate = m_uiDelegate->m_delegate.get();
     654    if (!delegate)
     655        return completion(WebCore::CookieConsentDecisionResult::NotSupported);
     656
     657    // FIXME: Add support for the 'more info' handler.
     658    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() requestCookieConsentWithMoreInfoHandler:nil decisionHandler:makeBlockPtr([completion = WTFMove(completion)] (BOOL decision) mutable {
     659        completion(decision ? WebCore::CookieConsentDecisionResult::Consent : WebCore::CookieConsentDecisionResult::Dissent);
     660    }).get()];
     661}
     662
    644663#if PLATFORM(MAC)
    645664bool UIDelegate::UIClient::canRunModal() const
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r286632 r286640  
    1102511025#endif
    1102611026
     11027void WebPageProxy::requestCookieConsent(CompletionHandler<void(CookieConsentDecisionResult)>&& completion)
     11028{
     11029    m_uiClient->requestCookieConsent(WTFMove(completion));
     11030}
     11031
    1102711032} // namespace WebKit
    1102811033
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r286632 r286640  
    266266
    267267enum class AutoplayEvent : uint8_t;
     268enum class CookieConsentDecisionResult : uint8_t;
    268269enum class CreateNewGroupForHighlight : bool;
    269270enum class DOMPasteAccessCategory : uint8_t;
     
    20332034    void didDestroyNotification(uint64_t notificationID);
    20342035
     2036    void requestCookieConsent(CompletionHandler<void(WebCore::CookieConsentDecisionResult)>&&);
     2037
    20352038private:
    20362039    WebPageProxy(PageClient&, WebProcessProxy&, Ref<API::PageConfiguration>&&);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r286632 r286640  
    617617    AbortApplePayAMSUISession()
    618618#endif
     619
     620    RequestCookieConsent() -> (enum:uint8_t WebCore::CookieConsentDecisionResult result) Async
    619621}
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r286459 r286640  
    15601560#endif // ENABLE(APPLE_PAY_AMS_UI)
    15611561
     1562void WebChromeClient::requestCookieConsent(CompletionHandler<void(WebCore::CookieConsentDecisionResult)>&& completion)
     1563{
     1564    m_page.sendWithAsyncReply(Messages::WebPageProxy::RequestCookieConsent(), WTFMove(completion));
     1565}
     1566
    15621567} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h

    r286459 r286640  
    3232class HTMLImageElement;
    3333class RegistrableDomain;
     34enum class CookieConsentDecisionResult : uint8_t;
    3435enum class StorageAccessPromptWasShown : bool;
    3536enum class StorageAccessWasGranted : bool;
     
    463464#endif
    464465
     466    void requestCookieConsent(CompletionHandler<void(WebCore::CookieConsentDecisionResult)>&&) final;
     467
    465468    mutable bool m_cachedMainFrameHasHorizontalScrollbar { false };
    466469    mutable bool m_cachedMainFrameHasVerticalScrollbar { false };
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r286632 r286640  
     12021-12-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for `navigator.requestCookieConsent()` behind a disabled feature flag
     4        https://bugs.webkit.org/show_bug.cgi?id=233890
     5        rdar://86117718
     6
     7        Reviewed by Darin Adler.
     8
     9        Add an implementation stub for the new chrome client hook, `requestCookieConsent()`.
     10
     11        * WebCoreSupport/WebChromeClient.h:
     12        * WebCoreSupport/WebChromeClient.mm:
     13        (WebChromeClient::requestCookieConsent):
     14
    1152021-12-07  Devin Rousso  <drousso@apple.com>
    216
  • trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebChromeClient.h

    r286459 r286640  
    258258    RefPtr<PAL::WebGPU::GPU> createGPUForWebGPU() const final;
    259259
     260    void requestCookieConsent(CompletionHandler<void(WebCore::CookieConsentDecisionResult)>&&) final;
     261
    260262#if ENABLE(VIDEO_PRESENTATION_MODE)
    261263    bool m_mockVideoPresentationModeEnabled { false };
  • trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebChromeClient.mm

    r286459 r286640  
    5959#import <WebCore/ContextMenu.h>
    6060#import <WebCore/ContextMenuController.h>
     61#import <WebCore/CookieConsentDecisionResult.h>
    6162#import <WebCore/Cursor.h>
    6263#import <WebCore/DataListSuggestionPicker.h>
     
    11671168#endif
    11681169}
     1170
     1171void WebChromeClient::requestCookieConsent(CompletionHandler<void(CookieConsentDecisionResult)>&& completion)
     1172{
     1173    completion(CookieConsentDecisionResult::NotSupported);
     1174}
  • trunk/Source/WebKitLegacy/win/ChangeLog

    r286632 r286640  
     12021-12-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for `navigator.requestCookieConsent()` behind a disabled feature flag
     4        https://bugs.webkit.org/show_bug.cgi?id=233890
     5        rdar://86117718
     6
     7        Reviewed by Darin Adler.
     8
     9        Add an implementation stub for the new chrome client hook, `requestCookieConsent()`.
     10
     11        * WebCoreSupport/WebChromeClient.cpp:
     12        (WebChromeClient::requestCookieConsent):
     13        * WebCoreSupport/WebChromeClient.h:
     14
    1152021-12-07  Devin Rousso  <drousso@apple.com>
    216
  • trunk/Source/WebKitLegacy/win/WebCoreSupport/WebChromeClient.cpp

    r282606 r286640  
    3939#include <WebCore/BString.h>
    4040#include <WebCore/ContextMenu.h>
     41#include <WebCore/CookieConsentDecisionResult.h>
    4142#include <WebCore/Cursor.h>
    4243#include <WebCore/FileChooser.h>
     
    876877#endif
    877878}
     879
     880void WebChromeClient::requestCookieConsent(CompletionHandler<void(CookieConsentDecisionResult)>&& completion)
     881{
     882    completion(CookieConsentDecisionResult::NotSupported);
     883}
  • trunk/Source/WebKitLegacy/win/WebCoreSupport/WebChromeClient.h

    r282606 r286640  
    184184    void didFinishLoadingImageForElement(WebCore::HTMLImageElement&) final;
    185185
     186    void requestCookieConsent(CompletionHandler<void(WebCore::CookieConsentDecisionResult)>&&);
     187
    186188private:
    187189    COMPtr<IWebUIDelegate> uiDelegate();
  • trunk/Tools/ChangeLog

    r286633 r286640  
     12021-12-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for `navigator.requestCookieConsent()` behind a disabled feature flag
     4        https://bugs.webkit.org/show_bug.cgi?id=233890
     5        rdar://86117718
     6
     7        Reviewed by Darin Adler.
     8
     9        Add several new API tests that enable the feature flag and exercise the API.
     10
     11        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     12        * TestWebKitAPI/Tests/WebKit/CookieConsent.mm: Added.
     13        (-[CookieConsentDelegate _webView:requestCookieConsentWithMoreInfoHandler:decisionHandler:]):
     14        (TestWebKitAPI::createWebViewForTestingCookieConsent):
     15        (TestWebKitAPI::checkForString):
     16        (TestWebKitAPI::TEST):
     17        * TestWebKitAPI/Tests/WebKit/cookie-consent-basic.html: Added.
     18
    1192021-12-07  Yousuke Kimoto  <Yousuke.Kimoto@sony.com>
    220
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r286630 r286640  
    998998                F4010B8324DA267F00A876E2 /* PoseAsClass.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4010B8124DA267F00A876E2 /* PoseAsClass.mm */; };
    999999                F402F56C23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm in Sources */ = {isa = PBXBuildFile; fileRef = F402F56B23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm */; };
     1000                F4034FA1275D5402003A81F8 /* CookieConsent.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4034FA0275D5402003A81F8 /* CookieConsent.mm */; };
     1001                F4034FA3275D5AC6003A81F8 /* cookie-consent-basic.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4034FA2275D5449003A81F8 /* cookie-consent-basic.html */; };
    10001002                F407FE391F1D0DFC0017CF25 /* enormous.svg in Copy Resources */ = {isa = PBXBuildFile; fileRef = F407FE381F1D0DE60017CF25 /* enormous.svg */; };
    10011003                F4094CC725545BD5003D73E3 /* DisplayListTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F4094CC625545BD5003D73E3 /* DisplayListTests.cpp */; };
     
    12661268                                5142B2731517C8C800C32B19 /* ContextMenuCanCopyURL.html in Copy Resources */,
    12671269                                CD0BD0A81F79982D001AB2CF /* ContextMenuImgWithVideo.html in Copy Resources */,
     1270                                F4034FA3275D5AC6003A81F8 /* cookie-consent-basic.html in Copy Resources */,
    12681271                                5C2936961D5C00ED00DEAB1E /* CookieMessage.html in Copy Resources */,
    12691272                                9B1F6F791F90559E00B55744 /* copy-html.html in Copy Resources */,
     
    29262929                F4010B8224DA267F00A876E2 /* PoseAsClass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PoseAsClass.h; path = ../TestRunnerShared/cocoa/PoseAsClass.h; sourceTree = "<group>"; };
    29272930                F402F56B23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UIWKInteractionViewProtocol.mm; sourceTree = "<group>"; };
     2931                F4034FA0275D5402003A81F8 /* CookieConsent.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CookieConsent.mm; sourceTree = "<group>"; };
     2932                F4034FA2275D5449003A81F8 /* cookie-consent-basic.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "cookie-consent-basic.html"; sourceTree = "<group>"; };
    29282933                F407FE381F1D0DE60017CF25 /* enormous.svg */ = {isa = PBXFileReference; lastKnownFileType = text; path = enormous.svg; sourceTree = "<group>"; };
    29292934                F4094CC625545BD5003D73E3 /* DisplayListTests.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayListTests.cpp; sourceTree = "<group>"; };
     
    32733278                                C15CBB2F23F1FF1A00300CC7 /* BacklightLevelNotification.mm */,
    32743279                                C1692DC923D10DAE006E88F7 /* Battery.mm */,
     3280                                F4034FA0275D5402003A81F8 /* CookieConsent.mm */,
    32753281                                C13D82D82416F13200A62793 /* EnableAccessibility.mm */,
    32763282                                1C81802625FB09E200608B3E /* FontRegistrySandboxCheck.mm */,
     
    45954601                                9B270FED1DDC25FD002D53F3 /* closed-shadow-tree-test.html */,
    45964602                                5C9E56861DF9148E00C9EE33 /* contentBlockerCheck.html */,
     4603                                F4034FA2275D5449003A81F8 /* cookie-consent-basic.html */,
    45974604                                2DDD4DA3270B8B3300659A61 /* cube.usdz */,
    45984605                                290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */,
     
    54095416                                CD0BD0A61F79924D001AB2CF /* ContextMenuImgWithVideo.mm in Sources */,
    54105417                                A1C142C224AA7B2E00444207 /* ContextMenuMouseEvents.mm in Sources */,
     5418                                F4034FA1275D5402003A81F8 /* CookieConsent.mm in Sources */,
    54115419                                7CCE7EAC1A411A3400447C4C /* Counters.cpp in Sources */,
    54125420                                7AEAD47F1E20116C00416EFE /* CrossPartitionFileSchemeAccess.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.