4db0aba2aa2d34f5f1d82071d7230342cbb6341e
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / web-engine-context.h
1 #ifndef DALI_WEB_ENGINE_CONTEXT_H
2 #define DALI_WEB_ENGINE_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 <functional>
23 #include <memory>
24 #include <string>
25 #include <vector>
26
27 // INTERNAL INCLUDES
28 #include <dali/devel-api/adaptor-framework/web-engine-security-origin.h>
29
30 namespace Dali
31 {
32 /**
33  * @brief A class WebEngineContext for context of web engine.
34  */
35 class WebEngineContext
36 {
37 public:
38   /**
39    * @brief Callback for getting web database origins.
40    */
41   using WebEngineSecurityOriginAcquiredCallback = std::function<void(std::vector<std::unique_ptr<Dali::WebEngineSecurityOrigin>>&)>;
42
43   /**
44    * @brief Callback for getting web storage usage.
45    */
46   using WebEngineStorageUsageAcquiredCallback = std::function<void(uint64_t)>;
47
48   // forward declaration.
49   struct PasswordData;
50
51   /**
52    * @brief Callback for getting form password.
53    */
54   using WebEngineFormPasswordAcquiredCallback = std::function<void(std::vector<std::unique_ptr<PasswordData>>&)>;
55
56   /**
57    * @brief Callback for download started with url.
58    */
59   using WebEngineDownloadStartedCallback = std::function<void(const std::string&)>;
60
61   /**
62    * @brief Callback for overriding default mime type.
63    * @param[in] url for which the mime type can be overridden
64    * @param[in] current mime type that will be overridden
65    * @param[out] a new mime type for web engine.
66    * @return true if mime should be overridden by new mime, false otherwise.
67    */
68   using WebEngineMimeOverriddenCallback = std::function<bool(const std::string&, const std::string&, std::string&)>;
69
70   /**
71    * @brief Enumeration for cache model options.
72    */
73   enum class CacheModel
74   {
75     DOCUMENT_VIEWER,     ///< Use the smallest cache capacity.
76     DOCUMENT_BROWSER,    ///< Use the bigger cache capacity than DocumentBrowser.
77     PRIMARY_WEB_BROWSER, ///< Use the biggest cache capacity.
78   };
79
80   /**
81    * @brief Enumeration for application type.
82    */
83   enum class ApplicationType
84   {
85     WEB_BROWSER = 0,
86     HBB_TV      = 1,
87     WEB_RUNTIME = 2,
88     OTHER       = 3
89   };
90
91   /**
92    * @brief Struct for password data
93    */
94   struct PasswordData
95   {
96     std::string url;
97     bool        useFingerprint;
98   };
99
100   /**
101    * @brief Constructor.
102    */
103   WebEngineContext() = default;
104
105   /**
106    * @brief Destructor.
107    */
108   virtual ~WebEngineContext() = default;
109
110   /**
111    * @brief Return the cache model type.
112    * @return #CacheModel
113    */
114   virtual CacheModel GetCacheModel() const = 0;
115
116   /**
117    * @brief Request to set the cache model.
118    * @param[in] cacheModel The cache model
119    */
120   virtual void SetCacheModel(CacheModel cacheModel) = 0;
121
122   /**
123    * @brief Set the given proxy URI to network backend of specific context.
124    * @param[in] uri The proxy URI to set
125    */
126   virtual void SetProxyUri(const std::string& uri) = 0;
127
128   /**
129    * @brief Get the proxy URI from the network backend of specific context.
130    *
131    * @return current proxy URI or null if it's not set
132    */
133   virtual std::string GetProxyUri() const = 0;
134
135   /**
136    * @brief Set a proxy auth credential to network backend of specific context.
137    * @details Normally, proxy auth credential should be got from the callback
138    *          set by ewk_view_authentication_callback_set, once the username in
139    *          this API has been set with a non-null value, the authentication
140    *          callback will never been invoked. Try to avoid using this API.
141    * @param[in] username username to set
142    * @param[in] password password to set
143    */
144   virtual void SetDefaultProxyAuth(const std::string& username, const std::string& password) = 0;
145
146   /**
147    * @brief Set the given proxy to network backend of specific context.
148    *
149    * @param[in] proxy URI to set
150    * @param[in] bypass rule to set
151    */
152   virtual void SetProxyBypassRule(const std::string& proxy, const std::string& bypass) = 0;
153
154   /**
155    * @brief Get the proxy bypass rule from the network backend of specific context.
156    *
157    * @return current proxy bypass rule or null string if it's not set
158    */
159   virtual std::string GetProxyBypassRule() const = 0;
160
161   /**
162    * @brief Add CA certificates to persistent NSS certificate database
163    * Function accepts a path to a CA certificate file, a path to a directory
164    * containing CA certificate files, or a colon-seprarated list of those.
165    * Certificate files should have *.crt extension.
166    * Directories are traversed recursively.
167    * @param[in] certificatePath path to a CA certificate file(s), see above for details
168    */
169   virtual void SetCertificateFilePath(const std::string& certificatePath) = 0;
170
171   /**
172    * @brief Get CA certifcate file path
173    *
174    * It returns an internal string and should not be modified.
175    *
176    * @return certificate_file path which is set during ewk_context_certificate_file_set or null string otherwise
177    */
178   virtual std::string GetCertificateFilePath() const = 0;
179
180   /**
181    * @brief Request for deleting all web databases.
182    */
183   virtual void DeleteAllWebDatabase() = 0;
184
185   /**
186    * @brief Request for getting web database origins.
187    *
188    * @param[in] callback callback called after getting web database origins
189    *
190    * @return true if succeeded, false otherwise
191    */
192   virtual bool GetWebDatabaseOrigins(WebEngineSecurityOriginAcquiredCallback callback) = 0;
193
194   /**
195    * @brief Request for deleting web databases for origin.
196    *
197    * @param[in] origin application cache origin
198    *
199    * @return true if succeeded, false otherwise
200    */
201   virtual bool DeleteWebDatabase(WebEngineSecurityOrigin& origin) = 0;
202
203   /**
204    * @brief Get list of origins that is stored in web storage db.
205    *
206    * @param[in] callback callback called after getting web storage origins
207    *
208    * @return true if succeeded, false otherwise
209    */
210   virtual bool GetWebStorageOrigins(WebEngineSecurityOriginAcquiredCallback callback) = 0;
211
212   /**
213    * @brief Get list of origins that is stored in web storage db.
214    *
215    * @param[in] origin storage origin
216    * @param[in] callback callback called after getting web storage origins
217    *
218    * @return true if succeeded, false otherwise
219    */
220   virtual bool GetWebStorageUsageForOrigin(WebEngineSecurityOrigin& origin, WebEngineStorageUsageAcquiredCallback callback) = 0;
221
222   /**
223    * @brief Delete all web storage.
224    * @details This function does not ensure that all data will be removed.
225    *          Should be used to extend free physical memory.
226    */
227   virtual void DeleteAllWebStorage() = 0;
228
229   /**
230    * @brief Delete web storage database.
231    *
232    * @param[in] origin origin of database
233    *
234    * @return true if succeeded, false otherwise
235    */
236   virtual bool DeleteWebStorage(WebEngineSecurityOrigin& origin) = 0;
237
238   /**
239    * @brief Request for deleting all local file systems.
240    */
241   virtual void DeleteLocalFileSystem() = 0;
242
243   /**
244    * @brief Request to clear cache
245    */
246   virtual void ClearCache() = 0;
247
248   /**
249    * @brief Request for deleting web application cache for origin.
250    *
251    * @param[in] origin application cache origin
252    *
253    * @return true if succeeded, false otherwise
254    */
255   virtual bool DeleteApplicationCache(WebEngineSecurityOrigin& origin) = 0;
256
257   /**
258    * @brief Asynchronous request to get list of all password data.
259    *
260    * @param[in] callback callback called after getting form password
261    */
262   virtual void GetFormPasswordList(WebEngineFormPasswordAcquiredCallback callback) = 0;
263
264   /**
265    * @brief Register callback for download started.
266    *
267    * @param[in] callback callback for download started
268    */
269   virtual void RegisterDownloadStartedCallback(WebEngineDownloadStartedCallback callback) = 0;
270
271   /**
272    * @brief Register callback for mime overridden.
273    *
274    * @param[in] callback callback for mime overridden
275    */
276   virtual void RegisterMimeOverriddenCallback(WebEngineMimeOverriddenCallback callback) = 0;
277
278   /**
279    * @brief Toggle the cache to be enabled or disabled
280    * Function works asynchronously.
281    *
282    * @param[in] cacheEnabled enable or disable cache
283    */
284   virtual void EnableCache(bool cacheEnabled) = 0;
285
286   /**
287    * @brief Query if the cache is enabled
288    *
289    * @return @c true is cache is enabled or @c false otherwise
290    */
291   virtual bool IsCacheEnabled() const = 0;
292
293   /**
294    * @brief Set application id for context.
295    *
296    * @param[in] appId application id
297    */
298   virtual void SetAppId(const std::string& appId) = 0;
299
300   /**
301    * @brief Set application version for context.
302    *
303    * @param[in] appVersion application version
304    *
305    * @return true if successful, false otherwise
306    */
307   virtual bool SetAppVersion(const std::string& appVersion) = 0;
308
309   /**
310    * @brief To declare application type
311    *
312    * @param[in] applicationType The Application_Type enum
313    *
314    */
315   virtual void SetApplicationType(const ApplicationType applicationType) = 0;
316
317   /**
318    * @brief Set time offset
319    *
320    * @param[in] timeOffset The value will be added to system time as offset
321    */
322   virtual void SetTimeOffset(float timeOffset) = 0;
323
324   /**
325    * @brief Set timezone offset
326    *
327    * @param[in] timeZoneOffset offset for time zone.
328    * @param[in] daylightSavingTime The value is for daylight saving time use.
329    */
330   virtual void SetTimeZoneOffset(float timeZoneOffset, float daylightSavingTime) = 0;
331
332   /**
333    * @brief Set default zoom factor
334    *
335    * @param[in] zoomFactor default zoom factor
336    */
337   virtual void SetDefaultZoomFactor(float zoomFactor) = 0;
338
339   /**
340    * @brief Get default zoom factor
341    *
342    * Gets default zoom factor for all pages opened with this context.
343    *
344    * @return default zoom factor or negative value on error
345    */
346   virtual float GetDefaultZoomFactor() const = 0;
347
348   /**
349    * @brief Register url schemes as CORS enabled
350    *
351    * @param[in] schemes The URL schemes list which will be added to web security policy
352    *
353    */
354   virtual void RegisterUrlSchemesAsCorsEnabled(const std::vector<std::string>& schemes) = 0;
355
356   /**
357    * @brief Register JS plugin mime types. It is applied
358    *        for all the pages opened within the context.
359    *        The API is intended to be used by web applications to
360    *        override default behaviour of the object tag.
361    *
362    * @param[in] mimeTypes The MIME types will be checked by the renderer frame loader
363    *                   to skip creating default frame for the object tags
364    *                   with the registered MIME type.
365    */
366   virtual void RegisterJsPluginMimeTypes(const std::vector<std::string>& mimeTypes) = 0;
367
368   /**
369    * @brief Request for deleting all web application caches.
370    *
371    * @return @c true on success, otherwise @c false
372    */
373   virtual bool DeleteAllApplicationCache() = 0;
374
375   /**
376    * @brief Request for deleting all web indexed databases.
377    *
378    * @return @c true on success, otherwise @c false
379    */
380   virtual bool DeleteAllWebIndexedDatabase() = 0;
381
382   /**
383    * @brief Delete a given password data list
384    *
385    * @param[in] list List with Ewk_Password_Data
386    */
387   virtual void DeleteFormPasswordDataList(const std::vector<std::string>& list) = 0;
388
389   /**
390    * @brief Delete whole password data from DB
391    */
392   virtual void DeleteAllFormPasswordData() = 0;
393
394   /**
395    * @brief Delete all candidate form data from DB
396    */
397   virtual void DeleteAllFormCandidateData() = 0;
398
399   /**
400    * @brief Notify low memory to free unused memory.
401    *
402    * @return @c true on success or @c false otherwise.
403    */
404   virtual bool FreeUnusedMemory() = 0;
405 };
406
407 } // namespace Dali
408
409 #endif // DALI_WEB_ENGINE_CONTEXT_H