Commit 5444c345 authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios/web] Don't associate nil wk_item's.

Due to an unrelated issue, it's possible for about:// urls to be
written as an empty url.  Because an empty forward or backwards item
will return an empty URL, it was possible to associate to a nil
WKBackForwardItem and crash.

Bug: 1005211
Change-Id: I2becd93a8d35cde0f1a68fc2ac3da6853c023392
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1810803
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697892}
parent 0dce6bb7
......@@ -2633,6 +2633,19 @@ TEST_P(NavigationManagerTest, CommitNilPendingItem) {
navigation_manager()->GetLastCommittedItem()->GetURL());
}
// Tests that NavigationManagerImpl::CommitPendingItem() for an invalid URL
// doesn't crash.
TEST_P(NavigationManagerTest, CommitEmptyPendingItem) {
[mock_wk_list_ setCurrentURL:@"http://www.url.com/1"
backListURLs:nil
forwardListURLs:nil];
// Call CommitPendingItem() with a valid pending item.
auto item = std::make_unique<web::NavigationItemImpl>();
item->SetURL(GURL::EmptyGURL());
navigation_manager()->CommitPendingItem(std::move(item));
}
// Tests NavigationManagerImpl::CommitPendingItem() with a valid pending item.
TEST_P(NavigationManagerTest, CommitNonNilPendingItem) {
// Create navigation manager with a single forward item and no back items.
......
......@@ -335,10 +335,12 @@ void WKBasedNavigationManagerImpl::CommitPendingItem(
// URL is correctly updated. This is a bug in WKWebView. Check to see if
// the next or previous item matches, and update that item instead. If
// nothing matches, still update the the currentItem.
if (item_url == net::GURLWithNSURL(back_forward_list.backItem.URL)) {
if (back_forward_list.backItem &&
item_url == net::GURLWithNSURL(back_forward_list.backItem.URL)) {
SetNavigationItemInWKItem(back_forward_list.backItem, std::move(item));
} else if (item_url ==
net::GURLWithNSURL(back_forward_list.forwardItem.URL)) {
} else if (back_forward_list.forwardItem &&
item_url ==
net::GURLWithNSURL(back_forward_list.forwardItem.URL)) {
SetNavigationItemInWKItem(back_forward_list.forwardItem,
std::move(item));
} else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment