Skip to content

Commit

Permalink
Bugfix FXIOS-8334 [v122.1] Users can be moved from private browsing t…
Browse files Browse the repository at this point in the history
…abs 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
  • Loading branch information
razvanlitianu authored Feb 2, 2024
1 parent 0f0c734 commit 6c72365
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions firefox-ios/Client/TabManagement/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 6c72365

Please sign in to comment.