From 7475f2cbaf05ffc571ddeb222e5aed79e2b3a36e Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 10:27:20 -0500 Subject: [PATCH] Bugfix FXIOS-8334 [v122.1] Users can be moved from private browsing tabs to regular tabs with prefer switch to open tab enabled (backport #18513) (#18544) * Bugfix FXIOS-8334 [v122.1] Users can be moved from private browsing tabs to regular tabs with prefer switch to open tab enabled (#18513) * FXIOS-8334 #18469 Users can be moved from private browsing tabs to regular tabs, with prefer-switch-to-open-tab enabled * Revert method on tab manager (cherry picked from commit 6c72365bbb4a11e825494e280599791afd9e188e) # Conflicts: # Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift * Remove spaces * Add missing code changes --------- Co-authored-by: Litianu Razvan --- .../Views/BrowserViewController.swift | 12 ++++++++---- Client/TabManagement/Legacy/LegacyTabManager.swift | 3 +-- Client/TabManagement/TabManager.swift | 6 +----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift index 7946148786ec..4003ea54da98 100644 --- a/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift @@ -1906,10 +1906,12 @@ class BrowserViewController: UIViewController, // MARK: - LibraryPanelDelegate func libraryPanel(didSelectURL url: URL, visitType: VisitType) { - if isPreferSwitchToOpenTabOverDuplicateFeatureEnabled, let tab = tabManager.getTabFor(url, reversed: true) { + guard let tab = tabManager.selectedTab else { return } + + if isPreferSwitchToOpenTabOverDuplicateFeatureEnabled, + let tab = tabManager.tabs.reversed().first(where: { $0.url == url && $0.isPrivate == tab.isPrivate }) { tabManager.selectTab(tab) } else { - guard let tab = tabManager.selectedTab else { return } // Handle keyboard shortcuts from homepage with url selection // (ex: Cmd + Tap on Link; which is a cell in this case) if navigateLinkShortcutIfNeeded(url: url) { @@ -2140,14 +2142,16 @@ extension BrowserViewController: HomePanelDelegate { } func homePanel(didSelectURL url: URL, visitType: VisitType, isGoogleTopSite: Bool) { - if isPreferSwitchToOpenTabOverDuplicateFeatureEnabled, let tab = tabManager.getTabFor(url, reversed: true) { + guard let tab = tabManager.selectedTab else { return } + if isPreferSwitchToOpenTabOverDuplicateFeatureEnabled, + let tab = tabManager.tabs.reversed().first(where: { $0.url == url && $0.isPrivate == tab.isPrivate }) { tabManager.selectTab(tab) } else { - guard let tab = tabManager.selectedTab else { return } if isGoogleTopSite { tab.urlType = .googleTopSite searchTelemetry?.shouldSetGoogleTopSiteSearch = true } + // Handle keyboard shortcuts from homepage with url selection // (ex: Cmd + Tap on Link; which is a cell in this case) if navigateLinkShortcutIfNeeded(url: url) { diff --git a/Client/TabManagement/Legacy/LegacyTabManager.swift b/Client/TabManagement/Legacy/LegacyTabManager.swift index b3a25fcce890..8e331d58cd2f 100644 --- a/Client/TabManagement/Legacy/LegacyTabManager.swift +++ b/Client/TabManagement/Legacy/LegacyTabManager.swift @@ -231,8 +231,7 @@ class LegacyTabManager: NSObject, FeatureFlaggable, TabManager, TabEventHandler } // MARK: Get tabs - func getTabFor(_ url: URL, reversed: Bool = false) -> Tab? { - let tabs = reversed ? self.tabs.reversed() : self.tabs + func getTabFor(_ url: URL) -> Tab? { for tab in tabs { if let webViewUrl = tab.webView?.url, url.isEqual(webViewUrl) { diff --git a/Client/TabManagement/TabManager.swift b/Client/TabManagement/TabManager.swift index d07919125ee6..d1a6d62124b5 100644 --- a/Client/TabManagement/TabManager.swift +++ b/Client/TabManagement/TabManager.swift @@ -36,7 +36,7 @@ protocol TabManager: AnyObject { func removeTabs(_ tabs: [Tab]) func undoCloseTab(tab: Tab, position: Int?) func getMostRecentHomepageTab() -> Tab? - func getTabFor(_ url: URL, reversed: Bool) -> Tab? + func getTabFor(_ url: URL) -> Tab? func clearAllTabsHistory() func willSwitchTabMode(leavingPBM: Bool) func cleanupClosedTabs(_ closedTabs: [Tab], previous: Tab?, isPrivate: Bool) @@ -70,10 +70,6 @@ protocol TabManager: AnyObject { } extension TabManager { - func getTabFor(_ url: URL, reversed: Bool = false) -> Tab? { - getTabFor(url, reversed: reversed) - } - func removeDelegate(_ delegate: TabManagerDelegate) { removeDelegate(delegate, completion: nil) }