Changeset 286545 in webkit
- Timestamp:
- Dec 6, 2021, 9:46:01 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/contentextensions/ContentExtensionsBackend.cpp (modified) (1 diff)
-
Source/WebCore/loader/DocumentLoader.cpp (modified) (2 diffs)
-
Source/WebCore/loader/DocumentLoader.h (modified) (2 diffs)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/Shared/WebsitePoliciesData.cpp (modified) (1 diff)
-
Source/WebKit/Shared/WebsitePoliciesData.h (modified) (1 diff)
-
Source/WebKit/UIProcess/API/APIWebsitePolicies.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r286544 r286545 1 2021-12-06 Alex Christensen <achristensen@webkit.org> 2 3 WKWebpagePreferences._activeContentRuleListActionPatterns should be an NSDictionary of identifier to allowed patterns 4 https://bugs.webkit.org/show_bug.cgi?id=233842 5 6 Reviewed by Timothy Hatcher. 7 8 There's no need for nil to match everything because a pattern can be written to quickly match everything. 9 There is a need for different extensions (with different identifiers) to have different active action permissions, though. 10 11 * contentextensions/ContentExtensionsBackend.cpp: 12 (WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad): 13 * loader/DocumentLoader.cpp: 14 (WebCore::DocumentLoader::DocumentLoader): 15 (WebCore::DocumentLoader::setActiveContentRuleListActionPatterns): 16 (WebCore::DocumentLoader::allowsActiveContentRuleListActionsForURL const): 17 * loader/DocumentLoader.h: 18 1 19 2021-12-06 Antoine Quint <graouts@webkit.org> 2 20 -
trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp
r286402 r286545 229 229 RELEASE_ASSERT_NOT_REACHED(); 230 230 }, [&] (const ModifyHeadersAction& action) { 231 if (initiatingDocumentLoader.allowsActiveContentRuleListActionsForURL( url))231 if (initiatingDocumentLoader.allowsActiveContentRuleListActionsForURL(contentRuleListIdentifier, url)) 232 232 results.summary.modifyHeadersActions.append(action); 233 233 }, [&] (const RedirectAction& redirectAction) { 234 if (initiatingDocumentLoader.allowsActiveContentRuleListActionsForURL( url))235 results.summary.redirectActions.append({ redirectAction, m_contentExtensions.get( actionsFromContentRuleList.contentRuleListIdentifier)->extensionBaseURL() });234 if (initiatingDocumentLoader.allowsActiveContentRuleListActionsForURL(contentRuleListIdentifier, url)) 235 results.summary.redirectActions.append({ redirectAction, m_contentExtensions.get(contentRuleListIdentifier)->extensionBaseURL() }); 236 236 }), action.data()); 237 237 } -
trunk/Source/WebCore/loader/DocumentLoader.cpp
r286012 r286545 175 175 , m_substituteResourceDeliveryTimer(*this, &DocumentLoader::substituteResourceDeliveryTimerFired) 176 176 , m_applicationCacheHost(makeUnique<ApplicationCacheHost>(*this)) 177 , m_activeContentRuleListActionPatterns(Vector<UserContentURLPattern>()) 178 { 179 // FIXME: Vector default constructor shouldn't need to know the size of the elements, 180 // so m_activeContentRuleListActionPatterns ought to be able to be initialized with an initializer list in the header without including UserContentURLPattern.h. 177 { 181 178 } 182 179 … … 2438 2435 #endif // ENABLE(CONTENT_FILTERING) 2439 2436 2440 void DocumentLoader::setActiveContentRuleListActionPatterns(const std::optional<HashSet<String>>& patterns) 2441 { 2442 if (!patterns) { 2443 m_activeContentRuleListActionPatterns = std::nullopt; 2444 return; 2445 } 2446 Vector<WebCore::UserContentURLPattern> patternVector; 2447 patternVector.reserveInitialCapacity(patterns->size()); 2448 for (auto& patternString : *patterns) { 2449 WebCore::UserContentURLPattern parsedPattern(patternString); 2450 if (parsedPattern.isValid()) 2451 patternVector.uncheckedAppend(WTFMove(parsedPattern)); 2452 } 2453 2454 m_activeContentRuleListActionPatterns = WTFMove(patternVector); 2455 } 2456 2457 bool DocumentLoader::allowsActiveContentRuleListActionsForURL(const URL& url) const 2458 { 2459 if (!m_activeContentRuleListActionPatterns) 2460 return true; 2461 for (const auto& pattern : *m_activeContentRuleListActionPatterns) { 2437 void DocumentLoader::setActiveContentRuleListActionPatterns(const HashMap<String, Vector<String>>& patterns) 2438 { 2439 HashMap<String, Vector<UserContentURLPattern>> parsedPatternMap; 2440 2441 for (auto& pair : patterns) { 2442 Vector<UserContentURLPattern> patternVector; 2443 patternVector.reserveInitialCapacity(pair.value.size()); 2444 for (auto& patternString : pair.value) { 2445 UserContentURLPattern parsedPattern(patternString); 2446 if (parsedPattern.isValid()) 2447 patternVector.uncheckedAppend(WTFMove(parsedPattern)); 2448 } 2449 parsedPatternMap.set(pair.key, WTFMove(patternVector)); 2450 } 2451 2452 m_activeContentRuleListActionPatterns = WTFMove(parsedPatternMap); 2453 } 2454 2455 bool DocumentLoader::allowsActiveContentRuleListActionsForURL(const String& contentRuleListIdentifier, const URL& url) const 2456 { 2457 for (const auto& pattern : m_activeContentRuleListActionPatterns.get(contentRuleListIdentifier)) { 2462 2458 if (pattern.matches(url)) 2463 2459 return true; -
trunk/Source/WebCore/loader/DocumentLoader.h
r286012 r286545 303 303 void setUserContentExtensionsEnabled(bool enabled) { m_userContentExtensionsEnabled = enabled; } 304 304 305 bool allowsActiveContentRuleListActionsForURL(const URL&) const;306 WEBCORE_EXPORT void setActiveContentRuleListActionPatterns(const std::optional<HashSet<String>>&);305 bool allowsActiveContentRuleListActionsForURL(const String& contentRuleListIdentifier, const URL&) const; 306 WEBCORE_EXPORT void setActiveContentRuleListActionPatterns(const HashMap<String, Vector<String>>&); 307 307 308 308 #if ENABLE(DEVICE_ORIENTATION) … … 656 656 String m_customNavigatorPlatform; 657 657 bool m_userContentExtensionsEnabled { true }; 658 std::optional<Vector<UserContentURLPattern>> m_activeContentRuleListActionPatterns;658 HashMap<String, Vector<UserContentURLPattern>> m_activeContentRuleListActionPatterns; 659 659 #if ENABLE(DEVICE_ORIENTATION) 660 660 DeviceOrientationOrMotionPermissionState m_deviceOrientationAndMotionAccessState { DeviceOrientationOrMotionPermissionState::Prompt }; -
trunk/Source/WebKit/ChangeLog
r286538 r286545 1 2021-12-06 Alex Christensen <achristensen@webkit.org> 2 3 WKWebpagePreferences._activeContentRuleListActionPatterns should be an NSDictionary of identifier to allowed patterns 4 https://bugs.webkit.org/show_bug.cgi?id=233842 5 6 Reviewed by Timothy Hatcher. 7 8 * Shared/WebsitePoliciesData.cpp: 9 (WebKit::WebsitePoliciesData::decode): 10 * Shared/WebsitePoliciesData.h: 11 * UIProcess/API/APIWebsitePolicies.h: 12 * UIProcess/API/Cocoa/WKWebpagePreferences.mm: 13 (-[WKWebpagePreferences _setActiveContentRuleListActionPatterns:]): 14 (-[WKWebpagePreferences _activeContentRuleListActionPatterns]): 15 * UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h: 16 1 17 2021-12-05 Said Abou-Hallawa <said@apple.com> 2 18 -
trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp
r285980 r286545 65 65 return std::nullopt; 66 66 67 std::optional< std::optional<HashSet<String>>> activeContentRuleListActionPatterns;67 std::optional<HashMap<WTF::String, Vector<WTF::String>>> activeContentRuleListActionPatterns; 68 68 decoder >> activeContentRuleListActionPatterns; 69 69 if (!activeContentRuleListActionPatterns) -
trunk/Source/WebKit/Shared/WebsitePoliciesData.h
r285980 r286545 54 54 55 55 bool contentBlockersEnabled { true }; 56 std::optional<HashSet<String>> activeContentRuleListActionPatterns { HashSet<String>() };56 HashMap<WTF::String, Vector<WTF::String>> activeContentRuleListActionPatterns; 57 57 OptionSet<WebsiteAutoplayQuirk> allowedAutoplayQuirks; 58 58 WebsiteAutoplayPolicy autoplayPolicy { WebsiteAutoplayPolicy::Default }; -
trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h
r285980 r286545 64 64 void setContentBlockersEnabled(bool enabled) { m_contentBlockersEnabled = enabled; } 65 65 66 void setActiveContentRuleListActionPatterns( std::optional<HashSet<WTF::String>>&& patterns) { m_activeContentRuleListActionPatterns = WTFMove(patterns); }67 const std::optional<HashSet<WTF::String>>& activeContentRuleListActionPatterns() const { return m_activeContentRuleListActionPatterns; }66 void setActiveContentRuleListActionPatterns(HashMap<WTF::String, Vector<WTF::String>>&& patterns) { m_activeContentRuleListActionPatterns = WTFMove(patterns); } 67 const HashMap<WTF::String, Vector<WTF::String>>& activeContentRuleListActionPatterns() const { return m_activeContentRuleListActionPatterns; } 68 68 69 69 OptionSet<WebKit::WebsiteAutoplayQuirk> allowedAutoplayQuirks() const { return m_allowedAutoplayQuirks; } … … 141 141 // FIXME: replace most or all of these members with a WebsitePoliciesData. 142 142 bool m_contentBlockersEnabled { true }; 143 std::optional<HashSet<WTF::String>> m_activeContentRuleListActionPatterns { HashSet<WTF::String>() };143 HashMap<WTF::String, Vector<WTF::String>> m_activeContentRuleListActionPatterns; 144 144 OptionSet<WebKit::WebsiteAutoplayQuirk> m_allowedAutoplayQuirks; 145 145 WebKit::WebsiteAutoplayPolicy m_autoplayPolicy { WebKit::WebsiteAutoplayPolicy::Default }; -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm
r286267 r286545 142 142 } 143 143 144 - (void)_setActiveContentRuleListActionPatterns:(NSSet<NSString *> *)patterns 145 { 146 if (!patterns) { 147 _websitePolicies->setActiveContentRuleListActionPatterns(std::nullopt); 148 return; 149 } 150 151 HashSet<String> patternHashSet; 152 patternHashSet.reserveInitialCapacity(patterns.count); 153 for (NSString *pattern in patterns) 154 patternHashSet.add(pattern); 155 _websitePolicies->setActiveContentRuleListActionPatterns(WTFMove(patternHashSet)); 156 } 157 158 - (NSSet<NSString *> *)_activeContentRuleListActionPatterns 159 { 160 const auto& patterns = _websitePolicies->activeContentRuleListActionPatterns(); 161 if (!patterns) 162 return nil; 163 164 NSMutableSet<NSString *> *set = [NSMutableSet set]; 165 for (const auto& pattern : *patterns) 166 [set addObject:pattern]; 167 return set; 144 - (void)_setActiveContentRuleListActionPatterns:(NSDictionary<NSString *, NSSet<NSString *> *> *)patterns 145 { 146 __block HashMap<String, Vector<String>> map; 147 [patterns enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSSet<NSString *> *value, BOOL *) { 148 Vector<String> vector; 149 vector.reserveInitialCapacity(value.count); 150 for (NSString *pattern in value) 151 vector.uncheckedAppend(pattern); 152 map.add(key, WTFMove(vector)); 153 }]; 154 _websitePolicies->setActiveContentRuleListActionPatterns(WTFMove(map)); 155 } 156 157 - (NSDictionary<NSString *, NSSet<NSString *> *> *)_activeContentRuleListActionPatterns 158 { 159 NSMutableDictionary<NSString *, NSSet<NSString *> *> *dictionary = [NSMutableDictionary dictionary]; 160 for (const auto& pair : _websitePolicies->activeContentRuleListActionPatterns()) { 161 NSMutableSet<NSString *> *set = [NSMutableSet set]; 162 for (const auto& pattern : pair.value) 163 [set addObject:pattern]; 164 [dictionary setObject:set forKey:pair.key]; 165 } 166 return dictionary; 168 167 } 169 168 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h
r285980 r286545 70 70 71 71 @property (nonatomic, setter=_setContentBlockersEnabled:) BOOL _contentBlockersEnabled; 72 @property (nonatomic, copy, setter=_setActiveContentRuleListActionPatterns:) NS Set<NSString *> *_activeContentRuleListActionPatterns;72 @property (nonatomic, copy, setter=_setActiveContentRuleListActionPatterns:) NSDictionary<NSString *, NSSet<NSString *> *> *_activeContentRuleListActionPatterns WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 73 73 @property (nonatomic, setter=_setAllowedAutoplayQuirks:) _WKWebsiteAutoplayQuirk _allowedAutoplayQuirks; 74 74 @property (nonatomic, setter=_setAutoplayPolicy:) _WKWebsiteAutoplayPolicy _autoplayPolicy; -
trunk/Tools/ChangeLog
r286538 r286545 1 2021-12-06 Alex Christensen <achristensen@webkit.org> 2 3 WKWebpagePreferences._activeContentRuleListActionPatterns should be an NSDictionary of identifier to allowed patterns 4 https://bugs.webkit.org/show_bug.cgi?id=233842 5 6 Reviewed by Timothy Hatcher. 7 8 * TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm: 9 (navigationDelegateAllowingActiveActionsOnTestHost): 10 (TEST_F): 11 1 12 2021-12-05 Said Abou-Hallawa <said@apple.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm
r286492 r286545 500 500 static auto delegate = adoptNS([TestNavigationDelegate new]); 501 501 delegate.get().decidePolicyForNavigationActionWithPreferences = ^(WKNavigationAction *, WKWebpagePreferences *preferences, void (^decisionHandler)(WKNavigationActionPolicy, WKWebpagePreferences *)) { 502 preferences._activeContentRuleListActionPatterns = [NS Set setWithObject:@"*://testhost/*"];502 preferences._activeContentRuleListActionPatterns = [NSDictionary dictionaryWithObject:[NSSet setWithObject:@"*://testhost/*"] forKey:@"testidentifier"]; 503 503 decisionHandler(WKNavigationActionPolicyAllow, preferences); 504 504 }; … … 723 723 switch (delegateAction) { 724 724 case DelegateAction::AllowAll: 725 preferences._activeContentRuleListActionPatterns = nil;725 preferences._activeContentRuleListActionPatterns = [NSDictionary dictionaryWithObject:[NSSet setWithObject:@"*://*/*"] forKey:@"testidentifier"]; 726 726 break; 727 727 case DelegateAction::AllowNone: 728 preferences._activeContentRuleListActionPatterns = [NS Set set];728 preferences._activeContentRuleListActionPatterns = [NSDictionary dictionary]; 729 729 break; 730 730 case DelegateAction::AllowTestHost: 731 preferences._activeContentRuleListActionPatterns = [NS Set setWithObject:@"*://testhost/*"];731 preferences._activeContentRuleListActionPatterns = [NSDictionary dictionaryWithObject:[NSSet setWithObject:@"*://testhost/*"] forKey:@"testidentifier"]; 732 732 break; 733 733 } … … 774 774 auto delegate = adoptNS([TestNavigationDelegate new]); 775 775 delegate.get().decidePolicyForNavigationActionWithPreferences = ^(WKNavigationAction *, WKWebpagePreferences *preferences, void (^decisionHandler)(WKNavigationActionPolicy, WKWebpagePreferences *)) { 776 preferences._activeContentRuleListActionPatterns = nil;776 preferences._activeContentRuleListActionPatterns = [NSDictionary dictionaryWithObject:[NSSet setWithObject:@"*://testhost/*"] forKey:@"testidentifier"]; 777 777 decisionHandler(WKNavigationActionPolicyAllow, preferences); 778 778 };
Note:
See TracChangeset
for help on using the changeset viewer.