Some multiple tab fixes

This commit is contained in:
James Magahern
2020-07-31 14:39:18 -07:00
parent 4227e2ecaa
commit 9272c34d3d
5 changed files with 50 additions and 25 deletions

View File

@@ -44,33 +44,33 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
browserView.toolbarView = toolbarController.toolbarView browserView.toolbarView = toolbarController.toolbarView
// Refresh button // Refresh button
toolbarController.urlBar.refreshButton.addAction(UIAction(handler: { [webView] action in toolbarController.urlBar.refreshButton.addAction(UIAction(handler: { [unowned self] action in
if webView.isLoading { if self.webView.isLoading {
webView.stopLoading() self.webView.stopLoading()
} else { } else {
webView.reload() self.webView.reload()
} }
}), for: .touchUpInside) }), for: .touchUpInside)
// Back button // Back button
toolbarController.backButton.addAction(UIAction(handler: { [webView] _ in toolbarController.backButton.addAction(UIAction(handler: { [unowned self] _ in
webView.goBack() self.webView.goBack()
}), for: .touchUpInside) }), for: .touchUpInside)
// Forward button // Forward button
toolbarController.forwardButton.addAction(UIAction(handler: { [webView] _ in toolbarController.forwardButton.addAction(UIAction(handler: { [unowned self] _ in
webView.goForward() self.webView.goForward()
}), for: .touchUpInside) }), for: .touchUpInside)
// Share button // Share button
toolbarController.shareButton.addAction(UIAction(handler: { [unowned self, webView, toolbarController] _ in toolbarController.shareButton.addAction(UIAction(handler: { [unowned self, toolbarController] _ in
if let url = webView.url { if let url = self.webView.url {
let itemProvider = NSItemProvider(item: url as NSURL, typeIdentifier: UTType.url.identifier) let itemProvider = NSItemProvider(item: url as NSURL, typeIdentifier: UTType.url.identifier)
let config = UIActivityItemsConfiguration(itemProviders: [ itemProvider ]) let config = UIActivityItemsConfiguration(itemProviders: [ itemProvider ])
config.metadataProvider = { metadataKey in config.metadataProvider = { metadataKey in
switch metadataKey { switch metadataKey {
case .title: return webView.title case .title: return self.webView.title
case .messageBody: return webView.title case .messageBody: return self.webView.title
default: return nil default: return nil
} }
} }
@@ -142,6 +142,8 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
if let urlString = webView.url?.absoluteString { if let urlString = webView.url?.absoluteString {
toolbarController.urlBar.textField.text = urlString toolbarController.urlBar.textField.text = urlString
} else {
toolbarController.urlBar.textField.text = ""
} }
} }
@@ -191,7 +193,13 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
} }
private func updateScriptBlockerButton() { private func updateScriptBlockerButton() {
toolbarController.scriptControllerIconView.setBlockedScriptsNumber(tab.blockedScriptOrigins.count) var numBlockedScripts: Int = tab.blockedScriptOrigins.count
if tab.javaScriptEnabled == false {
// Because the page is blocked too, notify.
numBlockedScripts += 1
}
toolbarController.scriptControllerIconView.setBlockedScriptsNumber(numBlockedScripts)
} }
// MARK: UIPopoverPresentationControllerDelegate // MARK: UIPopoverPresentationControllerDelegate
@@ -205,7 +213,9 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
// Reset tracking this // Reset tracking this
tab.allowedScriptOrigins.removeAll()
tab.blockedScriptOrigins.removeAll() tab.blockedScriptOrigins.removeAll()
updateScriptBlockerButton()
updateTitleAndURL(forWebView: webView) updateTitleAndURL(forWebView: webView)

View File

@@ -46,6 +46,6 @@ class ScriptControllerIconView: UIButton
labelView.sizeToFit() labelView.sizeToFit()
labelView.center = CGPoint(x: bounds.center.x + 10, y: bounds.center.y + 10) labelView.center = CGPoint(x: bounds.center.x + 10, y: bounds.center.y + 10)
labelView.bounds = labelView.bounds.insetBy(dx: -2.0, dy: -2.0) labelView.bounds = labelView.bounds.insetBy(dx: -3.0, dy: -2.0)
} }
} }

View File

@@ -17,12 +17,15 @@ class Tab: NSObject, SBRProcessBundleBridgeDelegate
{ {
public weak var delegate: TabDelegate? public weak var delegate: TabDelegate?
public let homeURL: URL public let homeURL: URL?
public let bridge = SBRProcessBundleBridge() public let bridge = SBRProcessBundleBridge()
public var webView: WKWebView { public var webView: WKWebView {
if self.loadedWebView == nil { if self.loadedWebView == nil {
self.loadedWebView = bridge.webView self.loadedWebView = bridge.webView
beginLoadingURL(homeURL)
if let homeURL = homeURL {
beginLoadingURL(homeURL)
}
} }
return bridge.webView return bridge.webView
@@ -49,11 +52,15 @@ class Tab: NSObject, SBRProcessBundleBridgeDelegate
private var titleObservation: NSKeyValueObservation? private var titleObservation: NSKeyValueObservation?
private var urlObservation: NSKeyValueObservation? private var urlObservation: NSKeyValueObservation?
convenience init(urlString: String, policyManager: ResourcePolicyManager) { convenience init(policyManager: ResourcePolicyManager) {
self.init(url: URL(string: urlString)!, policyManager: policyManager) self.init(url: nil, policyManager: policyManager)
} }
init(url: URL, policyManager: ResourcePolicyManager) { convenience init(urlString: String, policyManager: ResourcePolicyManager) {
self.init(url: URL(string: urlString), policyManager: policyManager)
}
init(url: URL?, policyManager: ResourcePolicyManager) {
self.homeURL = url self.homeURL = url
self.policyManager = policyManager self.policyManager = policyManager
bridge.policyDataSource = policyManager bridge.policyDataSource = policyManager

View File

@@ -26,7 +26,7 @@ class TabController
} }
func createNewTab() -> Tab { func createNewTab() -> Tab {
let tab = Tab(urlString: "about:blank", policyManager: policyManager) let tab = Tab(policyManager: policyManager)
tabs.append(tab) tabs.append(tab)
return tab return tab

View File

@@ -63,20 +63,28 @@ class TabPickerViewController: UIViewController, UICollectionViewDelegate
var config = listCell.defaultContentConfiguration() var config = listCell.defaultContentConfiguration()
if let tab = self.tabController.tab(forIdentifier: item) { if let tab = self.tabController.tab(forIdentifier: item) {
if let title = tab.title { if let title = tab.title, title.count > 0 {
config.text = title config.text = title
config.secondaryText = tab.url?.absoluteString config.secondaryText = tab.url?.absoluteString
} else if let url = tab.url {
config.text = url.absoluteString
config.secondaryText = url.absoluteString
} else { } else {
config.text = tab.url?.absoluteString config.text = "New Tab"
config.secondaryText = tab.url?.absoluteString
} }
config.textProperties.numberOfLines = 1
config.secondaryTextProperties.numberOfLines = 1
if let image = tab.favicon { if let image = tab.favicon {
config.image = image config.image = image
config.imageProperties.maximumSize = CGSize(width: 21.0, height: 21.0) } else {
config.imageProperties.cornerRadius = 3.0 config.image = UIImage(systemName: "safari")
} }
config.imageProperties.maximumSize = CGSize(width: 21.0, height: 21.0)
config.imageProperties.cornerRadius = 3.0
if tab == self.selectedTab { if tab == self.selectedTab {
listCell.accessories = [ .checkmark() ] listCell.accessories = [ .checkmark() ]
} else { } else {