Bug 1461278 - Print a note to the web console when a web site is using shadow DOM (v1), preffed off by default, r=emilio

This commit is contained in:
Olli Pettay 2018-05-15 02:04:32 +03:00
parent 1b656c34aa
commit 20c34cefa0
4 changed files with 44 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include "AnimationCommon.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/StaticPrefs.h"
#include "mozilla/dom/Animation.h"
#include "mozilla/dom/Attr.h"
#include "mozilla/dom/Flex.h"
@ -1247,6 +1248,10 @@ Element::AttachShadow(const ShadowRootInit& aInit, ErrorResult& aError)
shadowRoot->SetIsComposedDocParticipant(IsInComposedDoc());
if (StaticPrefs::dom_webcomponents_shadowdom_report_usage()) {
OwnerDoc()->ReportShadowDOMUsage();
}
/**
* 5. Set context objects shadow root to shadow.
*/

View File

@ -1456,6 +1456,7 @@ nsIDocument::nsIDocument()
mWidthStrEmpty(false),
mParserAborted(false),
mReportedUseCounters(false),
mHasReportedShadowDOMUsage(false),
#ifdef DEBUG
mWillReparent(false),
#endif
@ -13220,3 +13221,27 @@ nsIDocument::ModuleScriptsEnabled()
return nsContentUtils::IsChromeDoc(this) || sEnabledForContent;
}
void
nsIDocument::ReportShadowDOMUsage()
{
if (mHasReportedShadowDOMUsage) {
return;
}
nsIDocument* topLevel = GetTopLevelContentDocument();
if (topLevel && !topLevel->mHasReportedShadowDOMUsage) {
topLevel->mHasReportedShadowDOMUsage = true;
nsString uri;
Unused << topLevel->GetDocumentURI(uri);
if (!uri.IsEmpty()) {
nsAutoString msg = NS_LITERAL_STRING("Shadow DOM used in [") + uri +
NS_LITERAL_STRING("] or in some of its subdocuments.");
nsContentUtils::ReportToConsoleNonLocalized(msg, nsIScriptError::infoFlag,
NS_LITERAL_CSTRING("DOM"),
topLevel);
}
}
mHasReportedShadowDOMUsage = true;
}

View File

@ -3536,6 +3536,8 @@ public:
*/
nsIContent* GetContentInThisDocument(nsIFrame* aFrame) const;
void ReportShadowDOMUsage();
protected:
already_AddRefed<nsIPrincipal> MaybeDowngradePrincipal(nsIPrincipal* aPrincipal);
@ -4052,6 +4054,8 @@ protected:
// that we only report them once for the document.
bool mReportedUseCounters: 1;
bool mHasReportedShadowDOMUsage: 1;
#ifdef DEBUG
public:
bool mWillReparent: 1;

View File

@ -87,6 +87,16 @@ VARCACHE_PREF(
bool, false
)
//---------------------------------------------------------------------------
// DOM prefs
//---------------------------------------------------------------------------
VARCACHE_PREF(
"dom.webcomponents.shadowdom.report_usage",
dom_webcomponents_shadowdom_report_usage,
bool, false
)
//---------------------------------------------------------------------------
// Full-screen prefs
//---------------------------------------------------------------------------