Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Unified Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2496593002: Adding an experimental flag to block autoplay with sound in cross-origin iframes (Closed)
Patch Set: falling back to adding a boolean flag Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
index a1f0ce6a74d593703d34135af4a59c9ecdc1652e..d9c1fa87fdb721cdc9931c54bc9d23704c609200 100644
--- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
@@ -285,6 +285,11 @@ String preloadTypeToString(WebMediaPlayer::Preload preloadType) {
return String();
}
+bool isDocumentCrossOrigin(Document& document) {
+ const LocalFrame* frame = document.frame();
+ return frame && frame->isCrossOriginSubframe();
+}
+
} // anonymous namespace
class HTMLMediaElement::AutoplayHelperClientImpl
@@ -330,8 +335,7 @@ class HTMLMediaElement::AutoplayHelperClientImpl
// Frame
bool isCrossOrigin() const override {
- const LocalFrame* frame = m_element->document().frame();
- return frame && frame->isCrossOriginSubframe();
+ return isDocumentCrossOrigin(m_element->document());
}
bool isAutoplayAllowedPerSettings() const override;
@@ -469,13 +473,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName,
BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")";
- // If any experiment is enabled, then we want to enable a user gesture by
- // default, otherwise the experiment does nothing.
- if ((document.settings() &&
- document.settings()->mediaPlaybackRequiresUserGesture()) ||
- m_autoplayHelper->isExperimentEnabled()) {
- m_lockedPendingUserGesture = true;
- }
+ m_lockedPendingUserGesture = computeLockedPendingUserGesture(document);
LocalFrame* frame = document.frame();
if (frame) {
@@ -519,13 +517,9 @@ void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) {
// If any experiment is enabled, then we want to enable a user gesture by
// default, otherwise the experiment does nothing.
bool oldDocumentRequiresUserGesture =
- (oldDocument.settings() &&
- oldDocument.settings()->mediaPlaybackRequiresUserGesture()) ||
- m_autoplayHelper->isExperimentEnabled();
+ computeLockedPendingUserGesture(oldDocument);
bool newDocumentRequiresUserGesture =
- (document().settings() &&
- document().settings()->mediaPlaybackRequiresUserGesture()) ||
- m_autoplayHelper->isExperimentEnabled();
+ computeLockedPendingUserGesture(document());
if (newDocumentRequiresUserGesture && !oldDocumentRequiresUserGesture) {
m_lockedPendingUserGesture = true;
}
@@ -3886,6 +3880,21 @@ void HTMLMediaElement::selectInitialTracksIfNecessary() {
videoTracks().anonymousIndexedGetter(0)->setSelected(true);
}
+bool HTMLMediaElement::computeLockedPendingUserGesture(
+ Document& document) const {
+ // TODO(zqzhang): deprecate AutoplayExperiment. See https://crbug.com/666370
+ if (m_autoplayHelper->isExperimentEnabled())
+ return true;
+ if (!document.settings())
+ return false;
+
+ if (document.settings()->crossOriginMediaPlaybackRequiresUserGesture() &&
+ isDocumentCrossOrigin(document))
+ return true;
+
+ return document.settings()->mediaPlaybackRequiresUserGesture();
+}
+
bool HTMLMediaElement::isLockedPendingUserGesture() const {
return m_lockedPendingUserGesture;
}

Powered by Google App Engine
This is Rietveld 408576698