Commit e01a46a2 authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios/web] Work around WKWebView WKBackForwardList mismatch with webView URL.

When quickly navigating back or forward, it's possible to trigger the
following WebKit error:
"[ProcessSwapping] WebPageProxy::suspendCurrentPageIfPossible: Not suspending
current page for process pid XXXX because fromItem's URL does not match the
page URL."

When this happens, the WKBackForwardList gets out of sync with the webView,
and currentItem.URL does not match webView.URL. This workaround takes the
naive approach and looks to see if the next or previous WKBackForwardList
item has the correct URL.

Bug: 960326
Change-Id: I2b9d9355949fcc3978aef4f37584bb4aeade75a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1627703
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarAli Juma <ajuma@chromium.org>
Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664071}
parent 70ffc432
......@@ -2657,6 +2657,7 @@ TEST_P(NavigationManagerTest, CommitNonNilPendingItem) {
// Call CommitPendingItem() with a valid pending item.
auto item = std::make_unique<web::NavigationItemImpl>();
item->SetURL(GURL("http://www.url.com/new"));
item->SetNavigationInitiationType(
web::NavigationInitiationType::BROWSER_INITIATED);
navigation_manager()->CommitPendingItem(std::move(item));
......
......@@ -298,8 +298,30 @@ void WKBasedNavigationManagerImpl::CommitPendingItem(
empty_window_open_item_ = std::move(item);
} else {
empty_window_open_item_.reset();
SetNavigationItemInWKItem(proxy.backForwardList.currentItem,
std::move(item));
const GURL item_url(item->GetURL());
WKBackForwardList* back_forward_list = proxy.backForwardList;
if (item_url == net::GURLWithNSURL(back_forward_list.currentItem.URL)) {
SetNavigationItemInWKItem(back_forward_list.currentItem, std::move(item));
} else {
// Sometimes |currentItem.URL| is not updated correctly while the webView
// 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)) {
SetNavigationItemInWKItem(back_forward_list.backItem, std::move(item));
} else if (item_url ==
net::GURLWithNSURL(back_forward_list.forwardItem.URL)) {
SetNavigationItemInWKItem(back_forward_list.forwardItem,
std::move(item));
} else {
// Otherwise default here. This can happen when restoring an NTP, since
// |back_forward_list.currentItem.URL| doesn't get updated when going
// from a file:// scheme to about:// scheme.
SetNavigationItemInWKItem(back_forward_list.currentItem,
std::move(item));
}
}
}
pending_item_index_ = -1;
......
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