Bug 1472580 - Gesture activate documents which are played via the tab audio indicator. r=mconley draft
authorChris Pearce <cpearce@mozilla.com>
Wed, 04 Jul 2018 09:32:22 +1200
changeset 818504 a099cd3eedf6785a7af0b95613c5bd210e791a53
parent 817312 fe17acc6e291e54463db3ea82697c714ae5a4b27
child 818505 f6a97dcdbc12cb53d58be6e7fe19de7825755425
push id116278
push userbmo:cpearce@mozilla.com
push dateSun, 15 Jul 2018 03:47:02 +0000
reviewersmconley
bugs1472580, 1463919
milestone63.0a1
Bug 1472580 - Gesture activate documents which are played via the tab audio indicator. r=mconley (This patch was first presented for review in bug 1463919, I've split it off into its own bug here). If the user opens a tab in the background, and that tab tries to play media, we'll delay playing that media until the tab is brought to the foreground. But the user can explicitly start playback of such delayed media by clicking the "play" icon we show in the tab indicator. Then if autoplay is disabled, we'll block the play (unless the origin is whitelisted). This is bad, as the user has clearly indicated intent to play media in this tab. So this patch "gesture activates" the root content document when the tab audio indicator play button is pressed. This means the block autoplay logic will behave as if there's been a user gesture in the tab (mouse click or keypress), and not block the play. Gesture activation state is per document, so it does not persist across document loads. MozReview-Commit-ID: 3pgrADRrJqt *** fix
toolkit/content/browser-content.js
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -521,16 +521,21 @@ var AudioPlaybackListener = {
         break;
       case "mediaControlPaused":
         utils.mediaSuspend = suspendTypes.SUSPENDED_PAUSE_DISPOSABLE;
         break;
       case "mediaControlStopped":
         utils.mediaSuspend = suspendTypes.SUSPENDED_STOP_DISPOSABLE;
         break;
       case "resumeMedia":
+        // User has clicked the tab audio indicator to play a delayed
+        // media. That's clear user intent to play, so gesture activate
+        // the content document tree so that the block-autoplay logic
+        // allows the media to autoplay.
+        content.document.notifyUserGestureActivation();
         utils.mediaSuspend = suspendTypes.NONE_SUSPENDED;
         break;
       default:
         dump("Error : wrong media control msg!\n");
         break;
     }
   },