зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1421070: Always enable custom elements in chrome. r=smaug
This allows custom elements to work in any document in the parent process that allows XUL and XBL. The test takes the easy option of moving the existing XUL custom element test to a run with the custom element pref disabled. MozReview-Commit-ID: CMiLzmp60jA --HG-- extra : rebase_source : b9632de82cf79c1df15be09fadf1d25817c8a894 extra : amend_source : 235a76453d1d6782903d5051ee8e234b965dcc36
This commit is contained in:
Родитель
55a80c8d40
Коммит
2626e1c261
|
@ -14,6 +14,7 @@
|
|||
#include "mozilla/dom/DocGroup.h"
|
||||
#include "nsHTMLTags.h"
|
||||
#include "jsapi.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -282,6 +283,26 @@ CustomElementRegistry::~CustomElementRegistry()
|
|||
mozilla::DropJSObjects(this);
|
||||
}
|
||||
|
||||
bool
|
||||
CustomElementRegistry::IsCustomElementEnabled(JSContext* aCx, JSObject* aObject)
|
||||
{
|
||||
if (nsContentUtils::IsCustomElementsEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return XRE_IsParentProcess() && nsContentUtils::AllowXULXBLForPrincipal(nsContentUtils::ObjectPrincipal(aObject));
|
||||
}
|
||||
|
||||
bool
|
||||
CustomElementRegistry::IsCustomElementEnabled(nsIDocument* aDoc)
|
||||
{
|
||||
if (nsContentUtils::IsCustomElementsEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return XRE_IsParentProcess() && nsContentUtils::AllowXULXBLForPrincipal(aDoc->NodePrincipal());
|
||||
}
|
||||
|
||||
CustomElementDefinition*
|
||||
CustomElementRegistry::LookupCustomElementDefinition(nsAtom* aNameAtom,
|
||||
nsAtom* aTypeAtom) const
|
||||
|
|
|
@ -363,11 +363,8 @@ public:
|
|||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CustomElementRegistry)
|
||||
|
||||
public:
|
||||
static bool IsCustomElementEnabled(JSContext* aCx = nullptr,
|
||||
JSObject* aObject = nullptr)
|
||||
{
|
||||
return nsContentUtils::IsCustomElementsEnabled();
|
||||
}
|
||||
static bool IsCustomElementEnabled(JSContext* aCx, JSObject* aObject);
|
||||
static bool IsCustomElementEnabled(nsIDocument* aDoc);
|
||||
|
||||
explicit CustomElementRegistry(nsPIDOMWindowInner* aWindow);
|
||||
|
||||
|
|
|
@ -1675,7 +1675,7 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|||
SetSubtreeRootPointer(aParent->SubtreeRoot());
|
||||
}
|
||||
|
||||
if (CustomElementRegistry::IsCustomElementEnabled() && IsInComposedDoc()) {
|
||||
if (CustomElementRegistry::IsCustomElementEnabled(OwnerDoc()) && IsInComposedDoc()) {
|
||||
// Connected callback must be enqueued whenever a custom element becomes
|
||||
// connected.
|
||||
CustomElementData* data = GetCustomElementData();
|
||||
|
@ -2017,7 +2017,7 @@ Element::UnbindFromTree(bool aDeep, bool aNullParent)
|
|||
|
||||
// Disconnected must be enqueued whenever a connected custom element becomes
|
||||
// disconnected.
|
||||
if (CustomElementRegistry::IsCustomElementEnabled()) {
|
||||
if (CustomElementRegistry::IsCustomElementEnabled(OwnerDoc())) {
|
||||
CustomElementData* data = GetCustomElementData();
|
||||
if (data) {
|
||||
if (data->mState == CustomElementData::State::eCustom) {
|
||||
|
@ -2689,7 +2689,7 @@ Element::SetAttrAndNotify(int32_t aNamespaceID,
|
|||
}
|
||||
}
|
||||
|
||||
if (CustomElementRegistry::IsCustomElementEnabled()) {
|
||||
if (CustomElementRegistry::IsCustomElementEnabled(OwnerDoc())) {
|
||||
CustomElementDefinition* definition = GetCustomElementDefinition();
|
||||
// Only custom element which is in `custom` state could get the
|
||||
// CustomElementDefinition.
|
||||
|
@ -2863,7 +2863,7 @@ Element::OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName,
|
|||
const nsAttrValueOrString& aValue,
|
||||
bool aNotify)
|
||||
{
|
||||
if (CustomElementRegistry::IsCustomElementEnabled()) {
|
||||
if (CustomElementRegistry::IsCustomElementEnabled(OwnerDoc())) {
|
||||
// Only custom element which is in `custom` state could get the
|
||||
// CustomElementDefinition.
|
||||
CustomElementDefinition* definition = GetCustomElementDefinition();
|
||||
|
@ -2996,7 +2996,7 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
|||
}
|
||||
}
|
||||
|
||||
if (CustomElementRegistry::IsCustomElementEnabled()) {
|
||||
if (CustomElementRegistry::IsCustomElementEnabled(OwnerDoc())) {
|
||||
CustomElementDefinition* definition = GetCustomElementDefinition();
|
||||
// Only custom element which is in `custom` state could get the
|
||||
// CustomElementDefinition.
|
||||
|
|
|
@ -7166,6 +7166,10 @@ nsContentUtils::PersistentLayerManagerForDocument(nsIDocument *aDoc)
|
|||
bool
|
||||
nsContentUtils::AllowXULXBLForPrincipal(nsIPrincipal* aPrincipal)
|
||||
{
|
||||
if (!aPrincipal) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsSystemPrincipal(aPrincipal)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -10124,13 +10128,14 @@ nsContentUtils::NewXULOrHTMLElement(Element** aResult, mozilla::dom::NodeInfo* a
|
|||
|
||||
MOZ_ASSERT_IF(aDefinition, isCustomElement);
|
||||
|
||||
bool customElementEnabled = CustomElementRegistry::IsCustomElementEnabled(nodeInfo->GetDocument());
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-create-element
|
||||
// We only handle the "synchronous custom elements flag is set" now.
|
||||
// For the unset case (e.g. cloning a node), see bug 1319342 for that.
|
||||
// Step 4.
|
||||
CustomElementDefinition* definition = aDefinition;
|
||||
if (CustomElementRegistry::IsCustomElementEnabled() && isCustomElement &&
|
||||
!definition) {
|
||||
if (customElementEnabled && isCustomElement && !definition) {
|
||||
MOZ_ASSERT(nodeInfo->NameAtom()->Equals(nodeInfo->LocalName()));
|
||||
definition =
|
||||
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
|
||||
|
@ -10237,7 +10242,7 @@ nsContentUtils::NewXULOrHTMLElement(Element** aResult, mozilla::dom::NodeInfo* a
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (CustomElementRegistry::IsCustomElementEnabled() && isCustomElement) {
|
||||
if (customElementEnabled && isCustomElement) {
|
||||
(*aResult)->SetCustomElementData(new CustomElementData(typeAtom));
|
||||
}
|
||||
|
||||
|
|
|
@ -5698,7 +5698,7 @@ nsIDocument::CreateElement(const nsAString& aTagName,
|
|||
const ElementCreationOptions& options =
|
||||
aOptions.GetAsElementCreationOptions();
|
||||
|
||||
if (CustomElementRegistry::IsCustomElementEnabled() &&
|
||||
if (CustomElementRegistry::IsCustomElementEnabled(this) &&
|
||||
options.mIs.WasPassed()) {
|
||||
is = &options.mIs.Value();
|
||||
}
|
||||
|
@ -5747,7 +5747,7 @@ nsIDocument::CreateElementNS(const nsAString& aNamespaceURI,
|
|||
}
|
||||
|
||||
const nsString* is = nullptr;
|
||||
if (CustomElementRegistry::IsCustomElementEnabled() &&
|
||||
if (CustomElementRegistry::IsCustomElementEnabled(this) &&
|
||||
aOptions.IsElementCreationOptions()) {
|
||||
const ElementCreationOptions& options = aOptions.GetAsElementCreationOptions();
|
||||
if (options.mIs.WasPassed()) {
|
||||
|
|
|
@ -442,7 +442,7 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (CustomElementRegistry::IsCustomElementEnabled() &&
|
||||
if (CustomElementRegistry::IsCustomElementEnabled(nodeInfo->GetDocument()) &&
|
||||
(clone->IsHTMLElement() || clone->IsXULElement())) {
|
||||
// The cloned node may be a custom element that may require
|
||||
// enqueing upgrade reaction.
|
||||
|
@ -512,7 +512,7 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
|
|||
|
||||
nsIDocument* newDoc = aNode->OwnerDoc();
|
||||
if (newDoc) {
|
||||
if (CustomElementRegistry::IsCustomElementEnabled()) {
|
||||
if (CustomElementRegistry::IsCustomElementEnabled(newDoc)) {
|
||||
// Adopted callback must be enqueued whenever a node’s
|
||||
// shadow-including inclusive descendants that is custom.
|
||||
Element* element = aNode->IsElement() ? aNode->AsElement() : nullptr;
|
||||
|
|
|
@ -7911,16 +7911,17 @@ class CGPerSignatureCall(CGThing):
|
|||
|
||||
if (idlNode.getExtendedAttribute('CEReactions') is not None and
|
||||
not getter):
|
||||
cgThings.append(CGGeneric(dedent(
|
||||
cgThings.append(CGGeneric(fill(
|
||||
"""
|
||||
Maybe<AutoCEReaction> ceReaction;
|
||||
if (CustomElementRegistry::IsCustomElementEnabled()) {
|
||||
if (CustomElementRegistry::IsCustomElementEnabled(cx, ${obj})) {
|
||||
DocGroup* docGroup = self->GetDocGroup();
|
||||
if (docGroup) {
|
||||
ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx);
|
||||
}
|
||||
}
|
||||
""")))
|
||||
""",
|
||||
obj=objectName)))
|
||||
|
||||
# If this is a method that was generated by a maplike/setlike
|
||||
# interface, use the maplike/setlike generator to fill in the body.
|
||||
|
|
|
@ -11,4 +11,3 @@ support-files =
|
|||
support-files =
|
||||
test_upgrade_page.html
|
||||
upgrade_tests.js
|
||||
[test_xul_custom_element.xul]
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
[DEFAULT]
|
||||
prefs =
|
||||
dom.webcomponents.customelements.enabled=false
|
||||
|
||||
[test_xul_custom_element.xul]
|
|
@ -20,8 +20,12 @@ function test_with_new_window(f, msg) {
|
|||
iframe.setAttribute('type', 'content');
|
||||
iframe.setAttribute('src', 'http://example.org/chrome/dom/tests/mochitest/webcomponents/test_upgrade_page.html');
|
||||
iframe.onload = function() {
|
||||
// Use window from iframe to isolate the test.
|
||||
f(iframe.contentWindow, msg);
|
||||
try {
|
||||
// Use window from iframe to isolate the test.
|
||||
f(iframe.contentWindow, msg);
|
||||
} catch (e) {
|
||||
SimpleTest.ok(false, e);
|
||||
}
|
||||
aResolve();
|
||||
};
|
||||
document.body.appendChild(iframe);
|
||||
|
|
|
@ -180,6 +180,7 @@ MOCHITEST_CHROME_MANIFESTS += [
|
|||
'mochitest/localstorage/chrome.ini',
|
||||
'mochitest/sessionstorage/chrome.ini',
|
||||
'mochitest/webcomponents/chrome.ini',
|
||||
'mochitest/webcomponents/chrome_disabled.ini',
|
||||
'mochitest/whatwg/chrome.ini',
|
||||
]
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче