diff --git a/dom/chrome-webidl/InspectorUtils.webidl b/dom/chrome-webidl/InspectorUtils.webidl index 8ae374e2efd7..c1a96f6a9ff0 100644 --- a/dom/chrome-webidl/InspectorUtils.webidl +++ b/dom/chrome-webidl/InspectorUtils.webidl @@ -11,7 +11,8 @@ */ [ChromeOnly] namespace InspectorUtils { - sequence getAllStyleSheets(Document document); + // documentOnly tells whether user and UA sheets should get included. + sequence getAllStyleSheets(Document document, optional boolean documentOnly = false); sequence getCSSStyleRules( Element element, [TreatNullAs=EmptyString] optional DOMString pseudo = ""); diff --git a/layout/inspector/InspectorUtils.cpp b/layout/inspector/InspectorUtils.cpp index e94530e8e8de..3c23e19ca369 100644 --- a/layout/inspector/InspectorUtils.cpp +++ b/layout/inspector/InspectorUtils.cpp @@ -61,6 +61,7 @@ namespace dom { /* static */ void InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject, nsIDocument& aDocument, + bool aDocumentOnly, nsTArray>& aResult) { // Get the agent, then user and finally xbl sheets in the style set. @@ -68,19 +69,24 @@ InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject, if (presShell) { ServoStyleSet* styleSet = presShell->StyleSet(); - SheetType sheetType = SheetType::Agent; - for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) { - aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i)); - } - sheetType = SheetType::User; - for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) { - aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i)); + + if (!aDocumentOnly) { + SheetType sheetType = SheetType::Agent; + for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) { + aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i)); + } + sheetType = SheetType::User; + for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) { + aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i)); + } } AutoTArray xblSheetArray; - styleSet->AppendAllXBLStyleSheets(xblSheetArray); + styleSet->AppendAllNonDocumentAuthorSheets(xblSheetArray); // The XBL stylesheet array will quite often be full of duplicates. Cope: + // + // FIXME(emilio, bug 1454467): I think this is not true since bug 1452525. nsTHashtable> sheetSet; for (StyleSheet* sheet : xblSheetArray) { if (!sheetSet.Contains(sheet)) { @@ -1048,16 +1054,8 @@ InspectorUtils::ParseStyleSheet(GlobalObject& aGlobalObject, ErrorResult& aRv) { - RefPtr servoSheet = do_QueryObject(&aSheet); - if (servoSheet) { - nsresult rv = servoSheet->ReparseSheet(aInput); - if (NS_FAILED(rv)) { - aRv.Throw(rv); - } - return; - } - - aRv.Throw(NS_ERROR_INVALID_POINTER); + RefPtr servoSheet = aSheet.AsServo(); + aRv = servoSheet->ReparseSheet(aInput); } void diff --git a/layout/inspector/InspectorUtils.h b/layout/inspector/InspectorUtils.h index d4968cec6141..8efa267b8f42 100644 --- a/layout/inspector/InspectorUtils.h +++ b/layout/inspector/InspectorUtils.h @@ -37,6 +37,7 @@ class InspectorUtils public: static void GetAllStyleSheets(GlobalObject& aGlobal, nsIDocument& aDocument, + bool aDocumentOnly, nsTArray>& aResult); static void GetCSSStyleRules(GlobalObject& aGlobal, Element& aElement, diff --git a/layout/style/ErrorReporter.cpp b/layout/style/ErrorReporter.cpp index defbbdc8abd6..a3ae41a24fc1 100644 --- a/layout/style/ErrorReporter.cpp +++ b/layout/style/ErrorReporter.cpp @@ -146,6 +146,7 @@ ErrorReporter::ErrorReporter(const StyleSheet* aSheet, ErrorReporter::~ErrorReporter() { + MOZ_ASSERT(NS_IsMainThread()); // Schedule deferred cleanup for cached data. We want to strike a // balance between performance and memory usage, so we only allow // short-term caching. diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index 76951ae58dc2..c52f2e7054e9 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -869,10 +869,15 @@ ServoStyleSet::StyleSheetAt(SheetType aType, int32_t aIndex) const } void -ServoStyleSet::AppendAllXBLStyleSheets(nsTArray& aArray) const +ServoStyleSet::AppendAllNonDocumentAuthorSheets(nsTArray& aArray) const { if (mDocument) { mDocument->BindingManager()->AppendAllSheets(aArray); + EnumerateShadowRoots(*mDocument, [&](ShadowRoot& aShadowRoot) { + for (auto index : IntegerRange(aShadowRoot.SheetCount())) { + aArray.AppendElement(aShadowRoot.SheetAt(index)); + } + }); } } diff --git a/layout/style/ServoStyleSet.h b/layout/style/ServoStyleSet.h index 178e70f6f4dc..94ae168c5115 100644 --- a/layout/style/ServoStyleSet.h +++ b/layout/style/ServoStyleSet.h @@ -244,7 +244,7 @@ public: int32_t SheetCount(SheetType aType) const; ServoStyleSheet* StyleSheetAt(SheetType aType, int32_t aIndex) const; - void AppendAllXBLStyleSheets(nsTArray& aArray) const; + void AppendAllNonDocumentAuthorSheets(nsTArray& aArray) const; template void EnumerateStyleSheetArrays(Func aCallback) const {