/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_intl_l10n_L10nRegistry_h #define mozilla_intl_l10n_L10nRegistry_h #include "nsIStreamLoader.h" #include "nsWrapperCache.h" #include "nsCycleCollectionParticipant.h" #include "mozilla/dom/L10nRegistryBinding.h" #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/intl/FluentBindings.h" #include "mozilla/intl/RegistryBindings.h" class nsIGlobalObject; namespace mozilla::dom { class L10nFileSourceDescriptor; } namespace mozilla::intl { class FluentBundleAsyncIterator final : public nsWrapperCache { public: NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(FluentBundleAsyncIterator) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(FluentBundleAsyncIterator) FluentBundleAsyncIterator( nsIGlobalObject* aGlobal, UniquePtr aRaw); virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; nsIGlobalObject* GetParentObject() const { return mGlobal; } // WebIDL already_AddRefed Next(); already_AddRefed Values(); protected: ~FluentBundleAsyncIterator() = default; nsCOMPtr mGlobal; UniquePtr mRaw; }; class FluentBundleIterator final : public nsWrapperCache { public: NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(FluentBundleIterator) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(FluentBundleIterator) FluentBundleIterator(nsIGlobalObject* aGlobal, UniquePtr aRaw); virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; nsIGlobalObject* GetParentObject() const { return mGlobal; } // WebIDL void Next(dom::FluentBundleIteratorResult& aResult); already_AddRefed Values(); protected: ~FluentBundleIterator() = default; nsCOMPtr mGlobal; UniquePtr mRaw; }; class L10nRegistry final : public nsWrapperCache { public: NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(L10nRegistry) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(L10nRegistry) L10nRegistry(nsIGlobalObject* aGlobal, bool aUseIsolating); L10nRegistry(nsIGlobalObject* aGlobal, RefPtr aRaw); static already_AddRefed Constructor( const dom::GlobalObject& aGlobal, const dom::L10nRegistryOptions& aOptions); static already_AddRefed GetInstance( const dom::GlobalObject& aGlobal); static void GetParentProcessFileSourceDescriptors( nsTArray& aRetVal); static void RegisterFileSourcesFromParentProcess( const nsTArray& aDescriptors); static nsresult Load(const nsACString& aPath, nsIStreamLoaderObserver* aObserver); static nsresult LoadSync(const nsACString& aPath, void** aData, uint64_t* aSize); static ffi::GeckoResourceId ResourceIdToFFI(const nsCString& aResourceId); static ffi::GeckoResourceId ResourceIdToFFI( const dom::OwningUTF8StringOrResourceId& aResourceId); static nsTArray ResourceIdsToFFI( const nsTArray& aResourceIds); static nsTArray ResourceIdsToFFI( const nsTArray& aResourceIds); void GetAvailableLocales(nsTArray& aRetVal); void RegisterSources( const dom::Sequence>& aSources); void UpdateSources( const dom::Sequence>& aSources); void RemoveSources(const dom::Sequence& aSources); bool HasSource(const nsACString& aName, ErrorResult& aRv); already_AddRefed GetSource(const nsACString& aName, ErrorResult& aRv); void GetSourceNames(nsTArray& aRetVal); void ClearSources(); already_AddRefed GenerateBundlesSync( const nsTArray& aLocales, const nsTArray& aResourceIds, ErrorResult& aRv); already_AddRefed GenerateBundlesSync( const dom::Sequence& aLocales, const dom::Sequence& aResourceIds, ErrorResult& aRv); already_AddRefed GenerateBundles( const nsTArray& aLocales, const nsTArray& aResourceIds, ErrorResult& aRv); already_AddRefed GenerateBundles( const dom::Sequence& aLocales, const dom::Sequence& aResourceIds, ErrorResult& aRv); nsIGlobalObject* GetParentObject() const { return mGlobal; } JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; const ffi::GeckoL10nRegistry* Raw() const { return mRaw; } protected: virtual ~L10nRegistry() = default; nsCOMPtr mGlobal; const RefPtr mRaw; static bool PopulateError(ErrorResult& aError, ffi::L10nRegistryStatus& aStatus); }; } // namespace mozilla::intl #endif