From 950db2288a55ced1a1e79d2662261bebcc9aa980 Mon Sep 17 00:00:00 2001 From: Brandon-T Date: Wed, 17 Jan 2024 15:33:29 -0500 Subject: [PATCH] Fix brave/brave-ios#8665: Fix an issue where URL won't load if already loaded in a different mode (brave/brave-ios#8666) - Fix URL not loading when the same URL is already open in a different mode --- .../BrowserViewController/BVC+Rewards.swift | 2 +- .../BrowserViewController.swift | 15 +++++++++++++-- Sources/Brave/Frontend/Browser/TabManager.swift | 6 +++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Rewards.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Rewards.swift index 1ed8227ce836..95095452d28c 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Rewards.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+Rewards.swift @@ -105,7 +105,7 @@ extension BrowserViewController { private func loadNewTabWithRewardsURL(_ url: URL) { self.presentedViewController?.dismiss(animated: true) - if let tab = tabManager.getTabForURL(url) { + if let tab = tabManager.getTabForURL(url, isPrivate: privateBrowsingManager.isPrivateBrowsing) { tabManager.selectTab(tab) } else { let request = URLRequest(url: url) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift index 20fab8f34f0f..e575ec52b4a1 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift @@ -1768,6 +1768,17 @@ public class BrowserViewController: UIViewController { // Catch history pushState navigation, but ONLY for same origin navigation, // for reasons above about URL spoofing risk. navigateInTab(tab: tab) + } else { + updateURLBar() + + // If navigation will start from NTP, tab display url will be nil until + // didCommit is called and it will cause url bar be empty in that period + // To fix this when tab display url is empty, webview url is used + if tab.url?.displayURL == nil { + if let url = webView.url, !url.isLocal, !InternalURL.isValid(url: url) { + updateToolbarCurrentURL(url.displayURL) + } + } } // Rewards reporting @@ -2027,7 +2038,7 @@ public class BrowserViewController: UIViewController { popToBVC() } - if let tab = tabManager.getTabForURL(url) { + if let tab = tabManager.getTabForURL(url, isPrivate: isPrivate) { tabManager.selectTab(tab) } else { openURLInNewTab(url, isPrivate: isPrivate, isPrivileged: isPrivileged) @@ -2039,7 +2050,7 @@ public class BrowserViewController: UIViewController { if let tabID = id, let tab = tabManager.getTabForID(tabID) { tabManager.selectTab(tab) - } else if let tab = tabManager.getTabForURL(url) { + } else if let tab = tabManager.getTabForURL(url, isPrivate: privateBrowsingManager.isPrivateBrowsing) { tabManager.selectTab(tab) } else { openURLInNewTab(url, isPrivate: privateBrowsingManager.isPrivateBrowsing, isPrivileged: false) diff --git a/Sources/Brave/Frontend/Browser/TabManager.swift b/Sources/Brave/Frontend/Browser/TabManager.swift index 3cc2706f62bf..cc5d92a00b6b 100644 --- a/Sources/Brave/Frontend/Browser/TabManager.swift +++ b/Sources/Brave/Frontend/Browser/TabManager.swift @@ -850,12 +850,12 @@ class TabManager: NSObject { return nil } - func getTabForURL(_ url: URL) -> Tab? { + func getTabForURL(_ url: URL, isPrivate: Bool) -> Tab? { assert(Thread.isMainThread) let tab = allTabs.filter { - guard let webViewURL = $0.webView?.url else { - return false + guard let webViewURL = $0.webView?.url, $0.isPrivate else { + return false } return webViewURL.schemelessAbsoluteDisplayString == url.schemelessAbsoluteDisplayString