Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.WebView / Tizen.WebView / CookieManager.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 using System;
17
18 namespace Tizen.WebView
19 {
20     /// <summary>
21     /// Enumeration that contains accept policies for the cookies.
22     /// </summary>
23     public enum CookieAcceptPolicy
24     {
25         Always,         /* Accepts every cookie sent from any page */
26         Never,          /* Rejects all cookies */
27         NoThirdParty    /* Accepts only cookies set by the main document loaded */
28     }
29
30     /// <summary>
31     /// Enumeration that creates a type name for the storage of persistent cookies.
32     /// </summary>
33     public enum CookiePersistentStorage
34     {
35         Text,       /* Cookies are stored in a text file in the Mozilla "cookies.txt" format */
36         SqlLite     /* Cookies are stored in a SQLite file in the current Mozilla format. */
37     }
38
39     public class CookieManager
40     {
41         private IntPtr _handle;
42
43         internal CookieManager(IntPtr handle)
44         {
45             _handle = handle;
46         }
47
48         /// <summary>
49         /// Sets the cookie acceptance policy.
50         /// </summary>
51         /// <remarks>
52         /// By default, only cookies set by the main document loaded are accepted.
53         /// </remarks>
54         /// <param name="policy">The cookie acceptance policy</param>
55         public void SetCookieAcceptPolicy(CookieAcceptPolicy policy)
56         {
57             Interop.ChromiumEwk.ewk_cookie_manager_accept_policy_set(_handle, (Interop.ChromiumEwk.CookieAcceptPolicy)policy);
58         }
59
60         /// <summary>
61         /// Deletes all the cookies.
62         /// </summary>
63         public void ClearCookies()
64         {
65             Interop.ChromiumEwk.ewk_cookie_manager_cookies_clear(_handle);
66         }
67
68         /// <summary>
69         /// Sets the storage where non-session cookies are stored persistently to read/write the cookies.
70         /// </summary>
71         ///<privilege>
72         /// http://tizen.org/privilege/mediastorage
73         /// http://tizen.org/privilege/externalstorage
74         /// </privilege>
75         /// <param name="path">The path where to read/write Cookies</param>
76         /// <param name="storage">The type of storage</param>
77         public void SetPersistentStorage(string path, CookiePersistentStorage storage)
78         {
79             Interop.ChromiumEwk.ewk_cookie_manager_persistent_storage_set(_handle, path, (Interop.ChromiumEwk.CookiePersistentStorage)storage);
80         }
81     }
82 }