Commit 2be19469 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

Fix trailer autoplay

Grant Kaleidoscope and it's subframes autoplay by
default.

Change-Id: I9e6a382173bc81dfd9ace1d024977eeefe03e612
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441801
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812776}
parent 7cb3d0fd
...@@ -13,6 +13,12 @@ ...@@ -13,6 +13,12 @@
namespace { namespace {
const url::Origin& KaleidoscopeOrigin() { const url::Origin& KaleidoscopeOrigin() {
static base::NoDestructor<url::Origin> origin(
url::Origin::Create(GURL(kKaleidoscopeUIURL)));
return *origin;
}
const url::Origin& KaleidoscopeUntrustedOrigin() {
static base::NoDestructor<url::Origin> origin( static base::NoDestructor<url::Origin> origin(
url::Origin::Create(GURL(kKaleidoscopeUntrustedContentUIURL))); url::Origin::Create(GURL(kKaleidoscopeUntrustedContentUIURL)));
return *origin; return *origin;
...@@ -28,6 +34,27 @@ enum class KaleidoscopeNavigation { ...@@ -28,6 +34,27 @@ enum class KaleidoscopeNavigation {
kMaxValue = kNormal, kMaxValue = kNormal,
}; };
bool IsOpenedFromKaleidoscope(content::NavigationHandle* handle) {
return (handle->GetInitiatorOrigin() &&
handle->GetInitiatorOrigin()->IsSameOriginWith(
KaleidoscopeUntrustedOrigin()));
}
bool ShouldAllowAutoplay(content::NavigationHandle* handle) {
// If the initiating origin is Kaleidoscope then we should allow autoplay.
if (IsOpenedFromKaleidoscope(handle))
return true;
// If the tab is Kaleidoscope then we should allow autoplay.
auto parent_origin =
url::Origin::Create(handle->GetWebContents()->GetLastCommittedURL());
if (parent_origin.IsSameOriginWith(KaleidoscopeOrigin())) {
return true;
}
return false;
}
} // namespace } // namespace
KaleidoscopeTabHelper::KaleidoscopeTabHelper(content::WebContents* web_contents) KaleidoscopeTabHelper::KaleidoscopeTabHelper(content::WebContents* web_contents)
...@@ -37,15 +64,11 @@ KaleidoscopeTabHelper::~KaleidoscopeTabHelper() = default; ...@@ -37,15 +64,11 @@ KaleidoscopeTabHelper::~KaleidoscopeTabHelper() = default;
void KaleidoscopeTabHelper::ReadyToCommitNavigation( void KaleidoscopeTabHelper::ReadyToCommitNavigation(
content::NavigationHandle* handle) { content::NavigationHandle* handle) {
if (!handle->IsInMainFrame() || handle->IsSameDocument() || if (handle->IsSameDocument() || handle->IsErrorPage())
handle->IsErrorPage()) {
return; return;
}
if (!handle->GetInitiatorOrigin() || if (!ShouldAllowAutoplay(handle))
!handle->GetInitiatorOrigin()->IsSameOriginWith(KaleidoscopeOrigin())) {
return; return;
}
mojo::AssociatedRemote<blink::mojom::AutoplayConfigurationClient> client; mojo::AssociatedRemote<blink::mojom::AutoplayConfigurationClient> client;
handle->GetRenderFrameHost()->GetRemoteAssociatedInterfaces()->GetInterface( handle->GetRenderFrameHost()->GetRemoteAssociatedInterfaces()->GetInterface(
...@@ -53,8 +76,11 @@ void KaleidoscopeTabHelper::ReadyToCommitNavigation( ...@@ -53,8 +76,11 @@ void KaleidoscopeTabHelper::ReadyToCommitNavigation(
client->AddAutoplayFlags(url::Origin::Create(handle->GetURL()), client->AddAutoplayFlags(url::Origin::Create(handle->GetURL()),
blink::mojom::kAutoplayFlagUserException); blink::mojom::kAutoplayFlagUserException);
// Only record metrics if this page was opened by Kaleidoscope.
if (IsOpenedFromKaleidoscope(handle)) {
base::UmaHistogramEnumeration(kKaleidoscopeNavigationHistogramName, base::UmaHistogramEnumeration(kKaleidoscopeNavigationHistogramName,
KaleidoscopeNavigation::kNormal); KaleidoscopeNavigation::kNormal);
}
} }
WEB_CONTENTS_USER_DATA_KEY_IMPL(KaleidoscopeTabHelper) WEB_CONTENTS_USER_DATA_KEY_IMPL(KaleidoscopeTabHelper)
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