Bug 1647431, make ReportShadowDOMUsage Fission compatible, r=edgar

Differential Revision: https://phabricator.services.mozilla.com/D83471
This commit is contained in:
Olli Pettay 2020-07-14 11:22:20 +00:00
Родитель 1f80851418
Коммит 58ab7096a2
3 изменённых файлов: 41 добавлений и 14 удалений

Просмотреть файл

@ -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<IDX_HasReportedShadowDOMUsage>,
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");

Просмотреть файл

@ -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<IDX_HasReportedShadowDOMUsage>, const bool& aValue,
ContentParent* aSource) {
return true;
}
void DidSet(FieldIndex<IDX_HasReportedShadowDOMUsage>, 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.

Просмотреть файл

@ -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