From 6c72365bbb4a11e825494e280599791afd9e188e Mon Sep 17 00:00:00 2001 From: Litianu Razvan Date: Fri, 2 Feb 2024 18:41:41 +0200 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 (#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 --- .../Views/BrowserViewController.swift | 13 ++++++++----- .../TabManagement/Legacy/LegacyTabManager.swift | 3 +-- firefox-ios/Client/TabManagement/TabManager.swift | 6 +----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/firefox-ios/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift b/firefox-ios/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift index f85074d39997..8da67a729c5b 100644 --- a/firefox-ios/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift +++ b/firefox-ios/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift @@ -2006,11 +2006,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) { @@ -2276,10 +2277,12 @@ 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 diff --git a/firefox-ios/Client/TabManagement/Legacy/LegacyTabManager.swift b/firefox-ios/Client/TabManagement/Legacy/LegacyTabManager.swift index fa71364cef3a..8be510d081b0 100644 --- a/firefox-ios/Client/TabManagement/Legacy/LegacyTabManager.swift +++ b/firefox-ios/Client/TabManagement/Legacy/LegacyTabManager.swift @@ -232,8 +232,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/firefox-ios/Client/TabManagement/TabManager.swift b/firefox-ios/Client/TabManagement/TabManager.swift index d89b32b330d6..47a164684a63 100644 --- a/firefox-ios/Client/TabManagement/TabManager.swift +++ b/firefox-ios/Client/TabManagement/TabManager.swift @@ -41,7 +41,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) @@ -94,10 +94,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) }