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

Changeset 271207 in webkit


Ignore:
Timestamp:
Jan 6, 2021, 11:35:15 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Add SPI to determine whether a regex is supported in WKContentRuleList
https://bugs.webkit.org/show_bug.cgi?id=220095
Source/WebKit:

<rdar://problem/72058626>

Patch by Alex Christensen <achristensen@webkit.org> on 2021-01-06
Reviewed by Tim Horton.

This is a more efficient way than making a little rule list and seeing if it compiles.
Here, we don't need access to the disk, and we don't need to hop to another thread and back.
Covered by API tests.

  • UIProcess/API/APIContentRuleList.cpp:

(API::ContentRuleList::supportsRegularExpression):

  • UIProcess/API/APIContentRuleList.h:
  • UIProcess/API/Cocoa/WKContentRuleList.mm:

(+[WKContentRuleList _supportsRegularExpression:]):

  • UIProcess/API/Cocoa/WKContentRuleListInternal.h:
  • UIProcess/API/Cocoa/WKContentRuleListPrivate.h: Copied from Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListInternal.h.
  • WebKit.xcodeproj/project.pbxproj:

Tools:

Patch by Alex Christensen <achristensen@webkit.org> on 2021-01-06
Reviewed by Tim Horton.

  • TestWebKitAPI/Tests/WebKitCocoa/ContentRuleListNotification.mm:

(TEST):

Location:
trunk
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r271206 r271207  
     12021-01-06  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add SPI to determine whether a regex is supported in WKContentRuleList
     4        https://bugs.webkit.org/show_bug.cgi?id=220095
     5        <rdar://problem/72058626>
     6
     7        Reviewed by Tim Horton.
     8
     9        This is a more efficient way than making a little rule list and seeing if it compiles.
     10        Here, we don't need access to the disk, and we don't need to hop to another thread and back.
     11        Covered by API tests.
     12
     13        * UIProcess/API/APIContentRuleList.cpp:
     14        (API::ContentRuleList::supportsRegularExpression):
     15        * UIProcess/API/APIContentRuleList.h:
     16        * UIProcess/API/Cocoa/WKContentRuleList.mm:
     17        (+[WKContentRuleList _supportsRegularExpression:]):
     18        * UIProcess/API/Cocoa/WKContentRuleListInternal.h:
     19        * UIProcess/API/Cocoa/WKContentRuleListPrivate.h: Copied from Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListInternal.h.
     20        * WebKit.xcodeproj/project.pbxproj:
     21
    1222021-01-06  Alex Christensen  <achristensen@webkit.org>
    223
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleList.cpp

    r244597 r271207  
    3030
    3131#include "WebCompiledContentRuleList.h"
     32#include <WebCore/CombinedURLFilters.h>
     33#include <WebCore/URLFilterParser.h>
    3234
    3335namespace API {
     
    4446}
    4547
     48bool ContentRuleList::supportsRegularExpression(const WTF::String& regex)
     49{
     50    using namespace WebCore::ContentExtensions;
     51    CombinedURLFilters combinedURLFilters;
     52    URLFilterParser urlFilterParser(combinedURLFilters);
     53
     54    switch (urlFilterParser.addPattern(regex, false, 0)) {
     55    case URLFilterParser::Ok:
     56    case URLFilterParser::MatchesEverything:
     57        return true;
     58    case URLFilterParser::NonASCII:
     59    case URLFilterParser::UnsupportedCharacterClass:
     60    case URLFilterParser::BackReference:
     61    case URLFilterParser::ForwardReference:
     62    case URLFilterParser::MisplacedStartOfLine:
     63    case URLFilterParser::WordBoundary:
     64    case URLFilterParser::AtomCharacter:
     65    case URLFilterParser::Group:
     66    case URLFilterParser::Disjunction:
     67    case URLFilterParser::MisplacedEndOfLine:
     68    case URLFilterParser::EmptyPattern:
     69    case URLFilterParser::YarrError:
     70    case URLFilterParser::InvalidQuantifier:
     71        break;
     72    }
     73    return false;
     74}
     75
    4676} // namespace API
    4777
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleList.h

    r244597 r271207  
    4949    const WTF::String& name() const { return m_name; }
    5050    const WebKit::WebCompiledContentRuleList& compiledRuleList() const { return m_compiledRuleList.get(); }
     51   
     52    static bool supportsRegularExpression(const WTF::String&);
    5153
    5254private:
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleList.mm

    r260366 r271207  
    5151
    5252@end
     53
     54@implementation WKContentRuleList (WKPrivate)
     55
     56+ (BOOL)_supportsRegularExpression:(NSString *)regex
     57{
     58    return API::ContentRuleList::supportsRegularExpression(regex);
     59}
     60
     61@end
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListInternal.h

    r242339 r271207  
    2424 */
    2525
    26 #import "WKContentRuleList.h"
     26#import "WKContentRuleListPrivate.h"
    2727
    2828#import "APIContentRuleList.h"
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListPrivate.h

    r271206 r271207  
    11/*
    2  * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import "WKContentRuleList.h"
     26#import <WebKit/WKContentRuleList.h>
    2727
    28 #import "APIContentRuleList.h"
    29 #import "WKObject.h"
     28@interface WKContentRuleList (WKPrivate)
    3029
    31 namespace WebKit {
     30+ (BOOL)_supportsRegularExpression:(NSString *)regex WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    3231
    33 template<> struct WrapperTraits<API::ContentRuleList> {
    34     using WrapperClass = WKContentRuleList;
    35 };
    36 
    37 }
    38 
    39 @interface WKContentRuleList () <WKObject> {
    40 @package
    41     API::ObjectStorage<API::ContentRuleList> _contentRuleList;
    42 }
    4332@end
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r271180 r271207  
    12431243                5C4609E8224317BB009943C2 /* _WKContentRuleListActionInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C4609E422430E4D009943C2 /* _WKContentRuleListActionInternal.h */; };
    12441244                5C4B9D8B210A8CCF008F14D1 /* UndoOrRedo.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C4B9D8A210A8C46008F14D1 /* UndoOrRedo.h */; };
     1245                5C5139DB25927D80009C3E30 /* WKContentRuleListPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C5139DA259277A2009C3E30 /* WKContentRuleListPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12451246                5C5D238C227A2CDA000B9BDA /* _WKCustomHeaderFields.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C5D2389227A1892000B9BDA /* _WKCustomHeaderFields.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12461247                5C62FDF91EFC271C00CE072E /* WKURLSchemeTaskPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C62FDF81EFC263C00CE072E /* WKURLSchemeTaskPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    43364337                5C46C0AE21B71AE200BC5991 /* _WKWebsiteDataStoreConfigurationInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKWebsiteDataStoreConfigurationInternal.h; sourceTree = "<group>"; };
    43374338                5C4B9D8A210A8C46008F14D1 /* UndoOrRedo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UndoOrRedo.h; sourceTree = "<group>"; };
     4339                5C5139DA259277A2009C3E30 /* WKContentRuleListPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContentRuleListPrivate.h; sourceTree = "<group>"; };
    43384340                5C53DCDD24465BF900A93124 /* ApplePayPaymentSetupFeatures.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ApplePayPaymentSetupFeatures.mm; sourceTree = "<group>"; };
    43394341                5C53DCDE24465BF900A93124 /* PaymentSetupConfigurationWebKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PaymentSetupConfigurationWebKit.h; sourceTree = "<group>"; };
     
    78517853                                5CD2864B1E722F440094FDC8 /* WKContentRuleList.mm */,
    78527854                                5CD2864C1E722F440094FDC8 /* WKContentRuleListInternal.h */,
     7855                                5C5139DA259277A2009C3E30 /* WKContentRuleListPrivate.h */,
    78537856                                5CD2864D1E722F440094FDC8 /* WKContentRuleListStore.h */,
    78547857                                5CD2864E1E722F440094FDC8 /* WKContentRuleListStore.mm */,
     
    1228512288                                5CD286541E7235B10094FDC8 /* WKContentRuleList.h in Headers */,
    1228612289                                5CD286551E7235B80094FDC8 /* WKContentRuleListInternal.h in Headers */,
     12290                                5C5139DB25927D80009C3E30 /* WKContentRuleListPrivate.h in Headers */,
    1228712291                                5CD286511E7235990094FDC8 /* WKContentRuleListStore.h in Headers */,
    1228812292                                5CD286571E7235C90094FDC8 /* WKContentRuleListStoreInternal.h in Headers */,
  • trunk/Tools/ChangeLog

    r271205 r271207  
     12021-01-06  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add SPI to determine whether a regex is supported in WKContentRuleList
     4        https://bugs.webkit.org/show_bug.cgi?id=220095
     5
     6        Reviewed by Tim Horton.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/ContentRuleListNotification.mm:
     9        (TEST):
     10
    1112021-01-06  Sihui Liu  <sihui_liu@appe.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentRuleListNotification.mm

    r259843 r271207  
    2727
    2828#import "PlatformUtilities.h"
     29#import <WebKit/WKContentRuleListPrivate.h>
    2930#import <WebKit/WKContentRuleListStore.h>
    3031#import <WebKit/WKNavigationDelegatePrivate.h>
     
    170171    EXPECT_TRUE(expectedNotifications == notificationList);
    171172}
     173
     174TEST(ContentRuleList, SupportsRegex)
     175{
     176    NSArray<NSString *> *allowed = @[
     177        @".*",
     178        @"a.*b"
     179    ];
     180    for (NSString *regex in allowed)
     181        EXPECT_TRUE([WKContentRuleList _supportsRegularExpression:regex]);
     182   
     183    NSArray<NSString *> *disallowed = @[
     184        @"Ä",
     185        @"\\d\\D\\w\\s\\v\\h\\i\\c",
     186        @"",
     187        @"(?<A>a)\\k<A>",
     188        @"a^",
     189        @"\\b",
     190        @"[\\d]",
     191        @"(?!)",
     192        @"this|that",
     193        @"$$",
     194        @"a{0,2}b"
     195    ];
     196    for (NSString *regex in disallowed)
     197        EXPECT_FALSE([WKContentRuleList _supportsRegularExpression:regex]);
     198}
Note: See TracChangeset for help on using the changeset viewer.