From 4a50082613c76b51f41f6adbca02bb56652c3eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 9 Mar 2023 20:19:08 +0000 Subject: [PATCH] Bug 1820280 - Enable chrome rules in Thunderbird's about:3pane. r=aleca,dholbert For now a static list of URIs is probably fine. I asked Nika / Gijs if we can do something better in any case. We already have tests for stuff not getting exposed to content. Differential Revision: https://phabricator.services.mozilla.com/D171641 --- .../PrototypeDocumentContentSink.cpp | 1 + layout/style/FontFace.h | 5 ++-- layout/style/URLExtraData.cpp | 27 +++++++++++++++++++ layout/style/URLExtraData.h | 5 +--- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/dom/prototype/PrototypeDocumentContentSink.cpp b/dom/prototype/PrototypeDocumentContentSink.cpp index 4cd92281560d..ea1a1dc6ff25 100644 --- a/dom/prototype/PrototypeDocumentContentSink.cpp +++ b/dom/prototype/PrototypeDocumentContentSink.cpp @@ -8,6 +8,7 @@ #include "mozilla/dom/PrototypeDocumentContentSink.h" #include "nsIParser.h" #include "mozilla/dom/Document.h" +#include "mozilla/dom/URL.h" #include "nsIContent.h" #include "nsIURI.h" #include "nsNetUtil.h" diff --git a/layout/style/FontFace.h b/layout/style/FontFace.h index a830217f3b3b..695cdd323085 100644 --- a/layout/style/FontFace.h +++ b/layout/style/FontFace.h @@ -17,6 +17,8 @@ #include "nsWrapperCache.h" class gfxFontFaceBufferSource; +class nsIGlobalObject; + struct RawServoFontFaceRule; namespace mozilla { @@ -44,8 +46,7 @@ class FontFace final : public nsISupports, public nsWrapperCache { NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FontFace) nsIGlobalObject* GetParentObject() const { return mParent; } - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; + JSObject* WrapObject(JSContext*, JS::Handle aGivenProto) override; static already_AddRefed CreateForRule(nsIGlobalObject* aGlobal, FontFaceSet* aFontFaceSet, diff --git a/layout/style/URLExtraData.cpp b/layout/style/URLExtraData.cpp index 0e7299b392d6..9288fdd39811 100644 --- a/layout/style/URLExtraData.cpp +++ b/layout/style/URLExtraData.cpp @@ -9,6 +9,7 @@ #include "mozilla/URLExtraData.h" #include "mozilla/NullPrincipal.h" +#include "nsAboutProtocolUtils.h" #include "ReferrerInfo.h" namespace mozilla { @@ -29,6 +30,32 @@ void URLExtraData::Init() { sDummyChrome->mChromeRulesEnabled = true; } +static bool IsPrivilegedAboutURIForCSS(nsIURI* aURI) { +#ifdef MOZ_THUNDERBIRD + if (!aURI->SchemeIs("about")) { + return false; + } + // TODO: we might want to do something a bit less special-casey, perhaps using + // nsIAboutModule::GetChromeURI or so? But nsIAboutModule can involve calling + // into JS so this is probably fine for now, if it doesn't get too unwieldy. + nsAutoCString name; + if (NS_WARN_IF(NS_FAILED(NS_GetAboutModuleName(aURI, name)))) { + return false; + } + return name.EqualsLiteral("3pane") || name.EqualsLiteral("addressbook"); +#else + return false; +#endif +} + +bool URLExtraData::ChromeRulesEnabled(nsIURI* aURI) { + if (!aURI) { + return false; + } + return aURI->SchemeIs("chrome") || aURI->SchemeIs("resource") || + IsPrivilegedAboutURIForCSS(aURI); +} + /* static */ void URLExtraData::Shutdown() { sDummy = nullptr; diff --git a/layout/style/URLExtraData.h b/layout/style/URLExtraData.h index 0da69a0ef3db..c63cbc4ca14c 100644 --- a/layout/style/URLExtraData.h +++ b/layout/style/URLExtraData.h @@ -13,7 +13,6 @@ #include "mozilla/StaticPtr.h" #include "mozilla/UserAgentStyleSheetID.h" -#include "mozilla/dom/URL.h" #include "nsCOMPtr.h" #include "nsIPrincipal.h" #include "nsIReferrerInfo.h" @@ -22,9 +21,7 @@ namespace mozilla { struct URLExtraData { - static bool ChromeRulesEnabled(nsIURI* aURI) { - return aURI && (aURI->SchemeIs("chrome") || aURI->SchemeIs("resource")); - } + static bool ChromeRulesEnabled(nsIURI* aURI); URLExtraData(already_AddRefed aBaseURI, already_AddRefed aReferrerInfo,