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

Fix #8383: Handling External links on NTP does not work #8384

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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