Skip to content

Commit

Permalink
Fix brave/brave-ios#8383: Handling External links on NTP does not work (
Browse files Browse the repository at this point in the history
brave/brave-ios#8384)

Check if it is nonactive but NTP tab whole triggering external link navigation
  • Loading branch information
soner-yuksel committed Nov 9, 2023
1 parent f3dad53 commit d5b9aad
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -794,17 +794,12 @@ extension BrowserViewController {
navigationAction: WKNavigationAction,
openedURLCompletionHandler: ((Bool) -> Void)? = nil
) {

let isMainFrame = navigationAction.targetFrame?.isMainFrame == true

// Do not open external links for child tabs automatically
// The user must tap on the link to open it.
if tab?.parent != nil && navigationAction.navigationType != .linkActivated {
return
}

var alertTitle = Strings.openExternalAppURLGenericTitle

// Check if the current url of the caller has changed
if let domain = tab?.url?.baseDomain,
domain != tab?.externalAppURLDomain {
Expand All @@ -820,10 +815,25 @@ extension BrowserViewController {

// We do not schemes to be opened externally when called from subframes.
// And external dialog should not be shown for non-active tabs #6687 - #7835
if !isMainFrame || tab?.url?.host != topToolbar.currentURL?.host {

// Check navigation action is from main frame as first step
let isMainFrame = navigationAction.targetFrame?.isMainFrame == true

// Check user trying to open on NTP like external link browsing
var isAboutHome = false
if let url = tab?.url {
isAboutHome = InternalURL(url)?.isAboutHomeURL == true
}

// Finally check non-active tab
let isNonActiveTab = isAboutHome ? false : tab?.url?.host != topToolbar.currentURL?.host

if !isMainFrame || isNonActiveTab {
return
}


var alertTitle = Strings.openExternalAppURLGenericTitle

if let displayHost = tab?.url?.withoutWWW.host {
alertTitle = String(format: Strings.openExternalAppURLTitle, displayHost)
}
Expand Down

0 comments on commit d5b9aad

Please sign in to comment.