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

Commit

Permalink
Fix #8383: Handling External links on NTP does not work (#8384)
Browse files Browse the repository at this point in the history
Check if it is nonactive but NTP tab whole triggering external link navigation
  • Loading branch information
soner-yuksel authored Nov 9, 2023
1 parent d23bcf4 commit 29f0c90
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 29f0c90

Please sign in to comment.