531ec000d7e7ca56f3e153efed811fb7d5a549fd
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / web-view / web-context.h
1 #ifndef DALI_TOOLKIT_WEB_CONTEXT_H
2 #define DALI_TOOLKIT_WEB_CONTEXT_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/web-engine-context.h>
23 #include <string>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/dali-toolkit-common.h>
27
28 namespace Dali
29 {
30 class WebEngineSecurityOrigin;
31
32 namespace Toolkit
33 {
34 /**
35  * @addtogroup dali_toolkit_controls_web_view
36  * @{
37  */
38
39 /**
40  * @brief WebContext is a control for context of WebView.
41  *
42  * For working WebContext, a WebEngineContext should be provided.
43  *
44  */
45 class DALI_TOOLKIT_API WebContext
46 {
47 public:
48   /**
49    * @brief Create a WebContext.
50    *
51    * @param[in] context The context of web engine.
52    */
53   WebContext(Dali::WebEngineContext& context);
54
55   /**
56    * @brief Destructor.
57    */
58   virtual ~WebContext() final;
59
60   /**
61    * @brief Return the cache model type.
62    *
63    * @return #Dali::WebEngineContext::CacheModel
64    */
65   Dali::WebEngineContext::CacheModel GetCacheModel() const;
66
67   /**
68    * @brief Request to set the cache model.
69    *
70    * @param[in] cacheModel The cache model
71    */
72   void SetCacheModel(Dali::WebEngineContext::CacheModel cacheModel);
73
74   /**
75    * @brief Set the given proxy URI to network backend of specific context.
76    *
77    * @param[in] uri The proxy URI to set
78    */
79   void SetProxyUri(const std::string& uri);
80
81   /**
82    * @brief Add CA certificates to persistent NSS certificate database
83    *
84    * Function accepts a path to a CA certificate file, a path to a directory
85    * containing CA certificate files, or a colon-seprarated list of those.
86    * Certificate files should have *.crt extension.
87    * Directories are traversed recursively.
88    *
89    * @param[in] certificatePath path to a CA certificate file(s), see above for details
90    */
91   void SetCertificateFilePath(const std::string& certificatePath);
92
93   /**
94    * @brief Set a proxy auth credential to network backend of specific context.
95    *
96    * @param[in] username username to set
97    * @param[in] password password to set
98    */
99   void SetDefaultProxyAuth(const std::string& username, const std::string& password);
100
101   /**
102    * @brief Requests for deleting all web databases.
103    */
104   void DeleteAllWebDatabase();
105
106   /**
107    * @brief Request for getting web database origins.
108    *
109    * @param[in] callback callback called after getting web database origins
110    *
111    * @return true if succeeded, false otherwise
112    */
113   bool GetWebDatabaseOrigins(Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback callback);
114
115   /**
116    * @brief Request for deleting web databases for origin.
117    *
118    * @param[in] origin database origin
119    *
120    * @return true if succeeded, false otherwise
121    */
122   bool DeleteWebDatabase(Dali::WebEngineSecurityOrigin& origin);
123
124   /**
125    * @brief Gets list of origins that is stored in web storage db.
126    *
127    * @param[in] callback callback called after getting web storage origins
128    *
129    * @return true if succeeded, false otherwise
130    */
131   bool GetWebStorageOrigins(Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback callback);
132
133   /**
134    * @brief Get list of origins that is stored in web storage db.
135    *
136    * @param[in] origin storage origin
137    * @param[in] callback callback called after getting web storage origins
138    *
139    * @return true if succeeded, false otherwise
140    */
141   bool GetWebStorageUsageForOrigin(Dali::WebEngineSecurityOrigin& origin, Dali::WebEngineContext::WebEngineStorageUsageAcquiredCallback callback);
142
143   /**
144    * @brief Delete all web storage.
145    *
146    * @details This function does not ensure that all data will be removed.
147    *          Should be used to extend free physical memory.
148    */
149   void DeleteAllWebStorage();
150
151   /**
152    * @brief Delete web storage db.
153    *
154    * @param[in] origin origin of db
155    *
156    * @return true if succeeded, false otherwise
157    */
158   bool DeleteWebStorage(Dali::WebEngineSecurityOrigin& origin);
159
160   /**
161    * @brief Request for deleting all local file systems.
162    */
163   void DeleteLocalFileSystem();
164
165   /**
166    * @brief Requests to clear cache
167    */
168   void ClearCache();
169
170   /**
171    * @brief Request for deleting web application cache for origin.
172    *
173    * @param[in] origin application cache origin
174    *
175    * @return true if succeeded, false otherwise
176    */
177   bool DeleteApplicationCache(Dali::WebEngineSecurityOrigin& origin);
178
179   /**
180    * @brief Asynchronous request to get list of all password data.
181    *
182    * @param[in] callback callback called after getting form password
183    */
184   void GetFormPasswordList(Dali::WebEngineContext::WebEngineFormPasswordAcquiredCallback callback);
185
186   /**
187    * @brief Register callback for download started.
188    *
189    * @param[in] callback callback for download started
190    */
191   void RegisterDownloadStartedCallback(Dali::WebEngineContext::WebEngineDownloadStartedCallback callback);
192
193   /**
194    * @brief Register callback for mime overridden.
195    *
196    * @param[in] callback callback for mime overridden
197    */
198   void RegisterMimeOverriddenCallback(Dali::WebEngineContext::WebEngineMimeOverriddenCallback callback);
199
200   /**
201    * @brief Toggle the cache to be enabled or disabled
202    *
203    * @param[in] cacheEnabled enable or disable cache
204    */
205   void EnableCache(bool cacheEnabled);
206
207   /**
208    * @brief Query if the cache is enabled
209    *
210    * @return @c true is cache is enabled or @c false otherwise
211    */
212   bool IsCacheEnabled() const;
213
214   /**
215    * @brief Get CA certifcate file path
216    *
217    * It returns an internal string and should not be modified.
218    *
219    * @return @c certificate_file is path which is set during ewk_context_certificate_file_set or @c null string otherwise
220    */
221   std::string GetContextCertificateFile() const;
222
223   /**
224    * @brief Set application id for @a context.
225    *
226    * @param[in] appID application id
227    */
228   void SetContextAppId(const std::string& appID);
229
230   /**
231    * @brief Set application version for @a context.
232    *
233    * @param[in] appVersion application version
234    *
235    * @return @c true if successful, @c false otherwise
236    */
237   bool SetContextAppVersion(const std::string& appVersion);
238
239   /**
240    * @brief To declare application type
241    *
242    * @param[in] applicationType The Application_Type enum
243    *
244    */
245   void SetContextApplicationType(const Dali::WebEngineContext::ApplicationType applicationType);
246
247   /**
248    * @brief Set time offset
249    *
250    * @param[in] timeOffset The value will be added to system time as offset
251    */
252   void SetContextTimeOffset(float timeOffset);
253
254   /**
255    * @brief Set timezone offset
256    *
257    * @param[in] timeZoneOffset offset for time zone.
258    * @param[in] daylightSavingTime The value is for daylight saving time use.
259    */
260   void SetContextTimeZoneOffset(float timeZoneOffset, float daylightSavingTime);
261
262   /**
263    * @brief Register url schemes as CORS enabled
264    *
265    * @param[in] schemes The URL schemes list which will be added to web security policy
266    *
267    */
268   void RegisterUrlSchemesAsCorsEnabled(const std::vector<std::string>& schemes);
269
270   /**
271    * @brief Register JS plugin mime types.
272    *
273    * @param[in] mimeTypes The MIME types will be checked by the renderer frame loader
274    * to skip creating default frame for the object tags with the registered MIME type.
275    */
276   void RegisterJsPluginMimeTypes(const std::vector<std::string>& mimeTypes);
277
278   /**
279    * @brief Set default zoom factor
280    *
281    * @param[in] zoomFactor default zoom factor
282    */
283   void SetDefaultZoomFactor(float zoomFactor);
284
285   /**
286    * @brief Get default zoom factor
287    *
288    * Gets default zoom factor for all pages opened with this context.
289    *
290    * @return @c default zoom factor or negative value on error
291    */
292   float GetContextDefaultZoomFactor() const;
293
294   /**
295    * @brief Request for deleting all web application caches.
296    *
297    * @return @c true on success, otherwise @c false
298    */
299   bool DeleteAllApplicationCache();
300
301   /**
302    * @brief Request for deleting all web indexed databases.
303    *
304    * @return @c true on success, otherwise @c false
305    */
306   bool DeleteAllWebIndexedDatabase();
307
308   /**
309    * @brief Delete a given password data list
310    *
311    * @param[in] list List with Ewk_Password_Data
312    */
313   void DeleteFormPasswordDataList(const std::vector<std::string>& list);
314
315   /**
316    * @brief Delete whole password data from DB
317    */
318   void DeleteAllFormPasswordData();
319
320   /**
321    * @brief Delete all candidate form data from DB
322    */
323   void DeleteAllFormCandidateData();
324
325   /**
326    * @brief Get the proxy URI from the network backend of specific context.
327    *
328    * @return current proxy URI or @c null string if it's not set
329    */
330   std::string GetContextProxy() const;
331
332   /**
333    * @brief Set the given proxy to network backend of specific context.
334    *
335    * @param[in] proxy URI to set
336    * @param[in] bypass rule to set
337    */
338   void SetContextProxy(const std::string& proxy, const std::string& bypass);
339
340   /**
341    * @brief Get the proxy bypass rule from the network backend of specific context.
342    *
343    * @return current proxy bypass rule or @c null string if it's not set
344    */
345   std::string GetProxyBypassRule() const;
346
347   /**
348    * @brief Notify low memory to free unused memory.
349    *
350    * @return @c true on success or @c false otherwise.
351    */
352   bool FreeUnusedMemory();
353
354 private:
355   Dali::WebEngineContext& mWebEngineContext;
356 };
357
358 /**
359  * @}
360  */
361
362 } // namespace Toolkit
363
364 } // namespace Dali
365
366 #endif // DALI_TOOLKIT_WEB_CONTEXT_H