From 5352b69a9286223272c0ed072900b4c78ba2ed7c Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Tue, 14 Apr 2020 21:24:51 -0400 Subject: Bug 1305458 - Changing -moz-appearence on hover breaks change event * Rename nsIDOMEventTarget::PreHandleEvent to nsIDOMEventTarget::GetEventTargetParent * Add nsIDOMEventTarget::PreHandleEvent * Add EventTargetChainItem::GetFirstEventTarget * Call EventTargetChainItem::PreHandleEvent even it sets mCanHandle=false * Move form control frame focus/blur from nsGenericHTMLFormElement::GetEventTargetParent to PreHandleEvent * Move fire change event from HTMLTextAreaElement::GetEventTargetParent to PreHandleEvent * Refine nsXULElement::GetEventTargetParent * Move dispatch XUL command from nsXULElement::GetEventTargetParent to PreHandleEvent * Move fire events and set value from HTMLInputElement::GetEventTargetParent to PreHandleEvent * Add test case * Let HTMLInputElement delegate event handling to it's parent class * Refine EventTargetChain flags to reduce overheads * Refine event target chain creation * Refine assertion in EventTargetChainItem::Create Tag #1375 --- dom/base/nsDocument.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dom/base/nsDocument.cpp') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index b05bf827b..45c80ca7f 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -7712,7 +7712,7 @@ nsDocument::GetExistingListenerManager() const } nsresult -nsDocument::PreHandleEvent(EventChainPreVisitor& aVisitor) +nsDocument::GetEventTargetParent(EventChainPreVisitor& aVisitor) { aVisitor.mCanHandle = true; // FIXME! This is a hack to make middle mouse paste working also in Editor. -- cgit v1.2.3 From 0d362ca50335d964a78dbba7e7d32574ee67899a Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 05:01:17 -0400 Subject: Bug 1330843 - Allow JS to create NAC pseudo-elements Tag #1375 --- dom/base/nsDocument.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'dom/base/nsDocument.cpp') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 45c80ca7f..d0e861b1a 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -5378,6 +5378,20 @@ nsDocument::GetCustomElementRegistry() return registry.forget(); } +// We only support pseudo-elements with two colons in this function. +static CSSPseudoElementType +GetPseudoElementType(const nsString& aString, ErrorResult& aRv) +{ + MOZ_ASSERT(!aString.IsEmpty(), "GetPseudoElementType aString should be non-null"); + if (aString.Length() <= 2 || aString[0] != ':' || aString[1] != ':') { + aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); + return CSSPseudoElementType::NotPseudo; + } + nsCOMPtr pseudo = NS_Atomize(Substring(aString, 1)); + return nsCSSPseudoElements::GetPseudoType(pseudo, + nsCSSProps::EnabledState::eInUASheets); +} + already_AddRefed nsDocument::CreateElement(const nsAString& aTagName, const ElementCreationOptionsOrString& aOptions, @@ -5395,10 +5409,36 @@ nsDocument::CreateElement(const nsAString& aTagName, } const nsString* is = nullptr; + CSSPseudoElementType pseudoType = CSSPseudoElementType::NotPseudo; + if (aOptions.IsElementCreationOptions()) { + const ElementCreationOptions& options = + aOptions.GetAsElementCreationOptions(); + + if (CustomElementRegistry::IsCustomElementEnabled() && + options.mIs.WasPassed()) { + is = &options.mIs.Value(); + } + + // Check 'pseudo' and throw an exception if it's not one allowed + // with CSS_PSEUDO_ELEMENT_IS_JS_CREATED_NAC. + if (options.mPseudo.WasPassed()) { + pseudoType = GetPseudoElementType(options.mPseudo.Value(), rv); + if (rv.Failed() || + pseudoType == CSSPseudoElementType::NotPseudo || + !nsCSSPseudoElements::PseudoElementIsJSCreatedNAC(pseudoType)) { + rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); + return nullptr; + } + } + } RefPtr elem = CreateElem( needsLowercase ? lcTagName : aTagName, nullptr, mDefaultElementType, is); + if (pseudoType != CSSPseudoElementType::NotPseudo) { + elem->SetPseudoElementType(pseudoType); + } + if (is) { elem->SetAttr(kNameSpaceID_None, nsGkAtoms::is, *is, true); } @@ -5413,8 +5453,8 @@ nsDocument::CreateElementNS(const nsAString& aNamespaceURI, { *aReturn = nullptr; ElementCreationOptionsOrString options; - options.SetAsString(); + options.SetAsString(); ErrorResult rv; nsCOMPtr element = CreateElementNS(aNamespaceURI, aQualifiedName, options, rv); @@ -5439,6 +5479,13 @@ nsDocument::CreateElementNS(const nsAString& aNamespaceURI, } const nsString* is = nullptr; + if (CustomElementRegistry::IsCustomElementEnabled() && + aOptions.IsElementCreationOptions()) { + const ElementCreationOptions& options = aOptions.GetAsElementCreationOptions(); + if (options.mIs.WasPassed()) { + is = &options.mIs.Value(); + } + } nsCOMPtr element; rv = NS_NewElement(getter_AddRefs(element), nodeInfo.forget(), -- cgit v1.2.3 From 940d191ef8b61309f4ea83d0fea77828f361251b Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 05:28:43 -0400 Subject: Bug 1367683 - Optimize initializing nsRange Tag #1375 --- dom/base/nsDocument.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dom/base/nsDocument.cpp') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index d0e861b1a..e16c1831c 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -6468,7 +6468,7 @@ already_AddRefed nsIDocument::CreateRange(ErrorResult& rv) { RefPtr range = new nsRange(this); - nsresult res = range->Set(this, 0, this, 0); + nsresult res = range->CollapseTo(this, 0); if (NS_FAILED(res)) { rv.Throw(res); return nullptr; -- cgit v1.2.3 From 2e2190a5044943bde31679996afdc3558d22231b Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 05:46:23 -0400 Subject: Bug 1332353 - Make it clearer when a stylesheet is really owned by its mDocument Tag #1375 --- dom/base/nsDocument.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'dom/base/nsDocument.cpp') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index e16c1831c..130580fad 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1452,11 +1452,11 @@ nsDocument::~nsDocument() // Let the stylesheets know we're going away for (StyleSheet* sheet : mStyleSheets) { - sheet->SetOwningDocument(nullptr); + sheet->ClearAssociatedDocument(); } for (auto& sheets : mAdditionalSheets) { for (StyleSheet* sheet : sheets) { - sheet->SetOwningDocument(nullptr); + sheet->ClearAssociatedDocument(); } } if (mAttrStyleSheet) { @@ -2113,7 +2113,7 @@ nsDocument::RemoveDocStyleSheetsFromStyleSets() { // The stylesheets should forget us for (StyleSheet* sheet : Reversed(mStyleSheets)) { - sheet->SetOwningDocument(nullptr); + sheet->ClearAssociatedDocument(); if (sheet->IsApplicable()) { nsCOMPtr shell = GetShell(); @@ -2132,7 +2132,7 @@ nsDocument::RemoveStyleSheetsFromStyleSets( { // The stylesheets should forget us for (StyleSheet* sheet : Reversed(aSheets)) { - sheet->SetOwningDocument(nullptr); + sheet->ClearAssociatedDocument(); if (sheet->IsApplicable()) { nsCOMPtr shell = GetShell(); @@ -4007,7 +4007,7 @@ nsDocument::AddStyleSheet(StyleSheet* aSheet) { NS_PRECONDITION(aSheet, "null arg"); mStyleSheets.AppendElement(aSheet); - aSheet->SetOwningDocument(this); + aSheet->SetAssociatedDocument(this, StyleSheet::OwnedByDocument); if (aSheet->IsApplicable()) { AddStyleSheetToStyleSets(aSheet); @@ -4044,7 +4044,7 @@ nsDocument::RemoveStyleSheet(StyleSheet* aSheet) NotifyStyleSheetRemoved(aSheet, true); } - aSheet->SetOwningDocument(nullptr); + aSheet->ClearAssociatedDocument(); } void @@ -4072,7 +4072,7 @@ nsDocument::UpdateStyleSheets(nsTArray>& aOldSheets, StyleSheet* newSheet = aNewSheets[i]; if (newSheet) { mStyleSheets.InsertElementAt(oldIndex, newSheet); - newSheet->SetOwningDocument(this); + newSheet->SetAssociatedDocument(this, StyleSheet::OwnedByDocument); if (newSheet->IsApplicable()) { AddStyleSheetToStyleSets(newSheet); } @@ -4091,7 +4091,7 @@ nsDocument::InsertStyleSheetAt(StyleSheet* aSheet, int32_t aIndex) mStyleSheets.InsertElementAt(aIndex, aSheet); - aSheet->SetOwningDocument(this); + aSheet->SetAssociatedDocument(this, StyleSheet::OwnedByDocument); if (aSheet->IsApplicable()) { AddStyleSheetToStyleSets(aSheet); @@ -4216,7 +4216,7 @@ nsDocument::LoadAdditionalStyleSheet(additionalSheetType aType, nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, &sheet); NS_ENSURE_SUCCESS(rv, rv); - sheet->SetOwningDocument(this); + sheet->SetAssociatedDocument(this, StyleSheet::OwnedByDocument); MOZ_ASSERT(sheet->IsApplicable()); return AddAdditionalStyleSheet(aType, sheet); @@ -4274,7 +4274,7 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet NotifyStyleSheetRemoved(sheetRef, false); EndUpdate(UPDATE_STYLE); - sheetRef->SetOwningDocument(nullptr); + sheetRef->ClearAssociatedDocument(); } } @@ -12126,7 +12126,7 @@ SizeOfOwnedSheetArrayExcludingThis(const nsTArray>& aSheets, size_t n = 0; n += aSheets.ShallowSizeOfExcludingThis(aMallocSizeOf); for (StyleSheet* sheet : aSheets) { - if (!sheet->GetOwningDocument()) { + if (!sheet->GetAssociatedDocument()) { // Avoid over-reporting shared sheets. continue; } -- cgit v1.2.3 From 61e46a6d58a58e249f1982d903780bf5bccb8f6b Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 06:24:43 -0400 Subject: Issue #1375 - Stop largely using the parser service This is based on Bug 1395828 * Add nsHTMLElement::IsBlock() * Rename nsHTMLTags methods * Remove AssertParserServiceIsCorrect() * Remove most uses of nsIParserService/nsParserService --- dom/base/nsDocument.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'dom/base/nsDocument.cpp') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 130580fad..87d860c6a 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -116,7 +116,6 @@ #include "nsBidiUtils.h" -#include "nsIParserService.h" #include "nsContentCreatorFunctions.h" #include "nsIScriptContext.h" -- cgit v1.2.3 From 5524318fe73a1123da10491a6a545b50af88ea60 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 07:07:09 -0400 Subject: Bug 1416999 - Remove document.registerElement Tag #1375 --- dom/base/nsDocument.cpp | 247 ------------------------------------------------ 1 file changed, 247 deletions(-) (limited to 'dom/base/nsDocument.cpp') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 87d860c6a..d69fff863 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -5352,31 +5352,6 @@ bool IsLowercaseASCII(const nsAString& aValue) return true; } -already_AddRefed -nsDocument::GetCustomElementRegistry() -{ - nsAutoString contentType; - GetContentType(contentType); - if (!IsHTMLDocument() && - !contentType.EqualsLiteral("application/xhtml+xml")) { - return nullptr; - } - - nsCOMPtr window( - do_QueryInterface(mScriptGlobalObject ? mScriptGlobalObject - : GetScopeObject())); - if (!window) { - return nullptr; - } - - RefPtr registry = window->CustomElements(); - if (!registry) { - return nullptr; - } - - return registry.forget(); -} - // We only support pseudo-elements with two colons in this function. static CSSPseudoElementType GetPseudoElementType(const nsString& aString, ErrorResult& aRv) @@ -5692,103 +5667,6 @@ nsIDocument::CreateAttributeNS(const nsAString& aNamespaceURI, return attribute.forget(); } -bool -nsDocument::CustomElementConstructor(JSContext* aCx, unsigned aArgc, JS::Value* aVp) -{ - JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp); - - JS::Rooted global(aCx, - JS_GetGlobalForObject(aCx, &args.callee())); - RefPtr window; - UNWRAP_OBJECT(Window, global, window); - MOZ_ASSERT(window, "Should have a non-null window"); - - nsDocument* document = static_cast(window->GetDoc()); - - // Function name is the type of the custom element. - JSString* jsFunName = - JS_GetFunctionId(JS_ValueToFunction(aCx, args.calleev())); - nsAutoJSString elemName; - if (!elemName.init(aCx, jsFunName)) { - return true; - } - - RefPtr registry = window->CustomElements(); - if (!registry) { - return true; - } - - nsCOMPtr typeAtom(NS_Atomize(elemName)); - CustomElementDefinition* definition = - registry->mCustomDefinitions.GetWeak(typeAtom); - if (!definition) { - return true; - } - - RefPtr element; - - // We integrate with construction stack and do prototype swizzling here, so - // that old upgrade behavior could also share the new upgrade steps. - // And this old upgrade will be remove at some point (when everything is - // switched to latest custom element spec). - nsTArray>& constructionStack = - definition->mConstructionStack; - if (constructionStack.Length()) { - element = constructionStack.LastElement(); - NS_ENSURE_TRUE(element != ALEADY_CONSTRUCTED_MARKER, false); - - // Do prototype swizzling if dom reflector exists. - JS::Rooted reflector(aCx, element->GetWrapper()); - if (reflector) { - Maybe ac; - JS::Rooted prototype(aCx, definition->mPrototype); - if (element->NodePrincipal()->SubsumesConsideringDomain(nsContentUtils::ObjectPrincipal(prototype))) { - ac.emplace(aCx, reflector); - if (!JS_WrapObject(aCx, &prototype) || - !JS_SetPrototype(aCx, reflector, prototype)) { - return false; - } - } else { - // We want to set the custom prototype in the compartment where it was - // registered. We store the prototype from define() without unwrapped, - // hence the prototype's compartment is the compartment where it was - // registered. - // In the case that |reflector| and |prototype| are in different - // compartments, this will set the prototype on the |reflector|'s wrapper - // and thus only visible in the wrapper's compartment, since we know - // reflector's principal does not subsume prototype's in this case. - ac.emplace(aCx, prototype); - if (!JS_WrapObject(aCx, &reflector) || - !JS_SetPrototype(aCx, reflector, prototype)) { - return false; - } - } - - // Wrap into current context. - if (!JS_WrapObject(aCx, &reflector)) { - return false; - } - - args.rval().setObject(*reflector); - return true; - } - } else { - nsDependentAtomString localName(definition->mLocalName); - element = - document->CreateElem(localName, nullptr, kNameSpaceID_XHTML, - (definition->mLocalName != typeAtom) ? &elemName - : nullptr); - NS_ENSURE_TRUE(element, false); - } - - // The prototype setup happens in Element::WrapObject(). - - nsresult rv = nsContentUtils::WrapNative(aCx, element, element, args.rval()); - NS_ENSURE_SUCCESS(rv, true); - - return true; -} - bool nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject) { @@ -5842,131 +5720,6 @@ nsDocument::IsWebComponentsEnabled(nsPIDOMWindowInner* aWindow) return false; } -void -nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType, - const ElementRegistrationOptions& aOptions, - JS::MutableHandle aRetval, - ErrorResult& rv) -{ - RefPtr registry(GetCustomElementRegistry()); - if (!registry) { - rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return; - } - - AutoCEReaction ceReaction(this->GetDocGroup()->CustomElementReactionsStack(), - aCx); - // Unconditionally convert TYPE to lowercase. - nsAutoString lcType; - nsContentUtils::ASCIIToLower(aType, lcType); - - nsIGlobalObject* sgo = GetScopeObject(); - if (!sgo) { - rv.Throw(NS_ERROR_UNEXPECTED); - return; - } - - JS::Rooted global(aCx, sgo->GetGlobalJSObject()); - JS::Rooted protoObject(aCx); - - if (!aOptions.mPrototype) { - JS::Rooted htmlProto(aCx); - htmlProto = HTMLElementBinding::GetProtoObjectHandle(aCx); - if (!htmlProto) { - rv.Throw(NS_ERROR_OUT_OF_MEMORY); - return; - } - - protoObject = JS_NewObjectWithGivenProto(aCx, nullptr, htmlProto); - if (!protoObject) { - rv.Throw(NS_ERROR_UNEXPECTED); - return; - } - } else { - protoObject = aOptions.mPrototype; - - // Get the unwrapped prototype to do some checks. - JS::Rooted protoObjectUnwrapped(aCx, js::CheckedUnwrap(protoObject)); - if (!protoObjectUnwrapped) { - // If the caller's compartment does not have permission to access the - // unwrapped prototype then throw. - rv.Throw(NS_ERROR_DOM_SECURITY_ERR); - return; - } - - // If PROTOTYPE is already an interface prototype object for any interface - // object or PROTOTYPE has a non-configurable property named constructor, - // throw a NotSupportedError and stop. - const js::Class* clasp = js::GetObjectClass(protoObjectUnwrapped); - if (IsDOMIfaceAndProtoClass(clasp)) { - rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return; - } - - JS::Rooted descRoot(aCx); - JS::MutableHandle desc(&descRoot); - // This check may go through a wrapper, but as we checked above - // it should be transparent or an xray. This should be fine for now, - // until the spec is sorted out. - if (!JS_GetPropertyDescriptor(aCx, protoObject, "constructor", desc)) { - rv.Throw(NS_ERROR_UNEXPECTED); - return; - } - - if (!desc.configurable()) { - rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return; - } - } - - JS::Rooted constructor(aCx); - { - // Go into the document's global compartment when creating the constructor - // function because we want to get the correct document (where the - // definition is registered) when it is called. - JSAutoCompartment ac(aCx, global); - - // Create constructor to return. Store the name of the custom element as the - // name of the function. - constructor = JS_NewFunction(aCx, nsDocument::CustomElementConstructor, 0, - JSFUN_CONSTRUCTOR, - NS_ConvertUTF16toUTF8(lcType).get()); - if (!constructor) { - rv.Throw(NS_ERROR_OUT_OF_MEMORY); - return; - } - } - - JS::Rooted wrappedConstructor(aCx); - wrappedConstructor = JS_GetFunctionObject(constructor); - if (!JS_WrapObject(aCx, &wrappedConstructor)) { - rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return; - } - - if (!JS_LinkConstructorAndPrototype(aCx, wrappedConstructor, protoObject)) { - rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return; - } - - ElementDefinitionOptions options; - if (!aOptions.mExtends.IsVoid()) { - // Only convert NAME to lowercase in HTML documents. - nsAutoString lcName; - IsHTMLDocument() ? nsContentUtils::ASCIIToLower(aOptions.mExtends, lcName) - : lcName.Assign(aOptions.mExtends); - - options.mExtends.Construct(lcName); - } - - RootedCallback> functionConstructor(aCx); - functionConstructor = new binding_detail::FastFunction(aCx, wrappedConstructor, sgo); - - registry->Define(lcType, functionConstructor, options, rv); - - aRetval.set(wrappedConstructor); -} - NS_IMETHODIMP nsDocument::GetElementsByTagName(const nsAString& aTagname, nsIDOMNodeList** aReturn) -- cgit v1.2.3 From fd7a325bc08f1f027b692181b6c7ab5efaf619aa Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 07:25:14 -0400 Subject: Bug 1422931 - Fix crash with slot element and make webcomponents preference per-doc Tag #1375 --- dom/base/nsDocument.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'dom/base/nsDocument.cpp') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index d69fff863..459ad6bdd 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1332,6 +1332,10 @@ nsIDocument::nsIDocument() { SetIsInDocument(); + // Set this when document is created and value stays the same for the lifetime + // of the document. + mIsWebComponentsEnabled = nsContentUtils::IsWebComponentsEnabled(); + PR_INIT_CLIST(&mDOMMediaQueryLists); } @@ -5685,6 +5689,12 @@ nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject) return IsWebComponentsEnabled(window); } +bool +nsDocument::IsWebComponentsEnabled(const nsINode* aNode) +{ + return aNode->OwnerDoc()->IsWebComponentsEnabled(); +} + bool nsDocument::IsWebComponentsEnabled(dom::NodeInfo* aNodeInfo) { -- cgit v1.2.3 From 7e506bd98dab604062bfe12a44c096eb287721bf Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 07:30:43 -0400 Subject: Bug 1412775 - Implement Event.composedPath Tag #1375 --- dom/base/nsDocument.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dom/base/nsDocument.cpp') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 459ad6bdd..d2763eddd 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -7531,8 +7531,8 @@ nsDocument::GetEventTargetParent(EventChainPreVisitor& aVisitor) // Load events must not propagate to |window| object, see bug 335251. if (aVisitor.mEvent->mMessage != eLoad) { nsGlobalWindow* window = nsGlobalWindow::Cast(GetWindow()); - aVisitor.mParentTarget = - window ? window->GetTargetForEventTargetChain() : nullptr; + aVisitor.SetParentTarget( + window ? window->GetTargetForEventTargetChain() : nullptr, false); } return NS_OK; } -- cgit v1.2.3 From 9e5e58c0f6e1c65674cc688816f387532661d6f1 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 07:42:07 -0400 Subject: Bug 1425769 - Base class for ShadowRoot and Document to manage style state Tag #1375 --- dom/base/nsDocument.cpp | 127 ++++++------------------------------------------ 1 file changed, 14 insertions(+), 113 deletions(-) (limited to 'dom/base/nsDocument.cpp') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index d2763eddd..745d170f1 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -570,78 +570,6 @@ struct nsRadioGroupStruct bool mGroupSuffersFromValueMissing; }; - -nsDOMStyleSheetList::nsDOMStyleSheetList(nsIDocument *aDocument) -{ - mLength = -1; - // Not reference counted to avoid circular references. - // The document will tell us when its going away. - mDocument = aDocument; - mDocument->AddObserver(this); -} - -nsDOMStyleSheetList::~nsDOMStyleSheetList() -{ - if (mDocument) { - mDocument->RemoveObserver(this); - } -} - -NS_IMPL_ISUPPORTS_INHERITED(nsDOMStyleSheetList, StyleSheetList, - nsIDocumentObserver, - nsIMutationObserver) - -uint32_t -nsDOMStyleSheetList::Length() -{ - if (!mDocument) { - return 0; - } - - // XXX Find the number and then cache it. We'll use the - // observer notification to figure out if new ones have - // been added or removed. - if (-1 == mLength) { - mLength = mDocument->GetNumberOfStyleSheets(); - } - return mLength; -} - -StyleSheet* -nsDOMStyleSheetList::IndexedGetter(uint32_t aIndex, bool& aFound) -{ - if (!mDocument || aIndex >= (uint32_t)mDocument->GetNumberOfStyleSheets()) { - aFound = false; - return nullptr; - } - aFound = true; - return mDocument->GetStyleSheetAt(aIndex); -} - -void -nsDOMStyleSheetList::NodeWillBeDestroyed(const nsINode *aNode) -{ - mDocument = nullptr; -} - -void -nsDOMStyleSheetList::StyleSheetAdded(StyleSheet* aStyleSheet, - bool aDocumentSheet) -{ - if (aDocumentSheet && -1 != mLength) { - mLength++; - } -} - -void -nsDOMStyleSheetList::StyleSheetRemoved(StyleSheet* aStyleSheet, - bool aDocumentSheet) -{ - if (aDocumentSheet && -1 != mLength) { - mLength--; - } -} - // nsOnloadBlocker implementation NS_IMPL_ISUPPORTS(nsOnloadBlocker, nsIRequest) @@ -1199,10 +1127,10 @@ nsDOMStyleSheetSetList::EnsureFresh() // no document, for sure } - int32_t count = mDocument->GetNumberOfStyleSheets(); + size_t count = mDocument->SheetCount(); nsAutoString title; - for (int32_t index = 0; index < count; index++) { - StyleSheet* sheet = mDocument->GetStyleSheetAt(index); + for (size_t index = 0; index < count; index++) { + StyleSheet* sheet = mDocument->SheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); // XXXheycam ServoStyleSheets don't expose their title yet. if (sheet->IsServo()) { @@ -3930,24 +3858,6 @@ nsDocument::AddOnDemandBuiltInUASheet(StyleSheet* aSheet) NotifyStyleSheetAdded(aSheet, false); } -int32_t -nsDocument::GetNumberOfStyleSheets() const -{ - return mStyleSheets.Length(); -} - -StyleSheet* -nsDocument::GetStyleSheetAt(int32_t aIndex) const -{ - return mStyleSheets.SafeElementAt(aIndex, nullptr); -} - -int32_t -nsDocument::GetIndexOfStyleSheet(const StyleSheet* aSheet) const -{ - return mStyleSheets.IndexOf(aSheet); -} - void nsDocument::AddStyleSheetToStyleSets(StyleSheet* aSheet) { @@ -4088,9 +3998,9 @@ nsDocument::UpdateStyleSheets(nsTArray>& aOldSheets, } void -nsDocument::InsertStyleSheetAt(StyleSheet* aSheet, int32_t aIndex) +nsDocument::InsertStyleSheetAt(StyleSheet* aSheet, size_t aIndex) { - NS_PRECONDITION(aSheet, "null ptr"); + MOZ_ASSERT(aSheet); mStyleSheets.InsertElementAt(aIndex, aSheet); @@ -5815,15 +5725,6 @@ nsDocument::GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets) return NS_OK; } -StyleSheetList* -nsDocument::StyleSheets() -{ - if (!mDOMStyleSheets) { - mDOMStyleSheets = new nsDOMStyleSheetList(this); - } - return mDOMStyleSheets; -} - NS_IMETHODIMP nsDocument::GetMozSelectedStyleSheetSet(nsAString& aSheetSet) { @@ -5837,10 +5738,10 @@ nsIDocument::GetSelectedStyleSheetSet(nsAString& aSheetSet) aSheetSet.Truncate(); // Look through our sheets, find the selected set title - int32_t count = GetNumberOfStyleSheets(); + size_t count = SheetCount(); nsAutoString title; - for (int32_t index = 0; index < count; index++) { - StyleSheet* sheet = GetStyleSheetAt(index); + for (size_t index = 0; index < count; index++) { + StyleSheet* sheet = SheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); // XXXheycam Make this work with ServoStyleSheets. @@ -5957,10 +5858,10 @@ nsDocument::EnableStyleSheetsForSetInternal(const nsAString& aSheetSet, bool aUpdateCSSLoader) { BeginUpdate(UPDATE_STYLE); - int32_t count = GetNumberOfStyleSheets(); + size_t count = SheetCount(); nsAutoString title; - for (int32_t index = 0; index < count; index++) { - StyleSheet* sheet = GetStyleSheetAt(index); + for (size_t index = 0; index < count; index++) { + StyleSheet* sheet = SheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); // XXXheycam Make this work with ServoStyleSheets. @@ -9668,9 +9569,9 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer) clonedDoc->mOriginalDocument->mStaticCloneCount++; - int32_t sheetsCount = GetNumberOfStyleSheets(); - for (int32_t i = 0; i < sheetsCount; ++i) { - RefPtr sheet = GetStyleSheetAt(i); + size_t sheetsCount = SheetCount(); + for (size_t i = 0; i < sheetsCount; ++i) { + RefPtr sheet = SheetAt(i); if (sheet) { if (sheet->IsApplicable()) { // XXXheycam Need to make ServoStyleSheet cloning work. -- cgit v1.2.3 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 +++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 53 deletions(-) (limited to 'dom/base/nsDocument.cpp') 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) -- cgit v1.2.3