From 58ab7096a292d89ea84e174042ab5fa021318a5c Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Tue, 14 Jul 2020 11:22:20 +0000 Subject: [PATCH] Bug 1647431, make ReportShadowDOMUsage Fission compatible, r=edgar Differential Revision: https://phabricator.services.mozilla.com/D83471 --- docshell/base/WindowContext.cpp | 22 ++++++++++++++++++++++ docshell/base/WindowContext.h | 9 ++++++++- dom/base/Document.cpp | 24 +++++++++++------------- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/docshell/base/WindowContext.cpp b/docshell/base/WindowContext.cpp index ead7cb7a57d3..fa6dc7faeeeb 100644 --- a/docshell/base/WindowContext.cpp +++ b/docshell/base/WindowContext.cpp @@ -12,7 +12,9 @@ #include "mozilla/dom/BrowsingContext.h" #include "mozilla/StaticPtr.h" #include "mozilla/ClearOnShutdown.h" +#include "nsIScriptError.h" #include "nsRefPtrHashtable.h" +#include "nsContentUtils.h" namespace mozilla { namespace dom { @@ -179,6 +181,26 @@ bool WindowContext::CanSet( return CheckOnlyOwningProcessCanSet(aSource); } +void WindowContext::DidSet(FieldIndex, + bool aOldValue) { + if (!aOldValue && GetHasReportedShadowDOMUsage() && IsInProcess()) { + MOZ_ASSERT(TopWindowContext() == this); + if (mBrowsingContext) { + Document* topLevelDoc = mBrowsingContext->GetDocument(); + if (topLevelDoc) { + nsAutoString uri; + Unused << topLevelDoc->GetDocumentURI(uri); + if (!uri.IsEmpty()) { + nsAutoString msg = u"Shadow DOM used in ["_ns + uri + + u"] or in some of its subdocuments."_ns; + nsContentUtils::ReportToConsoleNonLocalized( + msg, nsIScriptError::infoFlag, "DOM"_ns, topLevelDoc); + } + } + } + } +} + void WindowContext::CreateFromIPC(IPCInitializer&& aInit) { MOZ_RELEASE_ASSERT(XRE_IsContentProcess(), "Should be a WindowGlobalParent in the parent"); diff --git a/docshell/base/WindowContext.h b/docshell/base/WindowContext.h index fd50bae961ce..dd1469679eec 100644 --- a/docshell/base/WindowContext.h +++ b/docshell/base/WindowContext.h @@ -50,7 +50,8 @@ class BrowsingContextGroup; FIELD(DelegatedPermissions, \ PermissionDelegateHandler::DelegatedPermissionList) \ FIELD(DelegatedExactHostMatchPermissions, \ - PermissionDelegateHandler::DelegatedPermissionList) + PermissionDelegateHandler::DelegatedPermissionList) \ + FIELD(HasReportedShadowDOMUsage, bool) class WindowContext : public nsISupports, public nsWrapperCache { MOZ_DECL_SYNCED_CONTEXT(WindowContext, MOZ_EACH_WC_FIELD) @@ -173,6 +174,12 @@ class WindowContext : public nsISupports, public nsWrapperCache { const PermissionDelegateHandler::DelegatedPermissionList& aValue, ContentParent* aSource); + bool CanSet(FieldIndex, const bool& aValue, + ContentParent* aSource) { + return true; + } + void DidSet(FieldIndex, bool aOldValue); + // Overload `DidSet` to get notifications for a particular field being set. // // You can also overload the variant that gets the old value if you need it. diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index b841ffc8006f..d9150f466165 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -16256,24 +16256,22 @@ bool Document::ModuleScriptsEnabled() { } void Document::ReportShadowDOMUsage() { - if (mHasReportedShadowDOMUsage) { + nsPIDOMWindowInner* inner = GetInnerWindow(); + if (NS_WARN_IF(!inner)) { return; } - Document* topLevel = GetTopLevelContentDocument(); - if (topLevel && !topLevel->mHasReportedShadowDOMUsage) { - topLevel->mHasReportedShadowDOMUsage = true; - nsString uri; - Unused << topLevel->GetDocumentURI(uri); - if (!uri.IsEmpty()) { - nsAutoString msg = u"Shadow DOM used in ["_ns + uri + - u"] or in some of its subdocuments."_ns; - nsContentUtils::ReportToConsoleNonLocalized(msg, nsIScriptError::infoFlag, - "DOM"_ns, topLevel); - } + WindowContext* wc = inner->GetWindowContext(); + if (NS_WARN_IF(!wc)) { + return; } - mHasReportedShadowDOMUsage = true; + WindowContext* topWc = wc->TopWindowContext(); + if (topWc->GetHasReportedShadowDOMUsage()) { + return; + } + + topWc->SetHasReportedShadowDOMUsage(true); } // static