1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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<ffi::GeckoFluentBundleAsyncIteratorWrapper> aRaw);
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
nsIGlobalObject* GetParentObject() const { return mGlobal; }
// WebIDL
already_AddRefed<dom::Promise> Next(ErrorResult& aError);
already_AddRefed<FluentBundleAsyncIterator> Values();
protected:
~FluentBundleAsyncIterator() = default;
nsCOMPtr<nsIGlobalObject> mGlobal;
UniquePtr<ffi::GeckoFluentBundleAsyncIteratorWrapper> 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<ffi::GeckoFluentBundleIterator> aRaw);
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
nsIGlobalObject* GetParentObject() const { return mGlobal; }
// WebIDL
void Next(dom::FluentBundleIteratorResult& aResult);
already_AddRefed<FluentBundleIterator> Values();
protected:
~FluentBundleIterator() = default;
nsCOMPtr<nsIGlobalObject> mGlobal;
UniquePtr<ffi::GeckoFluentBundleIterator> 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<const ffi::GeckoL10nRegistry> aRaw);
static already_AddRefed<L10nRegistry> Constructor(
const dom::GlobalObject& aGlobal,
const dom::L10nRegistryOptions& aOptions);
static already_AddRefed<L10nRegistry> GetInstance(
const dom::GlobalObject& aGlobal);
static void GetParentProcessFileSourceDescriptors(
nsTArray<dom::L10nFileSourceDescriptor>& aRetVal);
static void RegisterFileSourcesFromParentProcess(
const nsTArray<dom::L10nFileSourceDescriptor>& 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<ffi::GeckoResourceId> ResourceIdsToFFI(
const nsTArray<nsCString>& aResourceIds);
static nsTArray<ffi::GeckoResourceId> ResourceIdsToFFI(
const nsTArray<dom::OwningUTF8StringOrResourceId>& aResourceIds);
void GetAvailableLocales(nsTArray<nsCString>& aRetVal);
void RegisterSources(
const dom::Sequence<OwningNonNull<L10nFileSource>>& aSources);
void UpdateSources(
const dom::Sequence<OwningNonNull<L10nFileSource>>& aSources);
void RemoveSources(const dom::Sequence<nsCString>& aSources);
bool HasSource(const nsACString& aName, ErrorResult& aRv);
already_AddRefed<L10nFileSource> GetSource(const nsACString& aName,
ErrorResult& aRv);
void GetSourceNames(nsTArray<nsCString>& aRetVal);
void ClearSources();
already_AddRefed<FluentBundleIterator> GenerateBundlesSync(
const nsTArray<nsCString>& aLocales,
const nsTArray<ffi::GeckoResourceId>& aResourceIds, ErrorResult& aRv);
already_AddRefed<FluentBundleIterator> GenerateBundlesSync(
const dom::Sequence<nsCString>& aLocales,
const dom::Sequence<dom::OwningUTF8StringOrResourceId>& aResourceIds,
ErrorResult& aRv);
already_AddRefed<FluentBundleAsyncIterator> GenerateBundles(
const nsTArray<nsCString>& aLocales,
const nsTArray<ffi::GeckoResourceId>& aResourceIds, ErrorResult& aRv);
already_AddRefed<FluentBundleAsyncIterator> GenerateBundles(
const dom::Sequence<nsCString>& aLocales,
const dom::Sequence<dom::OwningUTF8StringOrResourceId>& aResourceIds,
ErrorResult& aRv);
nsIGlobalObject* GetParentObject() const { return mGlobal; }
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
const ffi::GeckoL10nRegistry* Raw() const { return mRaw; }
protected:
virtual ~L10nRegistry() = default;
nsCOMPtr<nsIGlobalObject> mGlobal;
const RefPtr<const ffi::GeckoL10nRegistry> mRaw;
static bool PopulateError(ErrorResult& aError,
ffi::L10nRegistryStatus& aStatus);
};
} // namespace mozilla::intl
#endif
|