Bug 1513681 - part1 : dispatch 'GloballyAutoplayBlocked' event when site is permanent blocked. r=cpearce,smaug
☠☠ backed out by 0c02d1f0db78 ☠ ☠
authoralwu <alwu@mozilla.com>
Tue, 18 Dec 2018 18:11:56 +0000
changeset 512072 23b5a58e3bcc
parent 512071 6c185cbc16ec
child 512073 d0a9422928ae
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, smaug
bugs1513681
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1513681 - part1 : dispatch 'GloballyAutoplayBlocked' event when site is permanent blocked. r=cpearce,smaug This event is used to notify tab that this site is permanently blocked and we should show the blocking icon for it. Patch2 will handle following details. Differential Revision: https://phabricator.services.mozilla.com/D14794
dom/base/nsDocument.cpp
dom/base/nsIDocument.h
dom/html/HTMLMediaElement.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -11745,16 +11745,32 @@ void nsIDocument::NotifyUserGestureActiv
   while (doc && !doc->mUserGestureActivated) {
     MOZ_LOG(gUserInteractionPRLog, LogLevel::Debug,
             ("Document %p has been activated by user.", this));
     doc->mUserGestureActivated = true;
     doc = doc->GetSameTypeParentDocument();
   }
 }
 
+void nsIDocument::MaybeNotifyAutoplayBlocked() {
+  nsIDocument* topLevelDoc = GetTopLevelContentDocument();
+  if (!topLevelDoc ||
+      !nsContentUtils::IsExactSitePermDeny(topLevelDoc->NodePrincipal(),
+          "autoplay-media")) {
+    return;
+  }
+
+  // This event is used to notify front-end side that we've blocked autoplay
+  // permanantly, so front-end side should show blocking icon as well.
+  RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
+      topLevelDoc, NS_LITERAL_STRING("GloballyAutoplayBlocked"),
+      CanBubble::eYes, ChromeOnlyDispatch::eYes);
+  asyncDispatcher->PostDOMEvent();
+}
+
 void nsIDocument::SetDocTreeHadAudibleMedia() {
   nsIDocument* topLevelDoc = GetTopLevelContentDocument();
   if (!topLevelDoc) {
     return;
   }
 
   if (!topLevelDoc->mDocTreeHadAudibleMedia) {
     RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -3385,16 +3385,20 @@ class nsIDocument : public nsINode,
    * element containing the subdocument containing aFrame, and/or find the
    * nearest non-anonymous ancestor in this document.
    * Returns null if there is no such element.
    */
   nsIContent* GetContentInThisDocument(nsIFrame* aFrame) const;
 
   void ReportShadowDOMUsage();
 
+  // When the doc is blocked permanantly, we would dispatch event to notify
+  // front-end side to show blocking icon.
+  void MaybeNotifyAutoplayBlocked();
+
   // Sets flags for media autoplay telemetry.
   void SetDocTreeHadAudibleMedia();
   void SetDocTreeHadPlayRevoked();
 
  protected:
   void DoUpdateSVGUseElementShadowTrees();
 
   already_AddRefed<nsIPrincipal> MaybeDowngradePrincipal(
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3692,16 +3692,17 @@ void HTMLMediaElement::DispatchEventsWhe
     DispatchAsyncEvent(NS_LITERAL_STRING("blocked"));
   }
 #if defined(MOZ_WIDGET_ANDROID)
   RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
       this, NS_LITERAL_STRING("MozAutoplayMediaBlocked"), CanBubble::eYes,
       ChromeOnlyDispatch::eYes);
   asyncDispatcher->PostDOMEvent();
 #endif
+  OwnerDoc()->MaybeNotifyAutoplayBlocked();
 }
 
 void HTMLMediaElement::PlayInternal(bool aHandlingUserInput) {
   if (mPreloadAction == HTMLMediaElement::PRELOAD_NONE) {
     // The media load algorithm will be initiated by a user interaction.
     // We want to boost the channel priority for better responsiveness.
     // Note this must be done before UpdatePreloadAction() which will
     // update |mPreloadAction|.