Bug 1532712 - Expose pause/resume observing methods on DocumentL10n. r=smaug
authorZibi Braniecki <zbraniecki@mozilla.com>
Wed, 13 Mar 2019 00:24:41 +0000
changeset 522068 9e076e178370e309828ca0b2a598058df83848af
parent 522066 9daec44d681e328c4827b23f16ad587c325fe20f
child 522069 10dfa9788b2b83e2a56a51d53cfe75813f89fa2e
push id10871
push usercbrindusan@mozilla.com
push dateMon, 18 Mar 2019 15:49:32 +0000
treeherdermozilla-beta@018abdd16060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1532712
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1532712 - Expose pause/resume observing methods on DocumentL10n. r=smaug Differential Revision: https://phabricator.services.mozilla.com//D23244
dom/webidl/DocumentL10n.webidl
intl/l10n/DocumentL10n.cpp
intl/l10n/DocumentL10n.h
intl/l10n/mozIDOMLocalization.idl
--- a/dom/webidl/DocumentL10n.webidl
+++ b/dom/webidl/DocumentL10n.webidl
@@ -137,13 +137,25 @@ interface DocumentL10n {
    * Example:
    *    await document.l10n.translateElements([elem1, elem2]);
    *    parent.appendChild(elem1);
    *    alert(elem2.textContent);
    */
   [NewObject] Promise<void> translateElements(sequence<Element> aElements);
 
   /**
+   * Pauses the MutationObserver set to observe
+   * localization related DOM mutations.
+   */
+  [Throws] void pauseObserving();
+
+  /**
+   * Resumes the MutationObserver set to observe
+   * localization related DOM mutations.
+   */
+  [Throws] void resumeObserving();
+
+  /**
    * A promise which gets resolved when the initial DOM localization resources
    * fetching is complete and the initial translation of the DOM is finished.
    */
   readonly attribute Promise<any> ready;
 };
--- a/intl/l10n/DocumentL10n.cpp
+++ b/intl/l10n/DocumentL10n.cpp
@@ -346,16 +346,24 @@ already_AddRefed<Promise> DocumentL10n::
   RefPtr<Promise> promise;
   aRv = mDOMLocalization->TranslateElements(elements, getter_AddRefs(promise));
   if (aRv.Failed()) {
     return nullptr;
   }
   return MaybeWrapPromise(promise);
 }
 
+void DocumentL10n::PauseObserving(ErrorResult& aRv) {
+  aRv = mDOMLocalization->PauseObserving();
+}
+
+void DocumentL10n::ResumeObserving(ErrorResult& aRv) {
+  aRv = mDOMLocalization->ResumeObserving();
+}
+
 class L10nReadyHandler final : public PromiseNativeHandler {
  public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(L10nReadyHandler)
 
   explicit L10nReadyHandler(Promise* aPromise, DocumentL10n* aDocumentL10n)
       : mPromise(aPromise), mDocumentL10n(aDocumentL10n) {}
 
--- a/intl/l10n/DocumentL10n.h
+++ b/intl/l10n/DocumentL10n.h
@@ -120,16 +120,19 @@ class DocumentL10n final : public nsIObs
                      ErrorResult& aRv);
   void GetAttributes(JSContext* aCx, Element& aElement, L10nKey& aResult,
                      ErrorResult& aRv);
 
   already_AddRefed<Promise> TranslateFragment(nsINode& aNode, ErrorResult& aRv);
   already_AddRefed<Promise> TranslateElements(
       const Sequence<OwningNonNull<Element>>& aElements, ErrorResult& aRv);
 
+  void PauseObserving(ErrorResult& aRv);
+  void ResumeObserving(ErrorResult& aRv);
+
   Promise* Ready();
 
   void TriggerInitialDocumentTranslation();
 
   void InitialDocumentTranslationCompleted();
 };
 
 }  // namespace dom
--- a/intl/l10n/mozIDOMLocalization.idl
+++ b/intl/l10n/mozIDOMLocalization.idl
@@ -20,16 +20,20 @@ interface mozIDOMLocalization : nsISuppo
   Promise formatValues(in Array<jsval> aKeys);
   Promise formatValue(in AString aId, [optional] in jsval aArgs);
 
   Promise translateFragment(in Node aNode);
   Promise translateElements(in Array<Element> aElements);
 
   void connectRoot(in Element aElement);
   void disconnectRoot(in Element aElement);
+
+  void pauseObserving();
+  void resumeObserving();
+
   Promise translateRoots();
   readonly attribute Promise ready;
 };
 
 [scriptable,uuid(96532d26-2422-11e9-a1ce-9bb586acd241)]
 interface mozIDOMLocalizationJSM : nsISupports
 {
   mozIDOMLocalization getDOMLocalization();