1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added a clearCookies method to WebBrowserComponent to clear any stored cookies

This commit is contained in:
hogliux 2017-04-18 18:03:53 +01:00
parent 837ac2143c
commit 6292ccf5c3
5 changed files with 61 additions and 0 deletions

View file

@ -79,6 +79,9 @@ public:
/** Refreshes the browser. */
void refresh();
/** Clear cookies that the OS has stored for the WebComponents of this application */
static void clearCookies();
//==============================================================================
/** This callback is called when the browser is about to navigate
to a new location.

View file

@ -115,3 +115,7 @@ void WebBrowserComponent::visibilityChanged()
void WebBrowserComponent::focusGained (FocusChangeType)
{
}
void WebBrowserComponent::clearCookies()
{
}

View file

@ -729,3 +729,10 @@ void WebBrowserComponent::visibilityChanged()
void WebBrowserComponent::focusGained (FocusChangeType)
{
}
void WebBrowserComponent::clearCookies()
{
// Currently not implemented on linux as WebBrowserComponent currently does not
// store cookies on linux
jassertfalse;
}

View file

@ -421,3 +421,18 @@ void WebBrowserComponent::visibilityChanged()
void WebBrowserComponent::focusGained (FocusChangeType)
{
}
void WebBrowserComponent::clearCookies()
{
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
if (NSArray<NSHTTPCookie *>* cookies = [storage cookies])
{
const NSUInteger n = [cookies count];
for (NSUInteger i = 0; i < n; ++i)
[storage deleteCookie:[cookies objectAtIndex:i]];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}

View file

@ -364,3 +364,35 @@ void WebBrowserComponent::focusGained (FocusChangeType)
oleObject->Release();
}
}
void WebBrowserComponent::clearCookies()
{
HeapBlock<::INTERNET_CACHE_ENTRY_INFO> entry;
::DWORD entrySize = sizeof (::INTERNET_CACHE_ENTRY_INFO);
::HANDLE urlCacheHandle = ::FindFirstUrlCacheEntry (TEXT ("cookie:"), entry.getData(), &entrySize);
if (urlCacheHandle == nullptr && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
entry.realloc (1, entrySize);
urlCacheHandle = ::FindFirstUrlCacheEntry (TEXT ("cookie:"), entry.getData(), &entrySize);
}
if (urlCacheHandle != nullptr)
{
while (true)
{
::DeleteUrlCacheEntry (entry.getData()->lpszSourceUrlName);
if (::FindNextUrlCacheEntry (urlCacheHandle, entry.getData(), &entrySize) == 0
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
entry.realloc (1, entrySize);
if (::FindNextUrlCacheEntry (urlCacheHandle, entry.getData(), &entrySize) == 0)
break;
}
}
FindCloseUrlCache (urlCacheHandle);
}
}