Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.

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:


Canonical link: https://commits.webkit.org/211106@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244197 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed Apr 11, 2019
1 parent c9602b8 commit 4d54b76
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 18 deletions.
16 changes: 16 additions & 0 deletions LayoutTests/ChangeLog
@@ -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
Expand Down
1 change: 1 addition & 0 deletions LayoutTests/TestExpectations
Expand Up @@ -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 ]
Expand Down
@@ -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

@@ -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>
3 changes: 3 additions & 0 deletions LayoutTests/platform/ios-simulator/TestExpectations
Expand Up @@ -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 ]

Expand Down
2 changes: 2 additions & 0 deletions LayoutTests/platform/ios/TestExpectations
Expand Up @@ -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 ]
Expand Down
23 changes: 23 additions & 0 deletions Source/WebCore/ChangeLog
@@ -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
Expand Down
17 changes: 17 additions & 0 deletions Source/WebCore/loader/DocumentLoader.cpp
Expand Up @@ -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)
Expand All @@ -1188,6 +1203,8 @@ void DocumentLoader::attachToFrame(Frame& frame)
#ifndef NDEBUG
m_hasEverBeenAttached = true;
#endif

applyPoliciesToSettings();
}

void DocumentLoader::attachToFrame()
Expand Down
20 changes: 16 additions & 4 deletions Source/WebCore/loader/DocumentLoader.h
Expand Up @@ -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
Expand Down Expand Up @@ -292,6 +298,9 @@ class DocumentLoader
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&);
Expand Down Expand Up @@ -359,6 +368,8 @@ class DocumentLoader
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&);

Expand Down Expand Up @@ -569,6 +580,7 @@ class DocumentLoader
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;
Expand Down
59 changes: 59 additions & 0 deletions Source/WebKit/ChangeLog
@@ -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()
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/Shared/WebPreferences.yaml
Expand Up @@ -590,6 +590,7 @@ MediaSourceEnabled:
type: bool
defaultValue: WebCore::Settings::platformDefaultMediaSourceEnabled()
condition: ENABLE(MEDIA_SOURCE)
webcoreBinding: none

ViewGestureDebuggingEnabled:
type: bool
Expand Down
51 changes: 51 additions & 0 deletions Source/WebKit/Shared/WebsiteMediaSourcePolicy.h
@@ -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
35 changes: 30 additions & 5 deletions Source/WebKit/Shared/WebsitePoliciesData.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand All @@ -118,6 +124,7 @@ Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder)
WTFMove(*customJavaScriptUserAgentAsSiteSpecificQuirks),
WTFMove(*customNavigatorPlatform),
WTFMove(*metaViewportPolicy),
WTFMove(*mediaSourcePolicy),
} };
}

Expand Down Expand Up @@ -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);
}

}
Expand Down

0 comments on commit 4d54b76

Please sign in to comment.