SPE 2450: Delete cookies Mac part

+ fixes of other parts
This commit is contained in:
David Kocik 2024-09-04 10:03:26 +02:00 committed by Lukas Matena
parent 1e55aaef62
commit 097ee2e85d
5 changed files with 26 additions and 12 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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

View File

@ -2,6 +2,8 @@
#import <WebKit/WKWebView.h>
#import <WebKit/WKNavigationDelegate.h>
#import <WebKit/WKWebViewConfiguration.h>
#import <WebKit/WKWebsiteDataStore.h>
#import <Foundation/Foundation.h>
#import <Foundation/NSURLSession.h>
@ -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<WKWebView*>(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<WKWebsiteDataRecord *> *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);
}];
}
}
}];
}
}

View File

@ -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<ICoreWebView2 *>(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<std::string>("name");
std::string domain = cookie.second.get<std::string>("domain");