Bug 1532712 - Expose pause/resume observing methods on DocumentL10n. r=smaug
☠☠ backed out by b8c1398f5a90 ☠ ☠
authorZibi Braniecki <zbraniecki@mozilla.com>
Wed, 13 Mar 2019 16:39:41 +0000
changeset 521730 5fb5272aec8ea6c5018441e7e9b5ba1e7e890203
parent 521729 a64d942b966da7d12a3a70fa823284052f514dc9
child 521731 1af088f5fc34935f780c2153f1d279ca482e735a
push id10867
push userdvarga@mozilla.com
push dateThu, 14 Mar 2019 15:20:45 +0000
treeherdermozilla-beta@abad13547875 [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();