Skip to content
Permalink
Browse files
[EFL][WK2] Add API to Ewk_Cookie_Manager to watch for cookie changes
https://bugs.webkit.org/show_bug.cgi?id=92484

Patch by Christophe Dumez <christophe.dumez@intel.com> on 2012-07-27
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Make use of soup/CookieStorageSoup.cpp for EFL port instead
of defining empty implementations for cookie storage
functions.

No new tests, no behavior change.

* PlatformEfl.cmake:
* platform/efl/TemporaryLinkStubs.cpp:

Source/WebKit2:

Add API tp Ewk_Cookie_Manager so that the client can watch
for cookie changes.

* UIProcess/API/efl/ewk_cookie_manager.cpp:
* UIProcess/API/efl/ewk_cookie_manager.h:
* UIProcess/API/efl/tests/test_ewk2_cookie_manager.cpp: Add unit tests
for cookie changes watching.

Canonical link: https://commits.webkit.org/110305@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@123870 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez authored and webkit-commit-queue committed Jul 27, 2012
1 parent 50ab508 commit daa2227a60e5a55abeb0fb6865bc5447b2bce709
Showing 7 changed files with 176 additions and 16 deletions.
@@ -1,3 +1,19 @@
2012-07-27 Christophe Dumez <christophe.dumez@intel.com>

[EFL][WK2] Add API to Ewk_Cookie_Manager to watch for cookie changes
https://bugs.webkit.org/show_bug.cgi?id=92484

Reviewed by Kenneth Rohde Christiansen.

Make use of soup/CookieStorageSoup.cpp for EFL port instead
of defining empty implementations for cookie storage
functions.

No new tests, no behavior change.

* PlatformEfl.cmake:
* platform/efl/TemporaryLinkStubs.cpp:

2012-07-27 Keishi Hattori <keishi@webkit.org>

Replace ColorChooserClient::elementRectRelativeToWindow with elementRectRelativeToRootView
@@ -82,6 +82,7 @@ LIST(APPEND WebCore_SOURCES
platform/linux/GamepadDeviceLinux.cpp
platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp
platform/network/soup/CookieJarSoup.cpp
platform/network/soup/CookieStorageSoup.cpp
platform/network/soup/CredentialStorageSoup.cpp
platform/network/soup/DNSSoup.cpp
platform/network/soup/GOwnPtrSoup.cpp
@@ -56,20 +56,5 @@ String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String &ch
return String();
}

void setCookieStoragePrivateBrowsingEnabled(bool)
{
notImplemented();
}

void startObservingCookieChanges()
{
notImplemented();
}

void stopObservingCookieChanges()
{
notImplemented();
}

}

@@ -1,3 +1,18 @@
2012-07-27 Christophe Dumez <christophe.dumez@intel.com>

[EFL][WK2] Add API to Ewk_Cookie_Manager to watch for cookie changes
https://bugs.webkit.org/show_bug.cgi?id=92484

Reviewed by Kenneth Rohde Christiansen.

Add API tp Ewk_Cookie_Manager so that the client can watch
for cookie changes.

* UIProcess/API/efl/ewk_cookie_manager.cpp:
* UIProcess/API/efl/ewk_cookie_manager.h:
* UIProcess/API/efl/tests/test_ewk2_cookie_manager.cpp: Add unit tests
for cookie changes watching.

2012-07-27 Christophe Dumez <christophe.dumez@intel.com>

[EFL][WK2] Stop using C API to interact with the page in Ewk_View
@@ -40,16 +40,47 @@

using namespace WebKit;

struct Cookie_Change_Handler {
Ewk_Cookie_Manager_Changes_Watch_Cb callback;
void* userData;

Cookie_Change_Handler()
: callback(0)
, userData(0)
{ }

Cookie_Change_Handler(Ewk_Cookie_Manager_Changes_Watch_Cb _callback, void* _userData)
: callback(_callback)
, userData(_userData)
{ }
};

static void cookiesDidChange(WKCookieManagerRef, const void* clientInfo);

/**
* \struct _Ewk_Cookie_Manager
* @brief Contains the cookie manager data.
*/
struct _Ewk_Cookie_Manager {
WKRetainPtr<WKCookieManagerRef> wkCookieManager;
Cookie_Change_Handler changeHandler;

_Ewk_Cookie_Manager(WKCookieManagerRef cookieManagerRef)
: wkCookieManager(cookieManagerRef)
{ }
{
WKCookieManagerClient wkCookieManagerClient = {
kWKCookieManagerClientCurrentVersion,
this, // clientInfo
cookiesDidChange
};
WKCookieManagerSetClient(wkCookieManager.get(), &wkCookieManagerClient);
}

~_Ewk_Cookie_Manager()
{
if (changeHandler.callback)
WKCookieManagerStopObservingCookieChanges(wkCookieManager.get());
}
};

#define EWK_COOKIE_MANAGER_WK_GET_OR_RETURN(manager, wkManager_, ...) \
@@ -72,12 +103,26 @@ COMPILE_ASSERT_MATCHING_ENUM(EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY, kWKHTTPCoo
COMPILE_ASSERT_MATCHING_ENUM(EWK_COOKIE_PERSISTENT_STORAGE_TEXT, SoupCookiePersistentStorageText);
COMPILE_ASSERT_MATCHING_ENUM(EWK_COOKIE_PERSISTENT_STORAGE_SQLITE, SoupCookiePersistentStorageSQLite);

static void cookiesDidChange(WKCookieManagerRef, const void* clientInfo)
{
Ewk_Cookie_Manager* manager = static_cast<Ewk_Cookie_Manager*>(const_cast<void*>(clientInfo));

ASSERT(manager->changeHandler.callback);
manager->changeHandler.callback(manager->changeHandler.userData);
}

void ewk_cookie_manager_persistent_storage_set(Ewk_Cookie_Manager* manager, const char* filename, Ewk_Cookie_Persistent_Storage storage)
{
EWK_COOKIE_MANAGER_WK_GET_OR_RETURN(manager, wkManager);
EINA_SAFETY_ON_NULL_RETURN(filename);

if (manager->changeHandler.callback)
WKCookieManagerStopObservingCookieChanges(wkManager);

toImpl(wkManager)->setCookiePersistentStorage(String::fromUTF8(filename), storage);

if (manager->changeHandler.callback)
WKCookieManagerStartObservingCookieChanges(wkManager);
}

void ewk_cookie_manager_accept_policy_set(Ewk_Cookie_Manager* manager, Ewk_Cookie_Accept_Policy policy)
@@ -174,6 +219,18 @@ void ewk_cookie_manager_cookies_clear(Ewk_Cookie_Manager* manager)
WKCookieManagerDeleteAllCookies(wkManager);
}

void ewk_cookie_manager_changes_watch(Ewk_Cookie_Manager* manager, Ewk_Cookie_Manager_Changes_Watch_Cb callback, void* data)
{
EWK_COOKIE_MANAGER_WK_GET_OR_RETURN(manager, wkManager);

manager->changeHandler = Cookie_Change_Handler(callback, data);

if (callback)
WKCookieManagerStartObservingCookieChanges(wkManager);
else
WKCookieManagerStopObservingCookieChanges(wkManager);
}

/**
* @internal
* Frees a Ewk_Cookie_Manager object.
@@ -89,6 +89,12 @@ typedef void (*Ewk_Cookie_Manager_Async_Policy_Get_Cb)(Ewk_Cookie_Accept_Policy
*/
typedef void (*Ewk_Cookie_Manager_Async_Hostnames_Get_Cb)(Eina_List* hostnames, Ewk_Web_Error *error, void *event_info);

/**
* @typedef Ewk_Cookie_Manager_Changes_Watch_Cb Ewk_Cookie_Manager_Changes_Watch_Cb
* @brief Callback type for use with ewk_cookie_manager_changes_watch()
*/
typedef void (*Ewk_Cookie_Manager_Changes_Watch_Cb)(void *event_info);

/**
* Set the @a filename where non-session cookies are stored persistently using @a storage as the format to read/write the cookies.
*
@@ -143,6 +149,17 @@ EAPI void ewk_cookie_manager_async_hostnames_with_cookies_get(const Ewk_Cookie_M
*/
EAPI void ewk_cookie_manager_hostname_cookies_clear(Ewk_Cookie_Manager *manager, const char *hostname);

/**
* Watch for cookies changes in @a manager.
*
* Pass @c NULL as value for @a callback to stop watching for changes.
*
* @param manager The cookie manager to watch.
* @param callback function that will be called every time cookies are added, removed or modified.
* @param data User data (may be @c NULL).
*/
EAPI void ewk_cookie_manager_changes_watch(Ewk_Cookie_Manager *manager, Ewk_Cookie_Manager_Changes_Watch_Cb callback, void *data);

/**
* Delete all cookies of @a manager.
*
@@ -153,6 +153,75 @@ TEST_F(EWK2UnitTestBase, ewk_cookie_manager_accept_policy)
ASSERT_EQ(countHostnamesWithCookies(cookieManager), 0);
}

void onCookiesChanged(void *eventInfo)
{
bool* cookiesChanged = static_cast<bool*>(eventInfo);
*cookiesChanged = true;
}

TEST_F(EWK2UnitTestBase, ewk_cookie_manager_changes_watch)
{
OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer);
httpServer->run(serverCallback);

Ewk_Cookie_Manager* cookieManager = ewk_context_cookie_manager_get(ewk_context_default_get());
ASSERT_TRUE(cookieManager);

ewk_cookie_manager_accept_policy_set(cookieManager, EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
ASSERT_EQ(getAcceptPolicy(cookieManager), EWK_COOKIE_ACCEPT_POLICY_ALWAYS);

// Watch for changes
bool cookiesChanged = false;
ewk_cookie_manager_changes_watch(cookieManager, onCookiesChanged, &cookiesChanged);

// Check for cookie changes notifications
loadUrlSync(httpServer->getURIForPath("/index.html").data());

while (!cookiesChanged)
ecore_main_loop_iterate();
ASSERT_TRUE(cookiesChanged);

cookiesChanged = false;
ewk_cookie_manager_cookies_clear(cookieManager);
while (!cookiesChanged)
ecore_main_loop_iterate();
ASSERT_TRUE(cookiesChanged);

// Stop watching for notifications
ewk_cookie_manager_changes_watch(cookieManager, 0, 0);
cookiesChanged = false;
loadUrlSync(httpServer->getURIForPath("/index.html").data());
ASSERT_EQ(countHostnamesWithCookies(cookieManager), 2);
ASSERT_FALSE(cookiesChanged);

// Watch again for notifications
ewk_cookie_manager_changes_watch(cookieManager, onCookiesChanged, &cookiesChanged);

// Make sure we don't get notifications when loading setting an existing persistent storage
char textStorage1[] = "/tmp/txt-cookie.XXXXXX";
ASSERT_TRUE(mktemp(textStorage1));
char textStorage2[] = "/tmp/txt-cookie.XXXXXX";
ASSERT_TRUE(mktemp(textStorage2));

ewk_cookie_manager_persistent_storage_set(cookieManager, textStorage1, EWK_COOKIE_PERSISTENT_STORAGE_TEXT);
loadUrlSync(httpServer->getURIForPath("/index.html").data());
ASSERT_EQ(countHostnamesWithCookies(cookieManager), 2);

cookiesChanged = false;
ewk_cookie_manager_persistent_storage_set(cookieManager, textStorage2, EWK_COOKIE_PERSISTENT_STORAGE_TEXT);
ASSERT_EQ(countHostnamesWithCookies(cookieManager), 0);

ewk_cookie_manager_persistent_storage_set(cookieManager, textStorage1, EWK_COOKIE_PERSISTENT_STORAGE_TEXT);
ASSERT_EQ(countHostnamesWithCookies(cookieManager), 2);

ASSERT_FALSE(cookiesChanged);

// Final clean up.
ewk_cookie_manager_changes_watch(cookieManager, 0, 0);
unlink(textStorage1);
unlink(textStorage2);
}

TEST_F(EWK2UnitTestBase, ewk_cookie_manager_cookies_delete)
{
OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer);

0 comments on commit daa2227

Please sign in to comment.