From b720fbaf7eb5461ae437cfe63fcc001ad6333b8a Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Wed, 16 Jan 2019 10:45:09 -0500 Subject: [PATCH] Fix #734: Shields update on first refresh of an upgraded http page Seems to be due to a WebKit bug where `WKNavigationAction.request.mainDocumentURL` is not also upgraded to https, therefore on the first refresh `url` has https and `mainDocumentURL` has http. These two properties become aligned once the page is refreshed once. --- .../BrowserViewController+WKNavigationDelegate.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Client/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift b/Client/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift index ab2f50080..3404d1cde 100644 --- a/Client/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift +++ b/Client/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift @@ -21,6 +21,14 @@ extension WKNavigationAction { } } +extension URL { + /// Obtain a schemeless absolute string + fileprivate var schemelessAbsoluteString: String { + guard let scheme = self.scheme else { return absoluteString } + return absoluteString.replacingOccurrences(of: "\(scheme)://", with: "") + } +} + extension BrowserViewController: WKNavigationDelegate { func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { if tabManager.selectedTab?.webView !== webView { @@ -169,7 +177,7 @@ extension BrowserViewController: WKNavigationDelegate { // request then the page is reloaded with a proper url and adblocking rules are applied. if let mainDocumentURL = navigationAction.request.mainDocumentURL, - mainDocumentURL == url, + mainDocumentURL.schemelessAbsoluteString == url.schemelessAbsoluteString, !url.isSessionRestoreURL, navigationAction.sourceFrame.isMainFrame || navigationAction.targetFrame?.isMainFrame == true {