Some more interesting visual state with script button

This commit is contained in:
James Magahern
2020-07-31 15:03:00 -07:00
parent 9a74042b59
commit 8728e1cf54
2 changed files with 33 additions and 5 deletions

View File

@@ -194,12 +194,20 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
private func updateScriptBlockerButton() {
var numBlockedScripts: Int = tab.blockedScriptOrigins.count
if tab.javaScriptEnabled == false {
if tab.url != nil, tab.javaScriptEnabled == false {
// Because the page is blocked too, notify.
numBlockedScripts += 1
}
toolbarController.scriptControllerIconView.setBlockedScriptsNumber(numBlockedScripts)
var scriptsAllowedForHost = false
if let url = webView.url, let host = url.host, policyManager.allowedOriginsForScriptResources().contains(host) {
scriptsAllowedForHost = true
}
let iconView = toolbarController.scriptControllerIconView
iconView.shieldsDown = tab.javaScriptEnabled
iconView.someScriptsAllowed = scriptsAllowedForHost
iconView.setBlockedScriptsNumber(numBlockedScripts)
}
// MARK: UIPopoverPresentationControllerDelegate
@@ -292,5 +300,6 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
func setScriptsEnabledForTab(_ enabled: Bool) {
tab.javaScriptEnabled = enabled
toolbarController.scriptControllerIconView.shieldsDown = enabled
}
}