From 097ee2e85de60796422723aebfb5c380ae07ff1b Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 4 Sep 2024 10:03:26 +0200 Subject: [PATCH] SPE 2450: Delete cookies Mac part + fixes of other parts --- src/slic3r/GUI/WebViewDialog.cpp | 8 +++---- src/slic3r/GUI/WebViewPlatformUtils.hpp | 2 +- src/slic3r/GUI/WebViewPlatformUtilsLinux.cpp | 2 +- src/slic3r/GUI/WebViewPlatformUtilsMac.mm | 23 ++++++++++++++++---- src/slic3r/GUI/WebViewPlatformUtilsWin32.cpp | 3 +-- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index cd09f07196..2905a7653d 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -1459,10 +1459,10 @@ void LoginWebViewDialog::on_navigation_request(wxWebViewEvent &evt) { wxString url = evt.GetURL(); if (url.starts_with(L"prusaslicer")) { - delete_cookies(m_browser, L"https://account.prusa3d.com"); - delete_cookies(m_browser, L"https://accounts.google.com"); - delete_cookies(m_browser, L"https://appleid.apple.com"); - delete_cookies(m_browser, L"https://facebook.com"); + delete_cookies(m_browser, "https://account.prusa3d.com"); + delete_cookies(m_browser, "https://accounts.google.com"); + delete_cookies(m_browser, "https://appleid.apple.com"); + delete_cookies(m_browser, "https://facebook.com"); evt.Veto(); m_ret_val = into_u8(url); EndModal(wxID_OK); diff --git a/src/slic3r/GUI/WebViewPlatformUtils.hpp b/src/slic3r/GUI/WebViewPlatformUtils.hpp index 55fc47b1d9..2c1429d21a 100644 --- a/src/slic3r/GUI/WebViewPlatformUtils.hpp +++ b/src/slic3r/GUI/WebViewPlatformUtils.hpp @@ -6,6 +6,6 @@ namespace Slic3r::GUI { void setup_webview_with_credentials(wxWebView* web_view, const std::string& username, const std::string& password); void remove_webview_credentials(wxWebView* web_view); - void delete_cookies(wxWebView* web_view, const wxString& url); + void delete_cookies(wxWebView* web_view, const std::string& url); } diff --git a/src/slic3r/GUI/WebViewPlatformUtilsLinux.cpp b/src/slic3r/GUI/WebViewPlatformUtilsLinux.cpp index 96de4d9d71..b14a561ddf 100644 --- a/src/slic3r/GUI/WebViewPlatformUtilsLinux.cpp +++ b/src/slic3r/GUI/WebViewPlatformUtilsLinux.cpp @@ -96,7 +96,7 @@ void get_cookie_callback (GObject* source_object, GAsyncResult* result, void* us g_list_free(cookies); } } -void delete_cookies(wxWebView* web_view, const wxString& url) +void delete_cookies(wxWebView* web_view, const std::string& url) { // Call webkit_cookie_manager_get_cookies // set its callback to call webkit_cookie_manager_get_cookies_finish diff --git a/src/slic3r/GUI/WebViewPlatformUtilsMac.mm b/src/slic3r/GUI/WebViewPlatformUtilsMac.mm index 5522c78c6a..b09c69f31f 100644 --- a/src/slic3r/GUI/WebViewPlatformUtilsMac.mm +++ b/src/slic3r/GUI/WebViewPlatformUtilsMac.mm @@ -2,6 +2,8 @@ #import #import +#import +#import #import #import @@ -114,7 +116,6 @@ } @end - namespace Slic3r::GUI { void setup_webview_with_credentials(wxWebView* web_view, const std::string& username, const std::string& password) { @@ -137,10 +138,24 @@ void remove_webview_credentials(wxWebView* web_view) } } -void delete_cookies(wxWebView* web_view, const wxString& url) +void delete_cookies(wxWebView* web_view, const std::string& url) { - -} + WKWebView* backend = static_cast(web_view->GetNativeBackend()); + NSString *url_string = [NSString stringWithCString:url.c_str() encoding:[NSString defaultCStringEncoding]]; + WKWebsiteDataStore *data_store = backend.configuration.websiteDataStore; + NSSet *website_data_types = [NSSet setWithObject:WKWebsiteDataTypeCookies]; + [data_store fetchDataRecordsOfTypes:website_data_types completionHandler:^(NSArray *records) { + for (WKWebsiteDataRecord *record in records) { + if ([url_string containsString:record.displayName]) { + [data_store removeDataOfTypes:website_data_types + forDataRecords:@[record] + completionHandler:^{ + //NSLog(@"Deleted cookies for domain: %@", record.displayName); + }]; + } + } + }]; } +} diff --git a/src/slic3r/GUI/WebViewPlatformUtilsWin32.cpp b/src/slic3r/GUI/WebViewPlatformUtilsWin32.cpp index 40bf882d8d..feb18b52e4 100644 --- a/src/slic3r/GUI/WebViewPlatformUtilsWin32.cpp +++ b/src/slic3r/GUI/WebViewPlatformUtilsWin32.cpp @@ -89,7 +89,7 @@ void remove_webview_credentials(wxWebView* webview) } } -void delete_cookies(wxWebView* webview, const wxString& url) +void delete_cookies(wxWebView* webview, const std::string& url) { ICoreWebView2 *webView2 = static_cast(webview->GetNativeBackend()); if (!webView2) { @@ -130,7 +130,6 @@ void delete_cookies(wxWebView* webview, const wxString& url) BOOST_LOG_TRIVIAL(error) << "Failed to parse cookies json: " << e.what(); return S_OK; } - BOOST_LOG_TRIVIAL(error) << url << " " << ptree.get_child("cookies").size(); for (const auto& cookie : ptree.get_child("cookies")) { std::string name = cookie.second.get("name"); std::string domain = cookie.second.get("domain");