Diff
Modified: trunk/Source/WebKit/ChangeLog (271206 => 271207)
--- trunk/Source/WebKit/ChangeLog 2021-01-06 19:31:01 UTC (rev 271206)
+++ trunk/Source/WebKit/ChangeLog 2021-01-06 19:35:15 UTC (rev 271207)
@@ -1,5 +1,26 @@
2021-01-06 Alex Christensen <[email protected]>
+ Add SPI to determine whether a regex is supported in WKContentRuleList
+ https://bugs.webkit.org/show_bug.cgi?id=220095
+ <rdar://problem/72058626>
+
+ 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:
+
+2021-01-06 Alex Christensen <[email protected]>
+
Modernize WebContextMenu
https://bugs.webkit.org/show_bug.cgi?id=219969
Modified: trunk/Source/WebKit/UIProcess/API/APIContentRuleList.cpp (271206 => 271207)
--- trunk/Source/WebKit/UIProcess/API/APIContentRuleList.cpp 2021-01-06 19:31:01 UTC (rev 271206)
+++ trunk/Source/WebKit/UIProcess/API/APIContentRuleList.cpp 2021-01-06 19:35:15 UTC (rev 271207)
@@ -29,6 +29,8 @@
#if ENABLE(CONTENT_EXTENSIONS)
#include "WebCompiledContentRuleList.h"
+#include <WebCore/CombinedURLFilters.h>
+#include <WebCore/URLFilterParser.h>
namespace API {
@@ -43,6 +45,34 @@
{
}
+bool ContentRuleList::supportsRegularExpression(const WTF::String& regex)
+{
+ using namespace WebCore::ContentExtensions;
+ CombinedURLFilters combinedURLFilters;
+ URLFilterParser urlFilterParser(combinedURLFilters);
+
+ switch (urlFilterParser.addPattern(regex, false, 0)) {
+ case URLFilterParser::Ok:
+ case URLFilterParser::MatchesEverything:
+ return true;
+ case URLFilterParser::NonASCII:
+ case URLFilterParser::UnsupportedCharacterClass:
+ case URLFilterParser::BackReference:
+ case URLFilterParser::ForwardReference:
+ case URLFilterParser::MisplacedStartOfLine:
+ case URLFilterParser::WordBoundary:
+ case URLFilterParser::AtomCharacter:
+ case URLFilterParser::Group:
+ case URLFilterParser::Disjunction:
+ case URLFilterParser::MisplacedEndOfLine:
+ case URLFilterParser::EmptyPattern:
+ case URLFilterParser::YarrError:
+ case URLFilterParser::InvalidQuantifier:
+ break;
+ }
+ return false;
+}
+
} // namespace API
#endif // ENABLE(CONTENT_EXTENSIONS)
Modified: trunk/Source/WebKit/UIProcess/API/APIContentRuleList.h (271206 => 271207)
--- trunk/Source/WebKit/UIProcess/API/APIContentRuleList.h 2021-01-06 19:31:01 UTC (rev 271206)
+++ trunk/Source/WebKit/UIProcess/API/APIContentRuleList.h 2021-01-06 19:35:15 UTC (rev 271207)
@@ -48,6 +48,8 @@
const WTF::String& name() const { return m_name; }
const WebKit::WebCompiledContentRuleList& compiledRuleList() const { return m_compiledRuleList.get(); }
+
+ static bool supportsRegularExpression(const WTF::String&);
private:
WTF::String m_name;
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleList.mm (271206 => 271207)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleList.mm 2021-01-06 19:31:01 UTC (rev 271206)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleList.mm 2021-01-06 19:35:15 UTC (rev 271207)
@@ -50,3 +50,12 @@
}
@end
+
+@implementation WKContentRuleList (WKPrivate)
+
++ (BOOL)_supportsRegularExpression:(NSString *)regex
+{
+ return API::ContentRuleList::supportsRegularExpression(regex);
+}
+
+@end
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListInternal.h (271206 => 271207)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListInternal.h 2021-01-06 19:31:01 UTC (rev 271206)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListInternal.h 2021-01-06 19:35:15 UTC (rev 271207)
@@ -23,7 +23,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#import "WKContentRuleList.h"
+#import "WKContentRuleListPrivate.h"
#import "APIContentRuleList.h"
#import "WKObject.h"
Copied: trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListPrivate.h (from rev 271206, trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListInternal.h) (0 => 271207)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListPrivate.h (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListPrivate.h 2021-01-06 19:35:15 UTC (rev 271207)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <WebKit/WKContentRuleList.h>
+
+@interface WKContentRuleList (WKPrivate)
+
++ (BOOL)_supportsRegularExpression:(NSString *)regex WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
+@end
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (271206 => 271207)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2021-01-06 19:31:01 UTC (rev 271206)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2021-01-06 19:35:15 UTC (rev 271207)
@@ -1242,6 +1242,7 @@
5C4609E7224317B4009943C2 /* _WKContentRuleListAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C4609E222430E4C009943C2 /* _WKContentRuleListAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
5C4609E8224317BB009943C2 /* _WKContentRuleListActionInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C4609E422430E4D009943C2 /* _WKContentRuleListActionInternal.h */; };
5C4B9D8B210A8CCF008F14D1 /* UndoOrRedo.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C4B9D8A210A8C46008F14D1 /* UndoOrRedo.h */; };
+ 5C5139DB25927D80009C3E30 /* WKContentRuleListPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C5139DA259277A2009C3E30 /* WKContentRuleListPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
5C5D238C227A2CDA000B9BDA /* _WKCustomHeaderFields.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C5D2389227A1892000B9BDA /* _WKCustomHeaderFields.h */; settings = {ATTRIBUTES = (Private, ); }; };
5C62FDF91EFC271C00CE072E /* WKURLSchemeTaskPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C62FDF81EFC263C00CE072E /* WKURLSchemeTaskPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
5C66A4B52320962400EA4D44 /* WKHTTPCookieStoreRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C66A4B42320961400EA4D44 /* WKHTTPCookieStoreRef.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -4335,6 +4336,7 @@
5C46C0AD21B7198C00BC5991 /* WebsiteDataStoreConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebsiteDataStoreConfiguration.h; sourceTree = "<group>"; };
5C46C0AE21B71AE200BC5991 /* _WKWebsiteDataStoreConfigurationInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKWebsiteDataStoreConfigurationInternal.h; sourceTree = "<group>"; };
5C4B9D8A210A8C46008F14D1 /* UndoOrRedo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UndoOrRedo.h; sourceTree = "<group>"; };
+ 5C5139DA259277A2009C3E30 /* WKContentRuleListPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContentRuleListPrivate.h; sourceTree = "<group>"; };
5C53DCDD24465BF900A93124 /* ApplePayPaymentSetupFeatures.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ApplePayPaymentSetupFeatures.mm; sourceTree = "<group>"; };
5C53DCDE24465BF900A93124 /* PaymentSetupConfigurationWebKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PaymentSetupConfigurationWebKit.h; sourceTree = "<group>"; };
5C53DCDF24465BF900A93124 /* ApplePayPaymentSetupFeaturesWebKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplePayPaymentSetupFeaturesWebKit.h; sourceTree = "<group>"; };
@@ -7850,6 +7852,7 @@
5CD2864A1E722F440094FDC8 /* WKContentRuleList.h */,
5CD2864B1E722F440094FDC8 /* WKContentRuleList.mm */,
5CD2864C1E722F440094FDC8 /* WKContentRuleListInternal.h */,
+ 5C5139DA259277A2009C3E30 /* WKContentRuleListPrivate.h */,
5CD2864D1E722F440094FDC8 /* WKContentRuleListStore.h */,
5CD2864E1E722F440094FDC8 /* WKContentRuleListStore.mm */,
5CD2864F1E722F440094FDC8 /* WKContentRuleListStoreInternal.h */,
@@ -12284,6 +12287,7 @@
E596DD6A251E71D400C275A7 /* WKContactPicker.h in Headers */,
5CD286541E7235B10094FDC8 /* WKContentRuleList.h in Headers */,
5CD286551E7235B80094FDC8 /* WKContentRuleListInternal.h in Headers */,
+ 5C5139DB25927D80009C3E30 /* WKContentRuleListPrivate.h in Headers */,
5CD286511E7235990094FDC8 /* WKContentRuleListStore.h in Headers */,
5CD286571E7235C90094FDC8 /* WKContentRuleListStoreInternal.h in Headers */,
5CD286581E7235D10094FDC8 /* WKContentRuleListStorePrivate.h in Headers */,
Modified: trunk/Tools/ChangeLog (271206 => 271207)
--- trunk/Tools/ChangeLog 2021-01-06 19:31:01 UTC (rev 271206)
+++ trunk/Tools/ChangeLog 2021-01-06 19:35:15 UTC (rev 271207)
@@ -1,3 +1,13 @@
+2021-01-06 Alex Christensen <[email protected]>
+
+ Add SPI to determine whether a regex is supported in WKContentRuleList
+ https://bugs.webkit.org/show_bug.cgi?id=220095
+
+ Reviewed by Tim Horton.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ContentRuleListNotification.mm:
+ (TEST):
+
2021-01-06 Sihui Liu <[email protected]>
Stop speech recognition if page becomes invisible
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentRuleListNotification.mm (271206 => 271207)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentRuleListNotification.mm 2021-01-06 19:31:01 UTC (rev 271206)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentRuleListNotification.mm 2021-01-06 19:35:15 UTC (rev 271207)
@@ -26,6 +26,7 @@
#import "config.h"
#import "PlatformUtilities.h"
+#import <WebKit/WKContentRuleListPrivate.h>
#import <WebKit/WKContentRuleListStore.h>
#import <WebKit/WKNavigationDelegatePrivate.h>
#import <WebKit/WKURLSchemeHandler.h>
@@ -169,3 +170,29 @@
};
EXPECT_TRUE(expectedNotifications == notificationList);
}
+
+TEST(ContentRuleList, SupportsRegex)
+{
+ NSArray<NSString *> *allowed = @[
+ @".*",
+ @"a.*b"
+ ];
+ for (NSString *regex in allowed)
+ EXPECT_TRUE([WKContentRuleList _supportsRegularExpression:regex]);
+
+ NSArray<NSString *> *disallowed = @[
+ @"Ä",
+ @"\\d\\D\\w\\s\\v\\h\\i\\c",
+ @"",
+ @"(?<A>a)\\k<A>",
+ @"a^",
+ @"\\b",
+ @"[\\d]",
+ @"(?!)",
+ @"this|that",
+ @"$$",
+ @"a{0,2}b"
+ ];
+ for (NSString *regex in disallowed)
+ EXPECT_FALSE([WKContentRuleList _supportsRegularExpression:regex]);
+}