mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 16:22:00 +00:00
Bug 1072107 - Part 2. Expose FontFaceSet on nsIGlobalObject. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D149245
This commit is contained in:
parent
47426f9e36
commit
508ecd766a
@ -1626,6 +1626,13 @@ OriginTrials nsGlobalWindowInner::Trials() const {
|
||||
return OriginTrials::FromWindow(this);
|
||||
}
|
||||
|
||||
FontFaceSet* nsGlobalWindowInner::Fonts() {
|
||||
if (mDoc) {
|
||||
return mDoc->Fonts();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t nsGlobalWindowInner::GetPrincipalHashValue() const {
|
||||
if (mDoc) {
|
||||
return mDoc->NodePrincipal()->GetHashValue();
|
||||
|
@ -249,6 +249,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
||||
bool ShouldResistFingerprinting() const final;
|
||||
uint32_t GetPrincipalHashValue() const final;
|
||||
mozilla::OriginTrials Trials() const final;
|
||||
mozilla::dom::FontFaceSet* Fonts() final;
|
||||
|
||||
JSObject* GetGlobalJSObject() final { return GetWrapper(); }
|
||||
JSObject* GetGlobalJSObjectPreserveColor() const final {
|
||||
|
@ -1683,6 +1683,13 @@ OriginTrials nsGlobalWindowOuter::Trials() const {
|
||||
: OriginTrials();
|
||||
}
|
||||
|
||||
FontFaceSet* nsGlobalWindowOuter::Fonts() {
|
||||
if (mDoc) {
|
||||
return mDoc->Fonts();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsresult nsGlobalWindowOuter::EnsureScriptEnvironment() {
|
||||
if (GetWrapperPreserveColor()) {
|
||||
return NS_OK;
|
||||
|
@ -235,6 +235,7 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
||||
bool ShouldResistFingerprinting() const final;
|
||||
uint32_t GetPrincipalHashValue() const final;
|
||||
mozilla::OriginTrials Trials() const final;
|
||||
mozilla::dom::FontFaceSet* Fonts() final;
|
||||
|
||||
// nsIGlobalJSObjectHolder
|
||||
JSObject* GetGlobalJSObject() final { return GetWrapper(); }
|
||||
|
@ -38,6 +38,7 @@ enum class StorageAccess;
|
||||
namespace dom {
|
||||
class VoidFunction;
|
||||
class DebuggerNotificationManager;
|
||||
class FontFaceSet;
|
||||
class Function;
|
||||
class Report;
|
||||
class ReportBody;
|
||||
@ -252,6 +253,8 @@ class nsIGlobalObject : public nsISupports,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual mozilla::dom::FontFaceSet* Fonts() { return nullptr; }
|
||||
|
||||
protected:
|
||||
virtual ~nsIGlobalObject();
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "mozilla/ServoStyleSet.h"
|
||||
#include "mozilla/ServoUtils.h"
|
||||
#include "mozilla/StaticPrefs_layout.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsStyleUtil.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -72,7 +71,7 @@ NS_INTERFACE_MAP_END
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(FontFace)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(FontFace)
|
||||
|
||||
FontFace::FontFace(nsISupports* aParent)
|
||||
FontFace::FontFace(nsIGlobalObject* aParent)
|
||||
: mParent(aParent), mLoadedRejection(NS_OK) {}
|
||||
|
||||
FontFace::~FontFace() {
|
||||
@ -90,7 +89,7 @@ JSObject* FontFace::WrapObject(JSContext* aCx,
|
||||
}
|
||||
|
||||
already_AddRefed<FontFace> FontFace::CreateForRule(
|
||||
nsISupports* aGlobal, FontFaceSet* aFontFaceSet,
|
||||
nsIGlobalObject* aGlobal, FontFaceSet* aFontFaceSet,
|
||||
RawServoFontFaceRule* aRule) {
|
||||
FontFaceSetImpl* setImpl = aFontFaceSet->GetImpl();
|
||||
MOZ_ASSERT(setImpl);
|
||||
@ -104,22 +103,20 @@ already_AddRefed<FontFace> FontFace::Constructor(
|
||||
const GlobalObject& aGlobal, const nsACString& aFamily,
|
||||
const UTF8StringOrArrayBufferOrArrayBufferView& aSource,
|
||||
const FontFaceDescriptors& aDescriptors, ErrorResult& aRv) {
|
||||
nsISupports* global = aGlobal.GetAsSupports();
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global);
|
||||
if (!window) {
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
|
||||
FontFaceSet* set = global->Fonts();
|
||||
if (!set) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Document* doc = window->GetDoc();
|
||||
if (!doc) {
|
||||
FontFaceSetImpl* setImpl = set->GetImpl();
|
||||
if (!setImpl) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FontFaceSetImpl* setImpl = doc->Fonts()->GetImpl();
|
||||
MOZ_ASSERT(setImpl);
|
||||
|
||||
RefPtr<FontFace> obj = new FontFace(global);
|
||||
obj->mImpl = new FontFaceImpl(obj, setImpl);
|
||||
if (!obj->mImpl->SetDescriptors(aFamily, aDescriptors)) {
|
||||
@ -321,18 +318,16 @@ already_AddRefed<URLExtraData> FontFace::GetURLExtraData() const {
|
||||
void FontFace::EnsurePromise() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (mLoaded || !mImpl) {
|
||||
if (mLoaded || !mImpl || !mParent) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mParent);
|
||||
|
||||
// If the pref is not set, don't create the Promise (which the page wouldn't
|
||||
// be able to get to anyway) as it causes the window.FontFace constructor
|
||||
// to be created.
|
||||
if (global && FontFaceSet::PrefEnabled()) {
|
||||
if (FontFaceSet::PrefEnabled()) {
|
||||
ErrorResult rv;
|
||||
mLoaded = Promise::Create(global, rv);
|
||||
mLoaded = Promise::Create(mParent, rv);
|
||||
|
||||
if (mImpl->Status() == FontFaceLoadStatus::Loaded) {
|
||||
mLoaded->MaybeResolve(this);
|
||||
|
@ -43,11 +43,11 @@ class FontFace final : public nsISupports, public nsWrapperCache {
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FontFace)
|
||||
|
||||
nsISupports* GetParentObject() const { return mParent; }
|
||||
nsIGlobalObject* GetParentObject() const { return mParent; }
|
||||
virtual JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
static already_AddRefed<FontFace> CreateForRule(nsISupports* aGlobal,
|
||||
static already_AddRefed<FontFace> CreateForRule(nsIGlobalObject* aGlobal,
|
||||
FontFaceSet* aFontFaceSet,
|
||||
RawServoFontFaceRule* aRule);
|
||||
|
||||
@ -97,7 +97,7 @@ class FontFace final : public nsISupports, public nsWrapperCache {
|
||||
already_AddRefed<URLExtraData> GetURLExtraData() const;
|
||||
|
||||
private:
|
||||
explicit FontFace(nsISupports* aParent);
|
||||
explicit FontFace(nsIGlobalObject* aParent);
|
||||
~FontFace();
|
||||
|
||||
/**
|
||||
@ -109,7 +109,7 @@ class FontFace final : public nsISupports, public nsWrapperCache {
|
||||
// reject mLoaded based on mStatus and mLoadedRejection.
|
||||
void EnsurePromise();
|
||||
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
nsCOMPtr<nsIGlobalObject> mParent;
|
||||
|
||||
RefPtr<FontFaceImpl> mImpl;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user