diff --git a/src/slic3r/GUI/WebViewPlatformUtilsLinux.cpp b/src/slic3r/GUI/WebViewPlatformUtilsLinux.cpp index 3f90999403..674a916508 100644 --- a/src/slic3r/GUI/WebViewPlatformUtilsLinux.cpp +++ b/src/slic3r/GUI/WebViewPlatformUtilsLinux.cpp @@ -11,6 +11,8 @@ struct Credentials { std::string password; }; +std::unordered_map g_webview_authorize_handlers; + gboolean webkit_authorize_handler(WebKitWebView *web_view, WebKitAuthenticationRequest *request, gpointer user_data) { const Credentials& creds = *static_cast(user_data); @@ -29,7 +31,8 @@ void setup_webview_with_credentials(wxWebView* web_view, const std::string& user WebKitWebView* native_backend = static_cast(web_view->GetNativeBackend()); Credentials* user_data = new Credentials{username, password}; - g_signal_connect_data( + remove_webview_credentials(web_view); + auto handler = g_signal_connect_data( native_backend, "authenticate", G_CALLBACK(webkit_authorize_handler), @@ -37,12 +40,17 @@ void setup_webview_with_credentials(wxWebView* web_view, const std::string& user &free_credentials, static_cast(0) ); + g_webview_authorize_handlers[native_backend] = handler; } void remove_webview_credentials(wxWebView* web_view) { WebKitWebView* native_backend = static_cast(web_view->GetNativeBackend()); - g_object_disconnect(native_backend, "authenticate"); + if (auto it = g_webview_authorize_handlers.find(native_backend); + it != g_webview_authorize_handlers.end()) { + g_signal_handler_disconnect(native_backend, it->second); + g_webview_authorize_handlers.erase(it); + } } } diff --git a/src/slic3r/GUI/WebViewPlatformUtilsMac.mm b/src/slic3r/GUI/WebViewPlatformUtilsMac.mm index fa2a76280c..123c1e21d7 100644 --- a/src/slic3r/GUI/WebViewPlatformUtilsMac.mm +++ b/src/slic3r/GUI/WebViewPlatformUtilsMac.mm @@ -118,6 +118,7 @@ namespace Slic3r::GUI { void setup_webview_with_credentials(wxWebView* web_view, const std::string& username, const std::string& password) { + remove_webview_credentials(web_view); WKWebView* backend = static_cast(web_view->GetNativeBackend()); if (![backend.navigationDelegate isKindOfClass:MyNavigationDelegate.class]) { backend.navigationDelegate = [[MyNavigationDelegate alloc] diff --git a/src/slic3r/GUI/WebViewPlatformUtilsWin32.cpp b/src/slic3r/GUI/WebViewPlatformUtilsWin32.cpp index 31fad65b3b..91ea861272 100644 --- a/src/slic3r/GUI/WebViewPlatformUtilsWin32.cpp +++ b/src/slic3r/GUI/WebViewPlatformUtilsWin32.cpp @@ -26,9 +26,10 @@ void setup_webview_with_credentials(wxWebView* webview, const std::string& usern return; } + remove_webview_credentials(webview); + // should it be stored? EventRegistrationToken basicAuthenticationRequestedToken = {}; - if (FAILED(wv2_10->add_BasicAuthenticationRequested( Microsoft::WRL::Callback( [username, password](ICoreWebView2 *sender, ICoreWebView2BasicAuthenticationRequestedEventArgs *args) { @@ -64,10 +65,13 @@ void remove_webview_credentials(wxWebView* webview) return; } - auto it = g_basic_auth_handler_tokens.find(webView2); - if (it != g_basic_auth_handler_tokens.end()) { + if (auto it = g_basic_auth_handler_tokens.find(webView2); + it != g_basic_auth_handler_tokens.end()) { + if (FAILED(wv2_10->remove_BasicAuthenticationRequested(it->second))) { BOOST_LOG_TRIVIAL(error) << "WebView: Unregistering authentication request handler failed"; + } else { + g_basic_auth_handler_tokens.erase(it); } } else { BOOST_LOG_TRIVIAL(error) << "WebView: Cannot unregister authentication request handler";