Skip to content

Commit 10b77f0

Browse files
authored
Merge pull request #29371 from brave/pr29368_ios-web-process-crash-fix_1.80.x
[iOS] Handle web process terminating when using Chromium web views (uplift to 1.80.x)
2 parents 6c6e75c + 2710000 commit 10b77f0

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+TabObserver.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,16 @@ extension BrowserViewController: TabObserver {
328328
}
329329
}
330330

331+
public func tabRenderProcessDidTerminate(_ tab: some TabState) {
332+
guard let url = tab.lastCommittedURL else { return }
333+
if InternalURL.isValid(url: url) {
334+
// No need to refresh an internal url
335+
return
336+
}
337+
// For now just reload the page when the process crashes
338+
tab.reload()
339+
}
340+
331341
public func tabDidUpdateURL(_ tab: some TabState) {
332342
if tab.isDisplayingBasicAuthPrompt == true {
333343
tab.setVirtualURL(

ios/brave-ios/Sources/Web/Chromium/TabCWVNavigationHandler.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ class TabCWVNavigationHandler: NSObject, BraveWebViewNavigationDelegate {
145145
tab.didFailNavigation(with: error)
146146
}
147147

148+
func webViewWebContentProcessDidTerminate(_ webView: CWVWebView) {
149+
tab?.renderProcessTerminated()
150+
}
151+
148152
public func webView(_ webView: CWVWebView, didRequestDownloadWith task: CWVDownloadTask) {
149153
guard let tab else { return }
150154
let pendingDownload = ChromiumDownload(

ios/brave-ios/Sources/Web/TabObserver.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public protocol TabObserver: AnyObject {
1717
func tabDidRedirectNavigation(_ tab: some TabState)
1818
func tabDidFinishNavigation(_ tab: some TabState)
1919
func tab(_ tab: some TabState, didFailNavigationWithError error: Error)
20+
func tabRenderProcessDidTerminate(_ tab: some TabState)
2021

2122
func tabDidUpdateURL(_ tab: some TabState)
2223
func tabDidChangeTitle(_ tab: some TabState)
@@ -47,6 +48,7 @@ extension TabObserver {
4748
public func tabDidRedirectNavigation(_ tab: some TabState) {}
4849
public func tabDidFinishNavigation(_ tab: some TabState) {}
4950
public func tab(_ tab: some TabState, didFailNavigationWithError error: Error) {}
51+
public func tabRenderProcessDidTerminate(_ tab: some TabState) {}
5052

5153
public func tabDidUpdateURL(_ tab: some TabState) {}
5254
public func tabDidChangeTitle(_ tab: some TabState) {}
@@ -75,6 +77,7 @@ class AnyTabObserver: TabObserver, Hashable, CustomDebugStringConvertible {
7577
private let _tabDidRedirectNavigation: (any TabState) -> Void
7678
private let _tabDidFinishNavigation: (any TabState) -> Void
7779
private let _tabDidFailNavigationWithError: (any TabState, Error) -> Void
80+
private let _tabRenderProcessDidTerminate: (any TabState) -> Void
7881

7982
private let _tabDidUpdateURL: (any TabState) -> Void
8083
private let _tabDidChangeTitle: (any TabState) -> Void
@@ -118,6 +121,8 @@ class AnyTabObserver: TabObserver, Hashable, CustomDebugStringConvertible {
118121
_tabDidFailNavigationWithError = { [weak observer] in
119122
observer?.tab($0, didFailNavigationWithError: $1)
120123
}
124+
_tabRenderProcessDidTerminate = { [weak observer] in observer?.tabRenderProcessDidTerminate($0)
125+
}
121126
_tabDidUpdateURL = { [weak observer] in observer?.tabDidUpdateURL($0) }
122127
_tabDidChangeTitle = { [weak observer] in observer?.tabDidChangeTitle($0) }
123128
_tabDidStartLoading = { [weak observer] in observer?.tabDidStartLoading($0) }
@@ -161,6 +166,9 @@ class AnyTabObserver: TabObserver, Hashable, CustomDebugStringConvertible {
161166
func tab(_ tab: some TabState, didFailNavigationWithError error: Error) {
162167
_tabDidFailNavigationWithError(tab, error)
163168
}
169+
func tabRenderProcessDidTerminate(_ tab: some TabState) {
170+
_tabRenderProcessDidTerminate(tab)
171+
}
164172
func tabDidUpdateURL(_ tab: some TabState) {
165173
_tabDidUpdateURL(tab)
166174
}

ios/brave-ios/Sources/Web/TabStateImpl.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,10 @@ extension TabStateImpl {
147147
$0.tab(self, didFailNavigationWithError: error)
148148
}
149149
}
150+
151+
func renderProcessTerminated() {
152+
observers.forEach {
153+
$0.tabRenderProcessDidTerminate(self)
154+
}
155+
}
150156
}

ios/brave-ios/Sources/Web/WebKit/TabWKNavigationHandler.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ class TabWKNavigationHandler: NSObject, WKNavigationDelegate {
326326
tab?.didFinishNavigation()
327327
}
328328

329+
func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {
330+
tab?.renderProcessTerminated()
331+
}
332+
329333
func webView(
330334
_ webView: WKWebView,
331335
didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!
@@ -352,11 +356,6 @@ class TabWKNavigationHandler: NSObject, WKNavigationDelegate {
352356
// original web page in the tab instead of replacing it with an error page.
353357
return
354358
}
355-
if error.code == WKError.webContentProcessTerminated.rawValue {
356-
Logger.module.warning("WebContent process has crashed. Trying to reload to restart it.")
357-
tab.reload()
358-
return
359-
}
360359
}
361360

362361
if let sslPinningError = sslPinningError {

0 commit comments

Comments
 (0)