From 37f08f36a06af545b901bffbabc2b7c3c097442c Mon Sep 17 00:00:00 2001 From: alwu Date: Thu, 16 Jul 2020 19:53:49 +0000 Subject: [PATCH] Bug 1647430 - part2 : store `DocTreeHadAudibleMedia` in WindowContext. r=nika After we enable Fissions, we can't always access the top level document because it might be in another process. Therefore, we should move `mDocTreeHadAudibleMedia` from document to the top window context, which can ensure that we set the value correctly even if setting `mDocTreeHadAudibleMedia` happens in a different process which is different from the process where the top level document exists. Differential Revision: https://phabricator.services.mozilla.com/D83162 --- docshell/base/WindowContext.cpp | 5 +++++ docshell/base/WindowContext.h | 5 +++++ dom/base/Document.cpp | 14 +++----------- dom/base/Document.h | 4 ---- dom/ipc/WindowGlobalParent.cpp | 5 +++++ 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/docshell/base/WindowContext.cpp b/docshell/base/WindowContext.cpp index fa6dc7faeeeb..e1099da08980 100644 --- a/docshell/base/WindowContext.cpp +++ b/docshell/base/WindowContext.cpp @@ -162,6 +162,11 @@ bool WindowContext::CanSet(FieldIndex, return CheckOnlyOwningProcessCanSet(aSource); } +bool WindowContext::CanSet(FieldIndex, + const bool& aValue, ContentParent* aSource) { + return GetBrowsingContext()->IsTop(); +} + bool WindowContext::CanSet(FieldIndex, const uint32_t& aValue, ContentParent* aSource) { return CheckOnlyOwningProcessCanSet(aSource); diff --git a/docshell/base/WindowContext.h b/docshell/base/WindowContext.h index dd1469679eec..d826f5ef2dd2 100644 --- a/docshell/base/WindowContext.h +++ b/docshell/base/WindowContext.h @@ -46,6 +46,9 @@ class BrowsingContextGroup; * mixed content loads to happen */ \ FIELD(AllowMixedContent, bool) \ FIELD(EmbedderPolicy, nsILoadInfo::CrossOriginEmbedderPolicy) \ + /* True if this document tree contained an HTMLMediaElement that \ + * played audibly. This should only be set on top level context. */ \ + FIELD(DocTreeHadAudibleMedia, bool) \ FIELD(AutoplayPermission, uint32_t) \ FIELD(DelegatedPermissions, \ PermissionDelegateHandler::DelegatedPermissionList) \ @@ -161,6 +164,8 @@ class WindowContext : public nsISupports, public nsWrapperCache { ContentParent* aSource); bool CanSet(FieldIndex, const bool& aIsSecureContext, ContentParent* aSource); + bool CanSet(FieldIndex, const bool& aValue, + ContentParent* aSource); bool CanSet(FieldIndex, const uint32_t& aValue, ContentParent* aSource); bool CanSet(FieldIndex, diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index b7e7ca666cdc..a5de1b9fb4c2 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -1320,7 +1320,6 @@ Document::Document(const char* aContentType) mParserAborted(false), mReportedUseCounters(false), mHasReportedShadowDOMUsage(false), - mDocTreeHadAudibleMedia(false), mDocTreeHadPlayRevoked(false), mHasDelayedRefreshEvent(false), mLoadEventFiring(false), @@ -1906,11 +1905,6 @@ Document::~Document() { ScalarAdd(Telemetry::ScalarID::MATHML_DOC_COUNT, 1); } - ScalarAdd(Telemetry::ScalarID::MEDIA_PAGE_COUNT, 1); - if (mDocTreeHadAudibleMedia) { - ScalarAdd(Telemetry::ScalarID::MEDIA_PAGE_HAD_MEDIA_COUNT, 1); - } - if (IsHTMLDocument()) { switch (GetCompatibilityMode()) { case eCompatibility_FullStandards: @@ -15276,12 +15270,10 @@ bool Document::ConsumeTransientUserGestureActivation() { } void Document::SetDocTreeHadAudibleMedia() { - Document* topLevelDoc = GetTopLevelContentDocument(); - if (!topLevelDoc) { - return; + RefPtr topWc = GetTopLevelWindowContext(); + if (topWc && !topWc->GetDocTreeHadAudibleMedia()) { + topWc->SetDocTreeHadAudibleMedia(true); } - - topLevelDoc->mDocTreeHadAudibleMedia = true; } void Document::SetDocTreeHadPlayRevoked() { diff --git a/dom/base/Document.h b/dom/base/Document.h index 68ef5ba1052c..f4a817fa340f 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -4544,10 +4544,6 @@ class Document : public nsINode, bool mHasReportedShadowDOMUsage : 1; - // True if this document contained, either directly or in a subdocument, - // an HTMLMediaElement that played audibly. This should only be set on - // top level content documents. - bool mDocTreeHadAudibleMedia : 1; // True if this document contained, either directly or in a subdocument, // an HTMLMediaElement that was playing inaudibly and became audible and we // paused the HTMLMediaElement because it wasn't allowed to autoplay audibly. diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index 84eee3060d5f..4f73ad2d59ed 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -724,6 +724,11 @@ void WindowGlobalParent::ActorDestroy(ActorDestroyReason aWhy) { mixedContentLevel = MIXED_DISPLAY_CONTENT; } Accumulate(Telemetry::MIXED_CONTENT_PAGE_LOAD, mixedContentLevel); + + ScalarAdd(Telemetry::ScalarID::MEDIA_PAGE_COUNT, 1); + if (GetDocTreeHadAudibleMedia()) { + ScalarAdd(Telemetry::ScalarID::MEDIA_PAGE_HAD_MEDIA_COUNT, 1); + } } // If there are any non-discarded nested contexts when this WindowContext is