From 8f95bacca42dd895b97d02b8bcb4629e039c1b3b Mon Sep 17 00:00:00 2001 From: athenian200 Date: Sun, 6 Sep 2020 13:51:08 -0500 Subject: Issue #1629 - Part 4: Ensure isExplicitlyEnabled is false upon sheet creation. This clarifies the assumptions the code is making and the order in which the variables pass through the loading process. The new variable is set after the sheet is created and prepared, and is assumed to be false in the beginning. --- layout/style/Loader.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'layout/style') diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index c21199238..5ca319b3f 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -2273,7 +2273,8 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet, state = eSheetComplete; } else { bool isAlternate; - bool isExplicitlyEnabled; + // For now, child sheets are not explicitly enabled. + bool isExplicitlyEnabled = false; const nsSubstring& empty = EmptyString(); // For now, use CORS_NONE for child sheets rv = CreateSheet(aURL, nullptr, principal, @@ -2397,7 +2398,9 @@ Loader::InternalLoadNonDocumentSheet(nsIURI* aURL, StyleSheetState state; bool isAlternate; - bool isExplicitlyEnabled; + // Sheets can only be explicitly enabled after creation and preparation, so + // set isExplicitlyEnabled to false. + bool isExplicitlyEnabled = false; RefPtr sheet; bool syncLoad = (aObserver == nullptr); const nsSubstring& empty = EmptyString(); -- cgit v1.2.3 From 1f65f171aa7bc29523654a1dbea770907e6195ac Mon Sep 17 00:00:00 2001 From: athenian200 Date: Wed, 9 Sep 2020 01:40:15 -0500 Subject: Issue #1629 - Part 5: Remove pointless local variables. Since the local variable is always initialized to false, we don't actually need to declare it and can just pass "false" directly as a parameter to the PrepareSheet function's bool. I was worried about code readability at first, but some well-placed comments took care of that. --- layout/style/Loader.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'layout/style') diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 5ca319b3f..155ecbeee 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -2273,8 +2273,6 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet, state = eSheetComplete; } else { bool isAlternate; - // For now, child sheets are not explicitly enabled. - bool isExplicitlyEnabled = false; const nsSubstring& empty = EmptyString(); // For now, use CORS_NONE for child sheets rv = CreateSheet(aURL, nullptr, principal, @@ -2284,8 +2282,9 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet, parentData ? parentData->mSyncLoad : false, false, empty, state, &isAlternate, &sheet); NS_ENSURE_SUCCESS(rv, rv); - - PrepareSheet(sheet, empty, empty, aMedia, nullptr, isAlternate, isExplicitlyEnabled); + // For now, child sheets are not explicitly enabled (seventh argument is + // always false here). + PrepareSheet(sheet, empty, empty, aMedia, nullptr, isAlternate, false); } rv = InsertChildSheet(sheet, aParentSheet, aParentRule); @@ -2398,9 +2397,6 @@ Loader::InternalLoadNonDocumentSheet(nsIURI* aURL, StyleSheetState state; bool isAlternate; - // Sheets can only be explicitly enabled after creation and preparation, so - // set isExplicitlyEnabled to false. - bool isExplicitlyEnabled = false; RefPtr sheet; bool syncLoad = (aObserver == nullptr); const nsSubstring& empty = EmptyString(); @@ -2410,7 +2406,10 @@ Loader::InternalLoadNonDocumentSheet(nsIURI* aURL, false, empty, state, &isAlternate, &sheet); NS_ENSURE_SUCCESS(rv, rv); - PrepareSheet(sheet, empty, empty, nullptr, nullptr, isAlternate, isExplicitlyEnabled); + // Sheets can only be explicitly enabled after creation and preparation, so + // we always pass false for the initial value of the explicitly enabled flag + // when calling PrepareSheet. + PrepareSheet(sheet, empty, empty, nullptr, nullptr, isAlternate, false); if (state == eSheetComplete) { LOG((" Sheet already complete")); -- cgit v1.2.3