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

Commit d63e4fa

Browse files
Merge pull request #6445 from montegoulding/bugfix-21107
[[ Bug 21107 ]] Further support for blank target links
2 parents 5da6156 + 7bac1e0 commit d63e4fa

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [21107] Fix some `target=_blank` links not navigating

libbrowser/src/libbrowser_cef.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ bool MCCefInitialise(void)
490490
CefSettings t_settings;
491491
t_settings.multi_threaded_message_loop = MC_CEF_USE_MULTITHREADED_MESSAGELOOP;
492492
t_settings.command_line_args_disabled = true;
493+
t_settings.windowless_rendering_enabled = true;
493494
t_settings.no_sandbox = true;
494495
t_settings.log_severity = LOGSEVERITY_DISABLE;
495496

@@ -725,7 +726,8 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
725726
{
726727
private:
727728
int m_browser_id;
728-
729+
int m_popup_browser_id = 0;
730+
729731
MCCefBrowserBase *m_owner;
730732

731733
MCCefMessageResult m_message_result;
@@ -917,7 +919,11 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
917919
if (m_owner != nil)
918920
m_owner->OnCefBrowserCreated(p_browser);
919921
}
920-
922+
else
923+
{
924+
m_popup_browser_id = p_browser->GetIdentifier();
925+
}
926+
921927
MCCefIncrementInstanceCount();
922928
}
923929

@@ -947,16 +953,11 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
947953
if (nil == m_owner)
948954
return true;
949955

950-
if (!m_owner->GetAllowNewWindow())
951-
{
952-
char *t_url_str = nullptr;
953-
if (MCCefStringToUtf8String(p_target_url, t_url_str))
954-
{
955-
m_owner->GoToURL(t_url_str);
956-
}
957-
}
958-
959-
return !m_owner->GetAllowNewWindow();
956+
CefWindowInfo(t_window_info);
957+
t_window_info.SetAsWindowless(p_browser->GetHost()->GetWindowHandle());
958+
p_window_info = t_window_info;
959+
return false;
960+
960961
}
961962

962963
// CefDragHandler interface
@@ -976,7 +977,18 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
976977
// IM-2014-07-21: [[ Bug 12296 ]] If browser has been closed then exit
977978
if (nil == m_owner)
978979
return true;
979-
980+
981+
if (p_browser->GetIdentifier() == m_popup_browser_id)
982+
{
983+
char * t_url = nullptr;
984+
if (MCCefStringToUtf8String(p_request->GetURL(), t_url))
985+
{
986+
m_owner->GoToURL(t_url);
987+
}
988+
p_browser->GetHost()->CloseBrowser(true);
989+
return false;
990+
}
991+
980992
bool t_cancel;
981993
t_cancel = false;
982994

libbrowser/src/libbrowser_osx_webview.mm

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,10 @@ - (void)webView:(WebView *)webView decidePolicyForMIMEType:(NSString *)type requ
11581158
else
11591159
{
11601160
[listener ignore];
1161-
m_instance->OnNavigationRequestUnhandled(![webView.mainFrame isEqual: frame], [request.URL.absoluteString cStringUsingEncoding: NSUTF8StringEncoding]);
1161+
if (request.URL.absoluteString != nil)
1162+
{
1163+
m_instance->OnNavigationRequestUnhandled(![webView.mainFrame isEqual: frame], [request.URL.absoluteString cStringUsingEncoding: NSUTF8StringEncoding]);
1164+
}
11621165
}
11631166
}
11641167

@@ -1169,14 +1172,25 @@ - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary
11691172
else
11701173
{
11711174
[listener ignore];
1172-
m_instance->OnNavigationRequestUnhandled(![webView.mainFrame isEqual: frame], [request.URL.absoluteString cStringUsingEncoding: NSUTF8StringEncoding]);
1175+
if (request.URL.absoluteString != nil)
1176+
{
1177+
m_instance->OnNavigationRequestUnhandled(![webView.mainFrame isEqual: frame], [request.URL.absoluteString cStringUsingEncoding: NSUTF8StringEncoding]);
1178+
}
11731179
}
11741180
}
11751181

11761182
@end
11771183

11781184
@implementation MCWebUIDelegate
11791185

1186+
- (WebView *)webView:(WebView *)webView
1187+
createWebViewWithRequest:(NSURLRequest *)request
1188+
{
1189+
[[webView frameLoadDelegate] setPendingRequest: false];
1190+
[[webView mainFrame] loadRequest:request];
1191+
return webView;
1192+
}
1193+
11801194
- (NSUInteger)webView:(WebView *)webView dragDestinationActionMaskForDraggingInfo:(id<NSDraggingInfo>)draggingInfo
11811195
{
11821196
return WebDragDestinationActionNone;

0 commit comments

Comments
 (0)