Bug 1346623 - Allow anonymous content created with nsIDocument::InsertAnonymousContent can change from non-native to native AC

* Prevent canvas custom content from becoming NAC when reframing the root element
* Add an API to get computed style values through an AnonymousContent object

Tag #1375
This commit is contained in:
Matt A. Tobin
2020-04-16 20:19:06 -04:00
committed by Roy Tam
parent 5a9d76e6d5
commit fda213de85
6 changed files with 120 additions and 4 deletions
+27
View File
@@ -7,6 +7,7 @@
#include "AnonymousContent.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/AnonymousContentBinding.h"
#include "nsComputedDOMStyle.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIDocument.h"
#include "nsIDOMHTMLCollection.h"
@@ -208,5 +209,31 @@ AnonymousContent::WrapObject(JSContext* aCx,
return AnonymousContentBinding::Wrap(aCx, this, aGivenProto, aReflector);
}
void
AnonymousContent::GetComputedStylePropertyValue(const nsAString& aElementId,
const nsAString& aPropertyName,
DOMString& aResult,
ErrorResult& aRv)
{
Element* element = GetElementById(aElementId);
if (!element) {
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
return;
}
nsIPresShell* shell = element->OwnerDoc()->GetShell();
if (!shell) {
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
return;
}
RefPtr<nsComputedDOMStyle> cs =
new nsComputedDOMStyle(element,
NS_LITERAL_STRING(""),
element->OwnerDoc(),
nsComputedDOMStyle::eAll);
aRv = cs->GetPropertyValue(aPropertyName, aResult);
}
} // namespace dom
} // namespace mozilla