Diff
Modified: trunk/Source/WebKit2/ChangeLog (215208 => 215209)
--- trunk/Source/WebKit2/ChangeLog 2017-04-10 23:59:41 UTC (rev 215208)
+++ trunk/Source/WebKit2/ChangeLog 2017-04-11 00:11:15 UTC (rev 215209)
@@ -1,3 +1,23 @@
+2017-04-10 Alex Christensen <[email protected]>
+
+ Add API to get available content extension identifiers in a WKContentExtensionStore
+ https://bugs.webkit.org/show_bug.cgi?id=170093
+
+ Reviewed by Geoffrey Garen.
+
+ * UIProcess/API/APIContentExtensionStore.cpp:
+ (API::constructedPathPrefix):
+ (API::constructedPathFilter):
+ (API::constructedPath):
+ (API::ContentExtensionStore::getAvailableContentExtensionIdentifiers):
+ * UIProcess/API/APIContentExtensionStore.h:
+ * UIProcess/API/Cocoa/WKContentExtensionStore.h:
+ * UIProcess/API/Cocoa/WKContentExtensionStore.mm:
+ (-[WKContentExtensionStore _compileContentExtensionForIdentifier:encodedContentExtension:completionHandler:releasesArgument:]):
+ (-[WKContentExtensionStore lookUpContentExtensionForIdentifier:completionHandler:]):
+ (-[WKContentExtensionStore getAvailableContentExtensionIdentifiers:]):
+ (-[WKContentExtensionStore removeContentExtensionForIdentifier:completionHandler:]):
+
2017-04-10 Jeremy Jones <[email protected]>
Add CoreAudioCaptureSource.
Modified: trunk/Source/WebKit2/UIProcess/API/APIContentExtensionStore.cpp (215208 => 215209)
--- trunk/Source/WebKit2/UIProcess/API/APIContentExtensionStore.cpp 2017-04-10 23:59:41 UTC (rev 215208)
+++ trunk/Source/WebKit2/UIProcess/API/APIContentExtensionStore.cpp 2017-04-11 00:11:15 UTC (rev 215209)
@@ -75,9 +75,20 @@
{
}
+static const String& constructedPathPrefix()
+{
+ static NeverDestroyed<String> prefix("ContentExtension-");
+ return prefix;
+}
+
+static const String constructedPathFilter()
+{
+ return makeString(constructedPathPrefix(), '*');
+}
+
static String constructedPath(const String& base, const String& identifier)
{
- return WebCore::pathByAppendingComponent(base, "ContentExtension-" + WebCore::encodeForFileName(identifier));
+ return WebCore::pathByAppendingComponent(base, makeString(constructedPathPrefix(), WebCore::encodeForFileName(identifier)));
}
// The size and offset of the densely packed bytes in the file, not sizeof and offsetof, which would
@@ -378,6 +389,23 @@
});
}
+void ContentExtensionStore::getAvailableContentExtensionIdentifiers(Function<void(WTF::Vector<WTF::String>)> completionHandler)
+{
+ m_readQueue->dispatch([protectedThis = makeRef(*this), storePath = m_storePath.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
+
+ Vector<String> fullPaths = WebCore::listDirectory(storePath, constructedPathFilter());
+ Vector<String> identifiers;
+ identifiers.reserveInitialCapacity(fullPaths.size());
+ const auto prefixLength = constructedPathPrefix().length();
+ for (const auto& path : fullPaths)
+ identifiers.uncheckedAppend(path.substring(path.reverseFind('/') + 1 + prefixLength));
+
+ RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler), identifiers = WTFMove(identifiers)]() mutable {
+ completionHandler(WTFMove(identifiers));
+ });
+ });
+}
+
void ContentExtensionStore::compileContentExtension(const WTF::String& identifier, WTF::String&& json, Function<void(RefPtr<API::ContentExtension>, std::error_code)> completionHandler)
{
AtomicString::init();
Modified: trunk/Source/WebKit2/UIProcess/API/APIContentExtensionStore.h (215208 => 215209)
--- trunk/Source/WebKit2/UIProcess/API/APIContentExtensionStore.h 2017-04-10 23:59:41 UTC (rev 215208)
+++ trunk/Source/WebKit2/UIProcess/API/APIContentExtensionStore.h 2017-04-11 00:11:15 UTC (rev 215209)
@@ -64,6 +64,7 @@
void compileContentExtension(const WTF::String& identifier, WTF::String&& json, Function<void(RefPtr<API::ContentExtension>, std::error_code)>);
void lookupContentExtension(const WTF::String& identifier, Function<void(RefPtr<API::ContentExtension>, std::error_code)>);
void removeContentExtension(const WTF::String& identifier, Function<void(std::error_code)>);
+ void getAvailableContentExtensionIdentifiers(Function<void(WTF::Vector<WTF::String>)>);
// For testing only.
void synchronousRemoveAllContentExtensions();
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtensionStore.h (215208 => 215209)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtensionStore.h 2017-04-10 23:59:41 UTC (rev 215208)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtensionStore.h 2017-04-11 00:11:15 UTC (rev 215209)
@@ -38,6 +38,7 @@
- (void)compileContentExtensionForIdentifier:(NSString *)identifier encodedContentExtension:(NSString *) encodedContentExtension completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler;
- (void)lookUpContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler;
- (void)removeContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(NSError *))completionHandler;
+- (void)getAvailableContentExtensionIdentifiers:(void (^)(NSArray<NSString *>*))completionHandler;
@end
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtensionStore.mm (215208 => 215209)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtensionStore.mm 2017-04-10 23:59:41 UTC (rev 215208)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKContentExtensionStore.mm 2017-04-11 00:11:15 UTC (rev 215209)
@@ -31,6 +31,7 @@
#import "APIContentExtensionStore.h"
#import "WKErrorInternal.h"
+#import <wtf/BlockPtr.h>
static WKErrorCode toWKErrorCode(const std::error_code& error)
{
@@ -76,8 +77,6 @@
- (void)_compileContentExtensionForIdentifier:(NSString *)identifier encodedContentExtension:(NSString *)encodedContentExtension completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler releasesArgument:(BOOL)releasesArgument
{
- auto handler = adoptNS([completionHandler copy]);
-
String json(encodedContentExtension);
if (releasesArgument) {
[encodedContentExtension release];
@@ -84,59 +83,52 @@
encodedContentExtension = nil;
}
- _contentExtensionStore->compileContentExtension(identifier, WTFMove(json), [handler](RefPtr<API::ContentExtension> contentExtension, std::error_code error) {
+ _contentExtensionStore->compileContentExtension(identifier, WTFMove(json), [completionHandler = makeBlockPtr(completionHandler)](RefPtr<API::ContentExtension> contentExtension, std::error_code error) {
if (error) {
- auto rawHandler = (void (^)(WKContentExtension *, NSError *))handler.get();
-
auto userInfo = @{NSHelpAnchorErrorKey: [NSString stringWithFormat:@"Extension compilation failed: %s", error.message().c_str()]};
// error.value() could have a specific compiler error that is not equal to WKErrorContentExtensionStoreCompileFailed.
// We want to use error.message, but here we want to only pass on CompileFailed with userInfo from the std::error_code.
- rawHandler(nil, [NSError errorWithDomain:WKErrorDomain code:WKErrorContentExtensionStoreCompileFailed userInfo:userInfo]);
- return;
+ return completionHandler(nil, [NSError errorWithDomain:WKErrorDomain code:WKErrorContentExtensionStoreCompileFailed userInfo:userInfo]);
}
-
- auto rawHandler = (void (^)(WKContentExtension *, NSError *))handler.get();
- rawHandler(WebKit::wrapper(*contentExtension.get()), nil);
+ completionHandler(WebKit::wrapper(*contentExtension.get()), nil);
});
}
- (void)lookUpContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(WKContentExtension *, NSError *))completionHandler
{
- auto handler = adoptNS([completionHandler copy]);
-
- _contentExtensionStore->lookupContentExtension(identifier, [handler](RefPtr<API::ContentExtension> contentExtension, std::error_code error) {
+ _contentExtensionStore->lookupContentExtension(identifier, [completionHandler = makeBlockPtr(completionHandler)](RefPtr<API::ContentExtension> contentExtension, std::error_code error) {
if (error) {
- auto rawHandler = (void (^)(WKContentExtension *, NSError *))handler.get();
-
auto userInfo = @{NSHelpAnchorErrorKey: [NSString stringWithFormat:@"Extension lookup failed: %s", error.message().c_str()]};
auto wkError = toWKErrorCode(error);
ASSERT(wkError == WKErrorContentExtensionStoreLookUpFailed || wkError == WKErrorContentExtensionStoreVersionMismatch);
- rawHandler(nil, [NSError errorWithDomain:WKErrorDomain code:wkError userInfo:userInfo]);
- return;
+ return completionHandler(nil, [NSError errorWithDomain:WKErrorDomain code:wkError userInfo:userInfo]);
}
- auto rawHandler = (void (^)(WKContentExtension *, NSError *))handler.get();
- rawHandler(WebKit::wrapper(*contentExtension.get()), nil);
+ completionHandler(WebKit::wrapper(*contentExtension.get()), nil);
});
}
+- (void)getAvailableContentExtensionIdentifiers:(void (^)(NSArray<NSString *>*))completionHandler
+{
+ _contentExtensionStore->getAvailableContentExtensionIdentifiers([completionHandler = makeBlockPtr(completionHandler)](Vector<String> identifiers) {
+ NSMutableArray<NSString *> *nsIdentifiers = [NSMutableArray arrayWithCapacity:identifiers.size()];
+ for (const auto& identifier : identifiers)
+ [nsIdentifiers addObject:identifier];
+ completionHandler(nsIdentifiers);
+ });
+}
+
- (void)removeContentExtensionForIdentifier:(NSString *)identifier completionHandler:(void (^)(NSError *))completionHandler
{
- auto handler = adoptNS([completionHandler copy]);
-
- _contentExtensionStore->removeContentExtension(identifier, [handler](std::error_code error) {
+ _contentExtensionStore->removeContentExtension(identifier, [completionHandler = makeBlockPtr(completionHandler)](std::error_code error) {
if (error) {
- auto rawHandler = (void (^)(NSError *))handler.get();
-
auto userInfo = @{NSHelpAnchorErrorKey: [NSString stringWithFormat:@"Extension removal failed: %s", error.message().c_str()]};
ASSERT(toWKErrorCode(error) == WKErrorContentExtensionStoreRemoveFailed);
- rawHandler([NSError errorWithDomain:WKErrorDomain code:WKErrorContentExtensionStoreRemoveFailed userInfo:userInfo]);
- return;
+ return completionHandler([NSError errorWithDomain:WKErrorDomain code:WKErrorContentExtensionStoreRemoveFailed userInfo:userInfo]);
}
- auto rawHandler = (void (^)(NSError *))handler.get();
- rawHandler(nil);
+ completionHandler(nil);
});
}
Modified: trunk/Tools/ChangeLog (215208 => 215209)
--- trunk/Tools/ChangeLog 2017-04-10 23:59:41 UTC (rev 215208)
+++ trunk/Tools/ChangeLog 2017-04-11 00:11:15 UTC (rev 215209)
@@ -1,3 +1,13 @@
+2017-04-10 Alex Christensen <[email protected]>
+
+ Add API to get available content extension identifiers in a WKContentExtensionStore
+ https://bugs.webkit.org/show_bug.cgi?id=170093
+
+ Reviewed by Geoffrey Garen.
+
+ * TestWebKitAPI/Tests/WebKit2Cocoa/WKUserContentExtensionStore.mm:
+ (TEST_F):
+
2017-04-10 Wenson Hsieh <[email protected]>
Refactor DataInteractionTests.UnresponsivePageDoesNotHangUI to not check against a fixed time interval
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKUserContentExtensionStore.mm (215208 => 215209)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKUserContentExtensionStore.mm 2017-04-10 23:59:41 UTC (rev 215208)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKUserContentExtensionStore.mm 2017-04-11 00:11:15 UTC (rev 215209)
@@ -199,6 +199,14 @@
NSString *identifier = @"TestExtension";
NSString *fileName = @"ContentExtension-TestExtension";
+ __block bool doneGettingAvailableIdentifiers = false;
+ [store getAvailableContentExtensionIdentifiers:^(NSArray<NSString *> *identifiers) {
+ EXPECT_NOT_NULL(identifiers);
+ EXPECT_EQ(identifiers.count, 0u);
+ doneGettingAvailableIdentifiers = true;
+ }];
+ TestWebKitAPI::Util::run(&doneGettingAvailableIdentifiers);
+
__block bool doneCompiling = false;
[store compileContentExtensionForIdentifier:identifier encodedContentExtension:basicFilter completionHandler:^(WKContentExtension *filter, NSError *error) {
EXPECT_NOT_NULL(filter);
@@ -207,6 +215,15 @@
}];
TestWebKitAPI::Util::run(&doneCompiling);
+ doneGettingAvailableIdentifiers = false;
+ [store getAvailableContentExtensionIdentifiers:^(NSArray<NSString *> *identifiers) {
+ EXPECT_NOT_NULL(identifiers);
+ EXPECT_EQ(identifiers.count, 1u);
+ EXPECT_STREQ(identifiers[0].UTF8String, "TestExtension");
+ doneGettingAvailableIdentifiers = true;
+ }];
+ TestWebKitAPI::Util::run(&doneGettingAvailableIdentifiers);
+
NSData *data = "" dataWithContentsOfURL:[tempDir URLByAppendingPathComponent:fileName]];
EXPECT_NOT_NULL(data);
EXPECT_EQ(data.length, 228u);
@@ -230,6 +247,27 @@
EXPECT_NULL(dataAfterRemoving);
}
+TEST_F(WKContentExtensionStoreTest, MultipleExtensions)
+{
+ __block bool done = false;
+ [[WKContentExtensionStore defaultStore] compileContentExtensionForIdentifier:@"FirstExtension" encodedContentExtension:basicFilter completionHandler:^(WKContentExtension *filter, NSError *error) {
+ EXPECT_NOT_NULL(filter);
+ EXPECT_NULL(error);
+ [[WKContentExtensionStore defaultStore] compileContentExtensionForIdentifier:@"SecondExtension" encodedContentExtension:basicFilter completionHandler:^(WKContentExtension *filter, NSError *error) {
+ EXPECT_NOT_NULL(filter);
+ EXPECT_NULL(error);
+ [[WKContentExtensionStore defaultStore] getAvailableContentExtensionIdentifiers:^(NSArray<NSString *> *identifiers) {
+ EXPECT_NOT_NULL(identifiers);
+ EXPECT_EQ(identifiers.count, 2u);
+ EXPECT_STREQ(identifiers[0].UTF8String, "FirstExtension");
+ EXPECT_STREQ(identifiers[1].UTF8String, "SecondExtension");
+ done = true;
+ }];
+ }];
+ }];
+ TestWebKitAPI::Util::run(&done);
+}
+
TEST_F(WKContentExtensionStoreTest, NonASCIISource)
{
static NSString *nonASCIIFilter = @"[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*webkit.org\"}, \"unused\":\"💩\"}]";