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