From 3fa5d195da71be01fae109fad0362281c343e843 Mon Sep 17 00:00:00 2001 From: chenyang Date: Thu, 27 Jun 2024 17:12:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCVE-2024-5497?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyang --- browser/ui/browser_commands.cc | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/browser/ui/browser_commands.cc b/browser/ui/browser_commands.cc index cd4c08c26..ed01fe93f 100644 --- a/browser/ui/browser_commands.cc +++ b/browser/ui/browser_commands.cc @@ -382,14 +382,30 @@ WebContents* GetTabAndRevertIfNecessary(Browser* browser, void ReloadInternal(Browser* browser, WindowOpenDisposition disposition, bool bypass_cache) { - const WebContents* active_contents = + const WebContents* const active_contents = browser->tab_strip_model()->GetActiveWebContents(); - const auto& selected_indices = - browser->tab_strip_model()->selection_model().selected_indices(); - for (int index : selected_indices) { - WebContents* selected_tab = - browser->tab_strip_model()->GetWebContentsAt(index); - WebContents* new_tab = + + // Reloading a tab may change the selection (see crbug.com/339061099), so take + // a defensive copy into a more stable form before we begin. We take + // WebContents* so we can follow the tabs as they shift within the same + // tabstrip (e.g. if `disposition` is NEW_BACKGROUND_TAB). + std::vector selected_tabs; + for (const int selected_index : + browser->tab_strip_model()->selection_model().selected_indices()) { + selected_tabs.push_back( + browser->tab_strip_model()->GetWebContentsAt(selected_index)); + } + + for (WebContents* const selected_tab : selected_tabs) { + // Skip this tab if it is no longer part of this tabstrip. N.B. we do this + // instead of using WeakPtr because we do not want to reload + // tabs that move to another browser. + if (browser->tab_strip_model()->GetIndexOfWebContents(selected_tab) == + TabStripModel::kNoTab) { + continue; + } + + WebContents* const new_tab = GetTabAndRevertIfNecessaryHelper(browser, disposition, selected_tab); // If the selected_tab is the activated page, give the focus to it, as this @@ -399,7 +415,7 @@ void ReloadInternal(Browser* browser, new_tab->Focus(); } - DevToolsWindow* devtools = + DevToolsWindow* const devtools = DevToolsWindow::GetInstanceForInspectedWebContents(new_tab); constexpr content::ReloadType kBypassingType = content::ReloadType::BYPASSING_CACHE; -- Gitee