Allow the MediaSource API to be enabled via website policy
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2019 22:15:01 +0000 (22:15 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2019 22:15:01 +0000 (22:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196429
<rdar://problem/48774333>

Reviewed by Tim Horton.

Source/WebCore:

Add support in DocumentLoader for adjusting page settings using its per-site policies. See WebKit ChangeLog for
more detail (in particular, the implementation of applyToDocumentLoader).

Test: fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode.html

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::applyPoliciesToSettings const):
(WebCore::DocumentLoader::attachToFrame):
* loader/DocumentLoader.h:

Add an enum class for MediaSource policies; while we're at it, make all of these enum values 8 bits wide.

(WebCore::DocumentLoader::mediaSourcePolicy const):
(WebCore::DocumentLoader::setMediaSourcePolicy):

Source/WebKit:

Adds support for using WebsitePolicies to determine whether to enable the MediaSource API.

* Shared/WebPreferences.yaml:

Disengage the mediaSourceEnabled internal preference from the corresponding WebCore setting; to ensure that
setting the preference to `true` still results in enabling the MediaSource API, we instead make it such that
turning on mediaSourceEnabled causes WebsitePolicies to set its WebsiteMediaSourcePolicy to Enable.

In the future, we should deprecate and remove this preference, in favor of simply setting preferred
compatibility mode on WKWebpagePreferences.

* Shared/WebPreferences.yaml:
* Shared/WebsiteMediaSourcePolicy.h: Copied from Source/WebKit/Shared/WebsitePoliciesData.h.
* Shared/WebsitePoliciesData.cpp:
(WebKit::WebsitePoliciesData::encode const):
(WebKit::WebsitePoliciesData::decode):

Add plumbing for m_mediaSourcePolicy in the set of website policies.

(WebKit::WebsitePoliciesData::applyToDocumentLoader):

Update the document loader with the given media source policy. There are two possibilities when applying the set
of policies to the document loader; either the document loader is already attached to a Frame, or the document
loader is yet to be attached to a Frame.

In the first case, we update Frame's settings on the spot, by calling the new applyPoliciesToSettings helper
method. In the second scenario, we stash the policy state on DocumentLoader; when the DocumentLoader is attached
to a Frame, we'll then update the Frame's settings using DocumentLoader's policy.

* Shared/WebsitePoliciesData.h:
* UIProcess/API/APIWebsitePolicies.cpp:
(API::WebsitePolicies::data):
* UIProcess/API/APIWebsitePolicies.h:
* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageNavigationClient):
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):

Move code that adjusts website policies after deciding policies for the navigation action from NavigationClient
::decidePolicyForNavigationAction to the completion handler of the policy listener. This allows us to respect
default website policies on the web view configuration, even when using the C API to set the navigation client,
and also allows us to have a single call site for adjustPoliciesForCompatibilityMode. This also enables our
layout tests to opt into modern compatibility mode by default, when specifying modern compatibility mode on
webpage preferences.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::decidePolicyForNavigationAction):
(WebKit::WebPageProxy::adjustPoliciesForCompatibilityMode):
* UIProcess/WebPageProxy.h:
* WebKit.xcodeproj/project.pbxproj:

LayoutTests:

Add an on-device layout test to ensure that enabling modern compability mode also enables MSE.

* TestExpectations:
* fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode-expected.txt: Added.
* fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode.html: Added.
* platform/ios-simulator/TestExpectations:
* platform/ios/TestExpectations:

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

20 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode-expected.txt [new file with mode: 0644]
LayoutTests/fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode.html [new file with mode: 0644]
LayoutTests/platform/ios-simulator/TestExpectations
LayoutTests/platform/ios/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/DocumentLoader.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferences.yaml
Source/WebKit/Shared/WebsiteMediaSourcePolicy.h [new file with mode: 0644]
Source/WebKit/Shared/WebsitePoliciesData.cpp
Source/WebKit/Shared/WebsitePoliciesData.h
Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp
Source/WebKit/UIProcess/API/APIWebsitePolicies.h
Source/WebKit/UIProcess/Cocoa/NavigationState.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/WebKit.xcodeproj/project.pbxproj

index 4ca18b0..c5fa31e 100644 (file)
@@ -1,3 +1,19 @@
+2019-04-11  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Allow the MediaSource API to be enabled via website policy
+        https://bugs.webkit.org/show_bug.cgi?id=196429
+        <rdar://problem/48774333>
+
+        Reviewed by Tim Horton.
+
+        Add an on-device layout test to ensure that enabling modern compability mode also enables MSE.
+
+        * TestExpectations:
+        * fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode-expected.txt: Added.
+        * fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode.html: Added.
+        * platform/ios-simulator/TestExpectations:
+        * platform/ios/TestExpectations:
+
 2019-04-11  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: Timelines: can't reliably stop/start a recording
index fc11adc..7ec0844 100644 (file)
@@ -57,6 +57,7 @@ editing/images [ Skip ]
 pointerevents/ios [ Skip ]
 editing/pasteboard/ios [ Skip ]
 editing/pasteboard/mac [ Skip ]
+fast/media/ios [ Skip ]
 
 # WebKit2 only.
 printing/printing-events.html [ Skip ]
diff --git a/LayoutTests/fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode-expected.txt b/LayoutTests/fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode-expected.txt
new file mode 100644 (file)
index 0000000..f34d491
--- /dev/null
@@ -0,0 +1,11 @@
+This test verifies that the MediaSource API is enabled when enabling modern compatibility mode.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS 'MediaSource' in window is true
+PASS MediaSource.prototype is Object.getPrototypeOf(new MediaSource)
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode.html b/LayoutTests/fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode.html
new file mode 100644 (file)
index 0000000..7f67131
--- /dev/null
@@ -0,0 +1,15 @@
+<!-- webkit-test-runner [ shouldUseModernCompatibilityMode=true ] -->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src="../../../../resources/js-test.js"></script>
+</head>
+<body>
+<script>
+description("This test verifies that the MediaSource API is enabled when enabling modern compatibility mode.");
+shouldBe("'MediaSource' in window", "true");
+shouldBe("MediaSource.prototype", "Object.getPrototypeOf(new MediaSource)");
+</script>
+</body>
+</html>
index cc58d9a..76c5689 100644 (file)
@@ -13,6 +13,9 @@ fast/forms/search-vertical-alignment.html [ Skip ]
 fast/forms/searchfield-heights.html [ Skip ]
 fast/forms/visual-hebrew-text-field.html [ Skip ]
 
+# The MediaSource API is unsupported on iOS simulator.
+fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode.html [ Skip ]
+
 # -webkit-flex off-by-one px
 webkit.org/b/126898 css3/flexbox/image-percent-max-height.html [ ImageOnlyFailure ]
 
index 6bcd4cd..b5ed869 100644 (file)
@@ -13,6 +13,8 @@ media/ios [ Pass ]
 quicklook [ Pass ]
 swipe [ Pass ]
 
+fast/media/ios [ Pass ]
+
 fast/forms/textarea/ios [ Pass ]
 fast/text-autosizing/ios [ Pass ]
 fast/zooming/ios [ Pass ]
index 62e4a6b..fd5c8f9 100644 (file)
@@ -1,3 +1,26 @@
+2019-04-11  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Allow the MediaSource API to be enabled via website policy
+        https://bugs.webkit.org/show_bug.cgi?id=196429
+        <rdar://problem/48774333>
+
+        Reviewed by Tim Horton.
+
+        Add support in DocumentLoader for adjusting page settings using its per-site policies. See WebKit ChangeLog for
+        more detail (in particular, the implementation of applyToDocumentLoader).
+
+        Test: fast/media/ios/ipad/enable-MediaSource-API-in-modern-compatibility-mode.html
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::applyPoliciesToSettings const):
+        (WebCore::DocumentLoader::attachToFrame):
+        * loader/DocumentLoader.h:
+
+        Add an enum class for MediaSource policies; while we're at it, make all of these enum values 8 bits wide.
+
+        (WebCore::DocumentLoader::mediaSourcePolicy const):
+        (WebCore::DocumentLoader::setMediaSourcePolicy):
+
 2019-04-11  Youenn Fablet  <youenn@apple.com>
 
         Support RTCDataChannel blob binaryType
index 1b2e21d..16823aa 100644 (file)
@@ -1175,6 +1175,21 @@ void DocumentLoader::checkLoadComplete()
     m_frame->document()->domWindow()->finishedLoading();
 }
 
+void DocumentLoader::applyPoliciesToSettings()
+{
+    if (!m_frame) {
+        ASSERT_NOT_REACHED();
+        return;
+    }
+
+    if (!m_frame->isMainFrame())
+        return;
+
+#if ENABLE(MEDIA_SOURCE)
+    m_frame->settings().setMediaSourceEnabled(m_mediaSourcePolicy == MediaSourcePolicy::Default ? Settings::platformDefaultMediaSourceEnabled() : m_mediaSourcePolicy == MediaSourcePolicy::Enable);
+#endif
+}
+
 void DocumentLoader::attachToFrame(Frame& frame)
 {
     if (m_frame == &frame)
@@ -1188,6 +1203,8 @@ void DocumentLoader::attachToFrame(Frame& frame)
 #ifndef NDEBUG
     m_hasEverBeenAttached = true;
 #endif
+
+    applyPoliciesToSettings();
 }
 
 void DocumentLoader::attachToFrame()
index df6a2da..2c04ffe 100644 (file)
@@ -92,32 +92,38 @@ enum class ShouldContinue;
 
 using ResourceLoaderMap = HashMap<unsigned long, RefPtr<ResourceLoader>>;
 
-enum class AutoplayPolicy {
+enum class AutoplayPolicy : uint8_t {
     Default, // Uses policies specified in document settings.
     Allow,
     AllowWithoutSound,
     Deny,
 };
 
-enum class AutoplayQuirk {
+enum class AutoplayQuirk : uint8_t {
     SynthesizedPauseEvents = 1 << 0,
     InheritedUserGestures = 1 << 1,
     ArbitraryUserGestures = 1 << 2,
     PerDocumentAutoplayBehavior = 1 << 3,
 };
 
-enum class PopUpPolicy {
+enum class PopUpPolicy : uint8_t {
     Default, // Uses policies specified in frame settings.
     Allow,
     Block,
 };
 
-enum class MetaViewportPolicy {
+enum class MetaViewportPolicy : uint8_t {
     Default,
     Respect,
     Ignore,
 };
 
+enum class MediaSourcePolicy : uint8_t {
+    Default,
+    Disable,
+    Enable
+};
+
 class DocumentLoader
     : public RefCounted<DocumentLoader>
     , public FrameDestructionObserver
@@ -292,6 +298,9 @@ public:
     MetaViewportPolicy metaViewportPolicy() const { return m_metaViewportPolicy; }
     void setMetaViewportPolicy(MetaViewportPolicy policy) { m_metaViewportPolicy = policy; }
 
+    MediaSourcePolicy mediaSourcePolicy() const { return m_mediaSourcePolicy; }
+    void setMediaSourcePolicy(MediaSourcePolicy policy) { m_mediaSourcePolicy = policy; }
+
     void addSubresourceLoader(ResourceLoader*);
     void removeSubresourceLoader(LoadCompletionType, ResourceLoader*);
     void addPlugInStreamLoader(ResourceLoader&);
@@ -359,6 +368,8 @@ public:
     void setDownloadAttribute(const String& attribute) { m_downloadAttribute = attribute; }
     const String& downloadAttribute() const { return m_downloadAttribute; }
 
+    WEBCORE_EXPORT void applyPoliciesToSettings();
+
 protected:
     WEBCORE_EXPORT DocumentLoader(const ResourceRequest&, const SubstituteData&);
 
@@ -569,6 +580,7 @@ private:
     OptionSet<AutoplayQuirk> m_allowedAutoplayQuirks;
     PopUpPolicy m_popUpPolicy { PopUpPolicy::Default };
     MetaViewportPolicy m_metaViewportPolicy { MetaViewportPolicy::Default };
+    MediaSourcePolicy m_mediaSourcePolicy { MediaSourcePolicy::Default };
 
 #if ENABLE(SERVICE_WORKER)
     Optional<ServiceWorkerRegistrationData> m_serviceWorkerRegistrationData;
index c0f0e92..453e0ef 100644 (file)
@@ -1,3 +1,62 @@
+2019-04-11  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Allow the MediaSource API to be enabled via website policy
+        https://bugs.webkit.org/show_bug.cgi?id=196429
+        <rdar://problem/48774333>
+
+        Reviewed by Tim Horton.
+
+        Adds support for using WebsitePolicies to determine whether to enable the MediaSource API.
+
+        * Shared/WebPreferences.yaml:
+
+        Disengage the mediaSourceEnabled internal preference from the corresponding WebCore setting; to ensure that
+        setting the preference to `true` still results in enabling the MediaSource API, we instead make it such that
+        turning on mediaSourceEnabled causes WebsitePolicies to set its WebsiteMediaSourcePolicy to Enable.
+
+        In the future, we should deprecate and remove this preference, in favor of simply setting preferred
+        compatibility mode on WKWebpagePreferences.
+
+        * Shared/WebPreferences.yaml:
+        * Shared/WebsiteMediaSourcePolicy.h: Copied from Source/WebKit/Shared/WebsitePoliciesData.h.
+        * Shared/WebsitePoliciesData.cpp:
+        (WebKit::WebsitePoliciesData::encode const):
+        (WebKit::WebsitePoliciesData::decode):
+
+        Add plumbing for m_mediaSourcePolicy in the set of website policies.
+
+        (WebKit::WebsitePoliciesData::applyToDocumentLoader):
+
+        Update the document loader with the given media source policy. There are two possibilities when applying the set
+        of policies to the document loader; either the document loader is already attached to a Frame, or the document
+        loader is yet to be attached to a Frame.
+
+        In the first case, we update Frame's settings on the spot, by calling the new applyPoliciesToSettings helper
+        method. In the second scenario, we stash the policy state on DocumentLoader; when the DocumentLoader is attached
+        to a Frame, we'll then update the Frame's settings using DocumentLoader's policy.
+
+        * Shared/WebsitePoliciesData.h:
+        * UIProcess/API/APIWebsitePolicies.cpp:
+        (API::WebsitePolicies::data):
+        * UIProcess/API/APIWebsitePolicies.h:
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageNavigationClient):
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):
+
+        Move code that adjusts website policies after deciding policies for the navigation action from NavigationClient
+        ::decidePolicyForNavigationAction to the completion handler of the policy listener. This allows us to respect
+        default website policies on the web view configuration, even when using the C API to set the navigation client,
+        and also allows us to have a single call site for adjustPoliciesForCompatibilityMode. This also enables our
+        layout tests to opt into modern compatibility mode by default, when specifying modern compatibility mode on
+        webpage preferences.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::decidePolicyForNavigationAction):
+        (WebKit::WebPageProxy::adjustPoliciesForCompatibilityMode):
+        * UIProcess/WebPageProxy.h:
+        * WebKit.xcodeproj/project.pbxproj:
+
 2019-04-11  Antti Koivisto  <antti@apple.com>
 
         REGRESSION: changing iPad orientation on blogger.com crashes under RemoteScrollingCoordinatorProxy::establishLayerTreeScrollingRelations()
index 2c9e0f2..2a56f89 100644 (file)
@@ -590,6 +590,7 @@ MediaSourceEnabled:
   type: bool
   defaultValue: WebCore::Settings::platformDefaultMediaSourceEnabled()
   condition: ENABLE(MEDIA_SOURCE)
+  webcoreBinding: none
 
 ViewGestureDebuggingEnabled:
   type: bool
diff --git a/Source/WebKit/Shared/WebsiteMediaSourcePolicy.h b/Source/WebKit/Shared/WebsiteMediaSourcePolicy.h
new file mode 100644 (file)
index 0000000..5233413
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#pragma once
+
+#include <wtf/Forward.h>
+
+namespace WebKit {
+
+enum class WebsiteMediaSourcePolicy : uint8_t {
+    Default,
+    Disable,
+    Enable
+};
+
+} // namespace WebKit
+
+namespace WTF {
+
+template<> struct EnumTraits<WebKit::WebsiteMediaSourcePolicy> {
+    using values = EnumValues<
+        WebKit::WebsiteMediaSourcePolicy,
+        WebKit::WebsiteMediaSourcePolicy::Default,
+        WebKit::WebsiteMediaSourcePolicy::Disable,
+        WebKit::WebsiteMediaSourcePolicy::Enable
+    >;
+};
+
+} // namespace WTF
index 4aefaca..f522050 100644 (file)
@@ -47,6 +47,7 @@ void WebsitePoliciesData::encode(IPC::Encoder& encoder) const
     encoder << customJavaScriptUserAgentAsSiteSpecificQuirks;
     encoder << customNavigatorPlatform;
     encoder << metaViewportPolicy;
+    encoder << mediaSourcePolicy;
 }
 
 Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder)
@@ -105,6 +106,11 @@ Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder)
     decoder >> metaViewportPolicy;
     if (!metaViewportPolicy)
         return WTF::nullopt;
+
+    Optional<WebsiteMediaSourcePolicy> mediaSourcePolicy;
+    decoder >> mediaSourcePolicy;
+    if (!mediaSourcePolicy)
+        return WTF::nullopt;
     
     return { {
         WTFMove(*contentBlockersEnabled),
@@ -118,6 +124,7 @@ Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder)
         WTFMove(*customJavaScriptUserAgentAsSiteSpecificQuirks),
         WTFMove(*customNavigatorPlatform),
         WTFMove(*metaViewportPolicy),
+        WTFMove(*mediaSourcePolicy),
     } };
 }
 
@@ -189,12 +196,30 @@ void WebsitePoliciesData::applyToDocumentLoader(WebsitePoliciesData&& websitePol
         break;
     }
 
-    if (websitePolicies.websiteDataStoreParameters) {
-        if (auto* frame = documentLoader.frame()) {
-            if (auto* page = frame->page())
-                page->setSessionID(websitePolicies.websiteDataStoreParameters->networkSessionParameters.sessionID);
-        }
+    switch (websitePolicies.mediaSourcePolicy) {
+    case WebsiteMediaSourcePolicy::Default:
+        documentLoader.setMediaSourcePolicy(WebCore::MediaSourcePolicy::Default);
+        break;
+    case WebsiteMediaSourcePolicy::Disable:
+        documentLoader.setMediaSourcePolicy(WebCore::MediaSourcePolicy::Disable);
+        break;
+    case WebsiteMediaSourcePolicy::Enable:
+        documentLoader.setMediaSourcePolicy(WebCore::MediaSourcePolicy::Enable);
+        break;
     }
+
+    auto* frame = documentLoader.frame();
+    if (!frame)
+        return;
+
+    documentLoader.applyPoliciesToSettings();
+
+    auto* page = frame->page();
+    if (!page)
+        return;
+
+    if (websitePolicies.websiteDataStoreParameters)
+        page->setSessionID(websitePolicies.websiteDataStoreParameters->networkSessionParameters.sessionID);
 }
 
 }
index 1911edd..39881b2 100644 (file)
@@ -28,6 +28,7 @@
 #include "WebsiteAutoplayPolicy.h"
 #include "WebsiteAutoplayQuirk.h"
 #include "WebsiteDataStoreParameters.h"
+#include "WebsiteMediaSourcePolicy.h"
 #include "WebsiteMetaViewportPolicy.h"
 #include "WebsitePopUpPolicy.h"
 #include <WebCore/HTTPHeaderField.h>
@@ -58,6 +59,7 @@ struct WebsitePoliciesData {
     String customJavaScriptUserAgentAsSiteSpecificQuirks;
     String customNavigatorPlatform;
     WebsiteMetaViewportPolicy metaViewportPolicy { WebsiteMetaViewportPolicy::Default };
+    WebsiteMediaSourcePolicy mediaSourcePolicy { WebsiteMediaSourcePolicy::Default };
 
     void encode(IPC::Encoder&) const;
     static Optional<WebsitePoliciesData> decode(IPC::Decoder&);
index b897469..4d91058 100644 (file)
@@ -87,6 +87,7 @@ WebKit::WebsitePoliciesData WebsitePolicies::data()
         m_customJavaScriptUserAgentAsSiteSpecificQuirks,
         m_customNavigatorPlatform,
         m_metaViewportPolicy,
+        m_mediaSourcePolicy
     };
 }
 
index 2ac80e4..bcd1889 100644 (file)
@@ -29,6 +29,7 @@
 #include "WebCompatibilityMode.h"
 #include "WebsiteAutoplayPolicy.h"
 #include "WebsiteAutoplayQuirk.h"
+#include "WebsiteMediaSourcePolicy.h"
 #include "WebsiteMetaViewportPolicy.h"
 #include "WebsitePopUpPolicy.h"
 #include <WebCore/HTTPHeaderField.h>
@@ -90,6 +91,9 @@ public:
     WebKit::WebsiteMetaViewportPolicy metaViewportPolicy() const { return m_metaViewportPolicy; }
     void setMetaViewportPolicy(WebKit::WebsiteMetaViewportPolicy policy) { m_metaViewportPolicy = policy; }
 
+    WebKit::WebsiteMediaSourcePolicy mediaSourcePolicy() const { return m_mediaSourcePolicy; }
+    void setMediaSourcePolicy(WebKit::WebsiteMediaSourcePolicy policy) { m_mediaSourcePolicy = policy; }
+
 private:
     WebsitePolicies(bool contentBlockersEnabled, OptionSet<WebKit::WebsiteAutoplayQuirk>, WebKit::WebsiteAutoplayPolicy, Vector<WebCore::HTTPHeaderField>&&, WebKit::WebsitePopUpPolicy, RefPtr<WebsiteDataStore>&&);
 
@@ -105,6 +109,7 @@ private:
     WTF::String m_customNavigatorPlatform;
     WebKit::WebCompatibilityMode m_preferredCompatibilityMode { WebKit::WebCompatibilityMode::Default };
     WebKit::WebsiteMetaViewportPolicy m_metaViewportPolicy { WebKit::WebsiteMetaViewportPolicy::Default };
+    WebKit::WebsiteMediaSourcePolicy m_mediaSourcePolicy { WebKit::WebsiteMediaSourcePolicy::Default };
 };
 
 } // namespace API
index bff649f..b53ada5 100644 (file)
@@ -525,9 +525,6 @@ void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
                 return;
             }
 
-            if (defaultWebsitePolicies)
-                webPage->adjustPoliciesForCompatibilityMode(navigationAction, *defaultWebsitePolicies);
-
             if (!navigationAction->targetFrame()) {
                 listener->use(defaultWebsitePolicies.get());
                 return;
@@ -597,8 +594,6 @@ void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
                 [NSException raise:NSInvalidArgumentException format:@"WKWebpagePreferences._customUserAgent must be nil for subframe navigations."];
             if (!apiWebsitePolicies->customNavigatorPlatform().isNull() && subframeNavigation)
                 [NSException raise:NSInvalidArgumentException format:@"WKWebpagePreferences._customNavigatorPlatform must be nil for subframe navigations."];
-
-            webPageProxy->adjustPoliciesForCompatibilityMode(navigationAction, *apiWebsitePolicies);
         }
 
         switch (actionPolicy) {
index af8ef91..2214438 100644 (file)
@@ -4569,6 +4569,14 @@ void WebPageProxy::decidePolicyForNavigationAction(Ref<WebProcessProxy>&& proces
     auto listener = makeRef(frame.setUpPolicyListenerProxy([this, protectedThis = makeRef(*this), frame = makeRef(frame), sender = WTFMove(sender), navigation] (PolicyAction policyAction, API::WebsitePolicies* policies, ProcessSwapRequestedByClient processSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&& safeBrowsingWarning) mutable {
 
         auto completionHandler = [this, protectedThis = protectedThis.copyRef(), frame = frame.copyRef(), sender = WTFMove(sender), navigation = WTFMove(navigation), processSwapRequestedByClient, policies = makeRefPtr(policies)] (PolicyAction policyAction) mutable {
+            if (frame->isMainFrame()) {
+                if (!policies) {
+                    if (auto* defaultPolicies = m_configuration->defaultWebsitePolicies())
+                        policies = defaultPolicies->copy();
+                }
+                if (policies)
+                    adjustPoliciesForCompatibilityMode(*policies);
+            }
             receivedNavigationPolicyDecision(policyAction, navigation.get(), processSwapRequestedByClient, frame, policies.get(), WTFMove(sender));
         };
 
@@ -8912,7 +8920,7 @@ void WebPageProxy::speechSynthesisResume(CompletionHandler<void()>&& completionH
 
 #if !PLATFORM(IOS_FAMILY) || !USE(APPLE_INTERNAL_SDK)
 
-void WebPageProxy::adjustPoliciesForCompatibilityMode(const API::NavigationAction&, API::WebsitePolicies&)
+void WebPageProxy::adjustPoliciesForCompatibilityMode(API::WebsitePolicies&)
 {
 }
 
index 45b6308..9faa7fe 100644 (file)
@@ -1514,7 +1514,6 @@ public:
 #endif
 
     void configureLoggingChannel(const String&, WTFLogChannelState, WTFLogLevel);
-    void adjustPoliciesForCompatibilityMode(const API::NavigationAction&, API::WebsitePolicies&);
 
     void addObserver(WebViewDidMoveToWindowObserver&);
     void removeObserver(WebViewDidMoveToWindowObserver&);
@@ -1622,6 +1621,8 @@ private:
     void unableToImplementPolicy(uint64_t frameID, const WebCore::ResourceError&, const UserData&);
     void beginSafeBrowsingCheck(const URL&, bool, WebFramePolicyListenerProxy&);
 
+    void adjustPoliciesForCompatibilityMode(API::WebsitePolicies&);
+
     void willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const Vector<std::pair<String, String>>& textFieldValues, uint64_t listenerID, const UserData&);
 
     void contentRuleListNotification(URL&&, WebCore::ContentRuleListResults&&);
index e530b38..72aa455 100644 (file)
                F44DFEB21E9E752F0038D196 /* WebIconUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = F44DFEB01E9E752F0038D196 /* WebIconUtilities.h */; };
                F48D2A8521583A7E00C6752B /* AppKitSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = F48D2A8421583A0200C6752B /* AppKitSPI.h */; };
                F496A4311F58A272004C1757 /* DragDropInteractionState.h in Headers */ = {isa = PBXBuildFile; fileRef = F496A42F1F58A272004C1757 /* DragDropInteractionState.h */; };
+               F4CB09E5225D5A0900891487 /* WebsiteMediaSourcePolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = F4CB09E4225D5A0300891487 /* WebsiteMediaSourcePolicy.h */; };
                F4D5F51D206087A10038BBA8 /* WKTextInputListViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = F4D5F519206087A00038BBA8 /* WKTextInputListViewController.h */; };
                F4D5F51F206087A10038BBA8 /* WKQuickboardListViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = F4D5F51B206087A10038BBA8 /* WKQuickboardListViewController.h */; };
                F6113E25126CE1820057D0A7 /* APIUserContentURLPattern.h in Headers */ = {isa = PBXBuildFile; fileRef = F6113E24126CE1820057D0A7 /* APIUserContentURLPattern.h */; };
                F496A42F1F58A272004C1757 /* DragDropInteractionState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DragDropInteractionState.h; path = ios/DragDropInteractionState.h; sourceTree = "<group>"; };
                F496A4301F58A272004C1757 /* DragDropInteractionState.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = DragDropInteractionState.mm; path = ios/DragDropInteractionState.mm; sourceTree = "<group>"; };
                F4B378D021DDBBAB0095A378 /* WebUndoStepID.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebUndoStepID.h; sourceTree = "<group>"; };
+               F4CB09E4225D5A0300891487 /* WebsiteMediaSourcePolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebsiteMediaSourcePolicy.h; sourceTree = "<group>"; };
                F4D5F519206087A00038BBA8 /* WKTextInputListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKTextInputListViewController.h; path = ios/forms/WKTextInputListViewController.h; sourceTree = "<group>"; };
                F4D5F51A206087A10038BBA8 /* WKTextInputListViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKTextInputListViewController.mm; path = ios/forms/WKTextInputListViewController.mm; sourceTree = "<group>"; };
                F4D5F51B206087A10038BBA8 /* WKQuickboardListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKQuickboardListViewController.h; path = ios/forms/WKQuickboardListViewController.h; sourceTree = "<group>"; };
                                5C8DD3811FE455CA00F2A556 /* WebsiteAutoplayQuirk.h */,
                                511F7D3F1EB1BCEE00E47B83 /* WebsiteDataStoreParameters.cpp */,
                                511F7D401EB1BCEE00E47B83 /* WebsiteDataStoreParameters.h */,
+                               F4CB09E4225D5A0300891487 /* WebsiteMediaSourcePolicy.h */,
+                               F430E941224732A9005FE053 /* WebsiteMetaViewportPolicy.h */,
                                5C3AEA8E1FE1F1DF002318D3 /* WebsitePoliciesData.cpp */,
                                5C13024A1FE341A7000D9B31 /* WebsitePoliciesData.h */,
-                               F430E941224732A9005FE053 /* WebsiteMetaViewportPolicy.h */,
                                0EDE85022004E74900030560 /* WebsitePopUpPolicy.h */,
                                8360349D1ACB34D600626549 /* WebSQLiteDatabaseTracker.cpp */,
                                8360349E1ACB34D600626549 /* WebSQLiteDatabaseTracker.h */,
                                1A4832D11A9BDC2F008B4DFE /* WebsiteDataRecord.h in Headers */,
                                1A53C2AA1A325730004E8C70 /* WebsiteDataStore.h in Headers */,
                                511F7D411EB1BCF500E47B83 /* WebsiteDataStoreParameters.h in Headers */,
+                               F4CB09E5225D5A0900891487 /* WebsiteMediaSourcePolicy.h in Headers */,
+                               F430E9422247335F005FE053 /* WebsiteMetaViewportPolicy.h in Headers */,
                                0EDE85032004E75D00030560 /* WebsitePopUpPolicy.h in Headers */,
                                C149380922347104000CD707 /* WebSpeechSynthesisClient.h in Headers */,
                                836034A01ACB34D600626549 /* WebSQLiteDatabaseTracker.h in Headers */,
                                BC4075F8124FF0270068F20A /* WKData.h in Headers */,
                                37A709A71E3EA0FD00CA5969 /* WKDataDetectorTypes.h in Headers */,
                                37A709A91E3EA40C00CA5969 /* WKDataDetectorTypesInternal.h in Headers */,
-                               F430E9422247335F005FE053 /* WebsiteMetaViewportPolicy.h in Headers */,
                                2E94FC1620351A6D00974BA0 /* WKDatePickerViewController.h in Headers */,
                                377EAD4517E2C51A002D193D /* WKDeclarationSpecifiers.h in Headers */,
                                5C359C0D2154739F009E7948 /* WKDeprecated.h in Headers */,