@@ -1834,6 +1834,7 @@ public class BrowserViewController: UIViewController {
1834
1834
}
1835
1835
1836
1836
tab. secureContentState = . mixedContent
1837
+ logSecureContentState ( tab: tab, path: path)
1837
1838
}
1838
1839
1839
1840
if let url = tab. webView? . url,
@@ -1844,18 +1845,22 @@ public class BrowserViewController: UIViewController {
1844
1845
if ErrorPageHelper . certificateError ( for: url) != 0 {
1845
1846
// Cert validation takes precedence over all other errors
1846
1847
tab. secureContentState = . invalidCert
1848
+ logSecureContentState ( tab: tab, path: path, details: " Cert validation takes precedence over all other errors " )
1847
1849
} else if NetworkErrorPageHandler . isNetworkError ( errorCode: ErrorPageHelper . errorCode ( for: url) ) {
1848
1850
// Network error takes precedence over missing cert
1849
1851
// Because we cannot determine if a cert is missing yet, if we cannot connect to the server
1850
1852
// Our network interstitial page shows
1851
1853
tab. secureContentState = . localhost
1854
+ logSecureContentState ( tab: tab, path: path, details: " Network error takes precedence over missing cert " )
1852
1855
} else {
1853
1856
// Since it's not a cert error explicitly, and it's not a network error, and the cert is missing (no serverTrust),
1854
1857
// then we display .missingSSL
1855
1858
tab. secureContentState = . missingSSL
1859
+ logSecureContentState ( tab: tab, path: path, details: " Certificate is missing (no serverTrust) " )
1856
1860
}
1857
1861
} else if url. isReaderModeURL || InternalURL . isValid ( url: url) {
1858
1862
tab. secureContentState = . localhost
1863
+ logSecureContentState ( tab: tab, path: path, details: " Reader Mode or Internal URL " )
1859
1864
}
1860
1865
}
1861
1866
@@ -1868,14 +1873,17 @@ public class BrowserViewController: UIViewController {
1868
1873
}
1869
1874
1870
1875
tab. secureContentState = . unknown
1871
-
1876
+ logSecureContentState ( tab: tab, path: path)
1877
+
1872
1878
guard let serverTrust = tab. webView? . serverTrust else {
1873
1879
if let url = tab. webView? . url ?? tab. url {
1874
1880
if InternalURL . isValid ( url: url) ,
1875
1881
let internalUrl = InternalURL ( url) ,
1876
1882
( internalUrl. isAboutURL || internalUrl. isAboutHomeURL) {
1877
1883
1878
1884
tab. secureContentState = . localhost
1885
+ logSecureContentState ( tab: tab, path: path, details: " Internal URL aboutURL or is aboutHomeURL " )
1886
+
1879
1887
if tabManager. selectedTab === tab {
1880
1888
updateToolbarSecureContentState ( . localhost)
1881
1889
}
@@ -1889,15 +1897,20 @@ public class BrowserViewController: UIViewController {
1889
1897
if ErrorPageHelper . certificateError ( for: url) != 0 {
1890
1898
// Cert validation takes precedence over all other errors
1891
1899
tab. secureContentState = . invalidCert
1900
+
1901
+ logSecureContentState ( tab: tab, path: path, details: " Cert validation takes precedence over all other errors " )
1892
1902
} else if NetworkErrorPageHandler . isNetworkError ( errorCode: ErrorPageHelper . errorCode ( for: url) ) {
1893
1903
// Network error takes precedence over missing cert
1894
1904
// Because we cannot determine if a cert is missing yet, if we cannot connect to the server
1895
1905
// Our network interstitial page shows
1896
1906
tab. secureContentState = . localhost
1907
+
1908
+ logSecureContentState ( tab: tab, path: path, details: " Network error takes precedence over missing cert " )
1897
1909
} else {
1898
1910
// Since it's not a cert error explicitly, and it's not a network error, and the cert is missing (no serverTrust),
1899
1911
// then we display .missingSSL
1900
1912
tab. secureContentState = . missingSSL
1913
+ logSecureContentState ( tab: tab, path: path, details: " Certificate is missing (no serverTrust) " )
1901
1914
}
1902
1915
1903
1916
if tabManager. selectedTab === tab {
@@ -1908,6 +1921,8 @@ public class BrowserViewController: UIViewController {
1908
1921
1909
1922
if url. isReaderModeURL || InternalURL . isValid ( url: url) {
1910
1923
tab. secureContentState = . localhost
1924
+ logSecureContentState ( tab: tab, path: path, details: " Reader Mode or Internal URL " )
1925
+
1911
1926
if tabManager. selectedTab === tab {
1912
1927
updateToolbarSecureContentState ( . localhost)
1913
1928
}
@@ -1916,9 +1931,13 @@ public class BrowserViewController: UIViewController {
1916
1931
1917
1932
// All our checks failed, we show the page as insecure
1918
1933
tab. secureContentState = . missingSSL
1934
+
1935
+ logSecureContentState ( tab: tab, path: path, details: " All our checks failed, we show the page as insecure " )
1919
1936
} else {
1920
1937
// When there is no URL, it's likely a new tab.
1921
1938
tab. secureContentState = . localhost
1939
+
1940
+ logSecureContentState ( tab: tab, path: path, details: " When there is no URL, it's likely a new tab " )
1922
1941
}
1923
1942
1924
1943
if tabManager. selectedTab === tab {
@@ -1930,6 +1949,8 @@ public class BrowserViewController: UIViewController {
1930
1949
guard let scheme = tab. webView? . url? . scheme,
1931
1950
let host = tab. webView? . url? . host else {
1932
1951
tab. secureContentState = . unknown
1952
+ logSecureContentState ( tab: tab, path: path, details: " No webview URL host scheme) " )
1953
+
1933
1954
self . updateURLBar ( )
1934
1955
return
1935
1956
}
@@ -1950,16 +1971,24 @@ public class BrowserViewController: UIViewController {
1950
1971
// Cert is valid!
1951
1972
if result == 0 {
1952
1973
tab. secureContentState = . secure
1974
+
1975
+ logSecureContentState ( tab: tab, path: path, details: " Cert is valid! " )
1953
1976
} else if result == Int32 . min {
1954
1977
// Cert is valid but should be validated by the system
1955
1978
// Let the system handle it and we'll show an error if the system cannot validate it
1956
1979
try await BraveCertificateUtils . evaluateTrust ( serverTrust, for: host)
1957
1980
tab. secureContentState = . secure
1981
+
1982
+ logSecureContentState ( tab: tab, path: path, details: " Cert is valid but should be validated by the system " )
1958
1983
} else {
1959
1984
tab. secureContentState = . invalidCert
1985
+
1986
+ logSecureContentState ( tab: tab, path: path, details: " Invalid Cert " )
1960
1987
}
1961
1988
} catch {
1962
1989
tab. secureContentState = . invalidCert
1990
+
1991
+ logSecureContentState ( tab: tab, path: path, details: " Verify Trust Error " )
1963
1992
}
1964
1993
1965
1994
self . updateURLBar ( )
@@ -1971,6 +2000,24 @@ public class BrowserViewController: UIViewController {
1971
2000
}
1972
2001
}
1973
2002
2003
+ func logSecureContentState( tab: Tab , path: KVOConstants ? = nil , details: String ? = nil ) {
2004
+ var text = """
2005
+ Tab URL: \( tab. url? . absoluteString ?? " Empty Tab URL " )
2006
+ Tab VebView URL: \( tab. webView? . url? . absoluteString ?? " Empty Webview URL " )
2007
+ Secure State: \( tab. secureContentState. rawValue)
2008
+ """
2009
+
2010
+ if let keyPath = path? . keyPath {
2011
+ text. append ( " \n Value Observed: \( keyPath) \n " )
2012
+ }
2013
+
2014
+ if let extraDetails = details {
2015
+ text. append ( " \n Extra Details: \( extraDetails) \n " )
2016
+ }
2017
+
2018
+ DebugLogger . log ( for: . secureState, text: text)
2019
+ }
2020
+
1974
2021
func updateForwardStatusIfNeeded( webView: WKWebView ) {
1975
2022
if let forwardListItem = webView. backForwardList. forwardList. first, forwardListItem. url. isReaderModeURL {
1976
2023
navigationToolbar. updateForwardStatus ( false )
0 commit comments