2020-07-22 19:29:38 -07:00
|
|
|
//
|
|
|
|
|
// BrowserViewController.swift
|
|
|
|
|
// SBrowser
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 7/21/20.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
|
|
class BrowserViewController: UIViewController, SBRProcessBundleBridgeDelegate
|
|
|
|
|
{
|
|
|
|
|
let bridge = SBRProcessBundleBridge()
|
|
|
|
|
let browserView = BrowserView()
|
|
|
|
|
|
|
|
|
|
private let policyManager = ResourcePolicyManager()
|
|
|
|
|
private var blockedScriptOrigins = Set<String>()
|
|
|
|
|
private var scriptBlockerButtonItem: UIBarButtonItem
|
|
|
|
|
|
|
|
|
|
init()
|
|
|
|
|
{
|
|
|
|
|
scriptBlockerButtonItem = UIBarButtonItem(title: "0", image: nil, primaryAction: UIAction(handler: { action in
|
|
|
|
|
// present
|
|
|
|
|
}), menu: nil)
|
|
|
|
|
|
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
|
|
|
|
|
|
|
|
|
override func loadView()
|
|
|
|
|
{
|
|
|
|
|
bridge.delegate = self
|
|
|
|
|
bridge.policyDataSource = policyManager
|
|
|
|
|
|
2020-07-22 19:42:38 -07:00
|
|
|
let webView = bridge.webView
|
|
|
|
|
webView.allowsBackForwardNavigationGestures = true
|
|
|
|
|
|
|
|
|
|
browserView.webView = webView
|
2020-07-22 19:29:38 -07:00
|
|
|
|
|
|
|
|
self.view = browserView
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func viewDidLoad()
|
|
|
|
|
{
|
|
|
|
|
let request = URLRequest(url: URL(string: "https://yahoo.com")!)
|
|
|
|
|
browserView.webView?.load(request)
|
|
|
|
|
|
2020-07-22 19:42:38 -07:00
|
|
|
setToolbarItems([ scriptBlockerButtonItem ], animated: false)
|
2020-07-22 19:29:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func updateScriptBlockerButton()
|
|
|
|
|
{
|
|
|
|
|
scriptBlockerButtonItem.title = "\(blockedScriptOrigins.count)"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: SBRProcessBundleBridgeDelegate
|
|
|
|
|
|
|
|
|
|
func webProcess(_ bridge: SBRProcessBundleBridge, didBlockScriptResourceFromOrigin origin: String)
|
|
|
|
|
{
|
|
|
|
|
print("Blocked script resource from origin: \(origin)")
|
|
|
|
|
|
|
|
|
|
blockedScriptOrigins.formUnion([ origin ])
|
|
|
|
|
updateScriptBlockerButton()
|
|
|
|
|
}
|
|
|
|
|
}
|