Skip to content

Commit

Permalink
Temporarily re-add _WKUserContentFilter and _WKUserContentExtensionStore
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=246050
<rdar://100785329>

Reviewed by Tim Horton.

* Source/WebKit/SourcesCocoa.txt:
* Source/WebKit/UIProcess/API/Cocoa/WKUserContentController.mm:
(-[WKUserContentController _addUserContentFilter:]):
* Source/WebKit/UIProcess/API/Cocoa/WKUserContentControllerPrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKUserContentExtensionStore.h: Added.
* Source/WebKit/UIProcess/API/Cocoa/_WKUserContentExtensionStore.mm: Added.
(toUserContentRuleListStoreError):
(+[_WKUserContentExtensionStore defaultStore]):
(+[_WKUserContentExtensionStore storeWithURL:]):
(-[_WKUserContentExtensionStore compileContentExtensionForIdentifier:encodedContentExtension:completionHandler:]):
(-[_WKUserContentExtensionStore lookupContentExtensionForIdentifier:completionHandler:]):
(-[_WKUserContentExtensionStore removeContentExtensionForIdentifier:completionHandler:]):
(-[_WKUserContentExtensionStore _apiObject]):
(-[_WKUserContentExtensionStore _removeAllContentExtensions]):
(-[_WKUserContentExtensionStore _invalidateContentExtensionVersionForIdentifier:]):
(-[_WKUserContentExtensionStore _initWithWKContentRuleListStore:]):
(-[_WKUserContentExtensionStore _contentRuleListStore]):
* Source/WebKit/UIProcess/API/Cocoa/_WKUserContentExtensionStoreInternal.h: Added.
* Source/WebKit/UIProcess/API/Cocoa/_WKUserContentExtensionStorePrivate.h: Added.
* Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilter.h: Added.
* Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilter.mm: Added.
(-[_WKUserContentFilter _apiObject]):
(-[_WKUserContentFilter _initWithWKContentRuleList:]):
* Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilterInternal.h: Added.
* Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilterPrivate.h: Added.
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/255149@main
  • Loading branch information
Alex Christensen authored and achristensen07 committed Oct 5, 2022
1 parent 49a7efc commit a80b289
Show file tree
Hide file tree
Showing 12 changed files with 478 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Source/WebKit/SourcesCocoa.txt
Expand Up @@ -291,6 +291,8 @@ UIProcess/API/Cocoa/_WKTextManipulationExclusionRule.mm
UIProcess/API/Cocoa/_WKTextManipulationItem.mm
UIProcess/API/Cocoa/_WKTextManipulationToken.mm
UIProcess/API/Cocoa/_WKThumbnailView.mm
UIProcess/API/Cocoa/_WKUserContentExtensionStore.mm
UIProcess/API/Cocoa/_WKUserContentFilter.mm
UIProcess/API/Cocoa/_WKUserContentWorld.mm
UIProcess/API/Cocoa/_WKUserInitiatedAction.mm
UIProcess/API/Cocoa/_WKUserStyleSheet.mm
Expand Down
11 changes: 11 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/WKUserContentController.mm
Expand Up @@ -40,6 +40,7 @@
#import "WKWebViewInternal.h"
#import "WebScriptMessageHandler.h"
#import "WebUserContentControllerProxy.h"
#import "_WKUserContentFilterInternal.h"
#import "_WKUserContentWorldInternal.h"
#import "_WKUserStyleSheetInternal.h"
#import <WebCore/SecurityOrigin.h>
Expand Down Expand Up @@ -277,6 +278,16 @@ - (void)_addUserScriptImmediately:(WKUserScript *)userScript
_userContentControllerProxy->addUserScript(*userScript->_userScript, WebKit::InjectUserScriptImmediately::Yes);
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
- (void)_addUserContentFilter:(_WKUserContentFilter *)userContentFilter
#pragma clang diagnostic pop
{
#if ENABLE(CONTENT_EXTENSIONS)
_userContentControllerProxy->addContentRuleList(*userContentFilter->_contentRuleList->_contentRuleList);
#endif
}

- (void)_addContentRuleList:(WKContentRuleList *)contentRuleList extensionBaseURL:(NSURL *)extensionBaseURL
{
#if ENABLE(CONTENT_EXTENSIONS)
Expand Down
Expand Up @@ -27,6 +27,7 @@

@class WKContentWorld;
@class WKUserScript;
@class _WKUserContentFilter;
@class _WKUserContentWorld;
@class _WKUserStyleSheet;

Expand All @@ -37,6 +38,9 @@

- (void)_addUserScriptImmediately:(WKUserScript *)userScript WK_API_AVAILABLE(macos(10.14), ios(12.0));

// FIXME: Remove this once rdar://100785999 is unblocked.
- (void)_addUserContentFilter:(_WKUserContentFilter *)userContentFilter WK_API_DEPRECATED_WITH_REPLACEMENT("addContentRuleList", macos(10.11, WK_MAC_TBA), ios(9.0, WK_IOS_TBA));

- (void)_removeUserContentFilter:(NSString *)userContentFilterName WK_API_AVAILABLE(macos(10.11), ios(9.0));
- (void)_removeAllUserContentFilters WK_API_AVAILABLE(macos(10.11), ios(9.0));
- (void)_addContentRuleList:(WKContentRuleList *)contentRuleList extensionBaseURL:(NSURL *)extensionBaseURL WK_API_AVAILABLE(macos(13.0), ios(16.0));
Expand Down
50 changes: 50 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/_WKUserContentExtensionStore.h
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2015 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/WKFoundation.h>

@class _WKUserContentFilter;

// FIXME: Remove this once rdar://100785999 is unblocked.
WK_CLASS_DEPRECATED_WITH_REPLACEMENT("WKContentRuleListStore", macos(10.11, WK_MAC_TBA), ios(9.0, WK_IOS_TBA))
@interface _WKUserContentExtensionStore : NSObject

+ (instancetype)defaultStore;
+ (instancetype)storeWithURL:(NSURL *)url;

- (void)compileContentExtensionForIdentifier:(NSString *)identifier encodedContentExtension:(NSString *) NS_RELEASES_ARGUMENT encodedContentExtension completionHandler:(void (^)(_WKUserContentFilter *, NSError *))completionHandler;
- (void)lookupContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(_WKUserContentFilter *, NSError *))completionHandler;
- (void)removeContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(NSError *))completionHandler;

@end

WK_EXTERN NSString * const _WKUserContentExtensionsDomain WK_API_AVAILABLE(macos(10.12), ios(10.0));

typedef NS_ENUM(NSInteger, _WKUserContentExtensionStoreErrorCode) {
_WKUserContentExtensionStoreErrorLookupFailed,
_WKUserContentExtensionStoreErrorVersionMismatch,
_WKUserContentExtensionStoreErrorCompileFailed,
_WKUserContentExtensionStoreErrorRemoveFailed,
} WK_API_AVAILABLE(macos(10.12), ios(10.0));
139 changes: 139 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/_WKUserContentExtensionStore.mm
@@ -0,0 +1,139 @@
/*
* Copyright (C) 2015 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 "config.h"
#import "_WKUserContentExtensionStoreInternal.h"

#import "WKContentRuleListStoreInternal.h"
#import "WKContentRuleListStorePrivate.h"
#import "WKErrorInternal.h"
#import "_WKUserContentExtensionStorePrivate.h"
#import "_WKUserContentFilterInternal.h"
#import "_WKUserContentFilterPrivate.h"
#import <string>

NSString * const _WKUserContentExtensionsDomain = @"WKErrorDomain";

static NSError *toUserContentRuleListStoreError(const NSError *error)
{
if (!error)
return nil;

ASSERT(error.domain == WKErrorDomain);
switch (error.code) {
case WKErrorContentRuleListStoreLookUpFailed:
return [NSError errorWithDomain:_WKUserContentExtensionsDomain code:_WKUserContentExtensionStoreErrorLookupFailed userInfo:error.userInfo];
case WKErrorContentRuleListStoreVersionMismatch:
return [NSError errorWithDomain:_WKUserContentExtensionsDomain code:_WKUserContentExtensionStoreErrorVersionMismatch userInfo:error.userInfo];
case WKErrorContentRuleListStoreCompileFailed:
return [NSError errorWithDomain:_WKUserContentExtensionsDomain code:_WKUserContentExtensionStoreErrorCompileFailed userInfo:error.userInfo];
case WKErrorContentRuleListStoreRemoveFailed:
return [NSError errorWithDomain:_WKUserContentExtensionsDomain code:_WKUserContentExtensionStoreErrorRemoveFailed userInfo:error.userInfo];
default:
RELEASE_ASSERT_NOT_REACHED();
}
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
@implementation _WKUserContentExtensionStore
#pragma clang diagnostic pop

+ (instancetype)defaultStore
{
return adoptNS([[_WKUserContentExtensionStore alloc] _initWithWKContentRuleListStore:[WKContentRuleListStore defaultStoreWithLegacyFilename]]).autorelease();
}

+ (instancetype)storeWithURL:(NSURL *)url
{
return adoptNS([[_WKUserContentExtensionStore alloc] _initWithWKContentRuleListStore:[WKContentRuleListStore storeWithURLAndLegacyFilename:url]]).autorelease();
}

- (void)compileContentExtensionForIdentifier:(NSString *)identifier encodedContentExtension:(NSString *)encodedContentRuleList completionHandler:(void (^)(_WKUserContentFilter *, NSError *))completionHandler
{
[_contentRuleListStore compileContentRuleListForIdentifier:identifier encodedContentRuleList:encodedContentRuleList completionHandler:^(WKContentRuleList *contentRuleList, NSError *error) {
auto contentFilter = contentRuleList ? adoptNS([[_WKUserContentFilter alloc] _initWithWKContentRuleList:contentRuleList]) : nil;
completionHandler(contentFilter.get(), toUserContentRuleListStoreError(error));
}];
}

- (void)lookupContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(_WKUserContentFilter *, NSError *))completionHandler
{
[_contentRuleListStore lookUpContentRuleListForIdentifier:identifier completionHandler:^(WKContentRuleList *contentRuleList, NSError *error) {
auto contentFilter = contentRuleList ? adoptNS([[_WKUserContentFilter alloc] _initWithWKContentRuleList:contentRuleList]) : nil;
completionHandler(contentFilter.get(), toUserContentRuleListStoreError(error));
}];
}

- (void)removeContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(NSError *))completionHandler
{
[_contentRuleListStore removeContentRuleListForIdentifier:identifier completionHandler:^(NSError *error) {
completionHandler(toUserContentRuleListStoreError(error));
}];
}

#pragma mark WKObject protocol implementation

- (API::Object&)_apiObject
{
return [_contentRuleListStore _apiObject];
}

@end

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
@implementation _WKUserContentExtensionStore (WKPrivate)
#pragma clang diagnostic pop

// For testing only.

- (void)_removeAllContentExtensions
{
[_contentRuleListStore _removeAllContentRuleLists];
}

- (void)_invalidateContentExtensionVersionForIdentifier:(NSString *)identifier
{
[_contentRuleListStore _invalidateContentRuleListVersionForIdentifier:identifier];
}

- (id)_initWithWKContentRuleListStore:(WKContentRuleListStore*)contentRuleListStore
{
self = [super init];
if (!self)
return nil;

_contentRuleListStore = contentRuleListStore;

return self;
}

- (WKContentRuleListStore *)_contentRuleListStore
{
return _contentRuleListStore.get();
}

@end
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2015 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 "_WKUserContentExtensionStorePrivate.h"

#import "APIContentRuleListStore.h"
#import "WKObject.h"

@class WKContentRuleListStore;

@interface _WKUserContentExtensionStore () <WKObject> {
@package
RetainPtr<WKContentRuleListStore> _contentRuleListStore;
}
@end
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2015 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/_WKUserContentExtensionStore.h>

@class WKContentRuleListStore;

@interface _WKUserContentExtensionStore (WKPrivate)

// For testing only.
- (void)_removeAllContentExtensions;
- (void)_invalidateContentExtensionVersionForIdentifier:(NSString *)identifier;

- (id)_initWithWKContentRuleListStore:(WKContentRuleListStore *)contentRuleListStore WK_API_AVAILABLE(macos(10.13), ios(11.0));
@property (nonatomic, readonly) WKContentRuleListStore *_contentRuleListStore WK_API_AVAILABLE(macos(10.15), ios(13.0));

@end
32 changes: 32 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilter.h
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2015 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/WKFoundation.h>

// FIXME: Remove this once rdar://100785999 is unblocked.
WK_CLASS_DEPRECATED_WITH_REPLACEMENT("WKContentRuleList", macos(10.11, WK_MAC_TBA), ios(9.0, WK_IOS_TBA))
@interface _WKUserContentFilter : NSObject

@end

0 comments on commit a80b289

Please sign in to comment.