Add APIs of webview context
[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 Set a proxy auth credential to network backend of specific context.
130    * @details Normally, proxy auth credential should be got from the callback
131    *          set by ewk_view_authentication_callback_set, once the username in
132    *          this API has been set with a non-null value, the authentication
133    *          callback will never been invoked. Try to avoid using this API.
134    * @param[in] username username to set
135    * @param[in] password password to set
136    */
137   virtual void SetDefaultProxyAuth(const std::string& username, const std::string& password) = 0;
138
139   /**
140    * @brief Add CA certificates to persistent NSS certificate database
141    * Function accepts a path to a CA certificate file, a path to a directory
142    * containing CA certificate files, or a colon-seprarated list of those.
143    * Certificate files should have *.crt extension.
144    * Directories are traversed recursively.
145    * @param[in] certificatePath path to a CA certificate file(s), see above for details
146    */
147   virtual void SetCertificateFilePath(const std::string& certificatePath) = 0;
148
149   /**
150    * @brief Request for deleting all web databases.
151    */
152   virtual void DeleteAllWebDatabase() = 0;
153
154   /**
155    * @brief Request for getting web database origins.
156    *
157    * @param[in] callback callback called after getting web database origins
158    *
159    * @return true if succeeded, false otherwise
160    */
161   virtual bool GetWebDatabaseOrigins(WebEngineSecurityOriginAcquiredCallback callback) = 0;
162
163   /**
164    * @brief Request for deleting web databases for origin.
165    *
166    * @param[in] origin application cache origin
167    *
168    * @return true if succeeded, false otherwise
169    */
170   virtual bool DeleteWebDatabase(WebEngineSecurityOrigin& origin) = 0;
171
172   /**
173    * @brief Get list of origins that is stored in web storage db.
174    *
175    * @param[in] callback callback called after getting web storage origins
176    *
177    * @return true if succeeded, false otherwise
178    */
179   virtual bool GetWebStorageOrigins(WebEngineSecurityOriginAcquiredCallback callback) = 0;
180
181   /**
182    * @brief Get list of origins that is stored in web storage db.
183    *
184    * @param[in] origin storage origin
185    * @param[in] callback callback called after getting web storage origins
186    *
187    * @return true if succeeded, false otherwise
188    */
189   virtual bool GetWebStorageUsageForOrigin(WebEngineSecurityOrigin& origin, WebEngineStorageUsageAcquiredCallback callback) = 0;
190
191   /**
192    * @brief Delete all web storage.
193    * @details This function does not ensure that all data will be removed.
194    *          Should be used to extend free physical memory.
195    */
196   virtual void DeleteAllWebStorage() = 0;
197
198   /**
199    * @brief Delete web storage database.
200    *
201    * @param[in] origin origin of database
202    *
203    * @return true if succeeded, false otherwise
204    */
205   virtual bool DeleteWebStorage(WebEngineSecurityOrigin& origin) = 0;
206
207   /**
208    * @brief Request for deleting all local file systems.
209    */
210   virtual void DeleteLocalFileSystem() = 0;
211
212   /**
213    * @brief Request to clear cache
214    */
215   virtual void ClearCache() = 0;
216
217   /**
218    * @brief Request for deleting web application cache for origin.
219    *
220    * @param[in] origin application cache origin
221    *
222    * @return true if succeeded, false otherwise
223    */
224   virtual bool DeleteApplicationCache(WebEngineSecurityOrigin& origin) = 0;
225
226   /**
227    * @brief Asynchronous request to get list of all password data.
228    *
229    * @param[in] callback callback called after getting form password
230    */
231   virtual void GetFormPasswordList(WebEngineFormPasswordAcquiredCallback callback) = 0;
232
233   /**
234    * @brief Register callback for download started.
235    *
236    * @param[in] callback callback for download started
237    */
238   virtual void RegisterDownloadStartedCallback(WebEngineDownloadStartedCallback callback) = 0;
239
240   /**
241    * @brief Register callback for mime overridden.
242    *
243    * @param[in] callback callback for mime overridden
244    */
245   virtual void RegisterMimeOverriddenCallback(WebEngineMimeOverriddenCallback callback) = 0;
246
247   /**
248    * @brief Toggle the cache to be enabled or disabled
249    * Function works asynchronously.
250    *
251    * @param[in] cacheEnabled enable or disable cache
252    */
253   virtual void EnableCache(bool cacheEnabled) = 0;
254
255   /**
256    * @brief Query if the cache is enabled
257    *
258    * @return @c true is cache is enabled or @c false otherwise
259    */
260   virtual bool IsCacheEnabled() const = 0;
261
262   /**
263    * @brief Get CA certifcate file path
264    *
265    * It returns an internal string and should not be modified.
266    *
267    * @return @c certificate_file is path which is set during ewk_context_certificate_file_set or @c null string otherwise
268    */
269   virtual std::string GetContextCertificateFile() const = 0;
270
271   /**
272    * @brief Set application id for @a context.
273    *
274    * @param[in] appID application id
275    */
276   virtual void SetContextAppId(const std::string& appID) = 0;
277
278   /**
279    * @brief Set application version for @a context.
280    *
281    * @param[in] appVersion application version
282    *
283    * @return @c true if successful, @c false otherwise
284    */
285   virtual bool SetContextAppVersion(const std::string& appVersion) = 0;
286
287   /**
288    * @brief To declare application type
289    *
290    * @param[in] applicationType The Application_Type enum
291    *
292    */
293   virtual void SetContextApplicationType(const ApplicationType applicationType) = 0;
294
295   /**
296    * @brief Set time offset
297    *
298    * @param[in] timeOffset The value will be added to system time as offset
299    */
300   virtual void SetContextTimeOffset(float timeOffset) = 0;
301
302   /**
303    * @brief Set timezone offset
304    *
305    * @param[in] timeZoneOffset offset for time zone.
306    * @param[in] daylightSavingTime The value is for daylight saving time use.
307    */
308   virtual void SetContextTimeZoneOffset(float timeZoneOffset, float daylightSavingTime) = 0;
309
310   /**
311    * @brief Register url schemes as CORS enabled
312    *
313    * @param[in] schemes The URL schemes list which will be added to web security policy
314    *
315    */
316   virtual void RegisterUrlSchemesAsCorsEnabled(const std::vector<std::string>& schemes) = 0;
317
318   /**
319    * @brief Register JS plugin mime types. It is applied
320    *        for all the pages opened within the context.
321    *        The API is intended to be used by web applications to
322    *        override default behaviour of the object tag.
323    *
324    * @param[in] mimeTypes The MIME types will be checked by the renderer frame loader
325    *                   to skip creating default frame for the object tags
326    *                   with the registered MIME type.
327    */
328   virtual void RegisterJsPluginMimeTypes(const std::vector<std::string>& mimeTypes) = 0;
329
330   /**
331    * @brief Set default zoom factor
332    *
333    * @param[in] zoomFactor default zoom factor
334    */
335   virtual void SetDefaultZoomFactor(float zoomFactor) = 0;
336
337   /**
338    * @brief Get default zoom factor
339    *
340    * Gets default zoom factor for all pages opened with this context.
341    *
342    * @return @c default zoom factor or negative value on error
343    */
344   virtual float GetContextDefaultZoomFactor() const = 0;
345
346   /**
347    * @brief Request for deleting all web application caches.
348    *
349    * @return @c true on success, otherwise @c false
350    */
351   virtual bool DeleteAllApplicationCache() = 0;
352
353   /**
354    * @brief Request for deleting all web indexed databases.
355    *
356    * @return @c true on success, otherwise @c false
357    */
358   virtual bool DeleteAllWebIndexedDatabase() = 0;
359
360   /**
361    * @brief Delete a given password data list
362    *
363    * @param[in] list List with Ewk_Password_Data
364    */
365   virtual void DeleteFormPasswordDataList(const std::vector<std::string>& list) = 0;
366
367   /**
368    * @brief Delete whole password data from DB
369    */
370   virtual void DeleteAllFormPasswordData() = 0;
371
372   /**
373    * @brief Delete all candidate form data from DB
374    */
375   virtual void DeleteAllFormCandidateData() = 0;
376
377   /**
378    * @brief Get the proxy URI from the network backend of specific context.
379    *
380    * @return current proxy URI or @c null string if it's not set
381    */
382   virtual std::string GetContextProxy() const = 0;
383
384   /**
385    * @brief Set the given proxy to network backend of specific context.
386    *
387    * @param[in] proxy URI to set
388    * @param[in] bypass rule to set
389    */
390   virtual void SetContextProxy(const std::string& proxy, const std::string& bypass) = 0;
391
392   /**
393    * @brief Get the proxy bypass rule from the network backend of specific context.
394    *
395    * @return current proxy bypass rule or @c null string if it's not set
396    */
397   virtual std::string GetProxyBypassRule() const = 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