Add decision handling for navigation actions

- use our list of host names as a white list when transitions are triggered from within a webpage.
This commit is contained in:
CypherPoet 2019-01-17 02:07:33 -05:00
parent e3badfc406
commit 4041484476
1 changed files with 28 additions and 12 deletions

View File

@ -47,6 +47,34 @@ class ViewController: UIViewController, WKNavigationDelegate {
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
progressView.progress = Float(webView.estimatedProgress)
}
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
let url = navigationAction.request.url
if let host = url?.host {
for siteName in siteNames {
if host.contains(siteName) {
decisionHandler(.allow)
return
}
}
}
decisionHandler(.cancel)
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
title = webView.title
}
func setupNavigationBar() {
navigationItem.rightBarButtonItem = UIBarButtonItem(
title: "🌐",
@ -93,17 +121,5 @@ class ViewController: UIViewController, WKNavigationDelegate {
webView.load(URLRequest(url: pageURL))
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
title = webView.title
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
progressView.progress = Float(webView.estimatedProgress)
}
}
}