@@ -67,8 +67,9 @@ extension BrowserViewController: WKNavigationDelegate {
67
67
68
68
// check if web view is loading a different origin than the one currently loaded
69
69
if let selectedTab = tabManager. selectedTab,
70
- selectedTab. url? . origin != webView. url? . origin {
71
-
70
+ selectedTab. url? . origin != webView. url? . origin
71
+ {
72
+
72
73
// new site has a different origin, hide wallet icon.
73
74
tabManager. selectedTab? . isWalletIconVisible = false
74
75
// new site, reset connected addresses
@@ -730,20 +731,25 @@ extension BrowserViewController: WKNavigationDelegate {
730
731
download. delegate = self
731
732
}
732
733
733
-
734
734
@MainActor
735
- public func webView( _ webView: WKWebView , respondTo challenge: URLAuthenticationChallenge ) async -> ( URLSession . AuthChallengeDisposition , URLCredential ? ) {
735
+
736
+ public func webView(
737
+ _ webView: WKWebView ,
738
+ respondTo challenge: URLAuthenticationChallenge
739
+ ) async -> ( URLSession . AuthChallengeDisposition , URLCredential ? ) {
740
+
736
741
// If this is a certificate challenge, see if the certificate has previously been
737
742
// accepted by the user.
738
743
let host = challenge. protectionSpace. host
739
744
let origin = " \( host) : \( challenge. protectionSpace. port) "
740
745
if challenge. protectionSpace. authenticationMethod == NSURLAuthenticationMethodServerTrust,
741
- let trust = challenge. protectionSpace. serverTrust {
742
-
746
+ let trust = challenge. protectionSpace. serverTrust
747
+ {
748
+
743
749
let cert = await Task < SecCertificate ? , Never > . detached {
744
750
return ( SecTrustCopyCertificateChain ( trust) as? [ SecCertificate ] ) ? . first
745
751
} . value
746
-
752
+
747
753
if let cert = cert, profile. certStore. containsCertificate ( cert, forOrigin: origin) {
748
754
return ( . useCredential, URLCredential ( trust: trust) )
749
755
}
@@ -777,19 +783,25 @@ extension BrowserViewController: WKNavigationDelegate {
777
783
Logger . module. error ( " CERTIFICATE_INVALID " )
778
784
let errorCode = CFNetworkErrors . braveCertificatePinningFailed. rawValue
779
785
780
- let underlyingError = NSError ( domain: kCFErrorDomainCFNetwork as String ,
781
- code: Int ( errorCode) ,
782
- userInfo: [ " _kCFStreamErrorCodeKey " : Int ( errorCode) ] )
783
-
784
- let error = NSError ( domain: kCFErrorDomainCFNetwork as String ,
785
- code: Int ( errorCode) ,
786
- userInfo: [ NSURLErrorFailingURLErrorKey: webView. url as Any ,
787
- " NSErrorPeerCertificateChainKey " : certificateChain,
788
- NSUnderlyingErrorKey: underlyingError] )
786
+ let underlyingError = NSError (
787
+ domain: kCFErrorDomainCFNetwork as String ,
788
+ code: Int ( errorCode) ,
789
+ userInfo: [ " _kCFStreamErrorCodeKey " : Int ( errorCode) ]
790
+ )
791
+
792
+ let error = NSError (
793
+ domain: kCFErrorDomainCFNetwork as String ,
794
+ code: Int ( errorCode) ,
795
+ userInfo: [
796
+ NSURLErrorFailingURLErrorKey: webView. url as Any ,
797
+ " NSErrorPeerCertificateChainKey " : certificateChain,
798
+ NSUnderlyingErrorKey: underlyingError,
799
+ ]
800
+ )
789
801
790
802
// Handle the error later in `didFailProvisionalNavigation`
791
803
self . tab ( for: webView) ? . sslPinningError = error
792
-
804
+
793
805
return ( . cancelAuthenticationChallenge, nil )
794
806
}
795
807
}
@@ -799,14 +811,15 @@ extension BrowserViewController: WKNavigationDelegate {
799
811
let credential = challenge. proposedCredential
800
812
let previousFailureCount = challenge. previousFailureCount
801
813
802
- guard protectionSpace. authenticationMethod == NSURLAuthenticationMethodHTTPBasic ||
803
- protectionSpace. authenticationMethod == NSURLAuthenticationMethodHTTPDigest ||
804
- protectionSpace. authenticationMethod == NSURLAuthenticationMethodNTLM,
805
- let tab = tab ( for: webView)
814
+ guard
815
+ protectionSpace. authenticationMethod == NSURLAuthenticationMethodHTTPBasic
816
+ || protectionSpace. authenticationMethod == NSURLAuthenticationMethodHTTPDigest
817
+ || protectionSpace. authenticationMethod == NSURLAuthenticationMethodNTLM,
818
+ let tab = tab ( for: webView)
806
819
else {
807
820
return ( . performDefaultHandling, nil )
808
821
}
809
-
822
+
810
823
// The challenge may come from a background tab, so ensure it's the one visible.
811
824
tabManager. selectTab ( tab)
812
825
@@ -817,11 +830,14 @@ extension BrowserViewController: WKNavigationDelegate {
817
830
protectionSpace: protectionSpace,
818
831
previousFailureCount: previousFailureCount
819
832
)
820
-
833
+
821
834
if BasicAuthCredentialsManager . validDomains. contains ( host) {
822
- BasicAuthCredentialsManager . setCredential ( origin: origin, credential: credentials. credentials)
835
+ BasicAuthCredentialsManager . setCredential (
836
+ origin: origin,
837
+ credential: credentials. credentials
838
+ )
823
839
}
824
-
840
+
825
841
return ( . useCredential, credentials. credentials)
826
842
} catch {
827
843
return ( . rejectProtectionSpace, nil )
@@ -993,7 +1009,7 @@ extension BrowserViewController: WKNavigationDelegate {
993
1009
if tab == self . tabManager. selectedTab {
994
1010
self . topToolbar. hideProgressBar ( )
995
1011
}
996
-
1012
+
997
1013
// If the local web server isn't working for some reason (Brave cellular data is
998
1014
// disabled in settings, for example), we'll fail to load the session restore URL.
999
1015
// We rely on loading that page to get the restore callback to reset the restoring
@@ -1059,16 +1075,7 @@ extension BrowserViewController {
1059
1075
// External dialog should not be shown for non-active tabs #6687 - #7835
1060
1076
let isVisibleTab = tab? . isTabVisible ( ) == true
1061
1077
1062
- // Check user trying to open on NTP like external link browsing
1063
- var isAboutHome = false
1064
- if let url = tab? . url {
1065
- isAboutHome = InternalURL ( url) ? . isAboutHomeURL == true
1066
- }
1067
-
1068
- // Finally check non-active tab
1069
- let isNonActiveTab = isAboutHome ? false : tab? . url? . host != topToolbar. currentURL? . host
1070
-
1071
- if !isVisibleTab || isNonActiveTab {
1078
+ if !isVisibleTab {
1072
1079
return false
1073
1080
}
1074
1081
0 commit comments