1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_intl_l10n_L10nRegistry_h
8 #define mozilla_intl_l10n_L10nRegistry_h
10 #include "nsIStreamLoader.h"
11 #include "nsWrapperCache.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "mozilla/dom/L10nRegistryBinding.h"
14 #include "mozilla/dom/BindingDeclarations.h"
15 #include "mozilla/intl/RegistryBindings.h"
16 #include "mozilla/intl/FluentBindings.h"
18 class nsIGlobalObject
;
20 namespace mozilla::dom
{
21 class L10nFileSourceDescriptor
;
24 namespace mozilla::intl
{
26 class FluentBundleAsyncIterator final
: public nsWrapperCache
{
28 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(FluentBundleAsyncIterator
)
29 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(FluentBundleAsyncIterator
)
31 FluentBundleAsyncIterator(
32 nsIGlobalObject
* aGlobal
,
33 UniquePtr
<ffi::GeckoFluentBundleAsyncIteratorWrapper
> aRaw
);
35 virtual JSObject
* WrapObject(JSContext
* aCx
,
36 JS::Handle
<JSObject
*> aGivenProto
) override
;
37 nsIGlobalObject
* GetParentObject() const { return mGlobal
; }
40 already_AddRefed
<dom::Promise
> Next();
41 already_AddRefed
<FluentBundleAsyncIterator
> Values();
44 ~FluentBundleAsyncIterator() = default;
45 nsCOMPtr
<nsIGlobalObject
> mGlobal
;
46 UniquePtr
<ffi::GeckoFluentBundleAsyncIteratorWrapper
> mRaw
;
49 class FluentBundleIterator final
: public nsWrapperCache
{
51 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(FluentBundleIterator
)
52 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(FluentBundleIterator
)
54 FluentBundleIterator(nsIGlobalObject
* aGlobal
,
55 UniquePtr
<ffi::GeckoFluentBundleIterator
> aRaw
);
57 virtual JSObject
* WrapObject(JSContext
* aCx
,
58 JS::Handle
<JSObject
*> aGivenProto
) override
;
59 nsIGlobalObject
* GetParentObject() const { return mGlobal
; }
62 void Next(dom::FluentBundleIteratorResult
& aResult
);
63 already_AddRefed
<FluentBundleIterator
> Values();
66 ~FluentBundleIterator() = default;
67 nsCOMPtr
<nsIGlobalObject
> mGlobal
;
68 UniquePtr
<ffi::GeckoFluentBundleIterator
> mRaw
;
71 class L10nRegistry final
: public nsWrapperCache
{
73 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(L10nRegistry
)
74 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(L10nRegistry
)
76 L10nRegistry(nsIGlobalObject
* aGlobal
, bool aUseIsolating
);
78 L10nRegistry(nsIGlobalObject
* aGlobal
,
79 RefPtr
<const ffi::GeckoL10nRegistry
> aRaw
);
81 static already_AddRefed
<L10nRegistry
> Constructor(
82 const dom::GlobalObject
& aGlobal
,
83 const dom::L10nRegistryOptions
& aOptions
);
85 static already_AddRefed
<L10nRegistry
> GetInstance(
86 const dom::GlobalObject
& aGlobal
);
88 static void GetParentProcessFileSourceDescriptors(
89 nsTArray
<dom::L10nFileSourceDescriptor
>& aRetVal
);
90 static void RegisterFileSourcesFromParentProcess(
91 const nsTArray
<dom::L10nFileSourceDescriptor
>& aDescriptors
);
93 static nsresult
Load(const nsACString
& aPath
,
94 nsIStreamLoaderObserver
* aObserver
);
95 static nsresult
LoadSync(const nsACString
& aPath
, void** aData
,
98 void GetAvailableLocales(nsTArray
<nsCString
>& aRetVal
);
100 void RegisterSources(
101 const dom::Sequence
<OwningNonNull
<L10nFileSource
>>& aSources
);
103 const dom::Sequence
<OwningNonNull
<L10nFileSource
>>& aSources
);
104 void RemoveSources(const dom::Sequence
<nsCString
>& aSources
);
105 bool HasSource(const nsACString
& aName
, ErrorResult
& aRv
);
106 already_AddRefed
<L10nFileSource
> GetSource(const nsACString
& aName
,
108 void GetSourceNames(nsTArray
<nsCString
>& aRetVal
);
111 already_AddRefed
<FluentBundleIterator
> GenerateBundlesSync(
112 const dom::Sequence
<nsCString
>& aLocales
,
113 const dom::Sequence
<nsCString
>& aResourceIds
, ErrorResult
& aRv
);
115 already_AddRefed
<FluentBundleAsyncIterator
> GenerateBundles(
116 const dom::Sequence
<nsCString
>& aLocales
,
117 const dom::Sequence
<nsCString
>& aResourceIds
, ErrorResult
& aRv
);
119 nsIGlobalObject
* GetParentObject() const { return mGlobal
; }
121 JSObject
* WrapObject(JSContext
* aCx
,
122 JS::Handle
<JSObject
*> aGivenProto
) override
;
124 const ffi::GeckoL10nRegistry
* Raw() const { return mRaw
; }
127 virtual ~L10nRegistry() = default;
128 nsCOMPtr
<nsIGlobalObject
> mGlobal
;
129 const RefPtr
<const ffi::GeckoL10nRegistry
> mRaw
;
130 static bool PopulateError(ErrorResult
& aError
,
131 ffi::L10nRegistryStatus
& aStatus
);
134 } // namespace mozilla::intl