From 49add6eaa8e96c5c946f35619bc87745de9bb4ee Mon Sep 17 00:00:00 2001 From: Kashav Madan Date: Fri, 31 Jul 2020 18:16:32 +0000 Subject: [PATCH] Bug 1655520 - Replace nsDocShell::GetAllDocShellsInSubtree in OnPrefChange, r=farre Differential Revision: https://phabricator.services.mozilla.com/D85342 --- dom/base/UIDirectionManager.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/dom/base/UIDirectionManager.cpp b/dom/base/UIDirectionManager.cpp index 2ff14b9bdf12..eb8033d05d13 100644 --- a/dom/base/UIDirectionManager.cpp +++ b/dom/base/UIDirectionManager.cpp @@ -31,17 +31,18 @@ void OnPrefChange(const char* aPrefName, void*) { continue; } - nsCOMPtr rootDocShell = window->GetDocShell(); - nsTArray> docShells; - rootDocShell->GetAllDocShellsInSubtree( - nsIDocShell::typeAll, nsIDocShell::ENUMERATE_FORWARDS, docShells); - for (auto& docShell : docShells) { - if (nsCOMPtr win = do_GetInterface(docShell)) { - if (dom::Document* doc = win->GetExtantDoc()) { - doc->ResetDocumentDirection(); - } - } + RefPtr context = window->GetBrowsingContext(); + MOZ_DIAGNOSTIC_ASSERT(context); + + if (context->IsDiscarded()) { + continue; } + + context->PreOrderWalk([](BrowsingContext* aContext) { + if (dom::Document* doc = aContext->GetDocument()) { + doc->ResetDocumentDirection(); + } + }); } }