Bug 1455492: Remove redundant ParseSheet arguments. r=bholley

For the async caller, pretty much everything can be extracted out of the loader
/ loadData.

For the sync callers, we need to be a bit more careful because ReparseSheet
tries to get its line number on its own.

I changed the compat mode passed to the reparse stuff to be the document's one
in this case, but that seems a bug fix.

MozReview-Commit-ID: 2wi5HPRAlPi
This commit is contained in:
Emilio Cobos Álvarez 2018-04-20 03:42:00 +02:00
Родитель 50f1e29000
Коммит 1c74b688f7
5 изменённых файлов: 37 добавлений и 70 удалений

Просмотреть файл

@ -1098,9 +1098,10 @@ nsTreeSanitizer::SanitizeStyleSheet(const nsAString& aOriginal,
sheet->SetURIs(aDocument->GetDocumentURI(), nullptr, aBaseURI);
sheet->SetPrincipal(aDocument->NodePrincipal());
sheet->AsServo()->ParseSheetSync(
aDocument->CSSLoader(), NS_ConvertUTF16toUTF8(aOriginal),
aDocument->GetDocumentURI(), aBaseURI, aDocument->NodePrincipal(),
/* aLoadData = */ nullptr, 0, aDocument->GetCompatibilityMode());
aDocument->CSSLoader(),
NS_ConvertUTF16toUTF8(aOriginal),
/* aLoadData = */ nullptr,
/* aLineNumber = */ 0);
NS_ENSURE_SUCCESS(rv, true);
// Mark the sheet as complete.
MOZ_ASSERT(!sheet->HasForcedUniqueInner(),

Просмотреть файл

@ -1635,16 +1635,7 @@ Loader::DoParseSheetServo(ServoStyleSheet* aSheet,
// Some cases, like inline style and UA stylesheets, need to be parsed
// synchronously. The former may trigger child loads, the latter must not.
if (aLoadData->mSyncLoad || !aAllowAsync) {
aSheet->ParseSheetSync(
this,
aBytes,
aSheet->GetSheetURI(),
aSheet->GetBaseURI(),
aSheet->Principal(),
aLoadData,
aLoadData->mLineNumber,
GetCompatibilityMode()
);
aSheet->ParseSheetSync(this, aBytes, aLoadData, aLoadData->mLineNumber);
aLoadData->mIsBeingParsed = false;
bool noPendingChildren = aLoadData->mPendingChildren == 0;
@ -1664,27 +1655,18 @@ Loader::DoParseSheetServo(ServoStyleSheet* aSheet,
BlockOnload();
RefPtr<SheetLoadData> loadData = aLoadData;
nsCOMPtr<nsISerialEventTarget> target = DispatchTarget();
aSheet->ParseSheet(
this,
aBytes,
aSheet->GetSheetURI(),
aSheet->GetBaseURI(),
aSheet->Principal(),
aLoadData,
aLoadData->mLineNumber,
GetCompatibilityMode()
)->Then(target, __func__,
[loadData](bool aDummy) {
MOZ_ASSERT(NS_IsMainThread());
loadData->mIsBeingParsed = false;
loadData->mLoader->UnblockOnload(/* aFireSync = */ false);
// If there are no child sheets outstanding, mark us as complete.
// Otherwise, the children are holding strong refs to the data and
// will call SheetComplete() on it when they complete.
if (loadData->mPendingChildren == 0) {
loadData->mLoader->SheetComplete(loadData, NS_OK);
}
}, [] { MOZ_CRASH("rejected parse promise"); }
aSheet->ParseSheet(this, aBytes, aLoadData)->Then(target, __func__,
[loadData](bool aDummy) {
MOZ_ASSERT(NS_IsMainThread());
loadData->mIsBeingParsed = false;
loadData->mLoader->UnblockOnload(/* aFireSync = */ false);
// If there are no child sheets outstanding, mark us as complete.
// Otherwise, the children are holding strong refs to the data and
// will call SheetComplete() on it when they complete.
if (loadData->mPendingChildren == 0) {
loadData->mLoader->SheetComplete(loadData, NS_OK);
}
}, [] { MOZ_CRASH("rejected parse promise"); }
);
return NS_OK;

Просмотреть файл

@ -234,18 +234,16 @@ AllowParallelParse(css::Loader* aLoader, nsIURI* aSheetURI)
RefPtr<StyleSheetParsePromise>
ServoStyleSheet::ParseSheet(css::Loader* aLoader,
const nsACString& aBytes,
nsIURI* aSheetURI,
nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal,
css::SheetLoadData* aLoadData,
uint32_t aLineNumber,
nsCompatibility aCompatMode)
css::SheetLoadData* aLoadData)
{
MOZ_ASSERT(aLoader);
MOZ_ASSERT(aLoadData);
MOZ_ASSERT(mParsePromise.IsEmpty());
RefPtr<StyleSheetParsePromise> p = mParsePromise.Ensure(__func__);
Inner()->mURLData = new URLExtraData(aBaseURI, aSheetURI, aSheetPrincipal); // RefPtr
Inner()->mURLData =
new URLExtraData(GetBaseURI(), GetSheetURI(), Principal()); // RefPtr
if (!AllowParallelParse(aLoader, aSheetURI)) {
if (!AllowParallelParse(aLoader, GetSheetURI())) {
RefPtr<RawServoStyleSheetContents> contents =
Servo_StyleSheet_FromUTF8Bytes(aLoader,
this,
@ -253,8 +251,8 @@ ServoStyleSheet::ParseSheet(css::Loader* aLoader,
&aBytes,
mParsingMode,
Inner()->mURLData,
aLineNumber,
aCompatMode,
aLoadData->mLineNumber,
aLoader->GetCompatibilityMode(),
/* reusable_sheets = */ nullptr)
.Consume();
FinishAsyncParse(contents.forget());
@ -265,8 +263,8 @@ ServoStyleSheet::ParseSheet(css::Loader* aLoader,
Inner()->mURLData,
&aBytes,
mParsingMode,
aLineNumber,
aCompatMode);
aLoadData->mLineNumber,
aLoader->GetCompatibilityMode());
}
return Move(p);
@ -286,16 +284,14 @@ ServoStyleSheet::FinishAsyncParse(already_AddRefed<RawServoStyleSheetContents> a
void
ServoStyleSheet::ParseSheetSync(css::Loader* aLoader,
const nsACString& aBytes,
nsIURI* aSheetURI,
nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal,
css::SheetLoadData* aLoadData,
uint32_t aLineNumber,
nsCompatibility aCompatMode,
css::LoaderReusableStyleSheets* aReusableSheets)
{
Inner()->mURLData = new URLExtraData(aBaseURI, aSheetURI, aSheetPrincipal); // RefPtr
nsCompatibility compatMode =
aLoader ? aLoader->GetCompatibilityMode() : eCompatibility_FullStandards;
Inner()->mURLData = new URLExtraData(GetBaseURI(), GetSheetURI(), Principal()); // RefPtr
Inner()->mContents = Servo_StyleSheet_FromUTF8Bytes(aLoader,
this,
aLoadData,
@ -303,7 +299,7 @@ ServoStyleSheet::ParseSheetSync(css::Loader* aLoader,
mParsingMode,
Inner()->mURLData,
aLineNumber,
aCompatMode,
compatMode,
aReusableSheets)
.Consume();
@ -390,12 +386,8 @@ ServoStyleSheet::ReparseSheet(const nsAString& aInput)
ParseSheetSync(loader,
NS_ConvertUTF16toUTF8(aInput),
mInner->mSheetURI,
mInner->mBaseURI,
mInner->mPrincipal,
/* aLoadData = */ nullptr,
lineNumber,
eCompatibility_FullStandards,
&reusableSheets);
DidDirty();

Просмотреть файл

@ -94,12 +94,7 @@ public:
RefPtr<StyleSheetParsePromise>
ParseSheet(css::Loader* aLoader,
const nsACString& aBytes,
nsIURI* aSheetURI,
nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal,
css::SheetLoadData* aLoadData,
uint32_t aLineNumber,
nsCompatibility aCompatMode);
css::SheetLoadData* aLoadData);
// Common code that needs to be called after servo finishes parsing. This is
// shared between the parallel and sequential paths.
@ -110,12 +105,8 @@ public:
void
ParseSheetSync(css::Loader* aLoader,
const nsACString& aBytes,
nsIURI* aSheetURI,
nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal,
css::SheetLoadData* aLoadData,
uint32_t aLineNumber,
nsCompatibility aCompatMode,
css::LoaderReusableStyleSheets* aReusableSheets = nullptr);
nsresult ReparseSheet(const nsAString& aInput);

Просмотреть файл

@ -888,10 +888,11 @@ nsLayoutStylesheetCache::BuildPreferenceSheet(RefPtr<StyleSheet>* aSheet,
"sheet without reallocation");
ServoStyleSheet* servoSheet = sheet->AsServo();
// NB: The pref sheet never has @import rules.
servoSheet->ParseSheetSync(nullptr, sheetText, uri, uri, nullptr,
/* aLoadData = */ nullptr, 0,
eCompatibility_FullStandards);
// NB: The pref sheet never has @import rules, thus no loader.
servoSheet->ParseSheetSync(nullptr,
sheetText,
/* aLoadData = */ nullptr,
/* aLineNumber = */ 0);
#undef NS_GET_R_G_B
}