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:
parent
837ac2143c
commit
6292ccf5c3
5 changed files with 61 additions and 0 deletions
|
|
@ -79,6 +79,9 @@ public:
|
||||||
/** Refreshes the browser. */
|
/** Refreshes the browser. */
|
||||||
void refresh();
|
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
|
/** This callback is called when the browser is about to navigate
|
||||||
to a new location.
|
to a new location.
|
||||||
|
|
|
||||||
|
|
@ -115,3 +115,7 @@ void WebBrowserComponent::visibilityChanged()
|
||||||
void WebBrowserComponent::focusGained (FocusChangeType)
|
void WebBrowserComponent::focusGained (FocusChangeType)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebBrowserComponent::clearCookies()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -729,3 +729,10 @@ void WebBrowserComponent::visibilityChanged()
|
||||||
void WebBrowserComponent::focusGained (FocusChangeType)
|
void WebBrowserComponent::focusGained (FocusChangeType)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebBrowserComponent::clearCookies()
|
||||||
|
{
|
||||||
|
// Currently not implemented on linux as WebBrowserComponent currently does not
|
||||||
|
// store cookies on linux
|
||||||
|
jassertfalse;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -421,3 +421,18 @@ void WebBrowserComponent::visibilityChanged()
|
||||||
void WebBrowserComponent::focusGained (FocusChangeType)
|
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];
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -364,3 +364,35 @@ void WebBrowserComponent::focusGained (FocusChangeType)
|
||||||
oleObject->Release();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue