Defer use of autoplay heuristics to clients
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jan 2017 19:16:34 +0000 (19:16 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jan 2017 19:16:34 +0000 (19:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167010

Patch by Matt Rajca <mrajca@apple.com> on 2017-01-13
Reviewed by Alex Christensen.

Switch the autoplay policy tristate to an on/off option since clients should run any
heuristics and simply send their final decision to WebKit.

* Shared/WebsitePolicies.h:
(WebKit::WebsitePolicies::encode):
(WebKit::WebsitePolicies::decode):
* UIProcess/API/APIWebsitePolicies.h:
* UIProcess/API/C/WKWebsitePolicies.cpp:
(WKWebsitePoliciesGetAutoplayEnabled):
(WKWebsitePoliciesSetAutoplayEnabled):
(WKWebsitePoliciesGetAutoplayPolicy): Replaced.
(WKWebsitePoliciesSetAutoplayPolicy): Replaced.
* UIProcess/API/C/WKWebsitePolicies.h:
* UIProcess/API/Cocoa/_WKWebsitePolicies.h:
* UIProcess/API/Cocoa/_WKWebsitePolicies.mm:
(-[_WKWebsitePolicies setAutoplayEnabled:]):
(-[_WKWebsitePolicies autoplayEnabled]):
(-[_WKWebsitePolicies setAutoplayPolicy:]): Replaced.
(-[_WKWebsitePolicies autoplayPolicy]): Replaced.

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebsitePolicies.h
Source/WebKit2/UIProcess/API/APIWebsitePolicies.h
Source/WebKit2/UIProcess/API/C/WKWebsitePolicies.cpp
Source/WebKit2/UIProcess/API/C/WKWebsitePolicies.h
Source/WebKit2/UIProcess/API/Cocoa/_WKWebsitePolicies.h
Source/WebKit2/UIProcess/API/Cocoa/_WKWebsitePolicies.mm

index cee28c7..3f11024 100644 (file)
@@ -1,3 +1,30 @@
+2017-01-13  Matt Rajca  <mrajca@apple.com>
+
+        Defer use of autoplay heuristics to clients
+        https://bugs.webkit.org/show_bug.cgi?id=167010
+
+        Reviewed by Alex Christensen.
+
+        Switch the autoplay policy tristate to an on/off option since clients should run any
+        heuristics and simply send their final decision to WebKit.
+
+        * Shared/WebsitePolicies.h:
+        (WebKit::WebsitePolicies::encode):
+        (WebKit::WebsitePolicies::decode):
+        * UIProcess/API/APIWebsitePolicies.h:
+        * UIProcess/API/C/WKWebsitePolicies.cpp:
+        (WKWebsitePoliciesGetAutoplayEnabled):
+        (WKWebsitePoliciesSetAutoplayEnabled):
+        (WKWebsitePoliciesGetAutoplayPolicy): Replaced.
+        (WKWebsitePoliciesSetAutoplayPolicy): Replaced.
+        * UIProcess/API/C/WKWebsitePolicies.h:
+        * UIProcess/API/Cocoa/_WKWebsitePolicies.h:
+        * UIProcess/API/Cocoa/_WKWebsitePolicies.mm:
+        (-[_WKWebsitePolicies setAutoplayEnabled:]):
+        (-[_WKWebsitePolicies autoplayEnabled]):
+        (-[_WKWebsitePolicies setAutoplayPolicy:]): Replaced.
+        (-[_WKWebsitePolicies autoplayPolicy]): Replaced.
+
 2017-01-13  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [SOUP] Simplify cookie storage handling
index a4f63ec..f3b9a10 100644 (file)
@@ -36,7 +36,7 @@ enum class WebsiteAutoplayPolicy {
 struct WebsitePolicies {
 
     bool contentBlockersEnabled { true };
-    WebsiteAutoplayPolicy autoplayPolicy { WebsiteAutoplayPolicy::UseHeuristics };
+    bool autoplayEnabled { true };
     
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static bool decode(Decoder&, WebsitePolicies&);
@@ -45,14 +45,14 @@ struct WebsitePolicies {
 template<class Encoder> void WebsitePolicies::encode(Encoder& encoder) const
 {
     encoder << contentBlockersEnabled;
-    encoder.encodeEnum(autoplayPolicy);
+    encoder << autoplayEnabled;
 }
 
 template<class Decoder> bool WebsitePolicies::decode(Decoder& decoder, WebsitePolicies& result)
 {
     if (!decoder.decode(result.contentBlockersEnabled))
         return false;
-    if (!decoder.decodeEnum(result.autoplayPolicy))
+    if (!decoder.decode(result.autoplayEnabled))
         return false;
     return true;
 }
index ca74f81..af747ba 100644 (file)
@@ -39,8 +39,8 @@ public:
     bool contentBlockersEnabled() const { return m_websitePolicies.contentBlockersEnabled; }
     void setContentBlockersEnabled(bool enabled) { m_websitePolicies.contentBlockersEnabled = enabled; }
 
-    WebKit::WebsiteAutoplayPolicy autoplayPolicy() const { return m_websitePolicies.autoplayPolicy; }
-    void setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy policy) { m_websitePolicies.autoplayPolicy = policy; }
+    bool autoplayEnabled() const { return m_websitePolicies.autoplayEnabled; }
+    void setAutoplayEnabled(bool enabled) { m_websitePolicies.autoplayEnabled = enabled; }
 
     const WebKit::WebsitePolicies& websitePolicies() { return m_websitePolicies; }
     
index 36d6578..6e527cc 100644 (file)
@@ -52,32 +52,12 @@ bool WKWebsitePoliciesGetContentBlockersEnabled(WKWebsitePoliciesRef websitePoli
     return toImpl(websitePolicies)->contentBlockersEnabled();
 }
 
-WKWebsiteAutoplayPolicy WKWebsitePoliciesGetAutoplayPolicy(WKWebsitePoliciesRef websitePolicies)
+bool WKWebsitePoliciesGetAutoplayEnabled(WKWebsitePoliciesRef websitePolicies)
 {
-    switch (toImpl(websitePolicies)->autoplayPolicy()) {
-    case WebsiteAutoplayPolicy::AlwaysAllow:
-        return kWKWebsiteAutoplayPolicyAlwaysAllow;
-    case WebsiteAutoplayPolicy::AlwaysDeny:
-        return kWKWebsiteAutoplayPolicyAlwaysDeny;
-    case WebsiteAutoplayPolicy::UseHeuristics:
-        return kWKWebsiteAutoplayPolicyUseHeuristics;
-    }
-    ASSERT_NOT_REACHED();
-    return kWKWebsiteAutoplayPolicyUseHeuristics;
+    return toImpl(websitePolicies)->autoplayEnabled();
 }
 
-void WKWebsitePoliciesSetAutoplayPolicy(WKWebsitePoliciesRef websitePolicies, WKWebsiteAutoplayPolicy autoplayPolicy)
+void WKWebsitePoliciesSetAutoplayEnabled(WKWebsitePoliciesRef websitePolicies, bool enabled)
 {
-    switch (autoplayPolicy) {
-    case kWKWebsiteAutoplayPolicyAlwaysAllow:
-        toImpl(websitePolicies)->setAutoplayPolicy(WebsiteAutoplayPolicy::AlwaysAllow);
-        return;
-    case kWKWebsiteAutoplayPolicyAlwaysDeny:
-        toImpl(websitePolicies)->setAutoplayPolicy(WebsiteAutoplayPolicy::AlwaysDeny);
-        return;
-    case kWKWebsiteAutoplayPolicyUseHeuristics:
-        toImpl(websitePolicies)->setAutoplayPolicy(WebsiteAutoplayPolicy::UseHeuristics);
-        return;
-    }
-    ASSERT_NOT_REACHED();
+    toImpl(websitePolicies)->setAutoplayEnabled(enabled);
 }
index 54c5494..6551fdc 100644 (file)
@@ -44,8 +44,8 @@ WK_EXPORT WKWebsitePoliciesRef WKWebsitePoliciesCreate();
 WK_EXPORT bool WKWebsitePoliciesGetContentBlockersEnabled(WKWebsitePoliciesRef);
 WK_EXPORT void WKWebsitePoliciesSetContentBlockersEnabled(WKWebsitePoliciesRef, bool);
 
-WK_EXPORT WKWebsiteAutoplayPolicy WKWebsitePoliciesGetAutoplayPolicy(WKWebsitePoliciesRef);
-WK_EXPORT void WKWebsitePoliciesSetAutoplayPolicy(WKWebsitePoliciesRef, WKWebsiteAutoplayPolicy);
+WK_EXPORT bool WKWebsitePoliciesGetAutoplayEnabled(WKWebsitePoliciesRef);
+WK_EXPORT void WKWebsitePoliciesSetAutoplayEnabled(WKWebsitePoliciesRef, bool);
 
 #ifdef __cplusplus
 }
index f1a32d0..ba2587f 100644 (file)
@@ -37,7 +37,7 @@ WK_CLASS_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA))
 @interface _WKWebsitePolicies : NSObject
 
 @property (nonatomic) BOOL contentBlockersEnabled;
-@property (nonatomic) _WKWebsiteAutoplayPolicy autoplayPolicy;
+@property (nonatomic) BOOL autoplayEnabled;
 
 @end
 
index e1f88e2..1ee9ad3 100644 (file)
     return _websitePolicies->contentBlockersEnabled();
 }
 
-- (void)setAutoplayPolicy:(_WKWebsiteAutoplayPolicy)autoplayPolicy
+- (void)setAutoplayEnabled:(BOOL)enabled
 {
-    switch (autoplayPolicy) {
-    case _WKWebsiteAutoplayPolicyUseHeuristics:
-        _websitePolicies->setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy::UseHeuristics);
-        break;
-    case _WKWebsiteAutoplayPolicyAlwaysAllow:
-        _websitePolicies->setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy::AlwaysAllow);
-        break;
-    case _WKWebsiteAutoplayPolicyAlwaysDeny:
-        _websitePolicies->setAutoplayPolicy(WebKit::WebsiteAutoplayPolicy::AlwaysDeny);
-        break;
-    }
+    _websitePolicies->setAutoplayEnabled(enabled);
 }
 
-- (_WKWebsiteAutoplayPolicy)autoplayPolicy
+- (BOOL)autoplayEnabled
 {
-    switch (_websitePolicies->autoplayPolicy()) {
-    case WebKit::WebsiteAutoplayPolicy::UseHeuristics:
-        return _WKWebsiteAutoplayPolicyUseHeuristics;
-    case WebKit::WebsiteAutoplayPolicy::AlwaysAllow:
-        return _WKWebsiteAutoplayPolicyAlwaysAllow;
-    case WebKit::WebsiteAutoplayPolicy::AlwaysDeny:
-        return _WKWebsiteAutoplayPolicyAlwaysDeny;
-    }
+    return _websitePolicies->autoplayEnabled();
 }
 
 - (NSString *)description