Skip to content

Commit 010e2b2

Browse files
Eugene ButCommit Bot
authored andcommitted
Gracefully handle null pending item inside webView:didCommitNavigation:.
webView:didCommitNavigation: used to assume that pending item is always valid and crashed on dereferencing null pointer. Pending item should never be null inside webView:didCommitNavigation: but existing ownership model is incorrect, so pending item could be distroyed before committing. This CL adds checks before dereferencing pending item to avoid the crash. The real fix could be implemented by storing pending item in NavigationContext object (crbug.com/925304). Bug: 676458 Change-Id: Idf60e60cbe98111e8fed5d2903ae8bc8b8df3d90 Reviewed-on: https://chromium-review.googlesource.com/c/1444953 Reviewed-by: Justin Cohen <[email protected]> Commit-Queue: Eugene But <[email protected]> Cr-Commit-Position: refs/heads/master@{#627509}
1 parent 357f9dd commit 010e2b2

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

ios/web/web_state/ui/crw_web_controller.mm

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,12 @@ - (void)updateCurrentBackForwardListItemHolder {
17181718
if (_webUIManager)
17191719
return;
17201720

1721+
if (!self.currentNavItem) {
1722+
// TODO(crbug.com/925304): Pending item (which stores the holder) should be
1723+
// owned by NavigationContext object. Pending item should never be null.
1724+
return;
1725+
}
1726+
17211727
web::WKBackForwardListItemHolder* holder =
17221728
[self currentBackForwardListItemHolder];
17231729

@@ -2933,7 +2939,10 @@ - (void)webPageChangedWithContext:(const web::NavigationContextImpl*)context {
29332939
// keep it since it will have a more accurate URL and policy than what can
29342940
// be extracted from the landing page.)
29352941
web::NavigationItem* currentItem = self.currentNavItem;
2936-
if (!currentItem->GetReferrer().url.is_valid()) {
2942+
2943+
// TODO(crbug.com/925304): Pending item (which should be used here) should be
2944+
// owned by NavigationContext object. Pending item should never be null.
2945+
if (currentItem && !currentItem->GetReferrer().url.is_valid()) {
29372946
currentItem->SetReferrer(referrer);
29382947
}
29392948

@@ -4935,15 +4944,21 @@ - (void)webView:(WKWebView*)webView
49354944
}
49364945

49374946
[self commitPendingNavigationInfo];
4938-
if ([self currentBackForwardListItemHolder]->navigation_type() ==
4939-
WKNavigationTypeBackForward) {
4940-
// A fast back/forward won't call decidePolicyForNavigationResponse, so
4941-
// the MIME type needs to be updated explicitly.
4942-
NSString* storedMIMEType =
4943-
[self currentBackForwardListItemHolder]->mime_type();
4944-
if (storedMIMEType) {
4945-
self.webStateImpl->SetContentsMimeType(
4946-
base::SysNSStringToUTF8(storedMIMEType));
4947+
4948+
// TODO(crbug.com/925304): Pending item (which is stores
4949+
// currentBackForwardListItemHolder) should be owned by NavigationContext.
4950+
// Pending item should never be null.
4951+
if (self.currentNavItem) {
4952+
if ([self currentBackForwardListItemHolder]
4953+
-> navigation_type() == WKNavigationTypeBackForward) {
4954+
// A fast back/forward won't call decidePolicyForNavigationResponse, so
4955+
// the MIME type needs to be updated explicitly.
4956+
NSString* storedMIMEType =
4957+
[self currentBackForwardListItemHolder] -> mime_type();
4958+
if (storedMIMEType) {
4959+
self.webStateImpl->SetContentsMimeType(
4960+
base::SysNSStringToUTF8(storedMIMEType));
4961+
}
49474962
}
49484963
}
49494964

0 commit comments

Comments
 (0)