| 1 | ---- |
| 2 | This tutorial is an effect of collaboration between Samsung Poland R&D Center and Silesian Univeristy of Technology. It's a part of subject: "Writing tutorial about a WebKit-Efl API" |
| 3 | |
| 4 | Author: Krzysztof Kuliga (kkrzysiek89 [at] interia.pl) |
| 5 | |
| 6 | ---- |
| 7 | === The Settings API === |
| 8 | |
| 9 | === Introduction === |
| 10 | |
| 11 | The ewk_cookies.h file is designed to manage the browser cookies. It has all of the important functions needed to use cookies (create cookie, delete,) and change their properties(change cookies policy). |
| 12 | |
| 13 | === Dependency diagram === |
| 14 | Parts of WebCore and libraries which are related to ewk_cookies.h |
| 15 | |
| 16 | [[Image(http://i.imgur.com/EmopC.jpg)]] |
| 17 | |
| 18 | === API Module Description=== |
| 19 | |
| 20 | === Initialization === |
| 21 | |
| 22 | Firstly initialization of the module depends on definition of the cookie object. After creating or during that operation we are obliged to define all the cookie object properties like for example: name, value, domain, path, expiration date. Closer look we will have in the example of use. |
| 23 | |
| 24 | === Objects Modification === |
| 25 | |
| 26 | After we created the object and define all of its important values/properties we can do some modifications. The ewk_cookies.h file provides us declaration on several functions that modificate cookie state. Functions: |
| 27 | * EAPI Eina_Bool ewk_cookies_file_set (const char * filename) |
| 28 | * EAPI void ewk_cookies_policy_set (Ewk_Cookie_Policy p) |
| 29 | * EAPI Eina_List* ewk_cookies_get_all (void ) |
| 30 | * EAPI Ewk_Cookie_Policy ewk_cookies_policy_get (void ) |
| 31 | |
| 32 | === Example of use === |
| 33 | |
| 34 | {{{ |
| 35 | #include "ewk_cookies.h" // including the library |
| 36 | |
| 37 | // modifying the function that is used after each load of the site |
| 38 | static void on_load_finished(void *user_data, Evas_Object *webview, void *event_info) |
| 39 | { |
| 40 | Ewk_cookie *cookie = new Ewk_cookie(); // defining the cookie pointer |
| 41 | Eina_list *list = 0; // defining list for storing all the webpage cookies |
| 42 | const Ewk_Frame_Load_Error *err = (const Ewk_Frame_Load_Error *)event_info; |
| 43 | const char* text = "~src/Webkit/cookies"; |
| 44 | if (!err) |
| 45 | info("Succeeded loading page.\n"); |
| 46 | else if (err->is_cancellation) |
| 47 | info("Load was cancelled.\n"); |
| 48 | else |
| 49 | info("Failed loading page: %d %s \"%s\", url=%s\n", |
| 50 | err->code, err->domain, err->description, err->failing_url); |
| 51 | |
| 52 | // checking if any path for storing cookies is set |
| 53 | if(ewk_cookies_file_set(*text)) |
| 54 | { |
| 55 | //defining cookie properties |
| 56 | cookie->name = "first_cookie"; //example name for cookie |
| 57 | cookie->value = 1; |
| 58 | cookie->domain = err->domain; // we get info about domain from err pointer |
| 59 | cookie->path = *text; // setting path which is stored in global variable |
| 60 | cookie->expires = 0; // setting cookie expiration time |
| 61 | |
| 62 | ewk_cookies_policy_set(SOUP_COOKIE_JAR_ACCEPT_ALWAYS); //setting cookie policy |
| 63 | } |
| 64 | else //when we can't set our path for storing cookies |
| 65 | { |
| 66 | info("Unable to set path where cookies to be stored.\n"); |
| 67 | ewk_cookies_policy_set(SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY); |
| 68 | } |
| 69 | list = ewk_cookies_get_all(); // we get all the cookies into list variable |
| 70 | currentZoom = ewk_view_zoom_get(webview); |
| 71 | currentZoomLevel = nearest_zoom_level_get(currentZoom); |
| 72 | info("WebCore Zoom=%f, currentZoomLevel=%d\n", currentZoom, currentZoomLevel); |
| 73 | } |
| 74 | }}} |
| 75 | |
| 76 | Example is based on the Tools/EWebLauncher/main.c. |