[webkit-changes] [WebKit/WebKit] 0b8cd1: Add filtering for WebNavigation events.

Brian Weinstein noreply at github.com
Wed Dec 14 13:32:03 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 0b8cd1e53947aed4b0679d330162f563f190b828
      https://github.com/WebKit/WebKit/commit/0b8cd1e53947aed4b0679d330162f563f190b828
  Author: Brian Weinstein <bweinstein at apple.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    A Source/WebKit/Shared/Extensions/_WKWebExtensionUtilities.h
    A Source/WebKit/Shared/Extensions/_WKWebExtensionUtilities.mm
    M Source/WebKit/WebKit.xcodeproj/project.pbxproj
    M Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIWebNavigationEventCocoa.mm
    M Source/WebKit/WebProcess/Extensions/API/WebExtensionAPIWebNavigationEvent.h
    A Source/WebKit/WebProcess/Extensions/Cocoa/_WKWebExtensionWebNavigationURLFilter.h
    A Source/WebKit/WebProcess/Extensions/Cocoa/_WKWebExtensionWebNavigationURLFilter.mm
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIWebNavigation.mm

  Log Message:
  -----------
  Add filtering for WebNavigation events.
https://bugs.webkit.org/show_bug.cgi?id=249258
rdar://102820594

Reviewed by Timothy Hatcher.

When a webNavigation event listener is added, parse and save the filter that was included with the listener.

When attempting to fire a webNavigation event, check the given URL and see if it passes the included filter.

The filter parsing + managing code is written in Objective-C, and more tests are coming in upcoming patches.

* Source/WebKit/Shared/Extensions/_WKWebExtensionUtilities.h: Added.
* Source/WebKit/Shared/Extensions/_WKWebExtensionUtilities.mm: Added.
(classToClassString):
(+[_WKWebExtensionUtilities validateContentsOfDictionary:requiredKeys:optionalKeys:keyToExpectedValueType:outExceptionString:]): Validates
the contents of the given dictionary, checking for the presence of required keys, possible optional keys, and type checking.
* Source/WebKit/WebKit.xcodeproj/project.pbxproj: Add new files.
* Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIWebNavigationEventCocoa.mm:
(WebKit::WebExtensionAPIWebNavigationEvent::invokeListenersWithArgument): If the listener has a filter, only invoke the listener if the filter
matches the target URL.
(WebKit::WebExtensionAPIWebNavigationEvent::addListener): Handle the filter.
(WebKit::WebExtensionAPIWebNavigationEvent::removeListener): Ditto.
(WebKit::WebExtensionAPIWebNavigationEvent::hasListener): Ditto.
* Source/WebKit/WebProcess/Extensions/API/WebExtensionAPIWebNavigationEvent.h: Change the listener vector to a vector of pairs.
* Source/WebKit/WebProcess/Extensions/Cocoa/_WKWebExtensionWebNavigationURLFilter.h: Copied from Source/WebKit/WebProcess/Extensions/API/WebExtensionAPIWebNavigationEvent.h.
* Source/WebKit/WebProcess/Extensions/Cocoa/_WKWebExtensionWebNavigationURLFilter.mm: Added.
(-[_WKWebExtensionWebNavigationURLPredicate initWithTypeString:value:outErrorMessage:]):
(-[_WKWebExtensionWebNavigationURLPredicate matchesURL:]):
(-[_WKWebExtensionWebNavigationURLFilter initWithDictionary:outErrorMessage:]):
(-[_WKWebExtensionWebNavigationURLFilter matchesURL:]):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIWebNavigation.mm:
(TestWebKitAPI::TEST): Add some basic tests around filtering.

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




More information about the webkit-changes mailing list