Bug 1524106 - Disconnect l10n root when destroying the document. r=smaug
authorZibi Braniecki <zbraniecki@mozilla.com>
Thu, 07 Feb 2019 14:37:26 +0000
changeset 457620 2fac327be8ce74768e2a26adb2e52195e20748ec
parent 457619 7e88e78b389830b2d335b5f5be83bb446a9c2d7c
child 457621 ac53eefd531e1ad41490211ed173b4ff3fe4a917
push id35516
push userrmaries@mozilla.com
push dateFri, 08 Feb 2019 04:23:26 +0000
treeherdermozilla-central@d599d1a73a3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1524106
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 1524106 - Disconnect l10n root when destroying the document. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D18774
dom/base/Document.cpp
intl/l10n/DocumentL10n.cpp
intl/l10n/DocumentL10n.h
intl/l10n/mozIDOMLocalization.idl
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -7493,16 +7493,20 @@ bool Document::CanSavePresentation(nsIRe
 
 void Document::Destroy() {
   // The ContentViewer wants to release the document now.  So, tell our content
   // to drop any references to the document so that it can be destroyed.
   if (mIsGoingAway) return;
 
   mIsGoingAway = true;
 
+  if (mDocumentL10n) {
+    mDocumentL10n->Destroy();
+  }
+
   ScriptLoader()->Destroy();
   SetScriptGlobalObject(nullptr);
   RemovedFromDocShell();
 
   bool oldVal = mInUnlinkOrDeletion;
   mInUnlinkOrDeletion = true;
 
 #ifdef DEBUG
--- a/intl/l10n/DocumentL10n.cpp
+++ b/intl/l10n/DocumentL10n.cpp
@@ -107,16 +107,25 @@ bool DocumentL10n::Init(nsTArray<nsStrin
   // gets turned on.
   if (NS_FAILED(mDOMLocalization->RegisterObservers())) {
     return false;
   }
 
   return true;
 }
 
+void DocumentL10n::Destroy() {
+  if (mDOMLocalization) {
+    Element* elem = mDocument->GetDocumentElement();
+    if (elem) {
+      mDOMLocalization->DisconnectRoot(elem);
+    }
+  }
+}
+
 JSObject* DocumentL10n::WrapObject(JSContext* aCx,
                                    JS::Handle<JSObject*> aGivenProto) {
   return DocumentL10n_Binding::Wrap(aCx, this, aGivenProto);
 }
 
 already_AddRefed<Promise> DocumentL10n::MaybeWrapPromise(
     Promise* aInnerPromise) {
   // For system principal we don't need to wrap the
--- a/intl/l10n/DocumentL10n.h
+++ b/intl/l10n/DocumentL10n.h
@@ -60,16 +60,17 @@ enum class DocumentL10nState {
 class DocumentL10n final : public nsWrapperCache {
  public:
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DocumentL10n)
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DocumentL10n)
 
  public:
   explicit DocumentL10n(Document* aDocument);
   bool Init(nsTArray<nsString>& aResourceIds);
+  void Destroy();
 
  protected:
   virtual ~DocumentL10n();
 
   RefPtr<Document> mDocument;
   RefPtr<Promise> mReady;
   DocumentL10nState mState;
   nsCOMPtr<mozIDOMLocalization> mDOMLocalization;
--- a/intl/l10n/mozIDOMLocalization.idl
+++ b/intl/l10n/mozIDOMLocalization.idl
@@ -19,16 +19,17 @@ interface mozIDOMLocalization : nsISuppo
   Promise formatMessages(in Array<jsval> aKeys);
   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);
   Promise translateRoots();
   readonly attribute Promise ready;
 };
 
 [scriptable,uuid(96532d26-2422-11e9-a1ce-9bb586acd241)]
 interface mozIDOMLocalizationJSM : nsISupports
 {
   mozIDOMLocalization getDOMLocalization();