Bug 1513681 - part1 : dispatch 'GloballyAutoplayBlocked' event when site is blocked r=cpearce,smaug
authorAlastor Wu <alwu@mozilla.com>
Fri, 04 Jan 2019 19:05:52 +0000
changeset 512606 9cb5b5f77ed8
parent 512605 763f3f9bc7c3
child 512607 d99f4d17ea92
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 blocked r=cpearce,smaug This event is used to notify tab that this site is 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/Document.cpp
dom/base/Document.h
dom/html/HTMLMediaElement.cpp
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -11733,16 +11733,30 @@ void Document::NotifyUserGestureActivati
   while (doc && !doc->mUserGestureActivated) {
     MOZ_LOG(gUserInteractionPRLog, LogLevel::Debug,
             ("Document %p has been activated by user.", this));
     doc->mUserGestureActivated = true;
     doc = doc->GetSameTypeParentDocument();
   }
 }
 
+void Document::MaybeNotifyAutoplayBlocked() {
+  Document* topLevelDoc = GetTopLevelContentDocument();
+  if (!topLevelDoc) {
+    return;
+  }
+
+  // This event is used to notify front-end side that we've blocked autoplay,
+  // 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 Document::SetDocTreeHadAudibleMedia() {
   Document* topLevelDoc = GetTopLevelContentDocument();
   if (!topLevelDoc) {
     return;
   }
 
   if (!topLevelDoc->mDocTreeHadAudibleMedia) {
     RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
--- a/dom/base/Document.h
+++ b/dom/base/Document.h
@@ -3480,16 +3480,20 @@ class Document : 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|.