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

Commit

Permalink
Refactor FXIOS-7773 [v122] Added URIFixup check in createWebViewWith …
Browse files Browse the repository at this point in the history
…when opening redirected urls in new window (#3967)
  • Loading branch information
nbhasin2 authored Dec 22, 2023
1 parent ffbb98d commit 864e6f2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions focus-ios/Blockzilla/Modules/WebView/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,20 @@ extension WebViewController: BrowserState {

extension WebViewController: WKUIDelegate {
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
if navigationAction.targetFrame == nil {
browserView.load(navigationAction.request)
// check if this is a new frame / window
guard navigationAction.targetFrame == nil else { return nil }

// validate the URL using URIFixup
guard let urlString = navigationAction.request.url?.absoluteString,
URIFixup.getURL(entry: urlString) != nil else {
// URL failed validation, prevent loading
return nil
}

// load validated URLs
browserView.load(navigationAction.request)

// we return nil to not open new window
return nil
}
}
Expand Down

0 comments on commit 864e6f2

Please sign in to comment.