From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- intl/l10n/L10nRegistry.h | 152 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 intl/l10n/L10nRegistry.h (limited to 'intl/l10n/L10nRegistry.h') diff --git a/intl/l10n/L10nRegistry.h b/intl/l10n/L10nRegistry.h new file mode 100644 index 0000000000..91047ec99c --- /dev/null +++ b/intl/l10n/L10nRegistry.h @@ -0,0 +1,152 @@ +/* -*- 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_NATIVE_WRAPPERCACHE_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(ErrorResult& aError); + 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_NATIVE_WRAPPERCACHE_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_NATIVE_WRAPPERCACHE_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 -- cgit v1.2.3