From 80c024779929d44397a8c03d2fa7808f97f2c21a Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 07:43:40 -0400 Subject: Issue #1375 - Fix IsWebComponentsEnabled checks --- dom/base/nsDocument.cpp | 76 +++++++--------------- dom/base/nsDocument.h | 16 ++--- dom/webidl/Element.webidl | 8 +-- layout/reftests/bugs/1066554-1.html | 20 +++--- layout/reftests/bugs/reftest.list | 2 +- .../css-display/display-contents-shadow-dom-1.html | 71 +++++++++++--------- layout/reftests/forms/legend/shadow-dom.html | 29 +++++---- layout/reftests/mathml/shadow-dom-1.html | 8 ++- .../webcomponents/cross-tree-selection-1.html | 5 ++ .../dynamic-insertion-point-distribution-1.html | 15 +++-- .../dynamic-insertion-point-distribution-2.html | 15 +++-- .../reftests/webcomponents/input-transition-1.html | 15 +++-- .../update-dist-node-descendants-1.html | 11 +++- 13 files changed, 154 insertions(+), 137 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 745d170f1..7b280a188 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -2242,6 +2242,29 @@ WarnIfSandboxIneffective(nsIDocShell* aDocShell, } } +bool +nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject) +{ + if (!nsContentUtils::IsWebComponentsEnabled()) { + return false; + } + + JS::Rooted obj(aCx, aObject); + + JSAutoCompartment ac(aCx, obj); + JS::Rooted global(aCx, JS_GetGlobalForObject(aCx, obj)); + nsCOMPtr window = + do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(global)); + + nsIDocument* doc = window ? window->GetExtantDoc() : nullptr; + if (doc && doc->IsStyledByServo()) { + NS_WARNING("stylo: Web Components not supported yet"); + return false; + } + + return true; +} + nsresult nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, @@ -5581,65 +5604,12 @@ nsIDocument::CreateAttributeNS(const nsAString& aNamespaceURI, return attribute.forget(); } -bool -nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject) -{ - JS::Rooted obj(aCx, aObject); - - if (nsContentUtils::IsWebComponentsEnabled()) { - return true; - } - - // Check for the webcomponents permission. See Bug 1181555. - JSAutoCompartment ac(aCx, obj); - JS::Rooted global(aCx, JS_GetGlobalForObject(aCx, obj)); - nsCOMPtr window = - do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(global)); - - return IsWebComponentsEnabled(window); -} - bool nsDocument::IsWebComponentsEnabled(const nsINode* aNode) { return aNode->OwnerDoc()->IsWebComponentsEnabled(); } -bool -nsDocument::IsWebComponentsEnabled(dom::NodeInfo* aNodeInfo) -{ - if (nsContentUtils::IsWebComponentsEnabled()) { - return true; - } - - nsIDocument* doc = aNodeInfo->GetDocument(); - // Use GetScopeObject() here so that data documents work the same way as the - // main document they're associated with. - nsCOMPtr window = - do_QueryInterface(doc->GetScopeObject()); - return IsWebComponentsEnabled(window); -} - -bool -nsDocument::IsWebComponentsEnabled(nsPIDOMWindowInner* aWindow) -{ - if (aWindow) { - nsresult rv; - nsCOMPtr permMgr = - do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, false); - - uint32_t perm; - rv = permMgr->TestPermissionFromWindow( - aWindow, "moz-extremely-unstable-and-will-change-webcomponents", &perm); - NS_ENSURE_SUCCESS(rv, false); - - return perm == nsIPermissionManager::ALLOW_ACTION; - } - - return false; -} - NS_IMETHODIMP nsDocument::GetElementsByTagName(const nsAString& aTagname, nsIDOMNodeList** aReturn) diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 4ab285840..6520d905d 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -755,6 +755,11 @@ public: virtual void NotifyLayerManagerRecreated() override; + // Check whether web components are enabled for the global of aObject. + static bool IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject); + // Check whether web components are enabled for the document this node belongs + // to. + static bool IsWebComponentsEnabled(const nsINode* aNode); private: void AddOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet); nsRadioGroupStruct* GetRadioGroupInternal(const nsAString& aName) const; @@ -1341,17 +1346,6 @@ protected: nsWeakPtr mFullscreenRoot; public: - // Check whether web components are enabled for the global of aObject. - static bool IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject); - // Check whether web components are enabled for the document this node belongs - // to. - static bool IsWebComponentsEnabled(const nsINode* aNode); - // Check whether web components are enabled for the global of the document - // this nodeinfo comes from. - static bool IsWebComponentsEnabled(mozilla::dom::NodeInfo* aNodeInfo); - // Check whether web components are enabled for the given window. - static bool IsWebComponentsEnabled(nsPIDOMWindowInner* aWindow); - RefPtr mListenerManager; RefPtr mStyleSheetSetList; RefPtr mScriptLoader; diff --git a/dom/webidl/Element.webidl b/dom/webidl/Element.webidl index 2f7e934b8..d5cac7c64 100644 --- a/dom/webidl/Element.webidl +++ b/dom/webidl/Element.webidl @@ -236,17 +236,17 @@ dictionary ShadowRootInit { // https://dom.spec.whatwg.org/#element partial interface Element { // Shadow DOM v1 - [Throws, Pref="nsDocument::IsWebComponentsEnabled"] + [Throws, Func="nsDocument::IsWebComponentsEnabled"] ShadowRoot attachShadow(ShadowRootInit shadowRootInitDict); [BinaryName="shadowRootByMode", Func="nsDocument::IsWebComponentsEnabled"] readonly attribute ShadowRoot? shadowRoot; - [BinaryName="assignedSlotByMode", Pref="nsDocument::IsWebComponentsEnabled"] + [BinaryName="assignedSlotByMode", Func="nsDocument::IsWebComponentsEnabled"] readonly attribute HTMLSlotElement? assignedSlot; - [CEReactions, Unscopable, SetterThrows, Pref="nsDocument::IsWebComponentsEnabled"] + [CEReactions, Unscopable, SetterThrows, Func="nsDocument::IsWebComponentsEnabled"] attribute DOMString slot; // [deprecated] Shadow DOM v0 - [Throws, Pref="nsDocument::IsWebComponentsEnabled"] + [Throws, Func="nsDocument::IsWebComponentsEnabled"] ShadowRoot createShadowRoot(); }; diff --git a/layout/reftests/bugs/1066554-1.html b/layout/reftests/bugs/1066554-1.html index bb0a97f96..f4df207a1 100644 --- a/layout/reftests/bugs/1066554-1.html +++ b/layout/reftests/bugs/1066554-1.html @@ -7,15 +7,17 @@ diff --git a/layout/reftests/forms/legend/shadow-dom.html b/layout/reftests/forms/legend/shadow-dom.html index ad7babcf7..0f0a53665 100644 --- a/layout/reftests/forms/legend/shadow-dom.html +++ b/layout/reftests/forms/legend/shadow-dom.html @@ -48,17 +48,19 @@ div.after::after {content: " Y";} return e; } - document.body.offsetHeight; + function run() { + document.body.offsetHeight; - shadow("host1").innerHTML = ' c'; - shadow("host2").innerHTML = 'a c'; - shadow("host3").innerHTML = 'a '; - shadow("host4").innerHTML = ''; - shadow("host5").innerHTML = 'a '; - shadow("host6").innerHTML = ' c'; - shadow("host7").innerHTML = 'a B'; - shadow("host8").innerHTML = 'A B'; - shadow("host9").innerHTML = 'A B '; + shadow("host1").innerHTML = ' c'; + shadow("host2").innerHTML = 'a c'; + shadow("host3").innerHTML = 'a '; + shadow("host4").innerHTML = ''; + shadow("host5").innerHTML = 'a '; + shadow("host6").innerHTML = ' c'; + shadow("host7").innerHTML = 'a B'; + shadow("host8").innerHTML = 'A B'; + shadow("host9").innerHTML = 'A B '; + } function tweak() { document.body.offsetHeight; @@ -105,7 +107,12 @@ div.after::after {content: " Y";} },0); } - window.addEventListener("MozReftestInvalidate", tweak, false); + if (document.body.createShadowRoot) { + run(); + window.addEventListener("MozReftestInvalidate", tweak, false); + } else { + document.documentElement.removeAttribute("class"); + } diff --git a/layout/reftests/mathml/shadow-dom-1.html b/layout/reftests/mathml/shadow-dom-1.html index 547253a3c..bbf27069f 100644 --- a/layout/reftests/mathml/shadow-dom-1.html +++ b/layout/reftests/mathml/shadow-dom-1.html @@ -7,9 +7,11 @@ diff --git a/layout/reftests/webcomponents/dynamic-insertion-point-distribution-2.html b/layout/reftests/webcomponents/dynamic-insertion-point-distribution-2.html index d753af09c..c58b9cfbd 100644 --- a/layout/reftests/webcomponents/dynamic-insertion-point-distribution-2.html +++ b/layout/reftests/webcomponents/dynamic-insertion-point-distribution-2.html @@ -7,9 +7,11 @@ diff --git a/layout/reftests/webcomponents/input-transition-1.html b/layout/reftests/webcomponents/input-transition-1.html index c11444d05..a4be5271b 100644 --- a/layout/reftests/webcomponents/input-transition-1.html +++ b/layout/reftests/webcomponents/input-transition-1.html @@ -7,9 +7,11 @@ diff --git a/layout/reftests/webcomponents/update-dist-node-descendants-1.html b/layout/reftests/webcomponents/update-dist-node-descendants-1.html index 003c23394..3ba96594b 100644 --- a/layout/reftests/webcomponents/update-dist-node-descendants-1.html +++ b/layout/reftests/webcomponents/update-dist-node-descendants-1.html @@ -6,8 +6,10 @@
text
-- cgit v1.2.3