Browse Source

Added a clearCookies method to WebBrowserComponent to clear any stored cookies

tags/2021-05-28
hogliux 8 years ago
parent
commit
6292ccf5c3
5 changed files with 61 additions and 0 deletions
  1. +3
    -0
      modules/juce_gui_extra/misc/juce_WebBrowserComponent.h
  2. +4
    -0
      modules/juce_gui_extra/native/juce_android_WebBrowserComponent.cpp
  3. +7
    -0
      modules/juce_gui_extra/native/juce_linux_X11_WebBrowserComponent.cpp
  4. +15
    -0
      modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm
  5. +32
    -0
      modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp

+ 3
- 0
modules/juce_gui_extra/misc/juce_WebBrowserComponent.h 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.


+ 4
- 0
modules/juce_gui_extra/native/juce_android_WebBrowserComponent.cpp View File

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

+ 7
- 0
modules/juce_gui_extra/native/juce_linux_X11_WebBrowserComponent.cpp 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;
}

+ 15
- 0
modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm 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];
}

+ 32
- 0
modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp 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);
}
}

Loading…
Cancel
Save