Bug 142710

Summary: [Content Filtering] Adopt new NEFilterSource SPI
Product: WebKit Reporter: Andy Estes <aestes>
Component: New BugsAssignee: Andy Estes <aestes>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, ddkilzer, kling, mitz, sam
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 128858    
Attachments:
Description Flags
Patch mitz: review+

Description Andy Estes 2015-03-15 02:54:30 PDT
[Content Filtering] Adopt new NEFilterSource SPI
Comment 1 Andy Estes 2015-03-15 02:55:05 PDT
rdar://problem/19023855
Comment 2 Andy Estes 2015-03-15 03:24:52 PDT
Created attachment 248676 [details]
Patch
Comment 3 WebKit Commit Bot 2015-03-15 03:27:49 PDT
Attachment 248676 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:77:  Code inside a namespace should not be indented.  [whitespace/indent] [4]
ERROR: Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:85:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
ERROR: Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:113:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
ERROR: Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:117:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
ERROR: Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:131:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
ERROR: Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:135:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
Total errors found: 6 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 mitz 2015-03-15 19:27:14 PDT
Comment on attachment 248676 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=248676&action=review

> Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h:30
> +#include <objc/NSObjCRuntime.h>

What is this used for here?

> Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:44
> +static inline NSData *decisionInfoReplacementData(NSDictionary *decisionInfo)

I’d call this replacementDataFromDecisionInfo, but that’s just a matter of taste.

> Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:85
> +    [m_neFilterSource receivedResponse:response.nsURLResponse() decisionHandler:^(NEFilterSourceStatus status, NSDictionary *decisionInfo) {

I think we prefer to use lambdas in C++ code, because it makes captures explicit.

> Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:99
> +    dispatch_release(m_queue);
> +    dispatch_release(m_semaphore);

Can we use OSObjectPtr for these things so that we don’t have to manage them manually?

> Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:118
> +    [m_neFilterSource receivedData:copiedData.get() decisionHandler:^(NEFilterSourceStatus status, NSDictionary *decisionInfo) {
> +        handleDecision(status, decisionInfoReplacementData(decisionInfo));
> +    }];
> +#else
> +    [m_neFilterSource addData:copiedData.get() withCompletionQueue:m_queue completionHandler:^(NEFilterSourceStatus status, NSData *replacementData) {
> +        handleDecision(status, replacementData);

Same comment about lambdas vs. blocks.

> Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:137
> +    [m_neFilterSource finishedLoadingWithDecisionHandler:^(NEFilterSourceStatus status, NSDictionary *decisionInfo) {
> +        handleDecision(status, decisionInfoReplacementData(decisionInfo));
>      }];
> +#else
> +    [m_neFilterSource dataCompleteWithCompletionQueue:m_queue completionHandler:^(NEFilterSourceStatus status, NSData *replacementData) {
> +        handleDecision(status, replacementData);
> +    }];

Ditto.

> Source/WebCore/platform/spi/cocoa/NEFilterSourceSPI.h:26
> +#define HAVE_MODERN_NE_FILTER_SOURCE (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000)

Hopefully we can retire this macro before modern becomes old.

> Source/WebCore/platform/spi/cocoa/NEFilterSourceSPI.h:49
> +@interface NEFilterSource (LegacyDetails)

Even though this class is SPI, best practice is for categories added by WebKit to be prefixed with Web (or WK).

> Source/WebCore/platform/spi/cocoa/NEFilterSourceSPI.h:63
> +@interface NEFilterSource (ModernDetails)

Ditto.
Comment 5 Andy Estes 2015-03-15 21:59:26 PDT
Comment on attachment 248676 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=248676&action=review

>> Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h:30
>> +#include <objc/NSObjCRuntime.h>
> 
> What is this used for here?

For NSInteger.

>> Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:85
>> +    [m_neFilterSource receivedResponse:response.nsURLResponse() decisionHandler:^(NEFilterSourceStatus status, NSDictionary *decisionInfo) {
> 
> I think we prefer to use lambdas in C++ code, because it makes captures explicit.

Ok, I'll do that.

>> Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm:99
>> +    dispatch_release(m_semaphore);
> 
> Can we use OSObjectPtr for these things so that we don’t have to manage them manually?

I had no idea this class existed! I can and will use it.

>> Source/WebCore/platform/spi/cocoa/NEFilterSourceSPI.h:49
>> +@interface NEFilterSource (LegacyDetails)
> 
> Even though this class is SPI, best practice is for categories added by WebKit to be prefixed with Web (or WK).

You're right. I'll change this. I've also updated our document on using SPI in WebKit to reflect this.
Comment 6 Andy Estes 2015-03-15 22:44:36 PDT
Committed r181523: <http://trac.webkit.org/changeset/181523>