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

Commit f007af0

Browse files
Merge pull request #7329 from livecodeian/bugfix-22688
[[ Bug 22688 ]] Fix bug preventing mobile browser control from loading after setting the "url" property to empty
2 parents 01ed23f + 15d56c8 commit f007af0

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [22688] Fix bug preventing mobile browser control from loading after setting the "url" property to empty

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)