Resolves "New Tab" bug after web content process jettison
This commit is contained in:
@@ -10,7 +10,11 @@ import WebKit
|
|||||||
extension BrowserViewController: WKNavigationDelegate, WKUIDelegate
|
extension BrowserViewController: WKNavigationDelegate, WKUIDelegate
|
||||||
{
|
{
|
||||||
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
|
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
|
||||||
currentTab.loadError = nil
|
if let tab = tabController.tab(forWebView: webView) {
|
||||||
|
// We're alive!
|
||||||
|
tab.contentProcessTerminated = false
|
||||||
|
tab.loadError = nil
|
||||||
|
}
|
||||||
|
|
||||||
// Check to make sure we have connected to the web content process
|
// Check to make sure we have connected to the web content process
|
||||||
if !currentTab.bridge.webContentProcessConnected {
|
if !currentTab.bridge.webContentProcessConnected {
|
||||||
@@ -120,6 +124,10 @@ extension BrowserViewController: WKNavigationDelegate, WKUIDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {
|
||||||
|
tabController.tab(forWebView: webView)?.contentProcessTerminated = true
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: WKUIDelegate
|
// MARK: WKUIDelegate
|
||||||
|
|
||||||
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView?
|
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView?
|
||||||
|
|||||||
@@ -520,6 +520,8 @@ class BrowserViewController: UIViewController
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal func updateTitleAndURL(forWebView webView: WKWebView) {
|
internal func updateTitleAndURL(forWebView webView: WKWebView) {
|
||||||
|
guard let tab = tabController.tab(forWebView: webView) else { return }
|
||||||
|
|
||||||
if webView == browserView.webView {
|
if webView == browserView.webView {
|
||||||
browserView.titlebarView.setTitle(webView.title ?? "")
|
browserView.titlebarView.setTitle(webView.title ?? "")
|
||||||
|
|
||||||
@@ -531,8 +533,7 @@ class BrowserViewController: UIViewController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Figure out which tab this corresponds to
|
// Figure out which tab this corresponds to
|
||||||
let tab = tabController.tabs.first { $0.webView == webView }
|
if let tabIndex = tabController.tabs.firstIndex(of: tab) {
|
||||||
if let tab = tab, let tabIndex = tabController.tabs.firstIndex(of: tab) {
|
|
||||||
tabBarViewController.tabBarView.reloadTab(atIndex: tabIndex)
|
tabBarViewController.tabBarView.reloadTab(atIndex: tabIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,8 @@ class Tab: NSObject, SBRProcessBundleBridgeDelegate
|
|||||||
|
|
||||||
public var tabInfo: TabInfo {
|
public var tabInfo: TabInfo {
|
||||||
get {
|
get {
|
||||||
TabInfo(
|
updateMetadata()
|
||||||
title: loadedWebView?.title,
|
return _tabInfo
|
||||||
urlString: loadedWebView?.url?.absoluteString ?? self.homeURL?.absoluteString,
|
|
||||||
faviconData: self.favicon?.pngData(),
|
|
||||||
identifier: self.identifier
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +39,8 @@ class Tab: NSObject, SBRProcessBundleBridgeDelegate
|
|||||||
}
|
}
|
||||||
public var policyManager: ResourcePolicyManager
|
public var policyManager: ResourcePolicyManager
|
||||||
|
|
||||||
|
private var _tabInfo: TabInfo = TabInfo()
|
||||||
|
|
||||||
private var loadedWebView: WKWebView? = nil
|
private var loadedWebView: WKWebView? = nil
|
||||||
public var title: String? { get { tabInfo.title } }
|
public var title: String? { get { tabInfo.title } }
|
||||||
public var url: URL? {
|
public var url: URL? {
|
||||||
@@ -82,6 +80,7 @@ class Tab: NSObject, SBRProcessBundleBridgeDelegate
|
|||||||
@Published public var favicon: UIImage?
|
@Published public var favicon: UIImage?
|
||||||
|
|
||||||
public var loadError: Error?
|
public var loadError: Error?
|
||||||
|
public var contentProcessTerminated: Bool = false
|
||||||
|
|
||||||
private var faviconHost: String?
|
private var faviconHost: String?
|
||||||
private var faviconRequest: AnyCancellable?
|
private var faviconRequest: AnyCancellable?
|
||||||
@@ -151,4 +150,15 @@ class Tab: NSObject, SBRProcessBundleBridgeDelegate
|
|||||||
.assign(to: \.favicon, on: self)
|
.assign(to: \.favicon, on: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func updateMetadata() {
|
||||||
|
guard contentProcessTerminated == false else { return }
|
||||||
|
|
||||||
|
_tabInfo = TabInfo(
|
||||||
|
title: loadedWebView?.title,
|
||||||
|
urlString: loadedWebView?.url?.absoluteString ?? self.homeURL?.absoluteString,
|
||||||
|
faviconData: self.favicon?.pngData(),
|
||||||
|
identifier: self.identifier
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ class TabController
|
|||||||
tabs.first { $0.identifier == identifier }
|
tabs.first { $0.identifier == identifier }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tab(forWebView webView: WKWebView) -> Tab? {
|
||||||
|
tabs.first { $0.webView == webView }
|
||||||
|
}
|
||||||
|
|
||||||
func createNewTab(url: URL?) -> Tab {
|
func createNewTab(url: URL?) -> Tab {
|
||||||
return self.createNewTab(url: url, webViewConfiguration: nil)
|
return self.createNewTab(url: url, webViewConfiguration: nil)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user