From 04c11b322dbda07d338622bfdb89f8f8daee96f9 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Thu, 11 Jan 2018 12:37:59 +0800 Subject: [PATCH] Bug 1427419 - Part 2: Move nsIDOMUtils.getAllStyleSheets to InspectorUtils. r=bz MozReview-Commit-ID: J6lIx4uvMlS --- devtools/server/actors/stylesheets.js | 4 +- .../mochitest/chrome/test_parsingMode.html | 2 +- dom/webidl/InspectorUtils.webidl | 1 + layout/inspector/InspectorUtils.h | 12 +++++ layout/inspector/inDOMUtils.cpp | 45 +++++++------------ layout/inspector/inIDOMUtils.idl | 4 -- .../tests/test_get_all_style_sheets.html | 6 +-- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/devtools/server/actors/stylesheets.js b/devtools/server/actors/stylesheets.js index 77c0a1d12791..f2374853b158 100644 --- a/devtools/server/actors/stylesheets.js +++ b/devtools/server/actors/stylesheets.js @@ -16,6 +16,7 @@ const {mediaRuleSpec, styleSheetSpec, styleSheetsSpec} = require("devtools/shared/specs/stylesheets"); const { addPseudoClassLock, removePseudoClassLock } = require("devtools/server/actors/highlighters/utils/markup"); +const InspectorUtils = require("InspectorUtils"); loader.lazyRequireGetter(this, "CssLogic", "devtools/shared/inspector/css-logic"); loader.lazyRequireGetter(this, "addPseudoClassLock", @@ -805,7 +806,8 @@ var StyleSheetsActor = protocol.ActorClassWithSpec(styleSheetsSpec, { doc.styleSheetChangeEventsEnabled = true; let isChrome = Services.scriptSecurityManager.isSystemPrincipal(doc.nodePrincipal); - let styleSheets = isChrome ? DOMUtils.getAllStyleSheets(doc) : doc.styleSheets; + let styleSheets = + isChrome ? InspectorUtils.getAllStyleSheets(doc) : doc.styleSheets; let actors = []; for (let i = 0; i < styleSheets.length; i++) { let sheet = styleSheets[i]; diff --git a/dom/tests/mochitest/chrome/test_parsingMode.html b/dom/tests/mochitest/chrome/test_parsingMode.html index d8905dc5230d..e55c09bff3e1 100644 --- a/dom/tests/mochitest/chrome/test_parsingMode.html +++ b/dom/tests/mochitest/chrome/test_parsingMode.html @@ -26,7 +26,7 @@ const authorUrl = "chrome://mochikit/content/tests/SimpleTest/test.css"; let results = []; - for (let sheet of domutils.getAllStyleSheets(document)) { + for (let sheet of InspectorUtils.getAllStyleSheets(document)) { if (sheet.href === agentUrl) { is(sheet.parsingMode, "agent", "agent sheet has expected mode"); results[sss.AGENT_SHEET] = 1; diff --git a/dom/webidl/InspectorUtils.webidl b/dom/webidl/InspectorUtils.webidl index 696fea87f963..b45a61e340a5 100644 --- a/dom/webidl/InspectorUtils.webidl +++ b/dom/webidl/InspectorUtils.webidl @@ -9,6 +9,7 @@ */ [ChromeOnly] namespace InspectorUtils { + sequence getAllStyleSheets(Document document); }; dictionary InspectorRGBTriple { diff --git a/layout/inspector/InspectorUtils.h b/layout/inspector/InspectorUtils.h index cb69a0b3913a..4c99b64f7b8c 100644 --- a/layout/inspector/InspectorUtils.h +++ b/layout/inspector/InspectorUtils.h @@ -8,6 +8,14 @@ #ifndef mozilla_dom_InspectorUtils_h #define mozilla_dom_InspectorUtils_h +#include "mozilla/dom/BindingDeclarations.h" + +class nsIDocument; + +namespace mozilla { +class StyleSheet; +} // namespace mozilla + namespace mozilla { namespace dom { @@ -16,6 +24,10 @@ namespace dom { */ class InspectorUtils { +public: + static void GetAllStyleSheets(GlobalObject& aGlobal, + nsIDocument& aDocument, + nsTArray>& aResult); }; } // namespace dom diff --git a/layout/inspector/inDOMUtils.cpp b/layout/inspector/inDOMUtils.cpp index e216c400e44a..289fc4f14290 100644 --- a/layout/inspector/inDOMUtils.cpp +++ b/layout/inspector/inDOMUtils.cpp @@ -54,6 +54,7 @@ #include "mozilla/ServoStyleRule.h" #include "mozilla/ServoStyleRuleMap.h" #include "mozilla/ServoCSSParser.h" +#include "mozilla/dom/InspectorUtils.h" using namespace mozilla; using namespace mozilla::css; @@ -74,29 +75,26 @@ NS_IMPL_ISUPPORTS(inDOMUtils, inIDOMUtils) /////////////////////////////////////////////////////////////////////////////// // inIDOMUtils -NS_IMETHODIMP -inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength, - nsISupports ***aSheets) +namespace mozilla { +namespace dom { + +/* static */ void +InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject, + nsIDocument& aDocument, + nsTArray>& aResult) { - NS_ENSURE_ARG_POINTER(aDocument); - - nsTArray> sheets; - - nsCOMPtr document = do_QueryInterface(aDocument); - MOZ_ASSERT(document); - // Get the agent, then user and finally xbl sheets in the style set. - nsIPresShell* presShell = document->GetShell(); + nsIPresShell* presShell = aDocument.GetShell(); if (presShell) { StyleSetHandle styleSet = presShell->StyleSet(); SheetType sheetType = SheetType::Agent; for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) { - sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i)); + aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i)); } sheetType = SheetType::User; for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) { - sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i)); + aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i)); } AutoTArray xblSheetArray; @@ -107,29 +105,20 @@ inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength, for (StyleSheet* sheet : xblSheetArray) { if (!sheetSet.Contains(sheet)) { sheetSet.PutEntry(sheet); - sheets.AppendElement(sheet); + aResult.AppendElement(sheet); } } } // Get the document sheets. - for (size_t i = 0; i < document->SheetCount(); i++) { - sheets.AppendElement(document->SheetAt(i)); + for (size_t i = 0; i < aDocument.SheetCount(); i++) { + aResult.AppendElement(aDocument.SheetAt(i)); } - - nsISupports** ret = static_cast(moz_xmalloc(sheets.Length() * - sizeof(nsISupports*))); - - for (size_t i = 0; i < sheets.Length(); i++) { - NS_ADDREF(ret[i] = NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, sheets[i])); - } - - *aLength = sheets.Length(); - *aSheets = ret; - - return NS_OK; } +} // namespace dom +} // namespace mozilla + NS_IMETHODIMP inDOMUtils::IsIgnorableWhitespace(nsIDOMCharacterData *aDataNode, bool *aReturn) diff --git a/layout/inspector/inIDOMUtils.idl b/layout/inspector/inIDOMUtils.idl index b2f47b3a095e..481326b77ffa 100644 --- a/layout/inspector/inIDOMUtils.idl +++ b/layout/inspector/inIDOMUtils.idl @@ -20,10 +20,6 @@ interface nsIDOMCSSStyleSheet; [scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)] interface inIDOMUtils : nsISupports { - // CSS utilities - void getAllStyleSheets (in nsIDOMDocument aDoc, - [optional] out unsigned long aLength, - [array, size_is (aLength), retval] out nsISupports aSheets); nsIArrayExtensions getCSSStyleRules(in nsIDOMElement aElement, [optional] in DOMString aPseudo); /** diff --git a/layout/inspector/tests/test_get_all_style_sheets.html b/layout/inspector/tests/test_get_all_style_sheets.html index 7e5a4d49b063..86894569e76f 100644 --- a/layout/inspector/tests/test_get_all_style_sheets.html +++ b/layout/inspector/tests/test_get_all_style_sheets.html @@ -12,12 +12,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=734861 /** Test for Bug 734861 **/ + const InspectorUtils = SpecialPowers.InspectorUtils; + SimpleTest.waitForExplicitFinish(); function runTest() { - var utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"] - .getService(SpecialPowers.Ci.inIDOMUtils); - var res = utils.getAllStyleSheets(document); + var res = InspectorUtils.getAllStyleSheets(document); var foundUA = false; for (var i = 0; i < res.length; i++) {