1 #ifndef DALI_WEB_ENGINE_CONTEXT_H
2 #define DALI_WEB_ENGINE_CONTEXT_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
34 * @brief A class WebEngineContext for context of web engine.
36 class WebEngineContext
40 * @brief WebView callback related with http request interceptor.
42 using WebEngineRequestInterceptedCallback = std::function<void(Dali::WebEngineRequestInterceptorPtr)>;
45 * @brief Callback for getting web database origins.
47 using WebEngineSecurityOriginAcquiredCallback = std::function<void(std::vector<std::unique_ptr<Dali::WebEngineSecurityOrigin>>&)>;
50 * @brief Callback for getting web storage usage.
52 using WebEngineStorageUsageAcquiredCallback = std::function<void(uint64_t)>;
54 // forward declaration.
58 * @brief Callback for getting form password.
60 using WebEngineFormPasswordAcquiredCallback = std::function<void(std::vector<std::unique_ptr<PasswordData>>&)>;
63 * @brief Callback for download started with url.
65 using WebEngineDownloadStartedCallback = std::function<void(const std::string&)>;
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.
74 using WebEngineMimeOverriddenCallback = std::function<bool(const std::string&, const std::string&, std::string&)>;
77 * @brief Enumeration for cache model options.
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.
87 * @brief Enumeration for application type.
89 enum class ApplicationType
98 * @brief Struct for password data
107 * @brief Constructor.
109 WebEngineContext() = default;
114 virtual ~WebEngineContext() = default;
117 * @brief Return the cache model type.
118 * @return #CacheModel
120 virtual CacheModel GetCacheModel() const = 0;
123 * @brief Request to set the cache model.
124 * @param[in] cacheModel The cache model
126 virtual void SetCacheModel(CacheModel cacheModel) = 0;
129 * @brief Set the given proxy URI to network backend of specific context.
130 * @param[in] uri The proxy URI to set
132 virtual void SetProxyUri(const std::string& uri) = 0;
135 * @brief Get the proxy URI from the network backend of specific context.
137 * @return current proxy URI or null if it's not set
139 virtual std::string GetProxyUri() const = 0;
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
150 virtual void SetDefaultProxyAuth(const std::string& username, const std::string& password) = 0;
153 * @brief Set the given proxy to network backend of specific context.
155 * @param[in] proxy URI to set
156 * @param[in] bypass rule to set
158 virtual void SetProxyBypassRule(const std::string& proxy, const std::string& bypass) = 0;
161 * @brief Get the proxy bypass rule from the network backend of specific context.
163 * @return current proxy bypass rule or null string if it's not set
165 virtual std::string GetProxyBypassRule() const = 0;
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
175 virtual void SetCertificateFilePath(const std::string& certificatePath) = 0;
178 * @brief Get CA certifcate file path
180 * It returns an internal string and should not be modified.
182 * @return certificate_file path which is set during ewk_context_certificate_file_set or null string otherwise
184 virtual std::string GetCertificateFilePath() const = 0;
187 * @brief Request for deleting all web databases.
189 virtual void DeleteAllWebDatabase() = 0;
192 * @brief Request for getting web database origins.
194 * @param[in] callback callback called after getting web database origins
196 * @return true if succeeded, false otherwise
198 virtual bool GetWebDatabaseOrigins(WebEngineSecurityOriginAcquiredCallback callback) = 0;
201 * @brief Request for deleting web databases for origin.
203 * @param[in] origin application cache origin
205 * @return true if succeeded, false otherwise
207 virtual bool DeleteWebDatabase(WebEngineSecurityOrigin& origin) = 0;
210 * @brief Get list of origins that is stored in web storage db.
212 * @param[in] callback callback called after getting web storage origins
214 * @return true if succeeded, false otherwise
216 virtual bool GetWebStorageOrigins(WebEngineSecurityOriginAcquiredCallback callback) = 0;
219 * @brief Get list of origins that is stored in web storage db.
221 * @param[in] origin storage origin
222 * @param[in] callback callback called after getting web storage origins
224 * @return true if succeeded, false otherwise
226 virtual bool GetWebStorageUsageForOrigin(WebEngineSecurityOrigin& origin, WebEngineStorageUsageAcquiredCallback callback) = 0;
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.
233 virtual void DeleteAllWebStorage() = 0;
236 * @brief Delete web storage database.
238 * @param[in] origin origin of database
240 * @return true if succeeded, false otherwise
242 virtual bool DeleteWebStorage(WebEngineSecurityOrigin& origin) = 0;
245 * @brief Request for deleting all local file systems.
247 virtual void DeleteLocalFileSystem() = 0;
250 * @brief Request to clear cache
252 virtual void ClearCache() = 0;
255 * @brief Request for deleting web application cache for origin.
257 * @param[in] origin application cache origin
259 * @return true if succeeded, false otherwise
261 virtual bool DeleteApplicationCache(WebEngineSecurityOrigin& origin) = 0;
264 * @brief Asynchronous request to get list of all password data.
266 * @param[in] callback callback called after getting form password
268 virtual void GetFormPasswordList(WebEngineFormPasswordAcquiredCallback callback) = 0;
271 * @brief Register callback for download started.
273 * @param[in] callback callback for download started
275 virtual void RegisterDownloadStartedCallback(WebEngineDownloadStartedCallback callback) = 0;
278 * @brief Register callback for mime overridden.
280 * @param[in] callback callback for mime overridden
282 virtual void RegisterMimeOverriddenCallback(WebEngineMimeOverriddenCallback callback) = 0;
285 * @brief Callback to be called when http request need be intercepted.
287 * @param[in] callback
289 virtual void RegisterRequestInterceptedCallback(WebEngineRequestInterceptedCallback callback) = 0;
292 * @brief Toggle the cache to be enabled or disabled
293 * Function works asynchronously.
295 * @param[in] cacheEnabled enable or disable cache
297 virtual void EnableCache(bool cacheEnabled) = 0;
300 * @brief Query if the cache is enabled
302 * @return @c true is cache is enabled or @c false otherwise
304 virtual bool IsCacheEnabled() const = 0;
307 * @brief Set application id for context.
309 * @param[in] appId application id
311 virtual void SetAppId(const std::string& appId) = 0;
314 * @brief Set application version for context.
316 * @param[in] appVersion application version
318 * @return true if successful, false otherwise
320 virtual bool SetAppVersion(const std::string& appVersion) = 0;
323 * @brief To declare application type
325 * @param[in] applicationType The Application_Type enum
328 virtual void SetApplicationType(const ApplicationType applicationType) = 0;
331 * @brief Set time offset
333 * @param[in] timeOffset The value will be added to system time as offset
335 virtual void SetTimeOffset(float timeOffset) = 0;
338 * @brief Set timezone offset
340 * @param[in] timeZoneOffset offset for time zone.
341 * @param[in] daylightSavingTime The value is for daylight saving time use.
343 virtual void SetTimeZoneOffset(float timeZoneOffset, float daylightSavingTime) = 0;
346 * @brief Set default zoom factor
348 * @param[in] zoomFactor default zoom factor
350 virtual void SetDefaultZoomFactor(float zoomFactor) = 0;
353 * @brief Get default zoom factor
355 * Gets default zoom factor for all pages opened with this context.
357 * @return default zoom factor or negative value on error
359 virtual float GetDefaultZoomFactor() const = 0;
362 * @brief Register url schemes as CORS enabled
364 * @param[in] schemes The URL schemes list which will be added to web security policy
367 virtual void RegisterUrlSchemesAsCorsEnabled(const std::vector<std::string>& schemes) = 0;
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.
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.
379 virtual void RegisterJsPluginMimeTypes(const std::vector<std::string>& mimeTypes) = 0;
382 * @brief Request for deleting all web application caches.
384 * @return @c true on success, otherwise @c false
386 virtual bool DeleteAllApplicationCache() = 0;
389 * @brief Request for deleting all web indexed databases.
391 * @return @c true on success, otherwise @c false
393 virtual bool DeleteAllWebIndexedDatabase() = 0;
396 * @brief Delete a given password data list
398 * @param[in] list List with Ewk_Password_Data
400 virtual void DeleteFormPasswordDataList(const std::vector<std::string>& list) = 0;
403 * @brief Delete whole password data from DB
405 virtual void DeleteAllFormPasswordData() = 0;
408 * @brief Delete all candidate form data from DB
410 virtual void DeleteAllFormCandidateData() = 0;
413 * @brief Notify low memory to free unused memory.
415 * @return @c true on success or @c false otherwise.
417 virtual bool FreeUnusedMemory() = 0;
422 #endif // DALI_WEB_ENGINE_CONTEXT_H