Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for clearing browsing data in wxWebView #24421

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

TcT2k
Copy link
Contributor

@TcT2k TcT2k commented Mar 20, 2024

Add new method wxWebView::ClearBrowsingData() for WKWebView, Edge and WebKitGTK

Clears the browsing data of the web view.
This function clears the browsing data of the web view, such as cookies, cache, history, etc. The exact data that is cleared depends on the types parameter and the backend used.

This operation is asynchronous and may take some time to complete.
When finished a wxEVT_WEBVIEW_BROWSING_DATA_CLEARED event is generated.

@vadz Could you please have a look at my usage of wxDateTime? From what I understand it would be initialized to min(int) but some of the backends treat 0 as a special value that's why I initialized it to 0. Not sure if there would be a better way.

@TcT2k TcT2k force-pushed the webview_browserdata branch 3 times, most recently from a90c9f9 to a5e39ca Compare March 20, 2024 13:48
Copy link
Contributor

@vadz vadz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for adding this and sorry for such a long delay with the review!

But, to answer your question, I think that using wxDateTime(0) is indeed a bit ugly and I believe it would be better to use wxInvalidDateTime and then do something like

date.IsValid() ? date.GetTicks() : 0

in the implementation code. This would be slightly more verbose but IMHO much more clear at the interface level.

WebKitWebsiteDataManager* manager = static_cast<wxWebViewConfigurationImplWebKit*>(m_config.GetImpl())->GetWebsiteDataManager();

if (types & wxWEBVIEW_BROWSING_DATA_OTHER)
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not map it to all the elements of WebKitWebsiteDataTypes not otherwise used below?

if (types & wxWEBVIEW_BROWSING_DATA_COOKIES)
[dataTypes addObject:WKWebsiteDataTypeCookies];
if (types & wxWEBVIEW_BROWSING_DATA_CACHE)
[dataTypes addObjectsFromArray:@[WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also WKWebsiteDataTypeFetchCache, is it excluded on purpose?

NSSet<NSString*>* clearDataTypes = nil;
if (types & wxWEBVIEW_BROWSING_DATA_OTHER)
{
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, it looks like we could map this to WKWebsiteDataTypeServiceWorkerRegistrations?

wxWEBVIEW_BROWSING_DATA_CACHE = 2,
wxWEBVIEW_BROWSING_DATA_DOM_STORAGE = 4,
wxWEBVIEW_BROWSING_DATA_OTHER = 8,
wxWEBVIEW_BROWSING_DATA_ALL = 16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should actually be 15, i.e. the sum of everything below, as otherwise it's not really clear what is the difference between specifying all of the previous constants together or this one -- by making it equal to their sum, this would clearly show that this is equivalent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants