Some multiple tab fixes
This commit is contained in:
@@ -44,33 +44,33 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
|
||||
browserView.toolbarView = toolbarController.toolbarView
|
||||
|
||||
// Refresh button
|
||||
toolbarController.urlBar.refreshButton.addAction(UIAction(handler: { [webView] action in
|
||||
if webView.isLoading {
|
||||
webView.stopLoading()
|
||||
toolbarController.urlBar.refreshButton.addAction(UIAction(handler: { [unowned self] action in
|
||||
if self.webView.isLoading {
|
||||
self.webView.stopLoading()
|
||||
} else {
|
||||
webView.reload()
|
||||
self.webView.reload()
|
||||
}
|
||||
}), for: .touchUpInside)
|
||||
|
||||
// Back button
|
||||
toolbarController.backButton.addAction(UIAction(handler: { [webView] _ in
|
||||
webView.goBack()
|
||||
toolbarController.backButton.addAction(UIAction(handler: { [unowned self] _ in
|
||||
self.webView.goBack()
|
||||
}), for: .touchUpInside)
|
||||
|
||||
// Forward button
|
||||
toolbarController.forwardButton.addAction(UIAction(handler: { [webView] _ in
|
||||
webView.goForward()
|
||||
toolbarController.forwardButton.addAction(UIAction(handler: { [unowned self] _ in
|
||||
self.webView.goForward()
|
||||
}), for: .touchUpInside)
|
||||
|
||||
// Share button
|
||||
toolbarController.shareButton.addAction(UIAction(handler: { [unowned self, webView, toolbarController] _ in
|
||||
if let url = webView.url {
|
||||
toolbarController.shareButton.addAction(UIAction(handler: { [unowned self, toolbarController] _ in
|
||||
if let url = self.webView.url {
|
||||
let itemProvider = NSItemProvider(item: url as NSURL, typeIdentifier: UTType.url.identifier)
|
||||
let config = UIActivityItemsConfiguration(itemProviders: [ itemProvider ])
|
||||
config.metadataProvider = { metadataKey in
|
||||
switch metadataKey {
|
||||
case .title: return webView.title
|
||||
case .messageBody: return webView.title
|
||||
case .title: return self.webView.title
|
||||
case .messageBody: return self.webView.title
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
@@ -142,6 +142,8 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
|
||||
|
||||
if let urlString = webView.url?.absoluteString {
|
||||
toolbarController.urlBar.textField.text = urlString
|
||||
} else {
|
||||
toolbarController.urlBar.textField.text = ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +193,13 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
|
||||
}
|
||||
|
||||
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
|
||||
@@ -205,7 +213,9 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
|
||||
|
||||
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
|
||||
// Reset tracking this
|
||||
tab.allowedScriptOrigins.removeAll()
|
||||
tab.blockedScriptOrigins.removeAll()
|
||||
updateScriptBlockerButton()
|
||||
|
||||
updateTitleAndURL(forWebView: webView)
|
||||
|
||||
|
||||
@@ -46,6 +46,6 @@ class ScriptControllerIconView: UIButton
|
||||
|
||||
labelView.sizeToFit()
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,15 @@ class Tab: NSObject, SBRProcessBundleBridgeDelegate
|
||||
{
|
||||
public weak var delegate: TabDelegate?
|
||||
|
||||
public let homeURL: URL
|
||||
public let homeURL: URL?
|
||||
public let bridge = SBRProcessBundleBridge()
|
||||
public var webView: WKWebView {
|
||||
if self.loadedWebView == nil {
|
||||
self.loadedWebView = bridge.webView
|
||||
beginLoadingURL(homeURL)
|
||||
|
||||
if let homeURL = homeURL {
|
||||
beginLoadingURL(homeURL)
|
||||
}
|
||||
}
|
||||
|
||||
return bridge.webView
|
||||
@@ -49,11 +52,15 @@ class Tab: NSObject, SBRProcessBundleBridgeDelegate
|
||||
private var titleObservation: NSKeyValueObservation?
|
||||
private var urlObservation: NSKeyValueObservation?
|
||||
|
||||
convenience init(urlString: String, policyManager: ResourcePolicyManager) {
|
||||
self.init(url: URL(string: urlString)!, policyManager: policyManager)
|
||||
convenience init(policyManager: ResourcePolicyManager) {
|
||||
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.policyManager = policyManager
|
||||
bridge.policyDataSource = policyManager
|
||||
|
||||
@@ -26,7 +26,7 @@ class TabController
|
||||
}
|
||||
|
||||
func createNewTab() -> Tab {
|
||||
let tab = Tab(urlString: "about:blank", policyManager: policyManager)
|
||||
let tab = Tab(policyManager: policyManager)
|
||||
tabs.append(tab)
|
||||
|
||||
return tab
|
||||
|
||||
@@ -63,20 +63,28 @@ class TabPickerViewController: UIViewController, UICollectionViewDelegate
|
||||
var config = listCell.defaultContentConfiguration()
|
||||
|
||||
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.secondaryText = tab.url?.absoluteString
|
||||
} else if let url = tab.url {
|
||||
config.text = url.absoluteString
|
||||
config.secondaryText = url.absoluteString
|
||||
} else {
|
||||
config.text = tab.url?.absoluteString
|
||||
config.secondaryText = tab.url?.absoluteString
|
||||
config.text = "New Tab"
|
||||
}
|
||||
|
||||
config.textProperties.numberOfLines = 1
|
||||
config.secondaryTextProperties.numberOfLines = 1
|
||||
|
||||
if let image = tab.favicon {
|
||||
config.image = image
|
||||
config.imageProperties.maximumSize = CGSize(width: 21.0, height: 21.0)
|
||||
config.imageProperties.cornerRadius = 3.0
|
||||
} else {
|
||||
config.image = UIImage(systemName: "safari")
|
||||
}
|
||||
|
||||
config.imageProperties.maximumSize = CGSize(width: 21.0, height: 21.0)
|
||||
config.imageProperties.cornerRadius = 3.0
|
||||
|
||||
if tab == self.selectedTab {
|
||||
listCell.accessories = [ .checkmark() ]
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user