Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 4511b50

Browse files
author
Ian Macphail
committed
[[ Bug 22688 ]] Don't set empty url on WKWebView
This patch fixes a bug where setting the url to empty would block subsequent requests. Loading an empty url in the WKWebView browser would happen without the expected 'decidePolicyForNavigationAction' message being sent to the browser delegate as expected. To ensure the message is sent, we now load the html text of a blank page into the browser instead.
1 parent 3779ac7 commit 4511b50

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

libbrowser/src/libbrowser_wkwebview.mm

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -928,26 +928,35 @@ - (void)userContentController:(WKUserContentController *)userContentController d
928928
if (!GetWebView(t_view))
929929
return false;
930930

931-
// __block NSURL *t_url;
932931
NSURL *t_url;
933-
t_url = [NSURL URLWithString: [NSString stringWithUTF8String: p_url]];
932+
if (MCCStringIsEmpty(p_url))
933+
{
934+
// Sending an empty url to the webview will bypass the delegate's
935+
// decidePolicyForNavigationAction method. We can prevent that by
936+
// loading a blank page instead.
937+
[m_delegate loadRequest:[MCWKWebViewLoadRequest requestWithUrl:nil htmlText:@"<html><body></body></html>" quiet:YES] inWebView:t_view];
938+
}
939+
else
940+
{
941+
t_url = [NSURL URLWithString: [NSString stringWithUTF8String: p_url]];
934942

935-
// reject file urls with empty path components
936-
if (t_url.fileURL && t_url.path.length == 0)
937-
return false;
943+
// reject file urls with empty path components
944+
if (t_url.fileURL && t_url.path.length == 0)
945+
return false;
938946

939-
// check that we have permission to access file urls before proceeding
940-
__block bool t_reachable = true;
941-
if (t_url.fileURL)
942-
{
943-
MCBrowserRunBlockOnMainFiber(^{
944-
t_reachable = [t_url checkResourceIsReachableAndReturnError:nil];
945-
});
947+
// check that we have permission to access file urls before proceeding
948+
__block bool t_reachable = true;
949+
if (t_url.fileURL)
950+
{
951+
MCBrowserRunBlockOnMainFiber(^{
952+
t_reachable = [t_url checkResourceIsReachableAndReturnError:nil];
953+
});
954+
}
955+
if (!t_reachable)
956+
return false;
957+
958+
[m_delegate loadRequest:[MCWKWebViewLoadRequest requestWithUrl:t_url htmlText:nil quiet:NO] inWebView:t_view];
946959
}
947-
if (!t_reachable)
948-
return false;
949-
950-
[m_delegate loadRequest:[MCWKWebViewLoadRequest requestWithUrl:t_url htmlText:nil quiet:NO] inWebView:t_view];
951960

952961
/* UNCHECKED */ MCBrowserCStringAssignCopy(m_url, p_url);
953962
MCBrowserCStringAssign(m_htmltext, nil);

0 commit comments

Comments
 (0)