Issue #3053 - Implement CSSStyleSheet constructor

This commit is contained in:
Basilisk-Dev 2026-05-22 12:35:37 -04:00 committed by wuggy
commit 536619ee89
5 changed files with 79 additions and 0 deletions

View file

@ -12,8 +12,10 @@
#include "mozilla/CSSStyleSheet.h"
#include "mozAutoDocUpdate.h"
#include "nsContentUtils.h"
#include "nsIMediaList.h"
#include "nsNullPrincipal.h"
#include "nsPIDOMWindow.h"
using namespace mozilla::dom;
@ -222,6 +224,40 @@ StyleSheet::DeleteRule(uint32_t aIndex)
// WebIDL CSSStyleSheet API
/* static */ already_AddRefed<StyleSheet>
StyleSheet::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindowInner> window =
do_QueryInterface(aGlobal.GetAsSupports());
if (!window) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsCOMPtr<nsIDocument> document = window->GetDoc();
if (!document) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsCOMPtr<nsIURI> documentURI = document->GetDocumentURI();
nsCOMPtr<nsIURI> baseURI = document->GetBaseURI();
nsIPrincipal* principal = nsContentUtils::ObjectPrincipal(aGlobal.Get());
if (!documentURI || !baseURI || !principal) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<StyleSheet> sheet =
new CSSStyleSheet(css::eAuthorSheetFeatures, CORS_NONE,
document->GetReferrerPolicy());
sheet->SetURIs(documentURI, nullptr, baseURI);
sheet->SetPrincipal(principal);
sheet->SetComplete();
return sheet.forget();
}
dom::CSSRuleList*
StyleSheet::GetCssRules(nsIPrincipal& aSubjectPrincipal,
ErrorResult& aRv)