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 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
137 virtual void SetDefaultProxyAuth(const std::string& username, const std::string& password) = 0;
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
147 virtual void SetCertificateFilePath(const std::string& certificatePath) = 0;
150 * @brief Request for deleting all web databases.
152 virtual void DeleteAllWebDatabase() = 0;
155 * @brief Request for getting web database origins.
157 * @param[in] callback callback called after getting web database origins
159 * @return true if succeeded, false otherwise
161 virtual bool GetWebDatabaseOrigins(WebEngineSecurityOriginAcquiredCallback callback) = 0;
164 * @brief Request for deleting web databases for origin.
166 * @param[in] origin application cache origin
168 * @return true if succeeded, false otherwise
170 virtual bool DeleteWebDatabase(WebEngineSecurityOrigin& origin) = 0;
173 * @brief Get list of origins that is stored in web storage db.
175 * @param[in] callback callback called after getting web storage origins
177 * @return true if succeeded, false otherwise
179 virtual bool GetWebStorageOrigins(WebEngineSecurityOriginAcquiredCallback callback) = 0;
182 * @brief Get list of origins that is stored in web storage db.
184 * @param[in] origin storage origin
185 * @param[in] callback callback called after getting web storage origins
187 * @return true if succeeded, false otherwise
189 virtual bool GetWebStorageUsageForOrigin(WebEngineSecurityOrigin& origin, WebEngineStorageUsageAcquiredCallback callback) = 0;
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.
196 virtual void DeleteAllWebStorage() = 0;
199 * @brief Delete web storage database.
201 * @param[in] origin origin of database
203 * @return true if succeeded, false otherwise
205 virtual bool DeleteWebStorage(WebEngineSecurityOrigin& origin) = 0;
208 * @brief Request for deleting all local file systems.
210 virtual void DeleteLocalFileSystem() = 0;
213 * @brief Request to clear cache
215 virtual void ClearCache() = 0;
218 * @brief Request for deleting web application cache for origin.
220 * @param[in] origin application cache origin
222 * @return true if succeeded, false otherwise
224 virtual bool DeleteApplicationCache(WebEngineSecurityOrigin& origin) = 0;
227 * @brief Asynchronous request to get list of all password data.
229 * @param[in] callback callback called after getting form password
231 virtual void GetFormPasswordList(WebEngineFormPasswordAcquiredCallback callback) = 0;
234 * @brief Register callback for download started.
236 * @param[in] callback callback for download started
238 virtual void RegisterDownloadStartedCallback(WebEngineDownloadStartedCallback callback) = 0;
241 * @brief Register callback for mime overridden.
243 * @param[in] callback callback for mime overridden
245 virtual void RegisterMimeOverriddenCallback(WebEngineMimeOverriddenCallback callback) = 0;
248 * @brief Toggle the cache to be enabled or disabled
249 * Function works asynchronously.
251 * @param[in] cacheEnabled enable or disable cache
253 virtual void EnableCache(bool cacheEnabled) = 0;
256 * @brief Query if the cache is enabled
258 * @return @c true is cache is enabled or @c false otherwise
260 virtual bool IsCacheEnabled() const = 0;
263 * @brief Get CA certifcate file path
265 * It returns an internal string and should not be modified.
267 * @return @c certificate_file is path which is set during ewk_context_certificate_file_set or @c null string otherwise
269 virtual std::string GetContextCertificateFile() const = 0;
272 * @brief Set application id for @a context.
274 * @param[in] appID application id
276 virtual void SetContextAppId(const std::string& appID) = 0;
279 * @brief Set application version for @a context.
281 * @param[in] appVersion application version
283 * @return @c true if successful, @c false otherwise
285 virtual bool SetContextAppVersion(const std::string& appVersion) = 0;
288 * @brief To declare application type
290 * @param[in] applicationType The Application_Type enum
293 virtual void SetContextApplicationType(const ApplicationType applicationType) = 0;
296 * @brief Set time offset
298 * @param[in] timeOffset The value will be added to system time as offset
300 virtual void SetContextTimeOffset(float timeOffset) = 0;
303 * @brief Set timezone offset
305 * @param[in] timeZoneOffset offset for time zone.
306 * @param[in] daylightSavingTime The value is for daylight saving time use.
308 virtual void SetContextTimeZoneOffset(float timeZoneOffset, float daylightSavingTime) = 0;
311 * @brief Register url schemes as CORS enabled
313 * @param[in] schemes The URL schemes list which will be added to web security policy
316 virtual void RegisterUrlSchemesAsCorsEnabled(const std::vector<std::string>& schemes) = 0;
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.
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.
328 virtual void RegisterJsPluginMimeTypes(const std::vector<std::string>& mimeTypes) = 0;
331 * @brief Set default zoom factor
333 * @param[in] zoomFactor default zoom factor
335 virtual void SetDefaultZoomFactor(float zoomFactor) = 0;
338 * @brief Get default zoom factor
340 * Gets default zoom factor for all pages opened with this context.
342 * @return @c default zoom factor or negative value on error
344 virtual float GetContextDefaultZoomFactor() const = 0;
347 * @brief Request for deleting all web application caches.
349 * @return @c true on success, otherwise @c false
351 virtual bool DeleteAllApplicationCache() = 0;
354 * @brief Request for deleting all web indexed databases.
356 * @return @c true on success, otherwise @c false
358 virtual bool DeleteAllWebIndexedDatabase() = 0;
361 * @brief Delete a given password data list
363 * @param[in] list List with Ewk_Password_Data
365 virtual void DeleteFormPasswordDataList(const std::vector<std::string>& list) = 0;
368 * @brief Delete whole password data from DB
370 virtual void DeleteAllFormPasswordData() = 0;
373 * @brief Delete all candidate form data from DB
375 virtual void DeleteAllFormCandidateData() = 0;
378 * @brief Get the proxy URI from the network backend of specific context.
380 * @return current proxy URI or @c null string if it's not set
382 virtual std::string GetContextProxy() const = 0;
385 * @brief Set the given proxy to network backend of specific context.
387 * @param[in] proxy URI to set
388 * @param[in] bypass rule to set
390 virtual void SetContextProxy(const std::string& proxy, const std::string& bypass) = 0;
393 * @brief Get the proxy bypass rule from the network backend of specific context.
395 * @return current proxy bypass rule or @c null string if it's not set
397 virtual std::string GetProxyBypassRule() const = 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