mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Bug 1422931
- Part 2: Make webcomponents preference per-doc. r=smaug
This is to fix the case where preference is restore to false when a testcase ends, but nsDocument::DeleteShell is called afterwards. So, we make the preference per-doc and set it when the document is created. The value does not change for the lifetime of the document.
This commit is contained in:
parent
b519c97d26
commit
7fe15d1a52
@ -12,6 +12,7 @@
|
|||||||
#include "nsIAnonymousContentCreator.h"
|
#include "nsIAnonymousContentCreator.h"
|
||||||
#include "nsIFrame.h"
|
#include "nsIFrame.h"
|
||||||
#include "nsCSSAnonBoxes.h"
|
#include "nsCSSAnonBoxes.h"
|
||||||
|
#include "nsDocument.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
@ -66,7 +67,7 @@ ExplicitChildIterator::ExplicitChildIterator(const nsIContent* aParent,
|
|||||||
mIsFirst(aStartAtBeginning),
|
mIsFirst(aStartAtBeginning),
|
||||||
mIndexInInserted(0)
|
mIndexInInserted(0)
|
||||||
{
|
{
|
||||||
mParentAsSlot = nsContentUtils::IsWebComponentsEnabled() ?
|
mParentAsSlot = nsDocument::IsWebComponentsEnabled(mParent) ?
|
||||||
HTMLSlotElement::FromContent(mParent) : nullptr;
|
HTMLSlotElement::FromContent(mParent) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7534,7 +7534,7 @@ nsContentUtils::IsContentInsertionPoint(nsIContent* aContent)
|
|||||||
bool
|
bool
|
||||||
nsContentUtils::HasDistributedChildren(nsIContent* aContent)
|
nsContentUtils::HasDistributedChildren(nsIContent* aContent)
|
||||||
{
|
{
|
||||||
if (!IsWebComponentsEnabled() || !aContent) {
|
if (!aContent || !nsDocument::IsWebComponentsEnabled(aContent)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1581,6 +1581,10 @@ nsIDocument::nsIDocument()
|
|||||||
for (auto& cnt : mIncCounters) {
|
for (auto& cnt : mIncCounters) {
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set this when document is created and value stays the same for the lifetime
|
||||||
|
// of the document.
|
||||||
|
mIsWebComponentsEnabled = nsContentUtils::IsWebComponentsEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsDocument::nsDocument(const char* aContentType)
|
nsDocument::nsDocument(const char* aContentType)
|
||||||
@ -2720,6 +2724,30 @@ nsDocument::IsSynthesized() {
|
|||||||
return synthesized;
|
return synthesized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject)
|
||||||
|
{
|
||||||
|
JS::Rooted<JSObject*> obj(aCx, aObject);
|
||||||
|
|
||||||
|
JSAutoCompartment ac(aCx, obj);
|
||||||
|
JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, obj));
|
||||||
|
nsCOMPtr<nsPIDOMWindowInner> window =
|
||||||
|
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(global));
|
||||||
|
|
||||||
|
nsIDocument* doc = window ? window->GetExtantDoc() : nullptr;
|
||||||
|
if (!doc) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return doc->IsWebComponentsEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
nsDocument::IsWebComponentsEnabled(const nsINode* aNode)
|
||||||
|
{
|
||||||
|
return aNode->OwnerDoc()->IsWebComponentsEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
|
nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
|
||||||
nsILoadGroup* aLoadGroup,
|
nsILoadGroup* aLoadGroup,
|
||||||
|
@ -665,6 +665,11 @@ public:
|
|||||||
virtual void ResolveScheduledSVGPresAttrs() override;
|
virtual void ResolveScheduledSVGPresAttrs() override;
|
||||||
bool IsSynthesized();
|
bool IsSynthesized();
|
||||||
|
|
||||||
|
// 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:
|
private:
|
||||||
void AddOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet);
|
void AddOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet);
|
||||||
void SendToConsole(nsCOMArray<nsISecurityConsoleMessage>& aMessages);
|
void SendToConsole(nsCOMArray<nsISecurityConsoleMessage>& aMessages);
|
||||||
|
@ -3256,6 +3256,11 @@ public:
|
|||||||
virtual bool AllowPaymentRequest() const = 0;
|
virtual bool AllowPaymentRequest() const = 0;
|
||||||
virtual void SetAllowPaymentRequest(bool aAllowPaymentRequest) = 0;
|
virtual void SetAllowPaymentRequest(bool aAllowPaymentRequest) = 0;
|
||||||
|
|
||||||
|
bool IsWebComponentsEnabled() const
|
||||||
|
{
|
||||||
|
return mIsWebComponentsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool GetUseCounter(mozilla::UseCounter aUseCounter)
|
bool GetUseCounter(mozilla::UseCounter aUseCounter)
|
||||||
{
|
{
|
||||||
@ -3612,6 +3617,9 @@ protected:
|
|||||||
// True if the encoding menu should be disabled.
|
// True if the encoding menu should be disabled.
|
||||||
bool mEncodingMenuDisabled : 1;
|
bool mEncodingMenuDisabled : 1;
|
||||||
|
|
||||||
|
// True if dom.webcomponents.enabled pref is set when document is created.
|
||||||
|
bool mIsWebComponentsEnabled : 1;
|
||||||
|
|
||||||
// Whether <style scoped> support is enabled in this document.
|
// Whether <style scoped> support is enabled in this document.
|
||||||
enum { eScopedStyle_Unknown, eScopedStyle_Disabled, eScopedStyle_Enabled };
|
enum { eScopedStyle_Unknown, eScopedStyle_Disabled, eScopedStyle_Enabled };
|
||||||
unsigned int mIsScopedStyleEnabled : 2;
|
unsigned int mIsScopedStyleEnabled : 2;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#include "nsRange.h"
|
#include "nsRange.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "nsDocument.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
@ -157,6 +158,12 @@ void nsTextNode::UnbindFromTree(bool aDeep, bool aNullParent)
|
|||||||
nsGenericDOMDataNode::UnbindFromTree(aDeep, aNullParent);
|
nsGenericDOMDataNode::UnbindFromTree(aDeep, aNullParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
nsTextNode::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject)
|
||||||
|
{
|
||||||
|
return nsDocument::IsWebComponentsEnabled(aCx, aObject);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
void
|
void
|
||||||
nsTextNode::List(FILE* out, int32_t aIndent) const
|
nsTextNode::List(FILE* out, int32_t aIndent) const
|
||||||
|
@ -75,6 +75,10 @@ public:
|
|||||||
|
|
||||||
virtual nsIDOMNode* AsDOMNode() override { return this; }
|
virtual nsIDOMNode* AsDOMNode() override { return this; }
|
||||||
|
|
||||||
|
// Need to have a copy here because including nsDocument.h in this file will
|
||||||
|
// fail to build on Windows.
|
||||||
|
static bool IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
virtual void List(FILE* out, int32_t aIndent) const override;
|
virtual void List(FILE* out, int32_t aIndent) const override;
|
||||||
virtual void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const override;
|
virtual void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const override;
|
||||||
|
@ -16,7 +16,7 @@ NS_NewHTMLSlotElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
|||||||
mozilla::dom::FromParser aFromParser)
|
mozilla::dom::FromParser aFromParser)
|
||||||
{
|
{
|
||||||
RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo);
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo);
|
||||||
if (nsContentUtils::IsWebComponentsEnabled()) {
|
if (nsDocument::IsWebComponentsEnabled(nodeInfo->GetDocument())) {
|
||||||
already_AddRefed<mozilla::dom::NodeInfo> nodeInfoArg(nodeInfo.forget());
|
already_AddRefed<mozilla::dom::NodeInfo> nodeInfoArg(nodeInfo.forget());
|
||||||
return new mozilla::dom::HTMLSlotElement(nodeInfoArg);
|
return new mozilla::dom::HTMLSlotElement(nodeInfoArg);
|
||||||
}
|
}
|
||||||
|
@ -254,19 +254,19 @@ dictionary ShadowRootInit {
|
|||||||
// https://dom.spec.whatwg.org/#element
|
// https://dom.spec.whatwg.org/#element
|
||||||
partial interface Element {
|
partial interface Element {
|
||||||
// Shadow DOM v1
|
// Shadow DOM v1
|
||||||
[Throws, Pref="dom.webcomponents.enabled"]
|
[Throws, Func="nsDocument::IsWebComponentsEnabled"]
|
||||||
ShadowRoot attachShadow(ShadowRootInit shadowRootInitDict);
|
ShadowRoot attachShadow(ShadowRootInit shadowRootInitDict);
|
||||||
[BinaryName="shadowRootByMode", Pref="dom.webcomponents.enabled"]
|
[BinaryName="shadowRootByMode", Func="nsDocument::IsWebComponentsEnabled"]
|
||||||
readonly attribute ShadowRoot? shadowRoot;
|
readonly attribute ShadowRoot? shadowRoot;
|
||||||
[BinaryName="assignedSlotByMode", Pref="dom.webcomponents.enabled"]
|
[BinaryName="assignedSlotByMode", Func="nsDocument::IsWebComponentsEnabled"]
|
||||||
readonly attribute HTMLSlotElement? assignedSlot;
|
readonly attribute HTMLSlotElement? assignedSlot;
|
||||||
[CEReactions, Unscopable, SetterThrows, Pref="dom.webcomponents.enabled"]
|
[CEReactions, Unscopable, SetterThrows, Func="nsDocument::IsWebComponentsEnabled"]
|
||||||
attribute DOMString slot;
|
attribute DOMString slot;
|
||||||
|
|
||||||
// [deprecated] Shadow DOM v0
|
// [deprecated] Shadow DOM v0
|
||||||
[Throws, Pref="dom.webcomponents.enabled"]
|
[Throws, Func="nsDocument::IsWebComponentsEnabled"]
|
||||||
ShadowRoot createShadowRoot();
|
ShadowRoot createShadowRoot();
|
||||||
[Pref="dom.webcomponents.enabled"]
|
[Func="nsDocument::IsWebComponentsEnabled"]
|
||||||
NodeList getDestinationInsertionPoints();
|
NodeList getDestinationInsertionPoints();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
* and create derivative works of this document.
|
* and create derivative works of this document.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
[Pref="dom.webcomponents.enabled", Exposed=Window, HTMLConstructor]
|
[Func="nsDocument::IsWebComponentsEnabled", Exposed=Window, HTMLConstructor]
|
||||||
interface HTMLSlotElement : HTMLElement {
|
interface HTMLSlotElement : HTMLElement {
|
||||||
[CEReactions, SetterThrows] attribute DOMString name;
|
[CEReactions, SetterThrows] attribute DOMString name;
|
||||||
sequence<Node> assignedNodes(optional AssignedNodesOptions options);
|
sequence<Node> assignedNodes(optional AssignedNodesOptions options);
|
||||||
|
@ -17,7 +17,7 @@ enum ShadowRootMode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#shadowroot
|
// https://dom.spec.whatwg.org/#shadowroot
|
||||||
[Pref="dom.webcomponents.enabled"]
|
[Func="nsDocument::IsWebComponentsEnabled"]
|
||||||
interface ShadowRoot : DocumentFragment
|
interface ShadowRoot : DocumentFragment
|
||||||
{
|
{
|
||||||
// Shadow DOM v1
|
// Shadow DOM v1
|
||||||
|
@ -19,7 +19,7 @@ interface Text : CharacterData {
|
|||||||
};
|
};
|
||||||
|
|
||||||
partial interface Text {
|
partial interface Text {
|
||||||
[BinaryName="assignedSlotByMode", Pref="dom.webcomponents.enabled"]
|
[BinaryName="assignedSlotByMode", Func="nsTextNode::IsWebComponentsEnabled"]
|
||||||
readonly attribute HTMLSlotElement? assignedSlot;
|
readonly attribute HTMLSlotElement? assignedSlot;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user