[M67 Dev][EWK] Classify EWK APIs by public, internal, or product
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / public / ewk_context.h
1 /*
2  * Copyright (C) 2016 Samsung Electronics
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 /**
21  * @file    ewk_context.h
22  * @brief   This file describes the Ewk Context API.
23  *
24  * @remarks ewk_context encapsulates all pages related to the specific use of
25  *          Chromium-efl
26  *
27  * Applications have the option of creating a context different from the default
28  * one and using it for a group of pages. All pages in the same context share
29  * the same preferences, visited link set, local storage, and so on.
30  *
31  * A process model can be specified per context. The default one is the shared
32  * model where the web-engine process is shared among the pages in the context.
33  * The second model allows each page to use a separate web-engine process.
34  * This latter model is currently not supported by Chromium-efl.
35  *
36  */
37
38 #ifndef ewk_context_h
39 #define ewk_context_h
40
41 #include <Eina.h>
42 #include <Evas.h>
43 #include <tizen.h>
44 #include "ewk_autofill_profile.h"
45 #include "ewk_cookie_manager.h"
46 #include "ewk_intercept_request.h"
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 /**
53  * @addtogroup WEBVIEW
54  * @{
55  */
56
57 /**
58  * @brief The structure type that creates a type name for #Ewk_Context.
59  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
60  */
61 typedef struct Ewk_Context Ewk_Context;
62
63 /**
64  * \enum    Ewk_Cache_Model
65  * @brief   Contains option for cache model
66  *
67  * @since_tizen 2.4
68  */
69 enum _Ewk_Cache_Model {
70     EWK_CACHE_MODEL_DOCUMENT_VIEWER,  /* Use the smallest cache capacity. */
71     EWK_CACHE_MODEL_DOCUMENT_BROWSER,  /* Use bigger cache capacity than EWK_CACHE_MODEL_DOCUMENT_VIEWER. */
72     EWK_CACHE_MODEL_PRIMARY_WEBBROWSER  /* Use the biggest cache capacity. */
73 };
74
75 /**
76  * @brief The structure type that creates a type name for Ewk_Cache_Model.
77  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 3.0 @endif
78  */
79 typedef enum _Ewk_Cache_Model Ewk_Cache_Model;
80
81 /**
82  * @brief Gets the cookie manager instance for this @a context.
83  *
84  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
85  *
86  * @param[in] context The context object to query
87  *
88  * @return The Ewk_Cookie_Manager object instance,\n
89  *         otherwise @c NULL in case of failure
90  */
91 EXPORT_API Ewk_Cookie_Manager* ewk_context_cookie_manager_get(const Ewk_Context* context);
92
93 /**
94  * @if MOBILE
95  * @brief Requests for deleting all web application caches.
96  *
97  * @since_tizen 2.4
98  *
99  * @param[in] context Context object
100  *
101  * @return @c EINA_TRUE on success, otherwise @c EINA FALSE
102  * @endif
103  */
104 EXPORT_API Eina_Bool ewk_context_application_cache_delete_all(Ewk_Context* context);
105
106 /**
107  * @brief Requests to set the cache model.
108  *
109  * The default cache option is EWK_CACHE_MODEL_DOCUMENT_VIEWER.
110  *
111  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
112  *
113  * @param[in] context The context object
114  * @param[in] model The cache model
115  *
116  * @return @c EINA_TRUE on success,\n
117  *         otherwise @c EINA_FALSE
118  */
119 EXPORT_API Eina_Bool ewk_context_cache_model_set(Ewk_Context* context, Ewk_Cache_Model model);
120
121 /**
122  * @brief Returns the cache model type.
123  *
124  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
125  *
126  * @param[in] context The context object
127  *
128  * @return #Ewk_Cache_Model
129  */
130 EXPORT_API Ewk_Cache_Model ewk_context_cache_model_get(Ewk_Context* context);
131
132 /**
133  * @if MOBILE
134  * @brief Saves the created profile into permenant storage
135  *
136  * The profile used to save must be created by ewk_autofill_profile_new.
137  * Data can be added to the created profile by ewk_autofill_profile_data_set.
138  *
139  * @since_tizen 2.4
140  *
141  * @param[in] context Context object
142  * @param[in] profile Ewk_Autofill_Profile
143  *
144  * @return @c EINA_TRUE if the profile data is saved successfully, otherwise
145  *         @c EINA_FALSE
146  *
147  * @see ewk_autofill_profile_new
148  * @endif
149  */
150 EXPORT_API Eina_Bool ewk_context_form_autofill_profile_add(Ewk_Context* context, Ewk_Autofill_Profile* profile);
151
152 /**
153  * @if MOBILE
154  * @brief Gets the existing profile for given index
155  *
156  * @since_tizen 2.4
157  *
158  * @param[in] context Context object
159  * @param[in] id Profile
160  *
161  * @return @c Ewk_Autofill_Profile if profile exists, otherwise @c NULL
162  *
163  * @see ewk_autofill_profile_delete
164  * @endif
165  */
166 EXPORT_API Ewk_Autofill_Profile* ewk_context_form_autofill_profile_get(Ewk_Context* context, unsigned id);
167
168 /**
169  * @if MOBILE
170  * @brief Gets a list of all existing profiles
171  *
172  * The obtained profile must be deleted by ewk_autofill_profile_delete.
173  *
174  * @since_tizen 2.4
175  *
176  * @param[in] context Context object
177  *
178  * @return @c Eina_List of Ewk_Autofill_Profile, otherwise @c NULL
179  *
180  * @see ewk_autofill_profile_delete
181  * @endif
182  */
183 EXPORT_API Eina_List* ewk_context_form_autofill_profile_get_all(Ewk_Context* context);
184
185 /**
186  * @if MOBILE
187  * @brief Sets the given profile for the given id
188  *
189  * Data can be added to the created profile by ewk_autofill_profile_data_set.
190  *
191  * @since_tizen 2.4
192  *
193  * @param[in] context Context object
194  * @param[in] id Profile
195  * @param[in] profile Ewk_Autofill_Profile
196  *
197  * @return @c EINA_TRUE if the profile data is set successfully, otherwise
198  *         @c EINA_FALSE
199  *
200  * @see ewk_autofill_profile_new
201  * @see ewk_context_form_autofill_profile_add
202  * @endif
203  */
204 EXPORT_API Eina_Bool ewk_context_form_autofill_profile_set(Ewk_Context* context, unsigned id, Ewk_Autofill_Profile* profile);
205
206 /**
207  * @if MOBILE
208  * @brief Removes Autofill Form profile completely
209  *
210  * @since_tizen 2.4
211  *
212  * @param[in] context Context object
213  * @param[in] id Profile
214  *
215  * @return @c EINA_TRUE if the profile data is removed successfully, otherwise
216            @c EINA_FALSE
217  *
218  * @see ewk_context_form_autofill_profile_get_all
219  * @endif
220  */
221 EXPORT_API Eina_Bool ewk_context_form_autofill_profile_remove(Ewk_Context* context, unsigned id);
222
223 /**
224  * @if MOBILE
225  * @brief Deletes all candidate form data from DB
226  *
227  * @since_tizen 2.4
228  *
229  * @param[in] context Context object
230  * @endif
231  */
232 EXPORT_API void ewk_context_form_candidate_data_delete_all(Ewk_Context* context);
233
234 /**
235  * @if MOBILE
236  * @brief Deletes whole password data from DB
237  *
238  * @since_tizen 2.4
239  *
240  * @param context Context object
241  * @endif
242  */
243 EXPORT_API void ewk_context_form_password_data_delete_all(Ewk_Context* context);
244
245 /**
246  * @brief Clears HTTP caches in the local storage and
247  *        all resources cached in memory\n
248  *        such as images, CSS, JavaScript, XSL, and fonts for @a context.
249  *
250  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
251  *
252  * @param[in] context The context object to clear all resource caches
253  */
254 EXPORT_API void ewk_context_resource_cache_clear(Ewk_Context* context);
255
256 /**
257  * @if MOBILE
258  * @brief Requests to get image representing the given URL.
259  *
260  * @since_tizen 2.4
261  *
262  * @param[in] context Context object
263  * @param[in] uri Which url to query icon, must not be @c 0
264  * @param[in] canvas Evas instance where to add resulting object,
265  *            must not be @c 0
266  *
267  * @return @c Evas_Object instance, otherwise @c 0
268  * @endif
269  */
270 EXPORT_API Evas_Object* ewk_context_icon_database_icon_object_add(Ewk_Context* context, const char* uri, Evas* canvas);
271
272 /**
273  * @if MOBILE
274  * @deprecated Deprecated 2.4
275  *
276  * @brief Sets the list of preferred languages.
277  *
278  * @details This function sets the list of preferred langages.\n
279  *          This list will be used to build the "Accept-Language" header that
280  *          will be included in the network requests.\n
281  *          The client can pass @c NULL for languages to clear what is set
282  *          before.
283  *
284  * @since_tizen 2.3
285  *
286  * @remarks All contexts will be affected.
287  *
288  * @param[in] languages The list of preferred languages (char* as data),\n
289  *                      otherwise @c NULL
290  * @endif
291  */
292 EXPORT_API void ewk_context_preferred_languages_set(Eina_List* languages);
293
294 /**
295  * @if MOBILE
296  * @brief Requests for deleting all web indexed databases.
297  *
298  * @since_tizen 2.4
299  *
300  * @param[in] context Context object
301  *
302  * @return @c EINA_TRUE on success, otherwise @c EINA_FALSE
303  * @endif
304  */
305 EXPORT_API Eina_Bool ewk_context_web_indexed_database_delete_all(Ewk_Context* context);
306
307 /**
308  * @if MOBILE
309  * @brief Deletes web storage.
310  *
311  * @details This function does not ensure that all data will be removed.
312  *          Should be used to extend free physical memory.
313  *
314  * @since_tizen 2.4
315  *
316  * @param[in] context Context object
317  *
318  * @return @c EINA_TRUE on success, otherwise @c EINA_FALSE
319  * @endif
320  */
321 EXPORT_API Eina_Bool ewk_context_web_storage_delete_all(Ewk_Context* context);
322
323 /**
324  * @brief   Callback for intercept request feature.
325  *
326  * @details Ewk_Context_Intercept_Request_Callback callback allows host
327  *          application to intercept a resource request and write custom
328  *          response.
329  *
330  * @warning Callback is not called on UI thread, so user should be cautious
331  *          when accessing their data also used on UI thread. No ewk api other
332  *          than ewk_intercept_request_* api should be used in the callback.
333  *
334  * @remarks Inside the callback user can use the following EWK API calls on
335  *          a given Ewk_Intercept_Request instance to decide if request should
336  *          be intercepted or handled normally:
337  *          - ewk_intercept_request_url_get
338  *          - ewk_intercept_request_http_method_get
339  *          - ewk_intercept_request_headers_get
340  *
341  *          To let engine handle the request normally, use
342  *          ewk_intercept_request_ignore *inside* the callback. Using it later
343  *          results in undefined behavior.
344  *
345  *          To respond to a request with a custom response, use
346  *          ewk_intercept_request_response_set or
347  *          ewk_intercept_request_response_body_set inside or outside the
348  *          callback. Using it outside of the callback is advised for better
349  *          responsiveness. If your responses take too much time to prepare, it
350  *          would block handling other requests. You can also use
351  *          ewk_intercept_request_response_write outside the callback to write
352  *          response in chunks.
353  *
354  *          Handling a request is done after using either
355  *          ewk_intercept_request_ignore, ewk_intercept_request_response_set,
356  *          ewk_intercept_request_response_body_set, and in some cases after
357  *          ewk_intercept_request_response_write_chunk.
358  *
359  *          Further EWK API calls on this Ewk_Intercept_Request instance result
360  *          in undefined behavior.
361  *
362  *          Failing to call one of these functions results in leaking
363  *          Ewk_Intercept_Request object.
364  *
365  * @since_tizen 3.0
366  *
367  * @param[in] ewk_context Ewk_Context for which callback was set
368  * @param[in] intercept_request Intercept request object for reading request
369  *            info and writing response data
370  * @param[in] user_data User data passed to
371  *            ewk_context_intercept_request_callback_set
372  */
373 typedef void (*Ewk_Context_Intercept_Request_Callback)(Ewk_Context* ewk_context, Ewk_Intercept_Request* intercept_request, void* user_data);
374
375 /**
376  * @brief   Sets Ewk_Context_Intercept_Request_Callback
377  *
378  * @details Sets Ewk_Context_Intercept_Request_Callback to give a chance to
379  *          intercept resource request before sending it and return a custom
380  *          response.
381  *
382  * @remarks Pass NULL pointer as @a callback to reset current callback.
383  *
384  * @since_tizen 3.0
385  *
386  * @param[in] ewk_context Ewk_Context object to intercept requests
387  * @param[in] callback New callback, NULL resets current callback
388  * @param[in] user_data User data passed to @a callback
389  *
390  * @see Ewk_Context_Intercept_Request_Callback
391  */
392 EXPORT_API void ewk_context_intercept_request_callback_set(Ewk_Context* ewk_context, Ewk_Context_Intercept_Request_Callback callback, void* user_data);
393
394 /**
395 * @}
396 */
397
398 #ifdef __cplusplus
399 }
400 #endif
401
402 #endif // ewk_context_h