Commit d084e913 authored by carlosgc@webkit.org's avatar carlosgc@webkit.org

[GTK] Don't use the C API internally in WebKitCookieManager

https://bugs.webkit.org/show_bug.cgi?id=96772

Reviewed by Gustavo Noronha Silva.

Using the C++ classes directly instead of the C API wrappers we
avoid a lot of toImpl/toAPI casts, string conversions and
allocations. The code is also a lot simpler and easier to read.

* UIProcess/API/gtk/WebKitCookieManager.cpp:
(_WebKitCookieManagerPrivate):
(webkitCookieManagerFinalize):
(webkitCookieManagerCreate):
(webkit_cookie_manager_set_persistent_storage):
(webkit_cookie_manager_set_accept_policy):
(webkit_cookie_manager_get_accept_policy):
(webkitCookieManagerGetDomainsWithCookiesCallback):
(webkit_cookie_manager_get_domains_with_cookies):
(webkit_cookie_manager_delete_cookies_for_domain):
(webkit_cookie_manager_delete_all_cookies):
* UIProcess/API/gtk/WebKitCookieManagerPrivate.h:
* UIProcess/API/gtk/WebKitWebContext.cpp:
(webkit_web_context_get_cookie_manager):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@131607 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 086b246f
2012-10-17 Carlos Garcia Campos <cgarcia@igalia.com>
[GTK] Don't use the C API internally in WebKitCookieManager
https://bugs.webkit.org/show_bug.cgi?id=96772
Reviewed by Gustavo Noronha Silva.
Using the C++ classes directly instead of the C API wrappers we
avoid a lot of toImpl/toAPI casts, string conversions and
allocations. The code is also a lot simpler and easier to read.
* UIProcess/API/gtk/WebKitCookieManager.cpp:
(_WebKitCookieManagerPrivate):
(webkitCookieManagerFinalize):
(webkitCookieManagerCreate):
(webkit_cookie_manager_set_persistent_storage):
(webkit_cookie_manager_set_accept_policy):
(webkit_cookie_manager_get_accept_policy):
(webkitCookieManagerGetDomainsWithCookiesCallback):
(webkit_cookie_manager_get_domains_with_cookies):
(webkit_cookie_manager_delete_cookies_for_domain):
(webkit_cookie_manager_delete_all_cookies):
* UIProcess/API/gtk/WebKitCookieManagerPrivate.h:
* UIProcess/API/gtk/WebKitWebContext.cpp:
(webkit_web_context_get_cookie_manager):
2012-10-17 Carlos Garcia Campos <cgarcia@igalia.com> 2012-10-17 Carlos Garcia Campos <cgarcia@igalia.com>
[GTK] Don't use the C API internally in WebKitContextMenu [GTK] Don't use the C API internally in WebKitContextMenu
......
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
#include <wtf/gobject/GRefPtr.h> #include <wtf/gobject/GRefPtr.h>
#include <wtf/text/CString.h> #include <wtf/text/CString.h>
using namespace WebKit;
enum { enum {
CHANGED, CHANGED,
...@@ -36,7 +34,7 @@ enum { ...@@ -36,7 +34,7 @@ enum {
}; };
struct _WebKitCookieManagerPrivate { struct _WebKitCookieManagerPrivate {
WKRetainPtr<WKCookieManagerRef> wkCookieManager; RefPtr<WebCookieManagerProxy> webCookieManager;
}; };
static guint signals[LAST_SIGNAL] = { 0, }; static guint signals[LAST_SIGNAL] = { 0, };
...@@ -46,9 +44,9 @@ G_DEFINE_TYPE(WebKitCookieManager, webkit_cookie_manager, G_TYPE_OBJECT) ...@@ -46,9 +44,9 @@ G_DEFINE_TYPE(WebKitCookieManager, webkit_cookie_manager, G_TYPE_OBJECT)
COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT, SoupCookiePersistentStorageText); COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT, SoupCookiePersistentStorageText);
COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE, SoupCookiePersistentStorageSQLite); COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE, SoupCookiePersistentStorageSQLite);
COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS, kWKHTTPCookieAcceptPolicyAlways); COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS, HTTPCookieAcceptPolicyAlways);
COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_NEVER, kWKHTTPCookieAcceptPolicyNever); COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_NEVER, HTTPCookieAcceptPolicyNever);
COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY, kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain); COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY, HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain);
static void webkit_cookie_manager_init(WebKitCookieManager* manager) static void webkit_cookie_manager_init(WebKitCookieManager* manager)
{ {
...@@ -60,7 +58,7 @@ static void webkit_cookie_manager_init(WebKitCookieManager* manager) ...@@ -60,7 +58,7 @@ static void webkit_cookie_manager_init(WebKitCookieManager* manager)
static void webkitCookieManagerFinalize(GObject* object) static void webkitCookieManagerFinalize(GObject* object)
{ {
WebKitCookieManagerPrivate* priv = WEBKIT_COOKIE_MANAGER(object)->priv; WebKitCookieManagerPrivate* priv = WEBKIT_COOKIE_MANAGER(object)->priv;
WKCookieManagerStopObservingCookieChanges(priv->wkCookieManager.get()); priv->webCookieManager->stopObservingCookieChanges();
priv->~WebKitCookieManagerPrivate(); priv->~WebKitCookieManagerPrivate();
G_OBJECT_CLASS(webkit_cookie_manager_parent_class)->finalize(object); G_OBJECT_CLASS(webkit_cookie_manager_parent_class)->finalize(object);
} }
...@@ -92,18 +90,18 @@ static void cookiesDidChange(WKCookieManagerRef, const void* clientInfo) ...@@ -92,18 +90,18 @@ static void cookiesDidChange(WKCookieManagerRef, const void* clientInfo)
g_signal_emit(WEBKIT_COOKIE_MANAGER(clientInfo), signals[CHANGED], 0); g_signal_emit(WEBKIT_COOKIE_MANAGER(clientInfo), signals[CHANGED], 0);
} }
WebKitCookieManager* webkitCookieManagerCreate(WKCookieManagerRef wkCookieManager) WebKitCookieManager* webkitCookieManagerCreate(WebCookieManagerProxy* webCookieManager)
{ {
WebKitCookieManager* manager = WEBKIT_COOKIE_MANAGER(g_object_new(WEBKIT_TYPE_COOKIE_MANAGER, NULL)); WebKitCookieManager* manager = WEBKIT_COOKIE_MANAGER(g_object_new(WEBKIT_TYPE_COOKIE_MANAGER, NULL));
manager->priv->wkCookieManager = wkCookieManager; manager->priv->webCookieManager = webCookieManager;
WKCookieManagerClient wkCookieManagerClient = { WKCookieManagerClient wkCookieManagerClient = {
kWKCookieManagerClientCurrentVersion, kWKCookieManagerClientCurrentVersion,
manager, // clientInfo manager, // clientInfo
cookiesDidChange cookiesDidChange
}; };
WKCookieManagerSetClient(wkCookieManager, &wkCookieManagerClient); WKCookieManagerSetClient(toAPI(webCookieManager), &wkCookieManagerClient);
WKCookieManagerStartObservingCookieChanges(wkCookieManager); manager->priv->webCookieManager->startObservingCookieChanges();
return manager; return manager;
} }
...@@ -127,9 +125,9 @@ void webkit_cookie_manager_set_persistent_storage(WebKitCookieManager* manager, ...@@ -127,9 +125,9 @@ void webkit_cookie_manager_set_persistent_storage(WebKitCookieManager* manager,
g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager)); g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
g_return_if_fail(filename); g_return_if_fail(filename);
WKCookieManagerStopObservingCookieChanges(manager->priv->wkCookieManager.get()); manager->priv->webCookieManager->stopObservingCookieChanges();
toImpl(manager->priv->wkCookieManager.get())->setCookiePersistentStorage(String::fromUTF8(filename), storage); manager->priv->webCookieManager->setCookiePersistentStorage(String::fromUTF8(filename), storage);
WKCookieManagerStartObservingCookieChanges(manager->priv->wkCookieManager.get()); manager->priv->webCookieManager->startObservingCookieChanges();
} }
/** /**
...@@ -143,7 +141,7 @@ void webkit_cookie_manager_set_accept_policy(WebKitCookieManager* manager, WebKi ...@@ -143,7 +141,7 @@ void webkit_cookie_manager_set_accept_policy(WebKitCookieManager* manager, WebKi
{ {
g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager)); g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
WKCookieManagerSetHTTPCookieAcceptPolicy(manager->priv->wkCookieManager.get(), policy); manager->priv->webCookieManager->setHTTPCookieAcceptPolicy(policy);
} }
struct GetAcceptPolicyAsyncData { struct GetAcceptPolicyAsyncData {
...@@ -186,7 +184,7 @@ void webkit_cookie_manager_get_accept_policy(WebKitCookieManager* manager, GCanc ...@@ -186,7 +184,7 @@ void webkit_cookie_manager_get_accept_policy(WebKitCookieManager* manager, GCanc
data->cancellable = cancellable; data->cancellable = cancellable;
g_simple_async_result_set_op_res_gpointer(result, data, reinterpret_cast<GDestroyNotify>(destroyGetAcceptPolicyAsyncData)); g_simple_async_result_set_op_res_gpointer(result, data, reinterpret_cast<GDestroyNotify>(destroyGetAcceptPolicyAsyncData));
WKCookieManagerGetHTTPCookieAcceptPolicy(manager->priv->wkCookieManager.get(), result, webkitCookieManagerGetAcceptPolicyCallback); manager->priv->webCookieManager->getHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicyCallback::create(result, webkitCookieManagerGetAcceptPolicyCallback));
} }
/** /**
...@@ -228,10 +226,11 @@ static void webkitCookieManagerGetDomainsWithCookiesCallback(WKArrayRef wkDomain ...@@ -228,10 +226,11 @@ static void webkitCookieManagerGetDomainsWithCookiesCallback(WKArrayRef wkDomain
if (g_cancellable_set_error_if_cancelled(data->cancellable.get(), &error)) if (g_cancellable_set_error_if_cancelled(data->cancellable.get(), &error))
g_simple_async_result_take_error(result.get(), error); g_simple_async_result_take_error(result.get(), error);
else { else {
ImmutableArray* domains = toImpl(wkDomains);
data->domains = adoptGRef(g_ptr_array_new_with_free_func(g_free)); data->domains = adoptGRef(g_ptr_array_new_with_free_func(g_free));
for (size_t i = 0; i < WKArrayGetSize(wkDomains); ++i) { for (size_t i = 0; i < domains->size(); ++i) {
WKStringRef wkDomain = static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkDomains, i)); WebString* domainString = static_cast<WebString*>(domains->at(i));
String domain = toImpl(wkDomain)->string(); String domain = domainString->string();
if (domain.isEmpty()) if (domain.isEmpty())
continue; continue;
g_ptr_array_add(data->domains.get(), g_strdup(domain.utf8().data())); g_ptr_array_add(data->domains.get(), g_strdup(domain.utf8().data()));
...@@ -262,7 +261,7 @@ void webkit_cookie_manager_get_domains_with_cookies(WebKitCookieManager* manager ...@@ -262,7 +261,7 @@ void webkit_cookie_manager_get_domains_with_cookies(WebKitCookieManager* manager
GetDomainsWithCookiesAsyncData* data = createGetDomainsWithCookiesAsyncData(); GetDomainsWithCookiesAsyncData* data = createGetDomainsWithCookiesAsyncData();
data->cancellable = cancellable; data->cancellable = cancellable;
g_simple_async_result_set_op_res_gpointer(result, data, reinterpret_cast<GDestroyNotify>(destroyGetDomainsWithCookiesAsyncData)); g_simple_async_result_set_op_res_gpointer(result, data, reinterpret_cast<GDestroyNotify>(destroyGetDomainsWithCookiesAsyncData));
WKCookieManagerGetHostnamesWithCookies(manager->priv->wkCookieManager.get(), result, webkitCookieManagerGetDomainsWithCookiesCallback); manager->priv->webCookieManager->getHostnamesWithCookies(ArrayCallback::create(result, webkitCookieManagerGetDomainsWithCookiesCallback));
} }
/** /**
...@@ -305,8 +304,7 @@ void webkit_cookie_manager_delete_cookies_for_domain(WebKitCookieManager* manage ...@@ -305,8 +304,7 @@ void webkit_cookie_manager_delete_cookies_for_domain(WebKitCookieManager* manage
g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager)); g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
g_return_if_fail(domain); g_return_if_fail(domain);
WKRetainPtr<WKStringRef> wkDomain(AdoptWK, WKStringCreateWithUTF8CString(domain)); manager->priv->webCookieManager->deleteCookiesForHostname(String::fromUTF8(domain));
WKCookieManagerDeleteCookiesForHostname(manager->priv->wkCookieManager.get(), wkDomain.get());
} }
/** /**
...@@ -319,5 +317,5 @@ void webkit_cookie_manager_delete_all_cookies(WebKitCookieManager* manager) ...@@ -319,5 +317,5 @@ void webkit_cookie_manager_delete_all_cookies(WebKitCookieManager* manager)
{ {
g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager)); g_return_if_fail(WEBKIT_IS_COOKIE_MANAGER(manager));
WKCookieManagerDeleteAllCookies(manager->priv->wkCookieManager.get()); manager->priv->webCookieManager->deleteAllCookies();
} }
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "WebKitCookieManager.h" #include "WebKitCookieManager.h"
#include "WebKitPrivate.h" #include "WebKitPrivate.h"
WebKitCookieManager* webkitCookieManagerCreate(WKCookieManagerRef); using namespace WebKit;
WebKitCookieManager* webkitCookieManagerCreate(WebCookieManagerProxy*);
#endif // WebKitCookieManagerPrivate_h #endif // WebKitCookieManagerPrivate_h
...@@ -318,7 +318,7 @@ WebKitCookieManager* webkit_web_context_get_cookie_manager(WebKitWebContext* con ...@@ -318,7 +318,7 @@ WebKitCookieManager* webkit_web_context_get_cookie_manager(WebKitWebContext* con
WebKitWebContextPrivate* priv = context->priv; WebKitWebContextPrivate* priv = context->priv;
if (!priv->cookieManager) if (!priv->cookieManager)
priv->cookieManager = adoptGRef(webkitCookieManagerCreate(toAPI(priv->context->cookieManagerProxy()))); priv->cookieManager = adoptGRef(webkitCookieManagerCreate(priv->context->cookieManagerProxy()));
return priv->cookieManager.get(); return priv->cookieManager.get();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment