1 #ifndef DALI_WEB_ENGINE_CONTEXT_H
2 #define DALI_WEB_ENGINE_CONTEXT_H
5 * Copyright (c) 2021 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-security-origin.h>
33 * @brief A class WebEngineContext for context of web engine.
35 class WebEngineContext
39 * @brief Callback for getting web database origins.
41 using WebEngineSecurityOriginAcquiredCallback = std::function<void(std::vector<std::unique_ptr<Dali::WebEngineSecurityOrigin>>&)>;
44 * @brief Callback for getting web storage usage.
46 using WebEngineStorageUsageAcquiredCallback = std::function<void(uint64_t)>;
48 // forward declaration.
52 * @brief Callback for getting form password.
54 using WebEngineFormPasswordAcquiredCallback = std::function<void(std::vector<std::unique_ptr<PasswordData>>&)>;
57 * @brief Callback for download started with url.
59 using WebEngineDownloadStartedCallback = std::function<void(const std::string&)>;
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.
68 using WebEngineMimeOverriddenCallback = std::function<bool(const std::string&, const std::string&, std::string&)>;
71 * @brief Enumeration for cache model options.
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.
81 * @brief Enumeration for application type.
83 enum class ApplicationType
92 * @brief Struct for password data
101 * @brief Constructor.
103 WebEngineContext() = default;
108 virtual ~WebEngineContext() = default;
111 * @brief Return the cache model type.
112 * @return #CacheModel
114 virtual CacheModel GetCacheModel() const = 0;
117 * @brief Request to set the cache model.
118 * @param[in] cacheModel The cache model
120 virtual void SetCacheModel(CacheModel cacheModel) = 0;
123 * @brief Set the given proxy URI to network backend of specific context.
124 * @param[in] uri The proxy URI to set
126 virtual void SetProxyUri(const std::string& uri) = 0;
129 * @brief Get the proxy URI from the network backend of specific context.
131 * @return current proxy URI or null if it's not set
133 virtual std::string GetProxyUri() const = 0;
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
144 virtual void SetDefaultProxyAuth(const std::string& username, const std::string& password) = 0;
147 * @brief Set the given proxy to network backend of specific context.
149 * @param[in] proxy URI to set
150 * @param[in] bypass rule to set
152 virtual void SetProxyBypassRule(const std::string& proxy, const std::string& bypass) = 0;
155 * @brief Get the proxy bypass rule from the network backend of specific context.
157 * @return current proxy bypass rule or null string if it's not set
159 virtual std::string GetProxyBypassRule() const = 0;
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
169 virtual void SetCertificateFilePath(const std::string& certificatePath) = 0;
172 * @brief Get CA certifcate file path
174 * It returns an internal string and should not be modified.
176 * @return certificate_file path which is set during ewk_context_certificate_file_set or null string otherwise
178 virtual std::string GetCertificateFilePath() const = 0;
181 * @brief Request for deleting all web databases.
183 virtual void DeleteAllWebDatabase() = 0;
186 * @brief Request for getting web database origins.
188 * @param[in] callback callback called after getting web database origins
190 * @return true if succeeded, false otherwise
192 virtual bool GetWebDatabaseOrigins(WebEngineSecurityOriginAcquiredCallback callback) = 0;
195 * @brief Request for deleting web databases for origin.
197 * @param[in] origin application cache origin
199 * @return true if succeeded, false otherwise
201 virtual bool DeleteWebDatabase(WebEngineSecurityOrigin& origin) = 0;
204 * @brief Get list of origins that is stored in web storage db.
206 * @param[in] callback callback called after getting web storage origins
208 * @return true if succeeded, false otherwise
210 virtual bool GetWebStorageOrigins(WebEngineSecurityOriginAcquiredCallback callback) = 0;
213 * @brief Get list of origins that is stored in web storage db.
215 * @param[in] origin storage origin
216 * @param[in] callback callback called after getting web storage origins
218 * @return true if succeeded, false otherwise
220 virtual bool GetWebStorageUsageForOrigin(WebEngineSecurityOrigin& origin, WebEngineStorageUsageAcquiredCallback callback) = 0;
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.
227 virtual void DeleteAllWebStorage() = 0;
230 * @brief Delete web storage database.
232 * @param[in] origin origin of database
234 * @return true if succeeded, false otherwise
236 virtual bool DeleteWebStorage(WebEngineSecurityOrigin& origin) = 0;
239 * @brief Request for deleting all local file systems.
241 virtual void DeleteLocalFileSystem() = 0;
244 * @brief Request to clear cache
246 virtual void ClearCache() = 0;
249 * @brief Request for deleting web application cache for origin.
251 * @param[in] origin application cache origin
253 * @return true if succeeded, false otherwise
255 virtual bool DeleteApplicationCache(WebEngineSecurityOrigin& origin) = 0;
258 * @brief Asynchronous request to get list of all password data.
260 * @param[in] callback callback called after getting form password
262 virtual void GetFormPasswordList(WebEngineFormPasswordAcquiredCallback callback) = 0;
265 * @brief Register callback for download started.
267 * @param[in] callback callback for download started
269 virtual void RegisterDownloadStartedCallback(WebEngineDownloadStartedCallback callback) = 0;
272 * @brief Register callback for mime overridden.
274 * @param[in] callback callback for mime overridden
276 virtual void RegisterMimeOverriddenCallback(WebEngineMimeOverriddenCallback callback) = 0;
279 * @brief Toggle the cache to be enabled or disabled
280 * Function works asynchronously.
282 * @param[in] cacheEnabled enable or disable cache
284 virtual void EnableCache(bool cacheEnabled) = 0;
287 * @brief Query if the cache is enabled
289 * @return @c true is cache is enabled or @c false otherwise
291 virtual bool IsCacheEnabled() const = 0;
294 * @brief Set application id for context.
296 * @param[in] appId application id
298 virtual void SetAppId(const std::string& appId) = 0;
301 * @brief Set application version for context.
303 * @param[in] appVersion application version
305 * @return true if successful, false otherwise
307 virtual bool SetAppVersion(const std::string& appVersion) = 0;
310 * @brief To declare application type
312 * @param[in] applicationType The Application_Type enum
315 virtual void SetApplicationType(const ApplicationType applicationType) = 0;
318 * @brief Set time offset
320 * @param[in] timeOffset The value will be added to system time as offset
322 virtual void SetTimeOffset(float timeOffset) = 0;
325 * @brief Set timezone offset
327 * @param[in] timeZoneOffset offset for time zone.
328 * @param[in] daylightSavingTime The value is for daylight saving time use.
330 virtual void SetTimeZoneOffset(float timeZoneOffset, float daylightSavingTime) = 0;
333 * @brief Set default zoom factor
335 * @param[in] zoomFactor default zoom factor
337 virtual void SetDefaultZoomFactor(float zoomFactor) = 0;
340 * @brief Get default zoom factor
342 * Gets default zoom factor for all pages opened with this context.
344 * @return default zoom factor or negative value on error
346 virtual float GetDefaultZoomFactor() const = 0;
349 * @brief Register url schemes as CORS enabled
351 * @param[in] schemes The URL schemes list which will be added to web security policy
354 virtual void RegisterUrlSchemesAsCorsEnabled(const std::vector<std::string>& schemes) = 0;
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.
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.
366 virtual void RegisterJsPluginMimeTypes(const std::vector<std::string>& mimeTypes) = 0;
369 * @brief Request for deleting all web application caches.
371 * @return @c true on success, otherwise @c false
373 virtual bool DeleteAllApplicationCache() = 0;
376 * @brief Request for deleting all web indexed databases.
378 * @return @c true on success, otherwise @c false
380 virtual bool DeleteAllWebIndexedDatabase() = 0;
383 * @brief Delete a given password data list
385 * @param[in] list List with Ewk_Password_Data
387 virtual void DeleteFormPasswordDataList(const std::vector<std::string>& list) = 0;
390 * @brief Delete whole password data from DB
392 virtual void DeleteAllFormPasswordData() = 0;
395 * @brief Delete all candidate form data from DB
397 virtual void DeleteAllFormCandidateData() = 0;
400 * @brief Notify low memory to free unused memory.
402 * @return @c true on success or @c false otherwise.
404 virtual bool FreeUnusedMemory() = 0;
409 #endif // DALI_WEB_ENGINE_CONTEXT_H