Bug 1860313 [wpt PR 42669] - Update wpt metadata, a=testonly
[gecko.git] / intl / l10n / FileSource.h
blobe719dff74fe5741fd188481e88d07cefe53d416d
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_FileSource_h
8 #define mozilla_intl_l10n_FileSource_h
10 #include "nsWrapperCache.h"
11 #include "mozilla/dom/BindingDeclarations.h"
12 #include "mozilla/dom/L10nRegistryBinding.h"
13 #include "mozilla/dom/FluentBinding.h"
14 #include "mozilla/intl/RegistryBindings.h"
16 class nsIGlobalObject;
18 namespace mozilla::intl {
20 class L10nFileSource : public nsWrapperCache {
21 public:
22 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(L10nFileSource)
23 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(L10nFileSource)
25 explicit L10nFileSource(RefPtr<const ffi::FileSource> aRaw,
26 nsIGlobalObject* aGlobal = nullptr);
28 static already_AddRefed<L10nFileSource> Constructor(
29 const dom::GlobalObject& aGlobal, const nsACString& aName,
30 const nsACString& aMetaSource, const nsTArray<nsCString>& aLocales,
31 const nsACString& aPrePath, const dom::FileSourceOptions& aOptions,
32 const dom::Optional<dom::Sequence<nsCString>>& aIndex, ErrorResult& aRv);
34 static already_AddRefed<L10nFileSource> CreateMock(
35 const dom::GlobalObject& aGlobal, const nsACString& aName,
36 const nsACString& aMetaSource, const nsTArray<nsCString>& aLocales,
37 const nsACString& aPrePath,
38 const nsTArray<dom::L10nFileSourceMockFile>& aFS, ErrorResult& aRv);
40 nsIGlobalObject* GetParentObject() const { return mGlobal; }
42 JSObject* WrapObject(JSContext* aCx,
43 JS::Handle<JSObject*> aGivenProto) override;
45 void GetName(nsCString& aRetVal);
46 void GetMetaSource(nsCString& aRetVal);
47 void GetLocales(nsTArray<nsCString>& aRetVal);
48 void GetPrePath(nsCString& aRetVal);
49 void GetIndex(dom::Nullable<nsTArray<nsCString>>& aRetVal);
51 dom::L10nFileSourceHasFileStatus HasFile(const nsACString& aLocale,
52 const nsACString& aPath,
53 ErrorResult& aRv);
54 already_AddRefed<dom::Promise> FetchFile(const nsACString& aLocale,
55 const nsACString& aPath,
56 ErrorResult& aRv);
57 already_AddRefed<FluentResource> FetchFileSync(const nsACString& aLocale,
58 const nsACString& aPath,
59 ErrorResult& aRv);
61 const ffi::FileSource* Raw() const { return mRaw; }
63 protected:
64 virtual ~L10nFileSource() = default;
65 nsCOMPtr<nsIGlobalObject> mGlobal;
66 const RefPtr<const ffi::FileSource> mRaw;
67 static bool PopulateError(ErrorResult& aError,
68 ffi::L10nFileSourceStatus& aStatus);
71 } // namespace mozilla::intl
73 #endif