User agent string override for navigator.userAgent should be site specific quirks
[WebKit-https.git] / Source / WebKit / UIProcess / API / Cocoa / _WKWebsitePolicies.mm
index 447088b..dde107a 100644 (file)
@@ -28,6 +28,8 @@
 
 #if WK_API_ENABLED
 
+#import "WKWebsiteDataStoreInternal.h"
+
 @implementation _WKWebsitePolicies
 
 - (void)dealloc
     return _websitePolicies->contentBlockersEnabled();
 }
 
+- (void)setDeviceOrientationEventEnabled:(BOOL)deviceOrientationEventEnabled
+{
+    _websitePolicies->setDeviceOrientationEventEnabled(deviceOrientationEventEnabled);
+}
+
+- (BOOL)deviceOrientationEventEnabled
+{
+    return _websitePolicies->deviceOrientationEventEnabled();
+}
+
 - (void)setAllowedAutoplayQuirks:(_WKWebsiteAutoplayQuirk)allowedQuirks
 {
     OptionSet<WebKit::WebsiteAutoplayQuirk> quirks;
 
     if (allowedQuirks & _WKWebsiteAutoplayQuirkInheritedUserGestures)
-        quirks |= WebKit::WebsiteAutoplayQuirk::InheritedUserGestures;
+        quirks.add(WebKit::WebsiteAutoplayQuirk::InheritedUserGestures);
 
     if (allowedQuirks & _WKWebsiteAutoplayQuirkSynthesizedPauseEvents)
-        quirks |= WebKit::WebsiteAutoplayQuirk::SynthesizedPauseEvents;
+        quirks.add(WebKit::WebsiteAutoplayQuirk::SynthesizedPauseEvents);
+
+    if (allowedQuirks & _WKWebsiteAutoplayQuirkArbitraryUserGestures)
+        quirks.add(WebKit::WebsiteAutoplayQuirk::ArbitraryUserGestures);
+
+    if (allowedQuirks & _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior)
+        quirks.add(WebKit::WebsiteAutoplayQuirk::PerDocumentAutoplayBehavior);
 
     _websitePolicies->setAllowedAutoplayQuirks(quirks);
 }
     if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::SynthesizedPauseEvents))
         quirks |= _WKWebsiteAutoplayQuirkSynthesizedPauseEvents;
 
+    if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::ArbitraryUserGestures))
+        quirks |= _WKWebsiteAutoplayQuirkArbitraryUserGestures;
+
+    if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::PerDocumentAutoplayBehavior))
+        quirks |= _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior;
+
     return quirks;
 }
 
     }
 }
 
+- (void)setPopUpPolicy:(_WKWebsitePopUpPolicy)policy
+{
+    switch (policy) {
+    case _WKWebsitePopUpPolicyDefault:
+        _websitePolicies->setPopUpPolicy(WebKit::WebsitePopUpPolicy::Default);
+        break;
+    case _WKWebsitePopUpPolicyAllow:
+        _websitePolicies->setPopUpPolicy(WebKit::WebsitePopUpPolicy::Allow);
+        break;
+    case _WKWebsitePopUpPolicyBlock:
+        _websitePolicies->setPopUpPolicy(WebKit::WebsitePopUpPolicy::Block);
+        break;
+    }
+}
+
+- (_WKWebsitePopUpPolicy)popUpPolicy
+{
+    switch (_websitePolicies->popUpPolicy()) {
+    case WebKit::WebsitePopUpPolicy::Default:
+        return _WKWebsitePopUpPolicyDefault;
+    case WebKit::WebsitePopUpPolicy::Allow:
+        return _WKWebsitePopUpPolicyAllow;
+    case WebKit::WebsitePopUpPolicy::Block:
+        return _WKWebsitePopUpPolicyBlock;
+    }
+}
+
+- (NSDictionary<NSString *, NSString *> *)customHeaderFields
+{
+    const auto& fields = _websitePolicies->customHeaderFields();
+    NSMutableDictionary *dictionary = [[[NSMutableDictionary alloc] initWithCapacity:fields.size()] autorelease];
+    for (const auto& field : fields)
+        [dictionary setObject:field.value() forKey:field.name()];
+    return dictionary;
+}
+
+- (void)setCustomHeaderFields:(NSDictionary<NSString *, NSString *> *)fields
+{
+    Vector<WebCore::HTTPHeaderField> parsedFields;
+    parsedFields.reserveInitialCapacity(fields.count);
+    
+    for (NSString* name in fields) {
+        auto field = WebCore::HTTPHeaderField::create(name, [fields objectForKey:name]);
+        if (field && startsWithLettersIgnoringASCIICase(field->name(), "x-"))
+            parsedFields.uncheckedAppend(WTFMove(*field));
+    }
+    _websitePolicies->setCustomHeaderFields(WTFMove(parsedFields));
+}
+
+- (WKWebsiteDataStore *)websiteDataStore
+{
+    return wrapper(_websitePolicies->websiteDataStore());
+}
+
+- (void)setWebsiteDataStore:(WKWebsiteDataStore *)websiteDataStore
+{
+    _websitePolicies->setWebsiteDataStore(websiteDataStore->_websiteDataStore.get());
+}
+
+- (void)setCustomUserAgent:(NSString *)customUserAgent
+{
+    _websitePolicies->setCustomUserAgent(customUserAgent);
+}
+
+- (NSString *)customUserAgent
+{
+    return _websitePolicies->customUserAgent();
+}
+
+- (void)setCustomJavaScriptUserAgentAsSiteSpecificQuirks:(NSString *)customUserAgent
+{
+    _websitePolicies->setCustomJavaScriptUserAgentAsSiteSpecificQuirks(customUserAgent);
+}
+
+- (NSString *)customJavaScriptUserAgentAsSiteSpecificQuirks
+{
+    return _websitePolicies->customJavaScriptUserAgentAsSiteSpecificQuirks();
+}
+
+- (void)setCustomNavigatorPlatform:(NSString *)customNavigatorPlatform
+{
+    _websitePolicies->setCustomNavigatorPlatform(customNavigatorPlatform);
+}
+
+- (NSString *)customNavigatorPlatform
+{
+    return _websitePolicies->customNavigatorPlatform();
+}
+
 - (NSString *)description
 {
     return [NSString stringWithFormat:@"<%@: %p; contentBlockersEnabled = %d>", NSStringFromClass(self.class), self, self.contentBlockersEnabled];