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
This commit is contained in:
Emilio Cobos Álvarez 2023-03-09 20:19:08 +00:00
parent 6e32187716
commit 4a50082613
4 changed files with 32 additions and 6 deletions

View File

@ -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"

View File

@ -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<JSObject*> aGivenProto) override;
JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
static already_AddRefed<FontFace> CreateForRule(nsIGlobalObject* aGlobal,
FontFaceSet* aFontFaceSet,

View File

@ -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;

View File

@ -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<nsIURI> aBaseURI,
already_AddRefed<nsIReferrerInfo> aReferrerInfo,