Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #8665: Fix an issue where URL won't load if already loaded in a d…
Browse files Browse the repository at this point in the history
…ifferent mode (#8666)

- Fix URL not loading when the same URL is already open in a different mode
  • Loading branch information
Brandon-T authored Jan 17, 2024
1 parent 86fefb6 commit 29df100
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Brave/Frontend/Browser/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29df100

Please sign in to comment.