Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.WebView / Tizen.WebView / Context.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
17 using System;
18
19 namespace Tizen.WebView
20 {
21     /// <summary>
22     /// Enumeration that contains option for cache model.
23     /// </summary>
24     public enum CacheModel
25     {
26         DocumentViewer,     /* Use the smallest cache capacity */
27         DocumentBrowser,    /* Use bigger cache capacity than DocumentBrowser */
28         PrimaryWebBrowser   /* Use the biggest cache capacity. */
29     }
30
31     public class Context
32     {
33         private IntPtr _handle;
34         private CookieManager _cookieManager;
35
36         internal Context(IntPtr handle)
37         {
38             _handle = handle;
39         }
40
41         /// <summary>
42         /// The cache model.
43         /// </summary>
44         /// <remarks>
45         /// The default cache model is DocumentViewer.
46         /// </remarks>
47         public CacheModel CacheModel
48         {
49             get
50             {
51                 return (CacheModel)Interop.ChromiumEwk.ewk_context_cache_model_get(_handle);
52             }
53
54             set
55             {
56                 Interop.ChromiumEwk.ewk_context_cache_model_set(_handle, (Interop.ChromiumEwk.CacheModel)value);
57             }
58         }
59
60         /// <summary>
61         /// Gets the CookieManager object for this context.
62         /// </summary>
63         /// <returns>The CookieManager object</returns>
64         public CookieManager GetCookieManager()
65         {
66             if (_cookieManager == null)
67             {
68                 IntPtr cookieManagerHandle = Interop.ChromiumEwk.ewk_context_cookie_manager_get(_handle);
69                 if (cookieManagerHandle == IntPtr.Zero)
70                 {
71                     return null;
72                 }
73                 _cookieManager = new CookieManager(cookieManagerHandle);
74             }
75             return _cookieManager;
76         }
77     }
78 }