Bug 1655413 [wpt PR 24763] - Make CSP default-src without 'unsafe-eval' block eval...
[gecko.git] / dom / l10n / DocumentL10n.h
blobf80b799e41ec628b06d9ecac15874dc57405562d
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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_dom_l10n_DocumentL10n_h
8 #define mozilla_dom_l10n_DocumentL10n_h
10 #include "mozilla/dom/Document.h"
11 #include "mozilla/dom/DOMLocalization.h"
13 namespace mozilla {
14 namespace dom {
16 enum class DocumentL10nState {
17 // State set when the DocumentL10n gets constructed.
18 Constructed = 0,
20 // State set when the initial translation got triggered. This happens
21 // if DocumentL10n was constructed during parsing of the document.
23 // If the DocumentL10n gets constructed later, we'll skip directly to
24 // Ready state.
25 InitialTranslationTriggered,
27 // State set the DocumentL10n has been fully initialized, potentially
28 // with initial translation being completed.
29 Ready,
32 /**
33 * This class maintains localization status of the document.
35 * The document will initialize it lazily when a link with a localization
36 * resource is added to the document.
38 * Once initialized, DocumentL10n relays all API methods to an
39 * instance of mozILocalization and maintains a single promise
40 * which gets resolved the first time the document gets translated.
42 class DocumentL10n final : public DOMLocalization {
43 public:
44 NS_DECL_ISUPPORTS_INHERITED
45 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocumentL10n, DOMLocalization)
47 static RefPtr<DocumentL10n> Create(Document* aDocument, const bool aSync);
49 protected:
50 explicit DocumentL10n(Document* aDocument, const bool aSync);
51 bool Init() override;
53 virtual ~DocumentL10n() = default;
55 RefPtr<Document> mDocument;
56 RefPtr<Promise> mReady;
57 DocumentL10nState mState;
58 nsCOMPtr<nsIContentSink> mContentSink;
60 public:
61 virtual JSObject* WrapObject(JSContext* aCx,
62 JS::Handle<JSObject*> aGivenProto) override;
64 Promise* Ready();
66 void TriggerInitialTranslation();
67 already_AddRefed<Promise> TranslateDocument(ErrorResult& aRv);
69 void InitialTranslationCompleted(bool aL10nCached);
71 Document* GetDocument() { return mDocument; };
72 void OnCreatePresShell();
74 void ConnectRoot(nsINode& aNode, bool aTranslate, ErrorResult& aRv);
76 DocumentL10nState GetState() { return mState; };
78 bool mBlockingLayout = false;
81 } // namespace dom
82 } // namespace mozilla
84 #endif // mozilla_dom_l10n_DocumentL10n_h