Commit 291c9617 authored by Sean Topping's avatar Sean Topping Committed by Commit Bot

[Chromecast] Enable main frame autoplay delegation

This forces autoplay on for all main frames, and turns on the autoplay
delegation mechanism via <iframe allow="autoplay" />. This turns off the
previous behavior of unconditionally allowing autoplay on all pages and
frames.

Bug: internal b/160651728
Test: Launch AMP Viewer via web sender, verify only the screen reader is
      active while videos/ads remain paused.

Change-Id: If570ca3911596bf27bcceb56360fad674a9236c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2296360Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Sean Topping <seantopping@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789315}
parent d777232f
...@@ -61,6 +61,7 @@ include_rules = [ ...@@ -61,6 +61,7 @@ include_rules = [
"+services/service_manager/embedder", "+services/service_manager/embedder",
"+storage/browser/quota/quota_settings.h", "+storage/browser/quota/quota_settings.h",
"+third_party/blink/public/common", "+third_party/blink/public/common",
"+third_party/blink/public/mojom/autoplay",
"+third_party/blink/public/mojom/loader/resource_load_info.mojom.h", "+third_party/blink/public/mojom/loader/resource_load_info.mojom.h",
"+third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h", "+third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h",
"+third_party/blink/public/mojom/messaging", "+third_party/blink/public/mojom/messaging",
......
...@@ -345,9 +345,6 @@ const DefaultCommandLineSwitch kDefaultSwitches[] = { ...@@ -345,9 +345,6 @@ const DefaultCommandLineSwitch kDefaultSwitches[] = {
{switches::kEnableUseZoomForDSF, "false"}, {switches::kEnableUseZoomForDSF, "false"},
// TODO(halliwell): Revert after fix for b/63101386. // TODO(halliwell): Revert after fix for b/63101386.
{switches::kDisallowNonExactResourceReuse, ""}, {switches::kDisallowNonExactResourceReuse, ""},
// Enable autoplay without requiring any user gesture.
{switches::kAutoplayPolicy,
switches::autoplay::kNoUserGestureRequiredPolicy},
// Disable pinch zoom gesture. // Disable pinch zoom gesture.
{switches::kDisablePinch, ""}, {switches::kDisablePinch, ""},
}; };
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/mojom/autoplay/autoplay.mojom.h"
#include "third_party/blink/public/mojom/favicon/favicon_url.mojom.h" #include "third_party/blink/public/mojom/favicon/favicon_url.mojom.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom.h" #include "third_party/blink/public/mojom/loader/resource_load_info.mojom.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
...@@ -629,6 +630,26 @@ void CastWebContentsImpl::ReadyToCommitNavigation( ...@@ -629,6 +630,26 @@ void CastWebContentsImpl::ReadyToCommitNavigation(
DCHECK(navigation_handle); DCHECK(navigation_handle);
if (!web_contents_ || closing_ || stopped_) if (!web_contents_ || closing_ || stopped_)
return; return;
// We want to honor the autoplay feature policy (via allow="autoplay") without
// explicit user activation, since media on Cast is extremely likely to have
// already been explicitly requested by a user via voice or over the network.
// By spoofing the "high media engagement" signal, we can bypass the user
// gesture requirement for autoplay.
int32_t autoplay_flags = blink::mojom::kAutoplayFlagHighMediaEngagement;
// Main frames should have autoplay enabled by default, since autoplay
// delegation via parent frame doesn't work here.
if (navigation_handle->IsInMainFrame())
autoplay_flags |= blink::mojom::kAutoplayFlagForceAllow;
mojo::AssociatedRemote<blink::mojom::AutoplayConfigurationClient> client;
navigation_handle->GetRenderFrameHost()
->GetRemoteAssociatedInterfaces()
->GetInterface(&client);
auto autoplay_origin = url::Origin::Create(navigation_handle->GetURL());
client->AddAutoplayFlags(autoplay_origin, autoplay_flags);
if (!navigation_handle->IsInMainFrame()) if (!navigation_handle->IsInMainFrame())
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment