Tabs implementation
Favicons and stuff too
This commit is contained in:
40
SBrowser/Tabs/TabController.swift
Normal file
40
SBrowser/Tabs/TabController.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// 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.
|
||||
_ = createNewTab()
|
||||
}
|
||||
|
||||
func tab(forURL url: URL) -> Tab? {
|
||||
tabs.first { $0.url == url }
|
||||
}
|
||||
|
||||
func tab(forIdentifier identifier: UUID) -> Tab? {
|
||||
tabs.first { $0.identifier == identifier }
|
||||
}
|
||||
|
||||
func createNewTab() -> Tab {
|
||||
let tab = Tab(urlString: "about:blank", policyManager: policyManager)
|
||||
tabs.append(tab)
|
||||
|
||||
return tab
|
||||
}
|
||||
|
||||
func closeTab(_ tab: Tab) {
|
||||
if let index = tabs.firstIndex(of: tab) {
|
||||
tabs.remove(at: index)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user