[tbb-commits] [tor-browser] 38/76: Bug 1751609, trigger localization at expected time, r=mccr8 a=RyanVM

gitolite role git at cupani.torproject.org
Wed Mar 30 20:40:06 UTC 2022


This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch tor-browser-91.8.0esr-11.0-1
in repository tor-browser.

commit cd1fe8df165ce7dd8f41a43cb5f25e8d4616a73d
Author: Olli Pettay <Olli.Pettay at helsinki.fi>
AuthorDate: Tue Mar 15 10:50:46 2022 +0000

    Bug 1751609, trigger localization at expected time, r=mccr8 a=RyanVM
    
    Differential Revision: https://phabricator.services.mozilla.com/D141094
---
 dom/base/Document.cpp     | 12 +++++++++---
 dom/l10n/DocumentL10n.cpp |  2 ++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp
index a58e76cb52580..4152a6d69217a 100644
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -4178,8 +4178,13 @@ void Document::LocalizationLinkAdded(Element* aLinkElement) {
   mDocumentL10n->AddResourceId(href);
 
   if (mReadyState >= READYSTATE_INTERACTIVE) {
-    mDocumentL10n->Activate(true);
-    mDocumentL10n->TriggerInitialTranslation();
+    RefPtr<DocumentL10n> l10n = mDocumentL10n;
+    RefPtr<Runnable> r = NS_NewRunnableFunction(
+        "DocumentL10n::TriggerInitialTranslation()", [l10n]() {
+          l10n->Activate(true);
+          l10n->TriggerInitialTranslation();
+        });
+    nsContentUtils::AddScriptRunner(r.forget());
   } else {
     if (!mDocumentL10n->mBlockingLayout) {
       // Our initial translation is going to block layout start.  Make sure
@@ -4235,7 +4240,8 @@ void Document::OnParsingCompleted() {
   OnL10nResourceContainerParsed();
 
   if (mDocumentL10n) {
-    mDocumentL10n->TriggerInitialTranslation();
+    RefPtr<DocumentL10n> l10n = mDocumentL10n;
+    l10n->TriggerInitialTranslation();
   }
 }
 
diff --git a/dom/l10n/DocumentL10n.cpp b/dom/l10n/DocumentL10n.cpp
index 3d8efec317d37..06b62d75f314b 100644
--- a/dom/l10n/DocumentL10n.cpp
+++ b/dom/l10n/DocumentL10n.cpp
@@ -6,6 +6,7 @@
 
 #include "DocumentL10n.h"
 #include "nsIContentSink.h"
+#include "nsContentUtils.h"
 #include "mozilla/dom/AutoEntryScript.h"
 #include "mozilla/dom/Document.h"
 #include "mozilla/dom/DocumentL10nBinding.h"
@@ -102,6 +103,7 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(L10nReadyHandler)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(L10nReadyHandler)
 
 void DocumentL10n::TriggerInitialTranslation() {
+  MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
   if (mState >= DocumentL10nState::InitialTranslationTriggered) {
     return;
   }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tbb-commits mailing list