From 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:33 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- layout/style/StyleSheet.cpp | 47 ++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'layout/style/StyleSheet.cpp') diff --git a/layout/style/StyleSheet.cpp b/layout/style/StyleSheet.cpp index 494618d879..b1ce1d66e2 100644 --- a/layout/style/StyleSheet.cpp +++ b/layout/style/StyleSheet.cpp @@ -28,7 +28,6 @@ #include "mozilla/css/SheetLoadData.h" #include "mozAutoDocUpdate.h" -#include "SheetLoadData.h" namespace mozilla { @@ -136,8 +135,12 @@ already_AddRefed StyleSheet::Constructor( // 3. Set the sheet's disabled flag according to aOptions. sheet->SetDisabled(aOptions.mDisabled); + sheet->SetURLExtraData(); sheet->SetComplete(); + sheet->ReplaceSync(""_ns, aRv); + MOZ_ASSERT(!aRv.Failed()); + // 4. Return sheet. return sheet.forget(); } @@ -740,7 +743,9 @@ already_AddRefed StyleSheet::Replace(const nsACString& aText, loadData->mIsBeingParsed = true; MOZ_ASSERT(!mReplacePromise); mReplacePromise = promise; - ParseSheet(*loader, aText, *loadData) + RefPtr holder( + new css::SheetLoadDataHolder(__func__, loadData, false)); + ParseSheet(*loader, aText, holder) ->Then( target, __func__, [loadData] { loadData->SheetFinishedParsingAsync(); }, @@ -769,7 +774,6 @@ void StyleSheet::ReplaceSync(const nsACString& aText, ErrorResult& aRv) { // 3. Parse aText into rules. // 4. If rules contain @imports, skip them and continue parsing. auto* loader = mConstructorDocument->CSSLoader(); - SetURLExtraData(); RefPtr rawContent = Servo_StyleSheet_FromUTF8Bytes( loader, this, @@ -1159,28 +1163,19 @@ already_AddRefed StyleSheet::CreateEmptyChildSheet( return child.forget(); } -// We disable parallel stylesheet parsing if the browser is recording CSS errors -// (which parallel parsing can't handle). -static bool AllowParallelParse(css::Loader& aLoader, URLExtraData* aUrlData) { - Document* doc = aLoader.GetDocument(); - if (doc && css::ErrorReporter::ShouldReportErrors(*doc)) { - return false; - } - // Otherwise we can parse in parallel. - return true; -} - RefPtr StyleSheet::ParseSheet( css::Loader& aLoader, const nsACString& aBytes, - css::SheetLoadData& aLoadData) { + const RefPtr& aLoadData) { MOZ_ASSERT(mParsePromise.IsEmpty()); + MOZ_ASSERT_IF(NS_IsMainThread(), mAsyncParseBlockers == 0); + RefPtr p = mParsePromise.Ensure(__func__); - if (!aLoadData.ShouldDefer()) { + if (!aLoadData->get()->ShouldDefer()) { mParsePromise.SetTaskPriority(nsIRunnablePriority::PRIORITY_RENDER_BLOCKING, __func__); } + BlockParsePromise(); SetURLExtraData(); - // @import rules are disallowed due to this decision: // https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418 // We may allow @import rules again in the future. @@ -1191,26 +1186,26 @@ RefPtr StyleSheet::ParseSheet( const bool shouldRecordCounters = aLoader.GetDocument() && aLoader.GetDocument()->GetStyleUseCounters() && !urlData->ChromeRulesEnabled(); - if (!AllowParallelParse(aLoader, urlData)) { + + if (aLoadData->get()->mRecordErrors) { + MOZ_ASSERT(NS_IsMainThread()); UniquePtr counters; if (shouldRecordCounters) { counters.reset(Servo_UseCounters_Create()); } - RefPtr contents = Servo_StyleSheet_FromUTF8Bytes( - &aLoader, this, &aLoadData, &aBytes, mParsingMode, urlData, - aLoadData.mCompatMode, + &aLoader, this, aLoadData->get(), &aBytes, mParsingMode, urlData, + aLoadData->get()->mCompatMode, /* reusable_sheets = */ nullptr, counters.get(), allowImportRules, StyleSanitizationKind::None, /* sanitized_output = */ nullptr) .Consume(); FinishAsyncParse(contents.forget(), std::move(counters)); } else { - auto holder = MakeRefPtr(__func__, &aLoadData); - Servo_StyleSheet_FromUTF8BytesAsync(holder, urlData, &aBytes, mParsingMode, - aLoadData.mCompatMode, - shouldRecordCounters, allowImportRules); + Servo_StyleSheet_FromUTF8BytesAsync( + aLoadData, urlData, &aBytes, mParsingMode, + aLoadData->get()->mCompatMode, shouldRecordCounters, allowImportRules); } return p; @@ -1224,7 +1219,7 @@ void StyleSheet::FinishAsyncParse( Inner().mContents = aSheetContents; Inner().mUseCounters = std::move(aUseCounters); FixUpRuleListAfterContentsChangeIfNeeded(); - mParsePromise.Resolve(true, __func__); + UnblockParsePromise(); } void StyleSheet::ParseSheetSync( -- cgit v1.2.3