Teach MiniBrowser how to enable the mock content filter
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 22 Nov 2015 17:45:50 +0000 (17:45 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 22 Nov 2015 17:45:50 +0000 (17:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151540

Reviewed by Andreas Kling.

Source/WebCore:

Moved the implementation of MockContentFilterEnabler from TestWebKitAPI to here, renamed it to
WebMockContentFilterEnabler, and made it compatible with the legacy Objective-C runtime. Renamed Decision and
DecisionPoint to WebMockContentFilterDecision and WebMockContentFilterDecisionPoint, and changed them from enum
classes to CF_ENUMs so that they can be used by both C++ and Objective-C source files.

* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSMockContentFilterSettingsCustom.cpp:
(WebCore::JSMockContentFilterSettings::decisionPoint):
(WebCore::JSMockContentFilterSettings::setDecisionPoint):
(WebCore::toDecision):
(WebCore::JSMockContentFilterSettings::decision):
(WebCore::JSMockContentFilterSettings::setDecision):
(WebCore::JSMockContentFilterSettings::unblockRequestDecision):
(WebCore::JSMockContentFilterSettings::setUnblockRequestDecision):
(WebCore::toJSValue): Deleted.
* testing/MockContentFilter.cpp:
(WebCore::MockContentFilter::willSendRequest):
(WebCore::MockContentFilter::responseReceived):
(WebCore::MockContentFilter::addData):
(WebCore::MockContentFilter::finishedAddingData):
(WebCore::MockContentFilter::unblockHandler):
(WebCore::MockContentFilter::maybeDetermineStatus):
* testing/MockContentFilter.h:
* testing/MockContentFilterEnabler.h: Added.
* testing/MockContentFilterEnabler.mm: Added.
(-[WebMockContentFilterEnabler initWithDecision:decisionPoint:blockedString:]):
(-[WebMockContentFilterEnabler initWithCoder:]):
(-[WebMockContentFilterEnabler encodeWithCoder:]):
(-[WebMockContentFilterEnabler enable]):
(-[WebMockContentFilterEnabler dealloc]):
(+[WebMockContentFilterEnabler supportsSecureCoding]):
(-[WebMockContentFilterEnabler copyWithZone:]):
* testing/MockContentFilterSettings.h:
(WebCore::MockContentFilterSettings::decisionPoint):
(WebCore::MockContentFilterSettings::setDecisionPoint):
(WebCore::MockContentFilterSettings::decision):
(WebCore::MockContentFilterSettings::setDecision):
(WebCore::MockContentFilterSettings::unblockRequestDecision):
(WebCore::MockContentFilterSettings::setUnblockRequestDecision):

Tools:

* MiniBrowser/Configurations/Base.xcconfig: Added WebCoreTestSupport and WTF to HEADER_SEARCH_PATHS.
* MiniBrowser/Configurations/MiniBrowser.xcconfig: Linked against libWebCoreTestSupport.
* MiniBrowser/Configurations/MiniBrowserBundle.xcconfig: Ditto.
* MiniBrowser/MiniBrowser.xcodeproj/project.pbxproj: Added blocked-page.html.
* MiniBrowser/MiniBrowserWebProcessPlugIn.m:
(-[MiniBrowserWebProcessPlugIn webProcessPlugIn:initializeWithObject:]): Observed the WebMockContentFilterEnabler key path.
(-[MiniBrowserWebProcessPlugIn dealloc]):
(-[MiniBrowserWebProcessPlugIn observeValueForKeyPath:ofObject:change:context:]): Stored the value in _contentFilterEnabler.
* MiniBrowser/blocked-page.html: Added.
* MiniBrowser/mac/AppDelegate.m:
(defaultConfiguration): Created a _WKProcessPoolConfiguration with MiniBrowser.wkbundle as the injected bundle.
* MiniBrowser/mac/BrowserWindowController.h:
* MiniBrowser/mac/BrowserWindowController.m:
(+[BrowserWindowController contentFilteringBlockedString]): Returned an NSString containing blocked-page.html.
* MiniBrowser/mac/SettingsController.h:
* MiniBrowser/mac/SettingsController.m:
(-[SettingsController _populateMenu]): Added [self _contentFilteringMenuItem] to the Settings menu.
(-[SettingsController validateMenuItem:]): Validated the new menu items. Disabled Decision and Decision Point items if filtering is disabled.
(-[SettingsController _contentFilteringMenuItem]): Returned a new Content Filtering menu item with a submenu.
(-[SettingsController toggleContentFilteringEnabled:]): Toggled ContentFilteringEnabledKey.
(-[SettingsController contentFilteringEnabled]): Returned value of ContentFilteringEnabledKey.
(-[SettingsController setContentFilteringDecision:]): Set ContentFilterDecisionKey and called -[BrowserAppDelegate didChangeSettings].
(-[SettingsController contentFilteringDecision]): Returned the value of ContentFilterDecisionKey as a WebMockContentFilterDecision.
Defaulted to WebMockContentFilterDecisionAllow if the value is invalid.
(-[SettingsController setContentFilteringDecisionPoint:]): Set ContentFilterDecisionPointKey and called -[BrowserAppDelegate didChangeSettings].
(-[SettingsController contentFilteringDecisionPoint]): Returned the value of ContentFilterDecisionPointKey as a WebMockContentFilterDecisionPoint.
Defaulted to WebMockContentFilterDecisionPointAfterWillSendRequest if the value is invalid.
* MiniBrowser/mac/WK1BrowserWindowController.h:
* MiniBrowser/mac/WK1BrowserWindowController.m:
(-[WK1BrowserWindowController dealloc]):
(-[WK1BrowserWindowController didChangeSettings]): Created a WebMockContentFilterEnabler with the current settings and stored it in _contentFilterEnabler.
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController didChangeSettings]): Created a WebMockContentFilterEnabler and set it as the object for the eponymous bundle parameter.
* TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig: Linked against libWebCoreTestSupport.
* TestWebKitAPI/Tests/WebKit2Cocoa/ContentFiltering.mm:
(configurationWithContentFilterSettings): Converted to use WebMockContentFilterEnabler, WebMockContentFilterDecision, and WebMockContentFilterDecisionPoint.
(TEST): Ditto.
(downloadTest): Ditto.
(+[MockContentFilterEnabler supportsSecureCoding]): Deleted.
(-[MockContentFilterEnabler copyWithZone:]): Deleted.
(-[MockContentFilterEnabler initWithCoder:]): Deleted.
(-[MockContentFilterEnabler initWithDecision:decisionPoint:]): Deleted.
(-[MockContentFilterEnabler encodeWithCoder:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/ContentFilteringPlugIn.mm:
(-[ContentFilteringPlugIn webProcessPlugIn:initializeWithObject:]): Converted to use WebMockContentFilterEnabler.
(-[ContentFilteringPlugIn dealloc]): Ditto.
(-[ContentFilteringPlugIn observeValueForKeyPath:ofObject:change:context:]): Ditto.
(+[MockContentFilterEnabler supportsSecureCoding]): Deleted.
(-[MockContentFilterEnabler copyWithZone:]): Deleted.
(-[MockContentFilterEnabler initWithCoder:]): Deleted.
(-[MockContentFilterEnabler dealloc]): Deleted.
(-[MockContentFilterEnabler encodeWithCoder:]): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192734 268f45cc-cd09-0410-ab3c-d52691b4dbfc

26 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSMockContentFilterSettingsCustom.cpp
Source/WebCore/testing/MockContentFilter.cpp
Source/WebCore/testing/MockContentFilter.h
Source/WebCore/testing/MockContentFilterEnabler.h [new file with mode: 0644]
Source/WebCore/testing/MockContentFilterEnabler.mm [new file with mode: 0644]
Source/WebCore/testing/MockContentFilterSettings.h
Tools/ChangeLog
Tools/MiniBrowser/Configurations/Base.xcconfig
Tools/MiniBrowser/Configurations/MiniBrowser.xcconfig
Tools/MiniBrowser/Configurations/MiniBrowserBundle.xcconfig
Tools/MiniBrowser/MiniBrowser.xcodeproj/project.pbxproj
Tools/MiniBrowser/MiniBrowserWebProcessPlugIn.m
Tools/MiniBrowser/blocked-page.html [new file with mode: 0644]
Tools/MiniBrowser/mac/AppDelegate.m
Tools/MiniBrowser/mac/BrowserWindowController.h
Tools/MiniBrowser/mac/BrowserWindowController.m
Tools/MiniBrowser/mac/SettingsController.h
Tools/MiniBrowser/mac/SettingsController.m
Tools/MiniBrowser/mac/WK1BrowserWindowController.h
Tools/MiniBrowser/mac/WK1BrowserWindowController.m
Tools/MiniBrowser/mac/WK2BrowserWindowController.m
Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ContentFiltering.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ContentFilteringPlugIn.mm

index 65f1a23..5474698 100644 (file)
@@ -1,3 +1,50 @@
+2015-11-22  Andy Estes  <aestes@apple.com>
+
+        Teach MiniBrowser how to enable the mock content filter
+        https://bugs.webkit.org/show_bug.cgi?id=151540
+
+        Reviewed by Andreas Kling.
+
+        Moved the implementation of MockContentFilterEnabler from TestWebKitAPI to here, renamed it to
+        WebMockContentFilterEnabler, and made it compatible with the legacy Objective-C runtime. Renamed Decision and
+        DecisionPoint to WebMockContentFilterDecision and WebMockContentFilterDecisionPoint, and changed them from enum
+        classes to CF_ENUMs so that they can be used by both C++ and Objective-C source files.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSMockContentFilterSettingsCustom.cpp:
+        (WebCore::JSMockContentFilterSettings::decisionPoint):
+        (WebCore::JSMockContentFilterSettings::setDecisionPoint):
+        (WebCore::toDecision):
+        (WebCore::JSMockContentFilterSettings::decision):
+        (WebCore::JSMockContentFilterSettings::setDecision):
+        (WebCore::JSMockContentFilterSettings::unblockRequestDecision):
+        (WebCore::JSMockContentFilterSettings::setUnblockRequestDecision):
+        (WebCore::toJSValue): Deleted.
+        * testing/MockContentFilter.cpp:
+        (WebCore::MockContentFilter::willSendRequest):
+        (WebCore::MockContentFilter::responseReceived):
+        (WebCore::MockContentFilter::addData):
+        (WebCore::MockContentFilter::finishedAddingData):
+        (WebCore::MockContentFilter::unblockHandler):
+        (WebCore::MockContentFilter::maybeDetermineStatus):
+        * testing/MockContentFilter.h:
+        * testing/MockContentFilterEnabler.h: Added.
+        * testing/MockContentFilterEnabler.mm: Added.
+        (-[WebMockContentFilterEnabler initWithDecision:decisionPoint:blockedString:]):
+        (-[WebMockContentFilterEnabler initWithCoder:]):
+        (-[WebMockContentFilterEnabler encodeWithCoder:]):
+        (-[WebMockContentFilterEnabler enable]):
+        (-[WebMockContentFilterEnabler dealloc]):
+        (+[WebMockContentFilterEnabler supportsSecureCoding]):
+        (-[WebMockContentFilterEnabler copyWithZone:]):
+        * testing/MockContentFilterSettings.h:
+        (WebCore::MockContentFilterSettings::decisionPoint):
+        (WebCore::MockContentFilterSettings::setDecisionPoint):
+        (WebCore::MockContentFilterSettings::decision):
+        (WebCore::MockContentFilterSettings::setDecision):
+        (WebCore::MockContentFilterSettings::unblockRequestDecision):
+        (WebCore::MockContentFilterSettings::setUnblockRequestDecision):
+
 2015-11-22  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Font selection should not consult font-variant property
index 09dd304..ab3d1f9 100644 (file)
                A182D5B71BE722670087A7CC /* SettingsCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A182D5B61BE722620087A7CC /* SettingsCocoa.mm */; };
                A18890AE1AA13F250026C301 /* ParentalControlsContentFilter.mm in Sources */ = {isa = PBXBuildFile; fileRef = A18890AC1AA13F250026C301 /* ParentalControlsContentFilter.mm */; };
                A18890AF1AA13F250026C301 /* ParentalControlsContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A18890AD1AA13F250026C301 /* ParentalControlsContentFilter.h */; };
+               A190AD1B1C002EE500DD8741 /* MockContentFilterEnabler.mm in Sources */ = {isa = PBXBuildFile; fileRef = A190AD191C002EE500DD8741 /* MockContentFilterEnabler.mm */; };
+               A190AD1C1C002EE500DD8741 /* MockContentFilterEnabler.h in Headers */ = {isa = PBXBuildFile; fileRef = A190AD1A1C002EE500DD8741 /* MockContentFilterEnabler.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A19AEA211AAA808600B52B25 /* JSMockContentFilterSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = A19AEA1E1AAA806E00B52B25 /* JSMockContentFilterSettings.h */; };
                A19AEA221AAA808A00B52B25 /* JSMockContentFilterSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A19AEA1D1AAA806E00B52B25 /* JSMockContentFilterSettings.cpp */; };
                A19D93461A9FEC7200B46C24 /* NEFilterSourceSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = A19D93441A9FEC7200B46C24 /* NEFilterSourceSPI.h */; };
                A182D5B61BE722620087A7CC /* SettingsCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SettingsCocoa.mm; sourceTree = "<group>"; };
                A18890AC1AA13F250026C301 /* ParentalControlsContentFilter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ParentalControlsContentFilter.mm; sourceTree = "<group>"; };
                A18890AD1AA13F250026C301 /* ParentalControlsContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParentalControlsContentFilter.h; sourceTree = "<group>"; };
+               A190AD191C002EE500DD8741 /* MockContentFilterEnabler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MockContentFilterEnabler.mm; sourceTree = "<group>"; };
+               A190AD1A1C002EE500DD8741 /* MockContentFilterEnabler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockContentFilterEnabler.h; sourceTree = "<group>"; };
                A19AEA1C1AAA7C4900B52B25 /* MockContentFilterSettings.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = MockContentFilterSettings.idl; sourceTree = "<group>"; };
                A19AEA1D1AAA806E00B52B25 /* JSMockContentFilterSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMockContentFilterSettings.cpp; sourceTree = "<group>"; };
                A19AEA1E1AAA806E00B52B25 /* JSMockContentFilterSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMockContentFilterSettings.h; sourceTree = "<group>"; };
                                CDC26B3D160A62B00026757B /* MockCDM.h */,
                                A1BF6B801AA96C7D00AF4A8A /* MockContentFilter.cpp */,
                                A1BF6B811AA96C7D00AF4A8A /* MockContentFilter.h */,
+                               A190AD1A1C002EE500DD8741 /* MockContentFilterEnabler.h */,
+                               A190AD191C002EE500DD8741 /* MockContentFilterEnabler.mm */,
                                A1B5B29C1AAA846E008B6042 /* MockContentFilterSettings.cpp */,
                                A1B5B29D1AAA846E008B6042 /* MockContentFilterSettings.h */,
                                A19AEA1C1AAA7C4900B52B25 /* MockContentFilterSettings.idl */,
                                CD5393D4175E018600C07123 /* JSMemoryInfo.h in Headers */,
                                A19AEA211AAA808600B52B25 /* JSMockContentFilterSettings.h in Headers */,
                                EBF5121D1696496C0056BD25 /* JSTypeConversions.h in Headers */,
+                               A190AD1C1C002EE500DD8741 /* MockContentFilterEnabler.h in Headers */,
                                CB8CF01D1A95DE42000D510B /* MicroTaskTest.h in Headers */,
                                CDC26B41160A8CCE0026757B /* MockCDM.h in Headers */,
                                A1BF6B831AA96C7D00AF4A8A /* MockContentFilter.h in Headers */,
                                CD5393D3175E018600C07123 /* JSMemoryInfo.cpp in Sources */,
                                A19AEA221AAA808A00B52B25 /* JSMockContentFilterSettings.cpp in Sources */,
                                A1E5B31F1AAD1DA4006EBEFB /* JSMockContentFilterSettingsCustom.cpp in Sources */,
+                               A190AD1B1C002EE500DD8741 /* MockContentFilterEnabler.mm in Sources */,
                                EBF5121C1696496C0056BD25 /* JSTypeConversions.cpp in Sources */,
                                CB8CF01F1A95DE59000D510B /* MicroTaskTest.cpp in Sources */,
                                CDC26B40160A8CC60026757B /* MockCDM.cpp in Sources */,
index deabc54..762c730 100644 (file)
@@ -35,84 +35,55 @@ using namespace JSC;
 
 namespace WebCore {
 
-using Decision = MockContentFilterSettings::Decision;
-using DecisionPoint = MockContentFilterSettings::DecisionPoint;
-
 JSValue JSMockContentFilterSettings::decisionPoint(ExecState&) const
 {
-    DecisionPoint decisionPoint = wrapped().decisionPoint();
-    switch (decisionPoint) {
-    case DecisionPoint::AfterWillSendRequest:
-    case DecisionPoint::AfterRedirect:
-    case DecisionPoint::AfterResponse:
-    case DecisionPoint::AfterAddData:
-    case DecisionPoint::AfterFinishedAddingData:
-    case DecisionPoint::Never:
-        return jsNumber(static_cast<uint8_t>(decisionPoint));
-    }
-
-    ASSERT_NOT_REACHED();
-    return jsUndefined();
+    return jsNumber(static_cast<uint8_t>(wrapped().decisionPoint()));
 }
 
 void JSMockContentFilterSettings::setDecisionPoint(ExecState& state, JSValue value)
 {
-    uint8_t nativeValue { toUInt8(&state, value, EnforceRange) };
+    uint8_t decisionPoint { toUInt8(&state, value, EnforceRange) };
     if (state.hadException())
         return;
-
-    DecisionPoint decisionPoint { static_cast<DecisionPoint>(nativeValue) };
+    
     switch (decisionPoint) {
-    case DecisionPoint::AfterWillSendRequest:
-    case DecisionPoint::AfterRedirect:
-    case DecisionPoint::AfterResponse:
-    case DecisionPoint::AfterAddData:
-    case DecisionPoint::AfterFinishedAddingData:
-    case DecisionPoint::Never:
-        wrapped().setDecisionPoint(decisionPoint);
+    case static_cast<uint8_t>(WebMockContentFilterDecisionPointAfterWillSendRequest):
+    case static_cast<uint8_t>(WebMockContentFilterDecisionPointAfterRedirect):
+    case static_cast<uint8_t>(WebMockContentFilterDecisionPointAfterResponse):
+    case static_cast<uint8_t>(WebMockContentFilterDecisionPointAfterAddData):
+    case static_cast<uint8_t>(WebMockContentFilterDecisionPointAfterFinishedAddingData):
+    case static_cast<uint8_t>(WebMockContentFilterDecisionPointNever):
+        wrapped().setDecisionPoint(static_cast<WebMockContentFilterDecisionPoint>(decisionPoint));
         return;
+    default:
+        throwTypeError(&state, String::format("%u is not a valid decisionPoint value.", decisionPoint));
     }
-
-    throwTypeError(&state, String::format("%u is not a valid decisionPoint value.", nativeValue));
 }
 
-static inline JSValue toJSValue(Decision decision)
+static inline WebMockContentFilterDecision toDecision(ExecState& state, JSValue value)
 {
-    switch (decision) {
-    case Decision::Allow:
-    case Decision::Block:
-        return jsNumber(static_cast<uint8_t>(decision));
-    }
-
-    ASSERT_NOT_REACHED();
-    return jsUndefined();
-}
-
-static inline Decision toDecision(ExecState& state, JSValue value)
-{
-    uint8_t nativeValue { toUInt8(&state, value, EnforceRange) };
+    uint8_t decision { toUInt8(&state, value, EnforceRange) };
     if (state.hadException())
-        return Decision::Allow;
+        return WebMockContentFilterDecisionAllow;
 
-    Decision decision { static_cast<Decision>(nativeValue) };
     switch (decision) {
-    case Decision::Allow:
-    case Decision::Block:
-        return decision;
+    case static_cast<uint8_t>(WebMockContentFilterDecisionAllow):
+    case static_cast<uint8_t>(WebMockContentFilterDecisionBlock):
+        return static_cast<WebMockContentFilterDecision>(decision);
+    default:
+        throwTypeError(&state, String::format("%u is not a valid decision value.", decision));
+        return WebMockContentFilterDecisionAllow;
     }
-
-    throwTypeError(&state, String::format("%u is not a valid decision value.", nativeValue));
-    return Decision::Allow;
 }
 
 JSValue JSMockContentFilterSettings::decision(ExecState&) const
 {
-    return toJSValue(wrapped().decision());
+    return jsNumber(static_cast<uint8_t>(wrapped().decision()));
 }
 
 void JSMockContentFilterSettings::setDecision(ExecState& state, JSValue value)
 {
-    Decision decision { toDecision(state, value) };
+    WebMockContentFilterDecision decision { toDecision(state, value) };
     if (state.hadException())
         return;
 
@@ -121,12 +92,12 @@ void JSMockContentFilterSettings::setDecision(ExecState& state, JSValue value)
 
 JSValue JSMockContentFilterSettings::unblockRequestDecision(ExecState&) const
 {
-    return toJSValue(wrapped().unblockRequestDecision());
+    return jsNumber(static_cast<uint8_t>(wrapped().unblockRequestDecision()));
 }
 
 void JSMockContentFilterSettings::setUnblockRequestDecision(ExecState& state, JSValue value)
 {
-    Decision unblockRequestDecision { toDecision(state, value) };
+    WebMockContentFilterDecision unblockRequestDecision { toDecision(state, value) };
     if (state.hadException())
         return;
 
index 11f9317..76c0a7b 100644 (file)
@@ -40,9 +40,6 @@
 
 namespace WebCore {
 
-using Decision = MockContentFilterSettings::Decision;
-using DecisionPoint = MockContentFilterSettings::DecisionPoint;
-
 void MockContentFilter::ensureInstalled()
 {
     static std::once_flag onceFlag;
@@ -71,9 +68,9 @@ std::unique_ptr<MockContentFilter> MockContentFilter::create()
 void MockContentFilter::willSendRequest(ResourceRequest& request, const ResourceResponse& redirectResponse)
 {
     if (redirectResponse.isNull())
-        maybeDetermineStatus(DecisionPoint::AfterWillSendRequest);
+        maybeDetermineStatus(WebMockContentFilterDecisionPointAfterWillSendRequest);
     else
-        maybeDetermineStatus(DecisionPoint::AfterRedirect);
+        maybeDetermineStatus(WebMockContentFilterDecisionPointAfterRedirect);
 
     if (m_status == Status::NeedsMoreData)
         return;
@@ -93,17 +90,17 @@ void MockContentFilter::willSendRequest(ResourceRequest& request, const Resource
 
 void MockContentFilter::responseReceived(const ResourceResponse&)
 {
-    maybeDetermineStatus(DecisionPoint::AfterResponse);
+    maybeDetermineStatus(WebMockContentFilterDecisionPointAfterResponse);
 }
 
 void MockContentFilter::addData(const char*, int)
 {
-    maybeDetermineStatus(DecisionPoint::AfterAddData);
+    maybeDetermineStatus(WebMockContentFilterDecisionPointAfterAddData);
 }
 
 void MockContentFilter::finishedAddingData()
 {
-    maybeDetermineStatus(DecisionPoint::AfterFinishedAddingData);
+    maybeDetermineStatus(WebMockContentFilterDecisionPointAfterFinishedAddingData);
 }
 
 bool MockContentFilter::needsMoreData() const
@@ -129,9 +126,9 @@ ContentFilterUnblockHandler MockContentFilter::unblockHandler() const
 
     return ContentFilterUnblockHandler {
         MockContentFilterSettings::unblockURLHost(), [](DecisionHandlerFunction decisionHandler) {
-            bool shouldAllow { settings().unblockRequestDecision() == Decision::Allow };
+            bool shouldAllow { settings().unblockRequestDecision() == WebMockContentFilterDecisionAllow };
             if (shouldAllow)
-                settings().setDecision(Decision::Allow);
+                settings().setDecision(WebMockContentFilterDecisionAllow);
             LOG(ContentFiltering, "MockContentFilter %s the unblock request.\n", shouldAllow ? "allowed" : "did not allow");
             decisionHandler(shouldAllow);
         }
@@ -143,14 +140,14 @@ String MockContentFilter::unblockRequestDeniedScript() const
     return ASCIILiteral("unblockRequestDenied()");
 }
 
-void MockContentFilter::maybeDetermineStatus(DecisionPoint decisionPoint)
+void MockContentFilter::maybeDetermineStatus(WebMockContentFilterDecisionPoint decisionPoint)
 {
     if (m_status != Status::NeedsMoreData || decisionPoint != settings().decisionPoint())
         return;
 
     LOG(ContentFiltering, "MockContentFilter stopped buffering with status %u at decision point %u.\n", m_status, decisionPoint);
 
-    m_status = settings().decision() == Decision::Allow ? Status::Allowed : Status::Blocked;
+    m_status = settings().decision() == WebMockContentFilterDecisionAllow ? Status::Allowed : Status::Blocked;
     if (m_status != Status::Blocked)
         return;
 
index 4acbe49..ab07fc6 100644 (file)
@@ -57,7 +57,7 @@ private:
     };
 
     MockContentFilter() = default;
-    void maybeDetermineStatus(MockContentFilterSettings::DecisionPoint);
+    void maybeDetermineStatus(WebMockContentFilterDecisionPoint);
 
     Vector<char> m_replacementData;
     Status m_status { Status::NeedsMoreData };
diff --git a/Source/WebCore/testing/MockContentFilterEnabler.h b/Source/WebCore/testing/MockContentFilterEnabler.h
new file mode 100644 (file)
index 0000000..7147dd6
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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 "MockContentFilterSettings.h"
+#import <WebCore/PlatformExportMacros.h>
+
+WEBCORE_EXPORT @interface WebMockContentFilterEnabler : NSObject <NSCopying, NSSecureCoding> {
+    BOOL _enabled;
+    WebMockContentFilterDecision _decision;
+    WebMockContentFilterDecisionPoint _decisionPoint;
+    NSString *_blockedString;
+}
+
+- (instancetype)initWithDecision:(WebMockContentFilterDecision)decision decisionPoint:(WebMockContentFilterDecisionPoint)decisionPoint blockedString:(NSString *)blockedString;
+- (void)enable;
+@end
diff --git a/Source/WebCore/testing/MockContentFilterEnabler.mm b/Source/WebCore/testing/MockContentFilterEnabler.mm
new file mode 100644 (file)
index 0000000..08947b5
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * 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 "MockContentFilterEnabler.h"
+
+static NSString * const DecisionKey = @"Decision";
+static NSString * const DecisionPointKey = @"DecisionPoint";
+static NSString * const BlockedStringKey = @"BlockedString";
+
+@implementation WebMockContentFilterEnabler
+
+- (instancetype)initWithDecision:(WebMockContentFilterDecision)decision decisionPoint:(WebMockContentFilterDecisionPoint)decisionPoint blockedString:(NSString *)blockedString
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _decision = decision;
+    _decisionPoint = decisionPoint;
+    _blockedString = [blockedString copy];
+    return self;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)decoder
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _decision = static_cast<WebMockContentFilterDecision>([decoder decodeIntForKey:DecisionKey]);
+    _decisionPoint = static_cast<WebMockContentFilterDecisionPoint>([decoder decodeIntForKey:DecisionPointKey]);
+    _blockedString = [[decoder decodeObjectOfClass:[NSString class] forKey:BlockedStringKey] retain];
+    return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder
+{
+    [coder encodeInt:static_cast<int>(_decision) forKey:DecisionKey];
+    [coder encodeInt:static_cast<int>(_decisionPoint) forKey:DecisionPointKey];
+    [coder encodeObject:_blockedString forKey:BlockedStringKey];
+}
+
+- (void)enable
+{
+    if (_enabled)
+        return;
+
+    auto& settings = WebCore::MockContentFilterSettings::singleton();
+    if (settings.enabled())
+        return;
+
+    settings.setEnabled(true);
+    settings.setDecision(_decision);
+    settings.setDecisionPoint(_decisionPoint);
+    settings.setBlockedString(_blockedString);
+    _enabled = YES;
+}
+
+- (void)dealloc
+{
+    [_blockedString release];
+    if (_enabled)
+        WebCore::MockContentFilterSettings::singleton().setEnabled(false);
+    [super dealloc];
+}
+
++ (BOOL)supportsSecureCoding
+{
+    return YES;
+}
+
+- (id)copyWithZone:(NSZone *)zone
+{
+    UNUSED_PARAM(zone);
+    return [self retain];
+}
+
+@end
index 691fe2f..2fd7f56 100644 (file)
 #ifndef MockContentFilterSettings_h
 #define MockContentFilterSettings_h
 
+#include <CoreFoundation/CoreFoundation.h>
+
+typedef CF_ENUM(int, WebMockContentFilterDecision) {
+    WebMockContentFilterDecisionAllow,
+    WebMockContentFilterDecisionBlock
+};
+
+typedef CF_ENUM(int, WebMockContentFilterDecisionPoint) {
+    WebMockContentFilterDecisionPointAfterWillSendRequest,
+    WebMockContentFilterDecisionPointAfterRedirect,
+    WebMockContentFilterDecisionPointAfterResponse,
+    WebMockContentFilterDecisionPointAfterAddData,
+    WebMockContentFilterDecisionPointAfterFinishedAddingData,
+    WebMockContentFilterDecisionPointNever
+};
+
+#ifdef __cplusplus
+
 #include <wtf/NeverDestroyed.h>
 #include <wtf/text/WTFString.h>
 
@@ -35,20 +53,6 @@ class MockContentFilterSettings {
     friend class NeverDestroyed<MockContentFilterSettings>;
 
 public:
-    enum class DecisionPoint {
-        AfterWillSendRequest,
-        AfterRedirect,
-        AfterResponse,
-        AfterAddData,
-        AfterFinishedAddingData,
-        Never
-    };
-
-    enum class Decision {
-        Allow,
-        Block
-    };
-
     WTF_EXPORT_PRIVATE static MockContentFilterSettings& singleton();
     static void reset();
     static const char* unblockURLHost() { return "mock-unblock"; }
@@ -63,14 +67,14 @@ public:
     const String& blockedString() const { return m_blockedString; }
     void setBlockedString(const String& blockedString) { m_blockedString = blockedString; }
 
-    DecisionPoint decisionPoint() const { return m_decisionPoint; }
-    void setDecisionPoint(DecisionPoint decisionPoint) { m_decisionPoint = decisionPoint; }
+    WebMockContentFilterDecisionPoint decisionPoint() const { return m_decisionPoint; }
+    void setDecisionPoint(WebMockContentFilterDecisionPoint decisionPoint) { m_decisionPoint = decisionPoint; }
 
-    Decision decision() const { return m_decision; }
-    void setDecision(Decision decision) { m_decision = decision; }
+    WebMockContentFilterDecision decision() const { return m_decision; }
+    void setDecision(WebMockContentFilterDecision decision) { m_decision = decision; }
 
-    Decision unblockRequestDecision() const { return m_unblockRequestDecision; }
-    void setUnblockRequestDecision(Decision unblockRequestDecision) { m_unblockRequestDecision = unblockRequestDecision; }
+    WebMockContentFilterDecision unblockRequestDecision() const { return m_unblockRequestDecision; }
+    void setUnblockRequestDecision(WebMockContentFilterDecision unblockRequestDecision) { m_unblockRequestDecision = unblockRequestDecision; }
 
     const String& unblockRequestURL() const;
 
@@ -83,13 +87,15 @@ private:
     MockContentFilterSettings& operator=(const MockContentFilterSettings&) = default;
 
     bool m_enabled { false };
-    DecisionPoint m_decisionPoint { DecisionPoint::AfterResponse };
-    Decision m_decision { Decision::Allow };
-    Decision m_unblockRequestDecision { Decision::Block };
+    WebMockContentFilterDecisionPoint m_decisionPoint { WebMockContentFilterDecisionPointAfterResponse };
+    WebMockContentFilterDecision m_decision { WebMockContentFilterDecisionAllow };
+    WebMockContentFilterDecision m_unblockRequestDecision { WebMockContentFilterDecisionBlock };
     String m_blockedString;
     String m_modifiedRequestURL;
 };
 
 } // namespace WebCore
 
+#endif // __cplusplus
+
 #endif // MockContentFilterSettings_h
index 4188fbc..85fb41c 100644 (file)
@@ -1,3 +1,63 @@
+2015-11-22  Andy Estes  <aestes@apple.com>
+
+        Teach MiniBrowser how to enable the mock content filter
+        https://bugs.webkit.org/show_bug.cgi?id=151540
+
+        Reviewed by Andreas Kling.
+
+        * MiniBrowser/Configurations/Base.xcconfig: Added WebCoreTestSupport and WTF to HEADER_SEARCH_PATHS.
+        * MiniBrowser/Configurations/MiniBrowser.xcconfig: Linked against libWebCoreTestSupport.
+        * MiniBrowser/Configurations/MiniBrowserBundle.xcconfig: Ditto.
+        * MiniBrowser/MiniBrowser.xcodeproj/project.pbxproj: Added blocked-page.html.
+        * MiniBrowser/MiniBrowserWebProcessPlugIn.m:
+        (-[MiniBrowserWebProcessPlugIn webProcessPlugIn:initializeWithObject:]): Observed the WebMockContentFilterEnabler key path.
+        (-[MiniBrowserWebProcessPlugIn dealloc]):
+        (-[MiniBrowserWebProcessPlugIn observeValueForKeyPath:ofObject:change:context:]): Stored the value in _contentFilterEnabler.
+        * MiniBrowser/blocked-page.html: Added.
+        * MiniBrowser/mac/AppDelegate.m:
+        (defaultConfiguration): Created a _WKProcessPoolConfiguration with MiniBrowser.wkbundle as the injected bundle.
+        * MiniBrowser/mac/BrowserWindowController.h:
+        * MiniBrowser/mac/BrowserWindowController.m:
+        (+[BrowserWindowController contentFilteringBlockedString]): Returned an NSString containing blocked-page.html.
+        * MiniBrowser/mac/SettingsController.h:
+        * MiniBrowser/mac/SettingsController.m:
+        (-[SettingsController _populateMenu]): Added [self _contentFilteringMenuItem] to the Settings menu.
+        (-[SettingsController validateMenuItem:]): Validated the new menu items. Disabled Decision and Decision Point items if filtering is disabled.
+        (-[SettingsController _contentFilteringMenuItem]): Returned a new Content Filtering menu item with a submenu.
+        (-[SettingsController toggleContentFilteringEnabled:]): Toggled ContentFilteringEnabledKey.
+        (-[SettingsController contentFilteringEnabled]): Returned value of ContentFilteringEnabledKey.
+        (-[SettingsController setContentFilteringDecision:]): Set ContentFilterDecisionKey and called -[BrowserAppDelegate didChangeSettings].
+        (-[SettingsController contentFilteringDecision]): Returned the value of ContentFilterDecisionKey as a WebMockContentFilterDecision.
+        Defaulted to WebMockContentFilterDecisionAllow if the value is invalid.
+        (-[SettingsController setContentFilteringDecisionPoint:]): Set ContentFilterDecisionPointKey and called -[BrowserAppDelegate didChangeSettings].
+        (-[SettingsController contentFilteringDecisionPoint]): Returned the value of ContentFilterDecisionPointKey as a WebMockContentFilterDecisionPoint.
+        Defaulted to WebMockContentFilterDecisionPointAfterWillSendRequest if the value is invalid.
+        * MiniBrowser/mac/WK1BrowserWindowController.h:
+        * MiniBrowser/mac/WK1BrowserWindowController.m:
+        (-[WK1BrowserWindowController dealloc]):
+        (-[WK1BrowserWindowController didChangeSettings]): Created a WebMockContentFilterEnabler with the current settings and stored it in _contentFilterEnabler.
+        * MiniBrowser/mac/WK2BrowserWindowController.m:
+        (-[WK2BrowserWindowController didChangeSettings]): Created a WebMockContentFilterEnabler and set it as the object for the eponymous bundle parameter.
+        * TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig: Linked against libWebCoreTestSupport.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/ContentFiltering.mm:
+        (configurationWithContentFilterSettings): Converted to use WebMockContentFilterEnabler, WebMockContentFilterDecision, and WebMockContentFilterDecisionPoint.
+        (TEST): Ditto.
+        (downloadTest): Ditto.
+        (+[MockContentFilterEnabler supportsSecureCoding]): Deleted.
+        (-[MockContentFilterEnabler copyWithZone:]): Deleted.
+        (-[MockContentFilterEnabler initWithCoder:]): Deleted.
+        (-[MockContentFilterEnabler initWithDecision:decisionPoint:]): Deleted.
+        (-[MockContentFilterEnabler encodeWithCoder:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/ContentFilteringPlugIn.mm:
+        (-[ContentFilteringPlugIn webProcessPlugIn:initializeWithObject:]): Converted to use WebMockContentFilterEnabler.
+        (-[ContentFilteringPlugIn dealloc]): Ditto.
+        (-[ContentFilteringPlugIn observeValueForKeyPath:ofObject:change:context:]): Ditto.
+        (+[MockContentFilterEnabler supportsSecureCoding]): Deleted.
+        (-[MockContentFilterEnabler copyWithZone:]): Deleted.
+        (-[MockContentFilterEnabler initWithCoder:]): Deleted.
+        (-[MockContentFilterEnabler dealloc]): Deleted.
+        (-[MockContentFilterEnabler encodeWithCoder:]): Deleted.
+
 2015-11-22  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Some unit tests fail when using the network process
index c7c70e5..7eb1c7b 100644 (file)
@@ -65,3 +65,5 @@ SDKROOT = macosx.internal;
 OTHER_CFLAGS = $(ASAN_OTHER_CFLAGS);
 OTHER_CPLUSPLUSFLAGS = $(ASAN_OTHER_CPLUSPLUSFLAGS);
 OTHER_LDFLAGS = $(ASAN_OTHER_LDFLAGS);
+
+HEADER_SEARCH_PATHS = $(inherited) $(BUILT_PRODUCTS_DIR)/usr/local/include $(BUILT_PRODUCTS_DIR)/WebCoreTestSupport
index f5c9e17..35d4360 100644 (file)
@@ -25,4 +25,5 @@ PRODUCT_NAME = MiniBrowser
 GCC_PREFIX_HEADER = mac/MiniBrowser_Prefix.pch
 INFOPLIST_FILE = mac/Info.plist
 EXCLUDED_SOURCE_FILE_NAMES[sdk=iphone*] = *
-OTHER_LDFLAGS[sdk=macosx*] = $(inherited) -framework Cocoa -framework WebKit
+OTHER_LDFLAGS[sdk=macosx*] = $(inherited) -framework Cocoa -framework WebKit -lWebCoreTestSupport
+LD_RUNPATH_SEARCH_PATHS = "@loader_path/."
index 1ad40d4..d18d313 100644 (file)
@@ -25,4 +25,5 @@ PRODUCT_NAME = MiniBrowser
 GCC_PREFIX_HEADER = mac/Bundle/MiniBrowserBundle_Prefix.pch
 INFOPLIST_FILE = mac/Bundle/Info.plist
 EXCLUDED_SOURCE_FILE_NAMES[sdk=iphone*] = *
-OTHER_LDFLAGS[sdk=macosx*] = $(inherited) -framework Cocoa
+OTHER_LDFLAGS[sdk=macosx*] = $(inherited) -framework Cocoa -lWebCoreTestSupport
+LD_RUNPATH_SEARCH_PATHS = "@loader_path/../../.."
index 31964fa..88eb416 100644 (file)
@@ -16,6 +16,7 @@
                51E244FA11EFCE07008228D1 /* MBToolbarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 51E244F911EFCE07008228D1 /* MBToolbarItem.m */; };
                7CA379421AC381C10079DC37 /* ExtensionManagerWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7CA379401AC381C10079DC37 /* ExtensionManagerWindowController.m */; };
                7CA379431AC381C10079DC37 /* ExtensionManagerWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7CA379411AC381C10079DC37 /* ExtensionManagerWindowController.xib */; };
+               A138DE441C007D240029832B /* blocked-page.html in Resources */ = {isa = PBXBuildFile; fileRef = A138DE431C007D240029832B /* blocked-page.html */; };
                BC329487116A92E2008635D0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BC329486116A92E2008635D0 /* main.m */; };
                BC329498116A941B008635D0 /* WK2BrowserWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = BC329497116A941B008635D0 /* WK2BrowserWindowController.m */; };
                BC72B89511E57E07001EB4EA /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58150DA1D0A300B32029 /* MainMenu.xib */; };
@@ -73,6 +74,7 @@
                7CA379401AC381C10079DC37 /* ExtensionManagerWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ExtensionManagerWindowController.m; path = mac/ExtensionManagerWindowController.m; sourceTree = "<group>"; };
                7CA379411AC381C10079DC37 /* ExtensionManagerWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ExtensionManagerWindowController.xib; path = mac/ExtensionManagerWindowController.xib; sourceTree = "<group>"; };
                8D1107320486CEB800E47090 /* MiniBrowser.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MiniBrowser.app; sourceTree = BUILT_PRODUCTS_DIR; };
+               A138DE431C007D240029832B /* blocked-page.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "blocked-page.html"; sourceTree = "<group>"; };
                BC329486116A92E2008635D0 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = mac/main.m; sourceTree = "<group>"; };
                BC329496116A941B008635D0 /* WK2BrowserWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WK2BrowserWindowController.h; path = mac/WK2BrowserWindowController.h; sourceTree = "<group>"; };
                BC329497116A941B008635D0 /* WK2BrowserWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WK2BrowserWindowController.m; path = mac/WK2BrowserWindowController.m; sourceTree = "<group>"; };
                                BC3294A2116A9852008635D0 /* BrowserWindow.xib */,
                                1DDD58150DA1D0A300B32029 /* MainMenu.xib */,
                                7CA379411AC381C10079DC37 /* ExtensionManagerWindowController.xib */,
+                               A138DE431C007D240029832B /* blocked-page.html */,
                        );
                        name = Resources;
                        sourceTree = "<group>";
                        files = (
                                BC72B89611E57E0F001EB4EA /* BrowserWindow.xib in Resources */,
                                7CA379431AC381C10079DC37 /* ExtensionManagerWindowController.xib in Resources */,
+                               A138DE441C007D240029832B /* blocked-page.html in Resources */,
                                BC72B89511E57E07001EB4EA /* MainMenu.xib in Resources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
index 12ec351..0bd4e34 100644 (file)
 
 #if WK_API_ENABLED
 
-@implementation MiniBrowserWebProcessPlugIn
+#import "MockContentFilterEnabler.h"
+
+@implementation MiniBrowserWebProcessPlugIn {
+    WebMockContentFilterEnabler *_contentFilterEnabler;
+    WKWebProcessPlugInController *_plugInController;
+}
 
 - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController initializeWithObject:(id)initializationObject
 {
-}   
+    _plugInController = [plugInController retain];
+    [_plugInController.parameters addObserver:self forKeyPath:NSStringFromClass([WebMockContentFilterEnabler class]) options:NSKeyValueObservingOptionInitial context:NULL];
+}
+
+- (void)dealloc
+{
+    [_plugInController.parameters removeObserver:self forKeyPath:NSStringFromClass([WebMockContentFilterEnabler class])];
+    [_plugInController release];
+    [_contentFilterEnabler release];
+    [super dealloc];
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+    WebMockContentFilterEnabler *enabler = [[object valueForKeyPath:keyPath] retain];
+    [_contentFilterEnabler release];
+    _contentFilterEnabler = enabler;
+    [_contentFilterEnabler enable];
+}
 
 @end
 
diff --git a/Tools/MiniBrowser/blocked-page.html b/Tools/MiniBrowser/blocked-page.html
new file mode 100644 (file)
index 0000000..2ca572e
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<style>
+span {
+    font-family: -apple-system-font;
+}
+
+.container {
+    position: absolute;
+    top: 50%;
+    left: 50%;
+    transform: translateX(-50%) translateY(-50%);
+}
+</style>
+<div class="container">
+    <span>Blocked by Content Filter</span>
+</div>
index 451b9b8..3dfff18 100644 (file)
@@ -74,12 +74,11 @@ static WKWebViewConfiguration *defaultConfiguration()
         configuration.preferences._fullScreenEnabled = YES;
         configuration.preferences._developerExtrasEnabled = YES;
 
-        if ([SettingsController shared].perWindowWebProcessesDisabled) {
-            _WKProcessPoolConfiguration *singleProcessConfiguration = [[_WKProcessPoolConfiguration alloc] init];
-            singleProcessConfiguration.maximumProcessCount = 1;
-            configuration.processPool = [[[WKProcessPool alloc] _initWithConfiguration:singleProcessConfiguration] autorelease];
-            [singleProcessConfiguration release];
-        }
+        _WKProcessPoolConfiguration *processPoolConfiguration = [[[_WKProcessPoolConfiguration alloc] init] autorelease];
+        processPoolConfiguration.injectedBundleURL = [[NSBundle mainBundle] URLForAuxiliaryExecutable:@"MiniBrowser.wkbundle"];
+        if ([SettingsController shared].perWindowWebProcessesDisabled)
+            processPoolConfiguration.maximumProcessCount = 1;
+        configuration.processPool = [[[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration] autorelease];
     }
 
     configuration.suppressesIncrementalRendering = [SettingsController shared].incrementalRenderingSuppressed;
index b4a4141..9b4fdf3 100644 (file)
@@ -76,5 +76,7 @@
 
 - (NSURL *)currentURL;
 
++ (NSString *)contentFilteringBlockedString;
+
 @end
 
index a069cd9..efe8418 100644 (file)
     return nil;
 }
 
++ (NSString *)contentFilteringBlockedString
+{
+    static NSString *blockedString;
+    if (!blockedString)
+        blockedString = [[NSString alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"blocked-page" withExtension:@"html"] encoding:NSUTF8StringEncoding error:NULL];
+    return blockedString;
+}
+
 @end
index 59b0e54..ed3882d 100644 (file)
@@ -23,6 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#import "MockContentFilterSettings.h"
 #import <Cocoa/Cocoa.h>
 
 @interface SettingsController : NSObject {
@@ -48,5 +49,8 @@
 @property (nonatomic, readonly) BOOL subPixelCSSOMMetricsEnabled;
 @property (nonatomic, readonly) BOOL acceleratedDrawingEnabled;
 @property (nonatomic, readonly) NSString *defaultURL;
+@property (nonatomic, readonly) BOOL contentFilteringEnabled;
+@property (nonatomic, readonly) WebMockContentFilterDecision contentFilteringDecision;
+@property (nonatomic, readonly) WebMockContentFilterDecisionPoint contentFilteringDecisionPoint;
 
 @end
index b078ffa..f83c7c0 100644 (file)
@@ -27,6 +27,7 @@
 
 #import "AppDelegate.h"
 #import "BrowserWindowController.h"
+#import "MockContentFilterSettings.h"
 
 static NSString * const defaultURL = @"http://www.webkit.org/";
 static NSString * const DefaultURLPreferenceKey = @"DefaultURL";
@@ -39,6 +40,10 @@ static NSString * const ResourceUsageOverlayVisiblePreferenceKey = @"ResourceUsa
 static NSString * const IncrementalRenderingSuppressedPreferenceKey = @"IncrementalRenderingSuppressed";
 static NSString * const AcceleratedDrawingEnabledPreferenceKey = @"AcceleratedDrawingEnabled";
 
+static NSString * const ContentFilteringEnabledKey = @"ContentFilteringEnabled";
+static NSString * const ContentFilterDecisionKey = @"ContentFilterDecision";
+static NSString * const ContentFilterDecisionPointKey = @"ContentFilterDecisionPoint";
+
 static NSString * const NonFastScrollableRegionOverlayVisiblePreferenceKey = @"NonFastScrollableRegionOverlayVisible";
 static NSString * const WheelEventHandlerRegionOverlayVisiblePreferenceKey = @"WheelEventHandlerRegionOverlayVisible";
 
@@ -110,6 +115,8 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
     [self _addItemWithTitle:@"Show Simple Line Layout Borders" action:@selector(toggleSimpleLineLayoutDebugBordersEnabled:) indented:NO];
     [self _addItemWithTitle:@"Suppress Incremental Rendering in New Windows" action:@selector(toggleIncrementalRenderingSuppressed:) indented:NO];
     [self _addItemWithTitle:@"Enable Accelerated Drawing" action:@selector(toggleAcceleratedDrawingEnabled:) indented:NO];
+    
+    [_menu addItem:[self _contentFilteringMenuItem]];
 
     [self _addHeaderWithTitle:@"WebKit2-only Settings"];
 
@@ -170,6 +177,17 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
         [menuItem setState:[self subPixelCSSOMMetricsEnabled] ? NSOnState : NSOffState];
     else if (action == @selector(toggleDebugOverlay:))
         [menuItem setState:[self debugOverlayVisible:menuItem] ? NSOnState : NSOffState];
+    else if (action == @selector(toggleContentFilteringEnabled:))
+        [menuItem setState:[self contentFilteringEnabled] ? NSOnState : NSOffState];
+    else if (action == @selector(setContentFilteringDecision:)) {
+        [menuItem setState:[self contentFilteringDecision] == menuItem.tag ? NSOnState : NSOffState];
+        if (![self contentFilteringEnabled])
+            return NO;
+    } else if (action == @selector(setContentFilteringDecisionPoint:)) {
+        [menuItem setState:[self contentFilteringDecisionPoint] == menuItem.tag ? NSOnState : NSOffState];
+        if (![self contentFilteringEnabled])
+            return NO;
+    }
 
     return YES;
 }
@@ -370,4 +388,123 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
         [[NSUserDefaults standardUserDefaults] setObject:customDefaultURL forKey:DefaultURLPreferenceKey];
 }
 
+#pragma mark Content Filtering
+
+- (NSMenuItem *)_contentFilteringMenuItem
+{
+    NSMenu *menu = [[[NSMenu alloc] initWithTitle:@"Content Filtering"] autorelease];
+
+    NSMenuItem *enabledItem = [[[NSMenuItem alloc] initWithTitle:@"Enabled" action:@selector(toggleContentFilteringEnabled:) keyEquivalent:@""] autorelease];
+    enabledItem.target = self;
+    [menu addItem:enabledItem];
+
+    [menu addItem:[NSMenuItem separatorItem]];
+    [menu addItem:[[[NSMenuItem alloc] initWithTitle:@"Decision" action:nil keyEquivalent:@""] autorelease]];
+
+    NSMenuItem *allowItem = [[[NSMenuItem alloc] initWithTitle:@"Allow" action:@selector(setContentFilteringDecision:) keyEquivalent:@""] autorelease];
+    allowItem.target = self;
+    allowItem.indentationLevel = 1;
+    allowItem.tag = WebMockContentFilterDecisionAllow;
+    [menu addItem:allowItem];
+
+    NSMenuItem *blockItem = [[[NSMenuItem alloc] initWithTitle:@"Block" action:@selector(setContentFilteringDecision:) keyEquivalent:@""] autorelease];
+    blockItem.target = self;
+    blockItem.indentationLevel = 1;
+    blockItem.tag = WebMockContentFilterDecisionBlock;
+    [menu addItem:blockItem];
+
+    [menu addItem:[NSMenuItem separatorItem]];
+    [menu addItem:[[[NSMenuItem alloc] initWithTitle:@"Decision Point" action:nil keyEquivalent:@""] autorelease]];
+
+    NSMenuItem *afterWillSendRequestItem = [[[NSMenuItem alloc] initWithTitle:@"After Will Send Request" action:@selector(setContentFilteringDecisionPoint:) keyEquivalent:@""] autorelease];
+    afterWillSendRequestItem.target = self;
+    afterWillSendRequestItem.indentationLevel = 1;
+    afterWillSendRequestItem.tag = WebMockContentFilterDecisionPointAfterWillSendRequest;
+    [menu addItem:afterWillSendRequestItem];
+    
+    NSMenuItem *afterRedirectItem = [[[NSMenuItem alloc] initWithTitle:@"After Redirect" action:@selector(setContentFilteringDecisionPoint:) keyEquivalent:@""] autorelease];
+    afterRedirectItem.target = self;
+    afterRedirectItem.indentationLevel = 1;
+    afterRedirectItem.tag = WebMockContentFilterDecisionPointAfterRedirect;
+    [menu addItem:afterRedirectItem];
+    
+    NSMenuItem *afterResponseItem = [[[NSMenuItem alloc] initWithTitle:@"After Response" action:@selector(setContentFilteringDecisionPoint:) keyEquivalent:@""] autorelease];
+    afterResponseItem.target = self;
+    afterResponseItem.indentationLevel = 1;
+    afterResponseItem.tag = WebMockContentFilterDecisionPointAfterResponse;
+    [menu addItem:afterResponseItem];
+    
+    NSMenuItem *afterAddDataItem = [[[NSMenuItem alloc] initWithTitle:@"After Add Data" action:@selector(setContentFilteringDecisionPoint:) keyEquivalent:@""] autorelease];
+    afterAddDataItem.target = self;
+    afterAddDataItem.indentationLevel = 1;
+    afterAddDataItem.tag = WebMockContentFilterDecisionPointAfterAddData;
+    [menu addItem:afterAddDataItem];
+    
+    NSMenuItem *afterFinishedAddingDataItem = [[[NSMenuItem alloc] initWithTitle:@"After Finished Adding Data" action:@selector(setContentFilteringDecisionPoint:) keyEquivalent:@""] autorelease];
+    afterFinishedAddingDataItem.target = self;
+    afterFinishedAddingDataItem.indentationLevel = 1;
+    afterFinishedAddingDataItem.tag = WebMockContentFilterDecisionPointAfterFinishedAddingData;
+    [menu addItem:afterFinishedAddingDataItem];
+    
+    NSMenuItem *neverMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Never" action:@selector(setContentFilteringDecisionPoint:) keyEquivalent:@""] autorelease];
+    neverMenuItem.target = self;
+    neverMenuItem.indentationLevel = 1;
+    neverMenuItem.tag = WebMockContentFilterDecisionPointNever;
+    [menu addItem:neverMenuItem];
+    
+    NSMenuItem *submenuItem = [[NSMenuItem alloc] initWithTitle:@"Content Filtering" action:nil keyEquivalent:@""];
+    [submenuItem setSubmenu:menu];
+    return [submenuItem autorelease];
+}
+
+- (void)toggleContentFilteringEnabled:(id)sender
+{
+    [self _toggleBooleanDefault:ContentFilteringEnabledKey];
+}
+
+- (BOOL)contentFilteringEnabled
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:ContentFilteringEnabledKey];
+}
+
+- (void)setContentFilteringDecision:(id)sender
+{
+    [[NSUserDefaults standardUserDefaults] setInteger:[sender tag] forKey:ContentFilterDecisionKey];
+    [(BrowserAppDelegate *)[[NSApplication sharedApplication] delegate] didChangeSettings];
+}
+
+- (WebMockContentFilterDecision)contentFilteringDecision
+{
+    NSInteger decision = [[NSUserDefaults standardUserDefaults] integerForKey:ContentFilterDecisionKey];
+    switch (decision) {
+    case (NSInteger)WebMockContentFilterDecisionAllow:
+    case (NSInteger)WebMockContentFilterDecisionBlock:
+        return (WebMockContentFilterDecision)decision;
+    default:
+        return WebMockContentFilterDecisionAllow;
+    }
+}
+
+- (void)setContentFilteringDecisionPoint:(id)sender
+{
+    [[NSUserDefaults standardUserDefaults] setInteger:[sender tag] forKey:ContentFilterDecisionPointKey];
+    [(BrowserAppDelegate *)[[NSApplication sharedApplication] delegate] didChangeSettings];
+}
+
+- (WebMockContentFilterDecisionPoint)contentFilteringDecisionPoint
+{
+    NSInteger decisionPoint = [[NSUserDefaults standardUserDefaults] integerForKey:ContentFilterDecisionPointKey];
+    switch (decisionPoint) {
+    case (NSInteger)WebMockContentFilterDecisionPointAfterWillSendRequest:
+    case (NSInteger)WebMockContentFilterDecisionPointAfterRedirect:
+    case (NSInteger)WebMockContentFilterDecisionPointAfterResponse:
+    case (NSInteger)WebMockContentFilterDecisionPointAfterAddData:
+    case (NSInteger)WebMockContentFilterDecisionPointAfterFinishedAddingData:
+    case (NSInteger)WebMockContentFilterDecisionPointNever:
+        return (WebMockContentFilterDecisionPoint)decisionPoint;
+    default:
+        return WebMockContentFilterDecisionPointAfterWillSendRequest;
+    }
+}
+
 @end
index 44ed8d2..853b230 100644 (file)
 
 #import "BrowserWindowController.h"
 
+@class WebMockContentFilterEnabler;
 @class WebView;
 
 @interface WK1BrowserWindowController : BrowserWindowController {
     WebView *_webView;
+    WebMockContentFilterEnabler *_contentFilterEnabler;
 }
 
 
index d0f85a9..37c4f4a 100644 (file)
@@ -26,6 +26,7 @@
 #import "WK1BrowserWindowController.h"
 
 #import "AppDelegate.h"
+#import "MockContentFilterEnabler.h"
 #import "SettingsController.h"
 #import <WebKit/WebKit.h>
 #import <WebKit/WebPreferences.h>
@@ -67,6 +68,7 @@
     [_webView setUIDelegate:nil];
     [_webView setResourceLoadDelegate:nil];
     [_webView release];
+    [_contentFilterEnabler release];
 
     [super dealloc];
 }
         } else
             [_webView _setPaginationMode:WebPaginationModeUnpaginated];
     }
+
+    [_contentFilterEnabler release];
+    _contentFilterEnabler = settings.contentFilteringEnabled ? [[WebMockContentFilterEnabler alloc] initWithDecision:settings.contentFilteringDecision decisionPoint:settings.contentFilteringDecisionPoint blockedString:[BrowserWindowController contentFilteringBlockedString]] : nil;
+    [_contentFilterEnabler enable];
 }
 
 - (IBAction)printWebView:(id)sender
index 7393cdc..5062258 100644 (file)
 #if WK_API_ENABLED
 
 #import "AppDelegate.h"
+#import "MockContentFilterEnabler.h"
 #import "SettingsController.h"
 #import <WebKit/WKFrameInfo.h>
 #import <WebKit/WKNavigationDelegate.h>
 #import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKUIDelegate.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
@@ -372,6 +374,9 @@ static CGFloat viewScaleForMenuItemTag(NSInteger tag)
         visibleOverlayRegions |= _WKWheelEventHandlerRegion;
     
     preferences._visibleDebugOverlayRegions = visibleOverlayRegions;
+
+    WebMockContentFilterEnabler *enabler = settings.contentFilteringEnabled ? [[[WebMockContentFilterEnabler alloc] initWithDecision:settings.contentFilteringDecision decisionPoint:settings.contentFilteringDecisionPoint blockedString:[BrowserWindowController contentFilteringBlockedString]] autorelease] : nil;
+    [_webView.configuration.processPool _setObject:enabler forBundleParameter:NSStringFromClass([WebMockContentFilterEnabler class])];
 }
 
 - (void)updateTitle:(NSString *)title
index 0c5a3f9..16b54d4 100644 (file)
@@ -26,8 +26,11 @@ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
 
 UNEXPORTED_SYMBOL_LDFLAGS = -Wl,-unexported_symbol -Wl,__ZN7testing4Test16TearDownTestCaseEv -Wl,-unexported_symbol -Wl,__ZN7testing4Test13SetUpTestCaseEv
 
-OTHER_LDFLAGS = $(inherited) $(UNEXPORTED_SYMBOL_LDFLAGS) -lgtest -force_load $(BUILT_PRODUCTS_DIR)/libTestWebKitAPI.a -framework JavaScriptCore -framework WebKit $(OTHER_LDFLAGS_PLATFORM);
+OTHER_LDFLAGS = $(inherited) $(UNEXPORTED_SYMBOL_LDFLAGS) -lgtest -force_load $(BUILT_PRODUCTS_DIR)/libTestWebKitAPI.a -framework JavaScriptCore -framework WebKit -lWebCoreTestSupport $(OTHER_LDFLAGS_PLATFORM);
 OTHER_LDFLAGS_PLATFORM[sdk=macosx*] = -framework Cocoa -framework Carbon;
 
 // FIXME: This should not be built on iOS. Instead we should create and use a TestWebKitAPI application.
 OTHER_LDFLAGS_PLATFORM[sdk=iphone*] = -framework WebCore -framework CoreGraphics;
+
+LD_RUNPATH_SEARCH_PATHS = "@loader_path/.";
+
index bcd5df6..f4a9abf 100644 (file)
@@ -27,7 +27,7 @@
 
 #if WK_API_ENABLED && PLATFORM(MAC)
 
-#import "MockContentFilterSettings.h"
+#import "MockContentFilterEnabler.h"
 #import "PlatformUtilities.h"
 #import "TestProtocol.h"
 #import "WKWebViewConfigurationExtras.h"
 #import <WebKit/_WKDownloadDelegate.h>
 #import <wtf/RetainPtr.h>
 
-using Decision = WebCore::MockContentFilterSettings::Decision;
-using DecisionPoint = WebCore::MockContentFilterSettings::DecisionPoint;
-
 static bool isDone;
 
-@interface MockContentFilterEnabler : NSObject <NSCopying, NSSecureCoding>
-- (instancetype)initWithDecision:(Decision)decision decisionPoint:(DecisionPoint)decisionPoint;
-@end
-
-@implementation MockContentFilterEnabler {
-    Decision _decision;
-    DecisionPoint _decisionPoint;
-}
-
-+ (BOOL)supportsSecureCoding
-{
-    return YES;
-}
-
-- (id)copyWithZone:(NSZone *)zone
-{
-    return [self retain];
-}
-
-- (instancetype)initWithCoder:(NSCoder *)decoder
-{
-    return [super init];
-}
-
-- (instancetype)initWithDecision:(Decision)decision decisionPoint:(DecisionPoint)decisionPoint
-{
-    if (!(self = [super init]))
-        return nil;
-
-    _decision = decision;
-    _decisionPoint = decisionPoint;
-    return self;
-}
-
-- (void)encodeWithCoder:(NSCoder *)coder
-{
-    [coder encodeInt:static_cast<int>(_decision) forKey:@"Decision"];
-    [coder encodeInt:static_cast<int>(_decisionPoint) forKey:@"DecisionPoint"];
-}
-
-@end
-
-static RetainPtr<WKWebViewConfiguration> configurationWithContentFilterSettings(Decision decision, DecisionPoint decisionPoint)
+static RetainPtr<WKWebViewConfiguration> configurationWithContentFilterSettings(WebMockContentFilterDecision decision, WebMockContentFilterDecisionPoint decisionPoint)
 {
     auto configuration = retainPtr([WKWebViewConfiguration testwebkitapi_configurationWithTestPlugInClassName:@"ContentFilteringPlugIn"]);
-    auto contentFilterEnabler = adoptNS([[MockContentFilterEnabler alloc] initWithDecision:decision decisionPoint:decisionPoint]);
-    [[configuration processPool] _setObject:contentFilterEnabler.get() forBundleParameter:NSStringFromClass([MockContentFilterEnabler class])];
+    auto contentFilterEnabler = adoptNS([[WebMockContentFilterEnabler alloc] initWithDecision:decision decisionPoint:decisionPoint blockedString:nil]);
+    [[configuration processPool] _setObject:contentFilterEnabler.get() forBundleParameter:NSStringFromClass([WebMockContentFilterEnabler class])];
     return configuration;
 }
 
@@ -121,7 +76,7 @@ TEST(ContentFiltering, URLAfterServerRedirect)
         [NSURLProtocol registerClass:[TestProtocol class]];
         [WKBrowsingContextController registerSchemeForCustomProtocol:[TestProtocol scheme]];
 
-        auto configuration = configurationWithContentFilterSettings(Decision::Allow, DecisionPoint::AfterAddData);
+        auto configuration = configurationWithContentFilterSettings(WebMockContentFilterDecisionAllow, WebMockContentFilterDecisionPointAfterAddData);
         auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
         auto navigationDelegate = adoptNS([[ServerRedirectNavigationDelegate alloc] init]);
         [webView setNavigationDelegate:navigationDelegate.get()];
@@ -169,7 +124,7 @@ static bool downloadDidStart;
 
 @end
 
-static void downloadTest(Decision decision, DecisionPoint decisionPoint)
+static void downloadTest(WebMockContentFilterDecision decision, WebMockContentFilterDecisionPoint decisionPoint)
 {
     @autoreleasepool {
         [NSURLProtocol registerClass:[TestProtocol class]];
@@ -185,7 +140,7 @@ static void downloadTest(Decision decision, DecisionPoint decisionPoint)
 
         isDone = false;
         downloadDidStart = false;
-        const bool downloadShouldStart = decision == Decision::Allow || decisionPoint > DecisionPoint::AfterResponse;
+        const bool downloadShouldStart = decision == WebMockContentFilterDecisionAllow || decisionPoint > WebMockContentFilterDecisionPointAfterResponse;
         if (downloadShouldStart)
             TestWebKitAPI::Util::run(&downloadDidStart);
         else
@@ -200,62 +155,62 @@ static void downloadTest(Decision decision, DecisionPoint decisionPoint)
 
 TEST(ContentFiltering, AllowDownloadAfterWillSendRequest)
 {
-    downloadTest(Decision::Allow, DecisionPoint::AfterWillSendRequest);
+    downloadTest(WebMockContentFilterDecisionAllow, WebMockContentFilterDecisionPointAfterWillSendRequest);
 }
 
 TEST(ContentFiltering, BlockDownloadAfterWillSendRequest)
 {
-    downloadTest(Decision::Block, DecisionPoint::AfterWillSendRequest);
+    downloadTest(WebMockContentFilterDecisionBlock, WebMockContentFilterDecisionPointAfterWillSendRequest);
 }
 
 TEST(ContentFiltering, AllowDownloadAfterRedirect)
 {
-    downloadTest(Decision::Allow, DecisionPoint::AfterRedirect);
+    downloadTest(WebMockContentFilterDecisionAllow, WebMockContentFilterDecisionPointAfterRedirect);
 }
 
 TEST(ContentFiltering, BlockDownloadAfterRedirect)
 {
-    downloadTest(Decision::Block, DecisionPoint::AfterRedirect);
+    downloadTest(WebMockContentFilterDecisionBlock, WebMockContentFilterDecisionPointAfterRedirect);
 }
 
 TEST(ContentFiltering, AllowDownloadAfterResponse)
 {
-    downloadTest(Decision::Allow, DecisionPoint::AfterResponse);
+    downloadTest(WebMockContentFilterDecisionAllow, WebMockContentFilterDecisionPointAfterResponse);
 }
 
 TEST(ContentFiltering, BlockDownloadAfterResponse)
 {
-    downloadTest(Decision::Block, DecisionPoint::AfterResponse);
+    downloadTest(WebMockContentFilterDecisionBlock, WebMockContentFilterDecisionPointAfterResponse);
 }
 
 TEST(ContentFiltering, AllowDownloadAfterAddData)
 {
-    downloadTest(Decision::Allow, DecisionPoint::AfterAddData);
+    downloadTest(WebMockContentFilterDecisionAllow, WebMockContentFilterDecisionPointAfterAddData);
 }
 
 TEST(ContentFiltering, BlockDownloadAfterAddData)
 {
-    downloadTest(Decision::Block, DecisionPoint::AfterAddData);
+    downloadTest(WebMockContentFilterDecisionBlock, WebMockContentFilterDecisionPointAfterAddData);
 }
 
 TEST(ContentFiltering, AllowDownloadAfterFinishedAddingData)
 {
-    downloadTest(Decision::Allow, DecisionPoint::AfterFinishedAddingData);
+    downloadTest(WebMockContentFilterDecisionAllow, WebMockContentFilterDecisionPointAfterFinishedAddingData);
 }
 
 TEST(ContentFiltering, BlockDownloadAfterFinishedAddingData)
 {
-    downloadTest(Decision::Block, DecisionPoint::AfterFinishedAddingData);
+    downloadTest(WebMockContentFilterDecisionBlock, WebMockContentFilterDecisionPointAfterFinishedAddingData);
 }
 
 TEST(ContentFiltering, AllowDownloadNever)
 {
-    downloadTest(Decision::Allow, DecisionPoint::Never);
+    downloadTest(WebMockContentFilterDecisionAllow, WebMockContentFilterDecisionPointNever);
 }
 
 TEST(ContentFiltering, BlockDownloadNever)
 {
-    downloadTest(Decision::Block, DecisionPoint::Never);
+    downloadTest(WebMockContentFilterDecisionBlock, WebMockContentFilterDecisionPointNever);
 }
 
 #endif // WK_API_ENABLED
index d1cb7e4..ffcf31f 100644 (file)
 
 #if WK_API_ENABLED
 
-#import "MockContentFilterSettings.h"
+#import "MockContentFilterEnabler.h"
 #import <WebKit/WKWebProcessPlugIn.h>
 
-using MockContentFilterSettings = WebCore::MockContentFilterSettings;
-using Decision = MockContentFilterSettings::Decision;
-using DecisionPoint = MockContentFilterSettings::DecisionPoint;
-
-@interface MockContentFilterEnabler : NSObject <NSCopying, NSSecureCoding>
-@end
-
-@implementation MockContentFilterEnabler
-
-+ (BOOL)supportsSecureCoding
-{
-    return YES;
-}
-
-- (id)copyWithZone:(NSZone *)zone
-{
-    return [self retain];
-}
-
-- (instancetype)initWithCoder:(NSCoder *)decoder
-{
-    if (!(self = [super init]))
-        return nil;
-
-    auto& settings = MockContentFilterSettings::singleton();
-    settings.setEnabled(true);
-    settings.setDecision(static_cast<Decision>([decoder decodeIntForKey:@"Decision"]));
-    settings.setDecisionPoint(static_cast<DecisionPoint>([decoder decodeIntForKey:@"DecisionPoint"]));
-    return self;
-}
-
-- (void)dealloc
-{
-    MockContentFilterSettings::singleton().setEnabled(false);
-    [super dealloc];
-}
-
-- (void)encodeWithCoder:(NSCoder *)coder
-{
-}
-
-@end
-
 @interface ContentFilteringPlugIn : NSObject <WKWebProcessPlugIn>
 @end
 
 @implementation ContentFilteringPlugIn {
-    RetainPtr<MockContentFilterEnabler> _contentFilterEnabler;
+    RetainPtr<WebMockContentFilterEnabler> _contentFilterEnabler;
     RetainPtr<WKWebProcessPlugInController> _plugInController;
 }
 
@@ -85,20 +42,21 @@ using DecisionPoint = MockContentFilterSettings::DecisionPoint;
 {
     ASSERT(!_plugInController);
     _plugInController = plugInController;
-    [plugInController.parameters addObserver:self forKeyPath:NSStringFromClass([MockContentFilterEnabler class]) options:NSKeyValueObservingOptionInitial context:NULL];
+    [plugInController.parameters addObserver:self forKeyPath:NSStringFromClass([WebMockContentFilterEnabler class]) options:NSKeyValueObservingOptionInitial context:NULL];
 }
 
 - (void)dealloc
 {
-    [[_plugInController parameters] removeObserver:self forKeyPath:NSStringFromClass([MockContentFilterEnabler class])];
+    [[_plugInController parameters] removeObserver:self forKeyPath:NSStringFromClass([WebMockContentFilterEnabler class])];
     [super dealloc];
 }
 
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
 {
     id contentFilterEnabler = [object valueForKeyPath:keyPath];
-    ASSERT([contentFilterEnabler isKindOfClass:[MockContentFilterEnabler class]]);
+    ASSERT(!contentFilterEnabler || [contentFilterEnabler isKindOfClass:[WebMockContentFilterEnabler class]]);
     _contentFilterEnabler = contentFilterEnabler;
+    [_contentFilterEnabler enable];
 }
 
 @end