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

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: 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 case WebMediaPlayer::PreloadMetaData: 275 case WebMediaPlayer::PreloadMetaData:
276 return "metadata"; 276 return "metadata";
277 case WebMediaPlayer::PreloadAuto: 277 case WebMediaPlayer::PreloadAuto:
278 return "auto"; 278 return "auto";
279 } 279 }
280 280
281 NOTREACHED(); 281 NOTREACHED();
282 return String(); 282 return String();
283 } 283 }
284 284
285 bool isCrossOrigin(Document& document) {
286 const LocalFrame* frame = document.frame();
287 return frame && frame->isCrossOriginSubframe();
288 }
289
285 } // anonymous namespace 290 } // anonymous namespace
286 291
287 class HTMLMediaElement::AutoplayHelperClientImpl 292 class HTMLMediaElement::AutoplayHelperClientImpl
288 : public AutoplayExperimentHelper::Client { 293 : public AutoplayExperimentHelper::Client {
289 public: 294 public:
290 static AutoplayHelperClientImpl* create(HTMLMediaElement* element) { 295 static AutoplayHelperClientImpl* create(HTMLMediaElement* element) {
291 return new AutoplayHelperClientImpl(element); 296 return new AutoplayHelperClientImpl(element);
292 } 297 }
293 298
294 virtual ~AutoplayHelperClientImpl(); 299 virtual ~AutoplayHelperClientImpl();
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 m_remotePlaybackClient(nullptr), 469 m_remotePlaybackClient(nullptr),
465 m_autoplayVisibilityObserver(nullptr) { 470 m_autoplayVisibilityObserver(nullptr) {
466 ThreadState::current()->registerPreFinalizer(this); 471 ThreadState::current()->registerPreFinalizer(this);
467 472
468 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")"; 473 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")";
469 474
470 // If any experiment is enabled, then we want to enable a user gesture by 475 // If any experiment is enabled, then we want to enable a user gesture by
471 // default, otherwise the experiment does nothing. 476 // default, otherwise the experiment does nothing.
472 if ((document.settings() && 477 if ((document.settings() &&
473 document.settings()->mediaPlaybackRequiresUserGesture()) || 478 document.settings()->mediaPlaybackRequiresUserGesture()) ||
479 (document.settings() && isCrossOrigin(document) &&
whywhat 2016/11/16 17:37:17 is it this that you don't like? you could've had a
Zhiqiang Zhang (Slow) 2016/11/16 18:11:40 Already merged them into a helper function in my l
480 document.settings()
481 ->mediaPlaybackInCrossOriginIframesRequiresUserGesture()) ||
474 m_autoplayHelper->isExperimentEnabled()) { 482 m_autoplayHelper->isExperimentEnabled()) {
475 m_lockedPendingUserGesture = true; 483 m_lockedPendingUserGesture = true;
476 } 484 }
477 485
478 LocalFrame* frame = document.frame(); 486 LocalFrame* frame = document.frame();
479 if (frame) { 487 if (frame) {
480 m_remotePlaybackClient = 488 m_remotePlaybackClient =
481 frame->loader().client()->createWebRemotePlaybackClient(*this); 489 frame->loader().client()->createWebRemotePlaybackClient(*this);
482 } 490 }
483 491
(...skipping 28 matching lines...) Expand all
512 520
513 void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) { 521 void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) {
514 BLINK_MEDIA_LOG << "didMoveToNewDocument(" << (void*)this << ")"; 522 BLINK_MEDIA_LOG << "didMoveToNewDocument(" << (void*)this << ")";
515 523
516 m_autoplayUmaHelper->didMoveToNewDocument(oldDocument); 524 m_autoplayUmaHelper->didMoveToNewDocument(oldDocument);
517 // If any experiment is enabled, then we want to enable a user gesture by 525 // If any experiment is enabled, then we want to enable a user gesture by
518 // default, otherwise the experiment does nothing. 526 // default, otherwise the experiment does nothing.
519 bool oldDocumentRequiresUserGesture = 527 bool oldDocumentRequiresUserGesture =
520 (oldDocument.settings() && 528 (oldDocument.settings() &&
521 oldDocument.settings()->mediaPlaybackRequiresUserGesture()) || 529 oldDocument.settings()->mediaPlaybackRequiresUserGesture()) ||
530 (oldDocument.settings() && isCrossOrigin(oldDocument) &&
531 oldDocument.settings()
532 ->mediaPlaybackInCrossOriginIframesRequiresUserGesture()) ||
522 m_autoplayHelper->isExperimentEnabled(); 533 m_autoplayHelper->isExperimentEnabled();
523 bool newDocumentRequiresUserGesture = 534 bool newDocumentRequiresUserGesture =
524 (document().settings() && 535 (document().settings() &&
525 document().settings()->mediaPlaybackRequiresUserGesture()) || 536 document().settings()->mediaPlaybackRequiresUserGesture()) ||
537 (document().settings() && isCrossOrigin(oldDocument) &&
538 document()
539 .settings()
540 ->mediaPlaybackInCrossOriginIframesRequiresUserGesture()) ||
526 m_autoplayHelper->isExperimentEnabled(); 541 m_autoplayHelper->isExperimentEnabled();
527 if (newDocumentRequiresUserGesture && !oldDocumentRequiresUserGesture) { 542 if (newDocumentRequiresUserGesture && !oldDocumentRequiresUserGesture) {
528 m_lockedPendingUserGesture = true; 543 m_lockedPendingUserGesture = true;
529 } 544 }
530 545
531 if (m_shouldDelayLoadEvent) { 546 if (m_shouldDelayLoadEvent) {
532 document().incrementLoadEventDelayCount(); 547 document().incrementLoadEventDelayCount();
533 // Note: Keeping the load event delay count increment on oldDocument that 548 // Note: Keeping the load event delay count increment on oldDocument that
534 // was added when m_shouldDelayLoadEvent was set so that destruction of 549 // was added when m_shouldDelayLoadEvent was set so that destruction of
535 // m_webMediaPlayer can not cause load event dispatching in oldDocument. 550 // m_webMediaPlayer can not cause load event dispatching in oldDocument.
(...skipping 3653 matching lines...) Expand 10 before | Expand all | Expand 10 after
4189 4204
4190 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() 4205 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect()
4191 const { 4206 const {
4192 IntRect result; 4207 IntRect result;
4193 if (LayoutObject* object = m_element->layoutObject()) 4208 if (LayoutObject* object = m_element->layoutObject())
4194 result = object->absoluteBoundingBoxRect(); 4209 result = object->absoluteBoundingBoxRect();
4195 return result; 4210 return result;
4196 } 4211 }
4197 4212
4198 } // namespace blink 4213 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/Settings.in ('k') | third_party/WebKit/Source/web/WebSettingsImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698