Release 4.0.0-preview1-00194
[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         /// <summary>
27         /// Use the smallest cache capacity.
28         /// </summary>
29         DocumentViewer,
30         /// <summary>
31         /// Use bigger cache capacity than DocumentBrowser.
32         /// </summary>
33         DocumentBrowser,
34         /// <summary>
35         /// Use the biggest cache capacity.
36         /// </summary>
37         PrimaryWebBrowser
38     }
39
40     /// <summary>
41     /// This class encapsulates all pages related to the specific use of Chromium-efl.
42     /// </summary>
43     /// <remarks>
44     /// Applications have the option of creating a context different from the default one and using it for a group of pages.
45     /// All pages in the same context share the same preferences, visited link set, local storage, and so on.
46     /// </remarks>
47     public class Context
48     {
49         private IntPtr _handle;
50         private CookieManager _cookieManager;
51
52         internal Context(IntPtr handle)
53         {
54             _handle = handle;
55         }
56
57         /// <summary>
58         /// The cache model.
59         /// </summary>
60         /// <remarks>
61         /// The default cache model is DocumentViewer.
62         /// </remarks>
63         public CacheModel CacheModel
64         {
65             get
66             {
67                 return (CacheModel)Interop.ChromiumEwk.ewk_context_cache_model_get(_handle);
68             }
69
70             set
71             {
72                 Interop.ChromiumEwk.ewk_context_cache_model_set(_handle, (Interop.ChromiumEwk.CacheModel)value);
73             }
74         }
75
76         /// <summary>
77         /// Gets the CookieManager object for this context.
78         /// </summary>
79         /// <returns>The CookieManager object</returns>
80         public CookieManager GetCookieManager()
81         {
82             if (_cookieManager == null)
83             {
84                 IntPtr cookieManagerHandle = Interop.ChromiumEwk.ewk_context_cookie_manager_get(_handle);
85                 if (cookieManagerHandle == IntPtr.Zero)
86                 {
87                     return null;
88                 }
89                 _cookieManager = new CookieManager(cookieManagerHandle);
90             }
91             return _cookieManager;
92         }
93     }
94 }