2019-07-08 12:27:47 +03:00
|
|
|
/* -*- 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/. */
|
2019-07-08 13:02:35 +03:00
|
|
|
|
2019-06-25 22:39:53 +03:00
|
|
|
#ifndef mozilla_intl_l10n_Localization_h
|
|
|
|
#define mozilla_intl_l10n_Localization_h
|
|
|
|
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "mozILocalization.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/Promise.h"
|
|
|
|
#include "mozilla/dom/LocalizationBinding.h"
|
|
|
|
#include "mozilla/dom/PromiseNativeHandler.h"
|
|
|
|
|
|
|
|
class nsIGlobalObject;
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace intl {
|
|
|
|
|
2019-06-25 22:43:50 +03:00
|
|
|
typedef Record<nsString, Nullable<OwningStringOrDouble>> L10nArgs;
|
|
|
|
|
2019-06-25 22:39:53 +03:00
|
|
|
class Localization : public nsIObserver,
|
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsWrapperCache {
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Localization,
|
|
|
|
nsIObserver)
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
explicit Localization(nsIGlobalObject* aGlobal);
|
|
|
|
void Init(nsTArray<nsString>& aResourceIds, ErrorResult& aRv);
|
|
|
|
void Init(nsTArray<nsString>& aResourceIds,
|
|
|
|
JS::Handle<JS::Value> aGenerateMessages, ErrorResult& aRv);
|
|
|
|
|
|
|
|
static already_AddRefed<Localization> Constructor(
|
|
|
|
const GlobalObject& aGlobal,
|
|
|
|
const Optional<Sequence<nsString>>& aResourceIds,
|
|
|
|
const Optional<OwningNonNull<GenerateMessages>>& aGenerateMessages,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
nsIGlobalObject* GetParentObject() const;
|
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Localization API
|
|
|
|
*
|
|
|
|
* Methods documentation in Localization.webidl
|
|
|
|
*/
|
|
|
|
uint32_t AddResourceIds(const nsTArray<nsString>& aResourceIds, bool aEager);
|
|
|
|
|
|
|
|
uint32_t RemoveResourceIds(const nsTArray<nsString>& aResourceIds);
|
|
|
|
|
2019-06-25 22:43:50 +03:00
|
|
|
already_AddRefed<Promise> FormatValue(JSContext* aCx, const nsAString& aId,
|
|
|
|
const Optional<L10nArgs>& aArgs,
|
|
|
|
ErrorResult& aRv);
|
2019-06-25 22:39:53 +03:00
|
|
|
|
|
|
|
already_AddRefed<Promise> FormatValues(JSContext* aCx,
|
|
|
|
const Sequence<L10nKey>& aKeys,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<Promise> FormatMessages(JSContext* aCx,
|
|
|
|
const Sequence<L10nKey>& aKeys,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~Localization();
|
|
|
|
void RegisterObservers();
|
2019-09-13 13:08:26 +03:00
|
|
|
virtual void OnChange();
|
2019-06-25 22:39:53 +03:00
|
|
|
already_AddRefed<Promise> MaybeWrapPromise(Promise* aInnerPromise);
|
2019-06-25 22:43:50 +03:00
|
|
|
void ConvertL10nArgsToJSValue(JSContext* aCx, const L10nArgs& aArgs,
|
|
|
|
JS::MutableHandle<JS::Value> aRetVal,
|
|
|
|
ErrorResult& aRv);
|
2019-06-25 22:39:53 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIGlobalObject> mGlobal;
|
|
|
|
nsCOMPtr<mozILocalization> mLocalization;
|
2019-07-01 20:56:57 +03:00
|
|
|
bool mIsSync;
|
2019-06-25 22:39:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace intl
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2019-07-08 12:27:47 +03:00
|
|
|
#endif
|