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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 case WebMediaPlayer::PreloadMetaData: 278 case WebMediaPlayer::PreloadMetaData:
279 return "metadata"; 279 return "metadata";
280 case WebMediaPlayer::PreloadAuto: 280 case WebMediaPlayer::PreloadAuto:
281 return "auto"; 281 return "auto";
282 } 282 }
283 283
284 NOTREACHED(); 284 NOTREACHED();
285 return String(); 285 return String();
286 } 286 }
287 287
288 bool isDocumentCrossOrigin(Document& document) {
289 const LocalFrame* frame = document.frame();
290 return frame && frame->isCrossOriginSubframe();
291 }
292
288 } // anonymous namespace 293 } // anonymous namespace
289 294
290 class HTMLMediaElement::AutoplayHelperClientImpl 295 class HTMLMediaElement::AutoplayHelperClientImpl
291 : public AutoplayExperimentHelper::Client { 296 : public AutoplayExperimentHelper::Client {
292 public: 297 public:
293 static AutoplayHelperClientImpl* create(HTMLMediaElement* element) { 298 static AutoplayHelperClientImpl* create(HTMLMediaElement* element) {
294 return new AutoplayHelperClientImpl(element); 299 return new AutoplayHelperClientImpl(element);
295 } 300 }
296 301
297 virtual ~AutoplayHelperClientImpl(); 302 virtual ~AutoplayHelperClientImpl();
(...skipping 25 matching lines...) Expand all
323 return m_element->isHTMLAudioElement(); 328 return m_element->isHTMLAudioElement();
324 } 329 }
325 330
326 // Document 331 // Document
327 bool isLegacyViewportType() override; 332 bool isLegacyViewportType() override;
328 PageVisibilityState pageVisibilityState() const override; 333 PageVisibilityState pageVisibilityState() const override;
329 String autoplayExperimentMode() const override; 334 String autoplayExperimentMode() const override;
330 335
331 // Frame 336 // Frame
332 bool isCrossOrigin() const override { 337 bool isCrossOrigin() const override {
333 const LocalFrame* frame = m_element->document().frame(); 338 return isDocumentCrossOrigin(m_element->document());
334 return frame && frame->isCrossOriginSubframe();
335 } 339 }
336 340
337 bool isAutoplayAllowedPerSettings() const override; 341 bool isAutoplayAllowedPerSettings() const override;
338 342
339 // LayoutObject 343 // LayoutObject
340 void setRequestPositionUpdates(bool) override; 344 void setRequestPositionUpdates(bool) override;
341 IntRect absoluteBoundingBoxRect() const override; 345 IntRect absoluteBoundingBoxRect() const override;
342 346
343 DEFINE_INLINE_VIRTUAL_TRACE() { 347 DEFINE_INLINE_VIRTUAL_TRACE() {
344 visitor->trace(m_element); 348 visitor->trace(m_element);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 m_autoplayHelperClient(AutoplayHelperClientImpl::create(this)), 466 m_autoplayHelperClient(AutoplayHelperClientImpl::create(this)),
463 m_autoplayHelper( 467 m_autoplayHelper(
464 AutoplayExperimentHelper::create(m_autoplayHelperClient.get())), 468 AutoplayExperimentHelper::create(m_autoplayHelperClient.get())),
465 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)), 469 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)),
466 m_remotePlaybackClient(nullptr), 470 m_remotePlaybackClient(nullptr),
467 m_autoplayVisibilityObserver(nullptr) { 471 m_autoplayVisibilityObserver(nullptr) {
468 ThreadState::current()->registerPreFinalizer(this); 472 ThreadState::current()->registerPreFinalizer(this);
469 473
470 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")"; 474 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")";
471 475
472 // If any experiment is enabled, then we want to enable a user gesture by 476 m_lockedPendingUserGesture = computeLockedPendingUserGesture(document);
473 // default, otherwise the experiment does nothing.
474 if ((document.settings() &&
475 document.settings()->mediaPlaybackRequiresUserGesture()) ||
476 m_autoplayHelper->isExperimentEnabled()) {
477 m_lockedPendingUserGesture = true;
478 }
479 477
480 LocalFrame* frame = document.frame(); 478 LocalFrame* frame = document.frame();
481 if (frame) { 479 if (frame) {
482 m_remotePlaybackClient = 480 m_remotePlaybackClient =
483 frame->loader().client()->createWebRemotePlaybackClient(*this); 481 frame->loader().client()->createWebRemotePlaybackClient(*this);
484 } 482 }
485 483
486 setHasCustomStyleCallbacks(); 484 setHasCustomStyleCallbacks();
487 addElementToDocumentMap(this, &document); 485 addElementToDocumentMap(this, &document);
488 486
(...skipping 23 matching lines...) Expand all
512 clearMediaPlayerAndAudioSourceProviderClientWithoutLocking(); 510 clearMediaPlayerAndAudioSourceProviderClientWithoutLocking();
513 } 511 }
514 512
515 void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) { 513 void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) {
516 BLINK_MEDIA_LOG << "didMoveToNewDocument(" << (void*)this << ")"; 514 BLINK_MEDIA_LOG << "didMoveToNewDocument(" << (void*)this << ")";
517 515
518 m_autoplayUmaHelper->didMoveToNewDocument(oldDocument); 516 m_autoplayUmaHelper->didMoveToNewDocument(oldDocument);
519 // If any experiment is enabled, then we want to enable a user gesture by 517 // If any experiment is enabled, then we want to enable a user gesture by
520 // default, otherwise the experiment does nothing. 518 // default, otherwise the experiment does nothing.
521 bool oldDocumentRequiresUserGesture = 519 bool oldDocumentRequiresUserGesture =
522 (oldDocument.settings() && 520 computeLockedPendingUserGesture(oldDocument);
523 oldDocument.settings()->mediaPlaybackRequiresUserGesture()) ||
524 m_autoplayHelper->isExperimentEnabled();
525 bool newDocumentRequiresUserGesture = 521 bool newDocumentRequiresUserGesture =
526 (document().settings() && 522 computeLockedPendingUserGesture(document());
527 document().settings()->mediaPlaybackRequiresUserGesture()) ||
528 m_autoplayHelper->isExperimentEnabled();
529 if (newDocumentRequiresUserGesture && !oldDocumentRequiresUserGesture) { 523 if (newDocumentRequiresUserGesture && !oldDocumentRequiresUserGesture) {
530 m_lockedPendingUserGesture = true; 524 m_lockedPendingUserGesture = true;
531 } 525 }
532 526
533 if (m_shouldDelayLoadEvent) { 527 if (m_shouldDelayLoadEvent) {
534 document().incrementLoadEventDelayCount(); 528 document().incrementLoadEventDelayCount();
535 // Note: Keeping the load event delay count increment on oldDocument that 529 // Note: Keeping the load event delay count increment on oldDocument that
536 // was added when m_shouldDelayLoadEvent was set so that destruction of 530 // was added when m_shouldDelayLoadEvent was set so that destruction of
537 // m_webMediaPlayer can not cause load event dispatching in oldDocument. 531 // m_webMediaPlayer can not cause load event dispatching in oldDocument.
538 } else { 532 } else {
(...skipping 3340 matching lines...) Expand 10 before | Expand all | Expand 10 after
3879 3873
3880 // Enable the first audio track if an audio track hasn't been enabled yet. 3874 // Enable the first audio track if an audio track hasn't been enabled yet.
3881 if (audioTracks().length() > 0 && !audioTracks().hasEnabledTrack()) 3875 if (audioTracks().length() > 0 && !audioTracks().hasEnabledTrack())
3882 audioTracks().anonymousIndexedGetter(0)->setEnabled(true); 3876 audioTracks().anonymousIndexedGetter(0)->setEnabled(true);
3883 3877
3884 // Select the first video track if a video track hasn't been selected yet. 3878 // Select the first video track if a video track hasn't been selected yet.
3885 if (videoTracks().length() > 0 && videoTracks().selectedIndex() == -1) 3879 if (videoTracks().length() > 0 && videoTracks().selectedIndex() == -1)
3886 videoTracks().anonymousIndexedGetter(0)->setSelected(true); 3880 videoTracks().anonymousIndexedGetter(0)->setSelected(true);
3887 } 3881 }
3888 3882
3883 bool HTMLMediaElement::computeLockedPendingUserGesture(
3884 Document& document) const {
3885 // TODO(zqzhang): deprecate AutoplayExperiment. See https://crbug.com/666370
3886 if (m_autoplayHelper->isExperimentEnabled())
3887 return true;
3888 if (!document.settings())
3889 return false;
3890
3891 if (document.settings()->crossOriginMediaPlaybackRequiresUserGesture() &&
3892 isDocumentCrossOrigin(document))
3893 return true;
3894
3895 return document.settings()->mediaPlaybackRequiresUserGesture();
3896 }
3897
3889 bool HTMLMediaElement::isLockedPendingUserGesture() const { 3898 bool HTMLMediaElement::isLockedPendingUserGesture() const {
3890 return m_lockedPendingUserGesture; 3899 return m_lockedPendingUserGesture;
3891 } 3900 }
3892 3901
3893 void HTMLMediaElement::unlockUserGesture() { 3902 void HTMLMediaElement::unlockUserGesture() {
3894 m_lockedPendingUserGesture = false; 3903 m_lockedPendingUserGesture = false;
3895 } 3904 }
3896 3905
3897 bool HTMLMediaElement::isGestureNeededForPlayback() const { 3906 bool HTMLMediaElement::isGestureNeededForPlayback() const {
3898 if (!m_lockedPendingUserGesture) 3907 if (!m_lockedPendingUserGesture)
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
4187 4196
4188 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() 4197 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect()
4189 const { 4198 const {
4190 IntRect result; 4199 IntRect result;
4191 if (LayoutObject* object = m_element->layoutObject()) 4200 if (LayoutObject* object = m_element->layoutObject())
4192 result = object->absoluteBoundingBoxRect(); 4201 result = object->absoluteBoundingBoxRect();
4193 return result; 4202 return result;
4194 } 4203 }
4195 4204
4196 } // namespace blink 4205 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698