From 5cf44383eb126875c07f32b4872a4ccbff0369cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 30 Nov 2018 18:01:48 +0100 Subject: [PATCH] Bug 1511138 - Never return styles for disconnected elements. r=smaug https://drafts.csswg.org/cssom/#dom-window-getcomputedstyle says: > If elt is connected, part of the flat tree, and its shadow-including root... WebKit and Blink already do this, and we do it already except for cross-document situations, where we can end up with a PresShell even if GetPresShellForContent returns null. The style system should be able to rely on ShadowRoots having a non-null shadow host. Differential Revision: https://phabricator.services.mozilla.com/D13472 --- layout/style/nsComputedDOMStyle.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index b2e976dc93f8..4494115c148b 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -508,11 +508,12 @@ already_AddRefed nsComputedDOMStyle::DoGetComputedStyleNoFlush( return nullptr; } - if (aElement->IsInNativeAnonymousSubtree() && !aElement->IsInComposedDoc()) { - // Normal web content can't access NAC, but Accessibility, DevTools and - // Editor use this same API and this may get called for anonymous content. - // Computing the style of a pseudo-element that doesn't have a parent - // doesn't really make sense. + if (!aElement->IsInComposedDoc()) { + // Don't return styles for disconnected elements, that makes no sense. This + // can only happen with a non-null presShell for cross-document calls. + // + // FIXME(emilio, bug 1483798): This should also not return styles for + // elements outside of the flat tree, not just outside of the document. return nullptr; }