532f1bfaa2f9a4f7c3f05bdc85cfd07c29593da9
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / public / ewk_cookie_manager.cc
1 // Copyright 2013 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ewk_cookie_manager.h"
6
7 #include "cookie_manager.h"
8 #include "public/ewk_log.h"
9 #include "private/ewk_cookie_manager_private.h"
10
11 #define EWK_COOKIE_MANAGER_GET_OR_RETURN(manager, cookie_manager, ...)   \
12   if (!(manager)) {                                                      \
13     CRITICAL("ewk cookie manager is NULL.");                            \
14     return __VA_ARGS__;                                                 \
15   }                                                                     \
16   if (!(manager)->cookieManager().get()) {                              \
17     CRITICAL("ewk cookie manager->cookieManager() is NULL.");           \
18     return __VA_ARGS__;                                                 \
19   }                                                                     \
20   scoped_refptr<CookieManager> cookie_manager = (manager)->cookieManager()
21
22
23 void ewk_cookie_manager_persistent_storage_set(Ewk_Cookie_Manager* manager,
24                                                const char* file_name,
25                                                Ewk_Cookie_Persistent_Storage storage)
26 {
27   EWK_COOKIE_MANAGER_GET_OR_RETURN(manager, cookie_manager);
28   EINA_SAFETY_ON_NULL_RETURN(file_name);
29   std::string fileName(file_name);
30   cookie_manager->SetStoragePath(file_name, true /*persist session*/, storage);
31 }
32
33 void ewk_cookie_manager_accept_policy_set(Ewk_Cookie_Manager* manager,
34                                           Ewk_Cookie_Accept_Policy policy)
35 {
36   EWK_COOKIE_MANAGER_GET_OR_RETURN(manager, cookie_manager);
37   cookie_manager->SetCookiePolicy(policy);
38 }
39
40 void ewk_cookie_manager_accept_policy_async_get(const Ewk_Cookie_Manager* manager,
41                                                 Ewk_Cookie_Manager_Policy_Async_Get_Cb callback,
42                                                 void* data)
43 {
44   EWK_COOKIE_MANAGER_GET_OR_RETURN(manager, cookie_manager);
45   EINA_SAFETY_ON_NULL_RETURN(callback);
46
47   cookie_manager->GetAcceptPolicyAsync(callback, data);
48 }
49
50 void ewk_cookie_manager_async_hostnames_with_cookies_get(const Ewk_Cookie_Manager* manager,
51                                                          Ewk_Cookie_Manager_Async_Hostnames_Get_Cb callback,
52                                                          void* data)
53 {
54   EWK_COOKIE_MANAGER_GET_OR_RETURN(manager, cookie_manager);
55   EINA_SAFETY_ON_NULL_RETURN(callback);
56   cookie_manager->GetHostNamesWithCookiesAsync(callback, data);
57 }
58
59 void ewk_cookie_manager_hostname_cookies_clear(Ewk_Cookie_Manager* manager,
60                                                const char* host_name)
61 {
62   EWK_COOKIE_MANAGER_GET_OR_RETURN(manager, cookie_manager);
63   EINA_SAFETY_ON_NULL_RETURN(host_name);
64   std::string url(host_name);
65   cookie_manager->DeleteCookiesAsync(url);
66 }
67
68 void ewk_cookie_manager_cookies_clear(Ewk_Cookie_Manager* manager)
69 {
70   EWK_COOKIE_MANAGER_GET_OR_RETURN(manager, cookie_manager);
71   cookie_manager->DeleteCookiesAsync();
72 }
73