Commit 4527bad8 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Use webView.backForwardList.currentItem.URL if webView.URL is nil.

It is possible for WKWebView.URL to be empty inside
webView:didCommitNavigation:. That's probably a bug, but WKWebView.URL
does not represent last committed URL anyway, so it is safer to fallback
to  WKBackForwardList's currentItem when WKWebView.URL is nil.

Using webView.backForwardList.currentItem.URL everywhere is not an option
because that URL is not correct for WebUI pages loaded via loadHTML:.
After dropping iOS 10 and switching WebUI to iOS 11's custom URL protocols
it might be possible to use webView.backForwardList.currentItem.URL
unconditionally.

Bug: 784480
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I2c2cdb9fad425afec6756bc8e841389e979d066b
Reviewed-on: https://chromium-review.googlesource.com/773621
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#518355}
parent 5f4de1c7
......@@ -4467,8 +4467,17 @@ registerLoadRequestForURL:(const GURL&)requestURL
- (void)webView:(WKWebView*)webView
didCommitNavigation:(WKNavigation*)navigation {
// TODO(crbug.com/787497): Always use webView.backForwardList.currentItem.URL
// to obtain lastCommittedURL once loadHTML: is no longer user for WebUI.
GURL webViewURL = net::GURLWithNSURL(webView.URL);
if (webViewURL.is_empty()) {
// It is possible for |webView.URL| to be nil, in which case
// webView.backForwardList.currentItem.URL will return the right committed
// URL (crbug.com/784480).
webViewURL = net::GURLWithNSURL(webView.backForwardList.currentItem.URL);
}
// If this is a placeholder navigation or if |navigation| has been previous
// aborted, return without modifying the navigation states. The latter case
// seems to happen due to asychronous nature of WKWebView; sometimes
......
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