2020-07-30 23:54:20 -07:00
|
|
|
//
|
|
|
|
|
// TabController.swift
|
|
|
|
|
// SBrowser
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 7/30/20.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
class TabController
|
|
|
|
|
{
|
|
|
|
|
var tabs: [Tab] = []
|
|
|
|
|
var policyManager = ResourcePolicyManager()
|
|
|
|
|
|
|
|
|
|
init() {
|
|
|
|
|
// TODO: load tabs from disk.
|
2020-07-31 14:41:30 -07:00
|
|
|
_ = createNewTab(url: nil)
|
2020-07-30 23:54:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func tab(forURL url: URL) -> Tab? {
|
|
|
|
|
tabs.first { $0.url == url }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func tab(forIdentifier identifier: UUID) -> Tab? {
|
|
|
|
|
tabs.first { $0.identifier == identifier }
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 14:41:30 -07:00
|
|
|
func createNewTab(url: URL?) -> Tab {
|
2020-09-24 16:36:31 -07:00
|
|
|
return self.createNewTab(url: url, webViewConfiguration: nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func createNewTab(url: URL?, webViewConfiguration: WKWebViewConfiguration?) -> Tab {
|
|
|
|
|
let tab = Tab(url: url, policyManager: policyManager, webViewConfiguration: webViewConfiguration)
|
2020-07-30 23:54:20 -07:00
|
|
|
tabs.append(tab)
|
|
|
|
|
|
|
|
|
|
return tab
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func closeTab(_ tab: Tab) {
|
|
|
|
|
if let index = tabs.firstIndex(of: tab) {
|
|
|
|
|
tabs.remove(at: index)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|