[EFL] Locate color picker popup to center of window
[WebKit-https.git] / Tools / MiniBrowser / efl / main.c
1 /*
2  * Copyright (C) 2012 Samsung Electronics
3  * Copyright (C) 2012 Intel Corporation. All rights reserved.
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Lesser General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public
16  *  License along with this library; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 #include "EWebKit2.h"
21 #include <Ecore.h>
22 #include <Ecore_Evas.h>
23 #include <Ecore_Getopt.h>
24 #include <Eet.h>
25 #include <Eina.h>
26 #include <Elementary.h>
27 #include <Evas.h>
28
29 extern int efreet_cache_update;
30
31 static const char DEFAULT_URL[] = "http://www.ewebkit.org/";
32 static const char APP_NAME[] = "EFL MiniBrowser";
33 static const char JAVASCRIPT_SCHEME[] = "javascript:";
34 static const char FILE_SCHEME[] = "file://";
35 static const char HTTP_SCHEME[] = "http://";
36 static const int TOOL_BAR_ICON_SIZE = 24;
37 static const int TOOL_BAR_BUTTON_SIZE = 32;
38 static const int SEARCH_FIELD_SIZE = 200;
39 static const int SEARCH_BUTTON_SIZE = 30;
40 static const int MAX_SEARCH_COUNT = 1000;
41 static const double TOOLTIP_DELAY_SECONDS = 1.0;
42 static const double LONGPRESS_INTERVAL_SECONDS = 1.5;
43 static const double LIST_ITEM_HEIGHT = 24.35;
44
45 static Eina_List *windows = NULL;
46 static char *evas_engine_name = NULL;
47 static char *user_agent_string = NULL;
48 static char *extensions_path = NULL;
49 static char *background_color_string = NULL;
50 static Eina_Bool encoding_detector_enabled = EINA_FALSE;
51 static Eina_Bool frame_flattening_enabled = EINA_FALSE;
52 static Eina_Bool local_storage_enabled = EINA_TRUE;
53 static Eina_Bool offline_web_application_cache_enabled = EINA_TRUE;
54 static Eina_Bool fullscreen_enabled = EINA_FALSE;
55 static Eina_Bool spell_checking_enabled = EINA_FALSE;
56 static Eina_Bool web_security_enabled = EINA_TRUE;
57 static Eina_Bool touch_events_enabled = EINA_FALSE;
58 static Eina_Bool fixed_layout_enabled = EINA_TRUE;
59 static Eina_Bool separated_process_enabled = EINA_FALSE;
60 static Eina_Bool longpress_enabled = EINA_FALSE;
61 static int window_width = 1000;
62 static int window_height = 800;
63 static int color_picker_width = 350;
64 static int color_picker_height = 500;
65 static int search_flags = EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_WRAP_AROUND | EWK_FIND_OPTIONS_CASE_INSENSITIVE;
66 /* Default value of device_pixel_ratio is '0' so that we don't set custom device
67  * scale factor unless it's required by the User. */
68 static double device_pixel_ratio = 0;
69 static Eina_Bool legacy_behavior_enabled = EINA_FALSE;
70
71 #define DEFAULT_ZOOM_LEVEL 5 // Set default zoom level to 1.0 (index 5 on zoomLevels).
72 // The zoom values are chosen to be like in Mozilla Firefox 3.
73 const static float zoomLevels[] = {0.3, 0.5, 0.67, 0.8, 0.9, 1.0, 1.1, 1.2, 1.33, 1.5, 1.7, 2.0, 2.4, 3.0};
74 static int _log_domain_id = -1;
75
76 #define INFO(...) EINA_LOG_DOM_INFO(_log_domain_id, __VA_ARGS__)
77 #define ERROR(...) EINA_LOG_DOM_ERR(_log_domain_id, __VA_ARGS__)
78
79 static Eina_Bool
80 zoom_level_set(Evas_Object *webview, int level)
81 {
82    if (level < 0  || level >= sizeof(zoomLevels) / sizeof(float))
83      return EINA_FALSE;
84
85    return ewk_view_page_zoom_set(webview, zoomLevels[level]);
86 }
87
88 static Ewk_View_Smart_Class *miniBrowserViewSmartClass()
89 {
90    static Ewk_View_Smart_Class ewkViewClass = EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION("MiniBrowser_View");
91    return &ewkViewClass;
92 }
93
94 typedef struct _Tooltip_Information {
95    Ecore_Timer *show_timer;
96    Eina_Bool activated;
97    Eina_Bool text_set;
98    Eina_Bool shown;
99 } Tooltip_Information;
100
101 typedef struct _Color_Selector {
102    Ewk_Color_Picker *ewk_picker;
103    Evas_Object *elm_selector;
104    Evas_Object *elm_selector_window;
105 } Color_Selector;
106
107 typedef struct _Browser_Window {
108    Evas_Object *elm_window;
109    Evas_Object *ewk_view;
110    Evas_Object *horizontal_layout;
111    Evas_Object *vertical_layout;
112    Evas_Object *url_bar;
113    Evas_Object *back_button;
114    Evas_Object *forward_button;
115    struct {
116      Evas_Object *elm_menu;
117      Ewk_Popup_Menu *ewk_menu;
118     } popup;
119    struct {
120      Evas_Object *search_bar;
121      Evas_Object *search_field;
122      Evas_Object *search_field_count;
123      Evas_Object *backward_button;
124      Evas_Object *forward_button;
125      Evas_Object *search_case_check_box;
126      Evas_Object *search_word_start_check_box;
127      Evas_Object *close_button;
128    } search;
129    struct {
130      Evas_Object *history_box;
131      Evas_Object *history_list;
132      Eina_List *history_list_items;
133    } history;
134    int current_zoom_level;
135    Tooltip_Information tooltip;
136    Color_Selector color_selector;
137    struct {
138      Evas_Object *elm_menu;
139      Ewk_Context_Menu *ewk_menu;
140    } context_menu;
141 } Browser_Window;
142
143 typedef struct _File_Selector_Data {
144    Browser_Window* parent;
145    Evas_Object *elm_window;
146    Ewk_File_Chooser_Request *request;
147 } File_Selector_Data;
148
149 typedef struct _Auth_Data {
150    Evas_Object *popup;
151    Ewk_Auth_Request *request;
152    Evas_Object *username_entry;
153    Evas_Object *password_entry;
154 } Auth_Data;
155
156 static const Ecore_Getopt options = {
157    "MiniBrowser",
158    "%prog [options] [url]",
159    "0.0.1",
160    "(C)2012 Samsung Electronics\n (C)2012 Intel Corporation\n",
161    "",
162    "Test Web Browser using the Enlightenment Foundation Libraries (EFL) port of WebKit2",
163    EINA_TRUE, {
164      ECORE_GETOPT_STORE_STR
165          ('e', "engine", "Ecore-evas engine to use."),
166      ECORE_GETOPT_STORE_STR
167          ('s', "window-size", "Window size in following format (width)x(height)."),
168      ECORE_GETOPT_STORE_STR
169          ('u', "user-agent", "User agent to set."),
170      ECORE_GETOPT_STORE_STR
171          ('x', "extensions-path", "The path which extensions are stored."),
172      ECORE_GETOPT_STORE_DOUBLE
173          ('r', "device-pixel-ratio", "Ratio between the CSS units and device pixels."),
174      ECORE_GETOPT_CALLBACK_NOARGS
175          ('E', "list-engines", "List ecore-evas engines.",
176           ecore_getopt_callback_ecore_evas_list_engines, NULL),
177      ECORE_GETOPT_STORE_DEF_BOOL
178          ('c', "encoding-detector", "Enable/disable encoding detector.", EINA_FALSE),
179      ECORE_GETOPT_STORE_STR
180          ('C', "background-color", "Background color of page. ex) -C=255:255:255:255"),
181      ECORE_GETOPT_STORE_DEF_BOOL
182          ('f', "flattening", "Enable/disable frame flattening.", EINA_FALSE),
183      ECORE_GETOPT_STORE_DEF_BOOL
184          ('l', "local-storage", "Enable/disable HTML5 local storage.", EINA_TRUE),
185      ECORE_GETOPT_STORE_DEF_BOOL
186          ('o', "offline-web-application-cache", "Enable/disable offline web application cache.", EINA_TRUE),
187      ECORE_GETOPT_STORE_DEF_BOOL
188          ('F', "full-screen", "Start in full-screen.", EINA_FALSE),
189      ECORE_GETOPT_STORE_DEF_BOOL
190          ('t', "text-checking", "Enable/disable text spell checking.", EINA_FALSE),
191      ECORE_GETOPT_STORE_DEF_BOOL
192          ('T', "touch-events", "Enable/disable touch events.", EINA_FALSE),
193      ECORE_GETOPT_STORE_DEF_BOOL
194          ('L', "fixed-layout", "Enable/disable fixed layout.", EINA_TRUE),
195      ECORE_GETOPT_STORE_DEF_STR
196          ('p', "policy-cookies", "Cookies policy:\n  always - always accept,\n  never - never accept,\n  no-third-party - don't accept third-party cookies.", "no-third-party"),
197      ECORE_GETOPT_STORE_DEF_BOOL
198          ('w', "web-security", "enable/disable web security.", EINA_TRUE),
199      ECORE_GETOPT_STORE_DEF_BOOL
200          ('S', "separate-process", "Create new window in separated web process.", EINA_FALSE),
201      ECORE_GETOPT_VERSION
202          ('V', "version"),
203      ECORE_GETOPT_COPYRIGHT
204          ('R', "copyright"),
205      ECORE_GETOPT_HELP
206          ('h', "help"),
207      ECORE_GETOPT_SENTINEL
208    }
209 };
210
211 static Eina_Stringshare *_file_entry_dialog_show(Browser_Window *window, const char *label_tag, const char *default_text);
212 static Browser_Window *window_create(Ewk_View_Configuration* configuration, int width, int height);
213 static Ewk_View_Configuration* configuration();
214
215 static Browser_Window *window_find_with_elm_window(Evas_Object *elm_window)
216 {
217    Eina_List *l;
218    void *data;
219
220    if (!elm_window)
221      return NULL;
222
223    EINA_LIST_FOREACH(windows, l, data) {
224      Browser_Window *window = (Browser_Window *)data;
225      if (window->elm_window == elm_window)
226        return window;
227    }
228    return NULL;
229 }
230
231 static Browser_Window *window_find_with_ewk_view(Evas_Object *ewk_view)
232 {
233    Eina_List *l;
234    void *data;
235
236    if (!ewk_view)
237      return NULL;
238
239    EINA_LIST_FOREACH(windows, l, data) {
240      Browser_Window *window = (Browser_Window *)data;
241      if (window->ewk_view == ewk_view)
242        return window;
243    }
244    return NULL;
245 }
246
247 static Eina_Bool
248 _tooltip_show(void *user_data)
249 {
250    Browser_Window *window = (Browser_Window *)user_data;
251
252    window->tooltip.show_timer = NULL;
253    elm_object_tooltip_show(window->elm_window);
254    window->tooltip.shown = EINA_TRUE;
255    return ECORE_CALLBACK_CANCEL;
256 }
257
258 static void
259 window_tooltip_hide(Browser_Window *window)
260 {
261    if (window->tooltip.show_timer) {
262      ecore_timer_del(window->tooltip.show_timer);
263      window->tooltip.show_timer = NULL;
264    }
265
266    if (window->tooltip.shown) {
267      elm_object_tooltip_hide(window->elm_window);
268      window->tooltip.shown = EINA_FALSE;
269    }
270 }
271
272 static void
273 window_tooltip_update(Browser_Window *window)
274 {
275    window_tooltip_hide(window);
276
277    if (window->tooltip.activated && window->tooltip.text_set)
278      window->tooltip.show_timer = ecore_timer_add(TOOLTIP_DELAY_SECONDS, _tooltip_show, window);
279 }
280
281 static void
282 _mouse_in_cb(void *user_data, Evas *e, Evas_Object *ewk_view, void *event_info)
283 {
284    Browser_Window *window = (Browser_Window *)user_data;
285
286    window->tooltip.activated = EINA_TRUE;
287    window_tooltip_update(window);
288 }
289
290 static void
291 _mouse_move_cb(void *user_data, Evas *e, Evas_Object *ewk_view, void *event_info)
292 {
293    window_tooltip_update((Browser_Window *)user_data);
294 }
295
296 static void
297 _mouse_out_cb(void *user_data, Evas *e, Evas_Object *ewk_view, void *event_info)
298 {
299    Browser_Window *window = (Browser_Window *)user_data;
300
301    window->tooltip.activated = EINA_FALSE;
302    window_tooltip_update(window);
303 }
304
305 static void
306 _mouse_wheel_cb(void *user_data, Evas *e, Evas_Object *ewk_view, void *event_info)
307 {
308    Browser_Window *window = (Browser_Window *)user_data;
309    const Evas_Modifier *mod = evas_key_modifier_get(e);
310    Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel *)event_info;
311    Eina_Bool shiftPressed = evas_key_modifier_is_set(mod, "Shift");
312    Eina_Bool ctrlPressed = evas_key_modifier_is_set(mod, "Control");
313
314    if (!shiftPressed && !ctrlPressed)
315      return;
316
317    /* navigate history or zoom web page based on mouse wheel scroll action with shift or control key */
318    if (shiftPressed) {
319      if (ev->z == -1 && ewk_view_forward_possible(ewk_view)) {
320        ewk_view_forward(ewk_view);
321        elm_object_disabled_set(window->forward_button, !ewk_view_forward_possible(ewk_view));
322      } else if (ev->z == 1 && ewk_view_back_possible(ewk_view)) {
323        ewk_view_back(ewk_view);
324        elm_object_disabled_set(window->back_button, !ewk_view_back_possible(ewk_view));
325      }
326    } else if (ctrlPressed) {
327      if (ev->z == -1 && zoom_level_set(ewk_view, window->current_zoom_level + 1)) {
328        window->current_zoom_level++;
329        INFO("Zoom in (Ctrl + 'scroll up') was pressed, zoom level became %.2f", zoomLevels[window->current_zoom_level]);
330      } else if (ev->z == 1 && zoom_level_set(ewk_view, window->current_zoom_level - 1)) {
331        window->current_zoom_level--;
332        INFO("Zoom out (Ctrl + 'scroll down') was pressed, zoom level became %.2f", zoomLevels[window->current_zoom_level]);
333      }
334    }
335 }
336
337 static void
338 _window_resize_cb(void *user_data, Evas *e, Evas_Object *elm_window, void *event_info)
339 {
340    Browser_Window *window = (Browser_Window *)user_data;
341
342    if (!window) {
343      ERROR("Window is NULL.");
344      return;
345    }
346
347    if (window->context_menu.ewk_menu)
348      ewk_context_menu_hide(window->context_menu.ewk_menu);
349    if (window->popup.ewk_menu)
350      ewk_popup_menu_close(window->popup.ewk_menu);
351    if (window->popup.elm_menu)
352      elm_menu_close(window->popup.elm_menu);
353 }
354
355 static void
356 update_view_favicon(Browser_Window *window, Evas_Object *icon)
357 {
358    /* Remove previous icon from URL bar */
359    Evas_Object *old_icon = elm_object_part_content_unset(window->url_bar, "icon");
360    if (old_icon) {
361      evas_object_unref(old_icon);
362      evas_object_del(old_icon);
363    }
364
365    /* Show new icon in URL bar */
366    if (icon) {
367      evas_object_size_hint_min_set(icon, 32, 32);
368      elm_object_part_content_set(window->url_bar, "icon", icon);
369      evas_object_ref(icon);
370    }
371 }
372
373 static void
374 _icon_changed_cb(Ewk_Favicon_Database *database, const char *url, void *user_data)
375 {
376    Browser_Window *window = (Browser_Window *)user_data;
377    Evas_Object *ewk_view = window->ewk_view;
378
379    if (strcmp(url, ewk_view_url_get(ewk_view)))
380      return;
381
382    Evas_Object *favicon = ewk_favicon_database_icon_get(database, url, evas_object_evas_get(ewk_view));
383    update_view_favicon(window, favicon);
384
385    if (favicon)
386      evas_object_unref(favicon);
387 }
388
389 static void window_free(Browser_Window *window)
390 {
391    evas_object_event_callback_del(window->ewk_view, EVAS_CALLBACK_MOUSE_IN, _mouse_in_cb);
392    evas_object_event_callback_del(window->ewk_view, EVAS_CALLBACK_MOUSE_OUT, _mouse_out_cb);
393    evas_object_event_callback_del(window->ewk_view, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move_cb);
394    evas_object_event_callback_del(window->ewk_view, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb);
395
396    evas_object_event_callback_del(window->elm_window, EVAS_CALLBACK_RESIZE, _window_resize_cb);
397
398    ewk_favicon_database_icon_change_callback_del(ewk_context_favicon_database_get(ewk_view_context_get(window->ewk_view)), _icon_changed_cb);
399
400    evas_object_del(window->ewk_view);
401    /* The elm_win will take care of freeing its children */
402    evas_object_del(window->elm_window);
403
404    if (window->tooltip.show_timer)
405      ecore_timer_del(window->tooltip.show_timer);
406
407    if (window->color_selector.elm_selector_window)
408      evas_object_del(window->color_selector.elm_selector_window);
409
410    free(window);
411 }
412
413 static void window_close(Browser_Window *window)
414 {
415    windows = eina_list_remove(windows, window);
416    window_free(window);
417
418    if (!windows)
419      elm_exit();
420 }
421
422 static void
423 search_icon_show(Browser_Window *window)
424 {
425    Evas_Object *icon = elm_icon_add(window->elm_window);
426    elm_icon_standard_set(icon, "edit-find");
427    elm_object_part_content_set(window->search.search_field, "icon", icon);
428    evas_object_size_hint_min_set(icon, 20, 20);
429    evas_object_size_hint_max_set(icon, 20, 20);
430    elm_entry_icon_visible_set(window->search.search_field, EINA_TRUE);
431    evas_object_show(icon);
432 }
433
434 static void
435 search_box_show(Browser_Window *window)
436 {
437    evas_object_size_hint_min_set(window->search.search_bar, SEARCH_FIELD_SIZE + 2 * SEARCH_BUTTON_SIZE, SEARCH_BUTTON_SIZE);
438
439    search_icon_show(window);
440    evas_object_show(window->search.search_bar);
441    evas_object_show(window->search.search_field);
442    evas_object_show(window->search.search_field_count);
443    evas_object_show(window->search.backward_button);
444    evas_object_show(window->search.forward_button);
445    evas_object_show(window->search.search_case_check_box);
446    evas_object_show(window->search.search_word_start_check_box);
447    evas_object_show(window->search.close_button);
448
449    /* Grab focus from the view */
450    evas_object_focus_set(window->ewk_view, EINA_FALSE);
451    elm_object_focus_set(window->search.search_field, EINA_TRUE);
452 }
453
454 static void
455 search_box_hide(Browser_Window *window)
456 {
457    ewk_view_text_find_highlight_clear(window->ewk_view);
458
459    evas_object_size_hint_min_set(window->search.search_bar, SEARCH_FIELD_SIZE + 2 * SEARCH_BUTTON_SIZE, 0);
460    evas_object_hide(window->search.search_bar);
461    evas_object_hide(window->search.search_field);
462    evas_object_hide(window->search.search_field_count);
463    evas_object_hide(window->search.backward_button);
464    evas_object_hide(window->search.forward_button);
465    evas_object_hide(window->search.search_case_check_box);
466    evas_object_hide(window->search.search_word_start_check_box);
467    evas_object_hide(window->search.close_button);
468
469    /* Give focus back to the view */
470    elm_object_focus_set(window->search.search_field, EINA_FALSE);
471    evas_object_focus_set(window->ewk_view, EINA_TRUE);
472 }
473
474 static void
475 history_list_hide(Browser_Window *window)
476 {
477    /* Hide history list */
478    evas_object_hide(window->history.history_box);
479    evas_object_hide(window->history.history_list);
480
481    /* Dereference the list items and clear the history list */
482    void *data;
483    EINA_LIST_FREE(window->history.history_list_items, data) {
484        ewk_object_unref(data);
485    }
486
487    elm_genlist_clear(window->history.history_list);
488
489    /* Give focus back to the view */
490    elm_object_focus_set(window->history.history_box, EINA_FALSE);
491    elm_object_focus_set(window->history.history_list, EINA_FALSE);
492    evas_object_focus_set(window->ewk_view, EINA_TRUE);
493
494    /* Reset flags */
495    longpress_enabled = EINA_FALSE;
496 }
497
498 static void save_page_contents_callback(Ewk_Page_Contents_Type type, const char *data, void *user_data)
499 {
500    Eet_File *ef;
501    Eina_Stringshare *fileName = (Eina_Stringshare *)user_data;
502
503    if (!eina_str_has_extension(fileName, ".mht")) {
504      Eina_Strbuf *fileNameWithMht = eina_strbuf_new();
505      eina_strbuf_append_printf(fileNameWithMht, "%s.mht", fileName);
506      ef = eet_open(eina_strbuf_string_get(fileNameWithMht), EET_FILE_MODE_WRITE);
507      INFO("Saving file to: %s", eina_strbuf_string_get(fileNameWithMht));
508      eina_strbuf_free(fileNameWithMht);
509    } else {
510      ef = eet_open(fileName, EET_FILE_MODE_WRITE);
511      INFO("Saving file to: %s", fileName);
512    }
513
514    if (!ef) {
515      ERROR("Could not create File");
516      return;
517    }
518
519    eet_write(ef, "MHTML data", data, strlen(data), 0 /* compress */);
520    eet_close(ef);
521    INFO("SUCCESS: saved.");
522
523    eina_stringshare_del(fileName);
524 }
525
526 static void
527 script_execute_callback(Evas_Object *ewk_view, const char *return_value, void *user_data)
528 {
529    Browser_Window *window = (Browser_Window *)user_data;
530
531    Eina_Strbuf *text_buffer = eina_strbuf_new();
532
533    if (return_value) {
534      eina_strbuf_append(text_buffer, return_value);
535      INFO("selected text is: %s", eina_strbuf_string_get(text_buffer));
536      elm_entry_entry_set(window->search.search_field, eina_strbuf_string_get(text_buffer));
537    }
538    eina_strbuf_free(text_buffer);
539    search_box_show(window);
540 }
541
542 static void
543 toggle_window_fullscreen(Browser_Window *window, Eina_Bool isFullScreen)
544 {
545    if (isFullScreen) {
546      evas_object_hide(window->horizontal_layout);
547      elm_box_unpack(window->vertical_layout, window->horizontal_layout);
548      elm_win_fullscreen_set(window->elm_window, EINA_TRUE);
549    } else {
550      elm_win_fullscreen_set(window->elm_window, EINA_FALSE);
551      elm_box_pack_start(window->vertical_layout, window->horizontal_layout);
552       evas_object_show(window->horizontal_layout);
553    }
554 }
555
556 static void
557 _key_down_cb(void *user_data, Evas *e, Evas_Object *ewk_view, void *event_info)
558 {
559    Browser_Window *window = (Browser_Window *)user_data;
560    Evas_Event_Key_Down *ev = (Evas_Event_Key_Down*) event_info;
561
562    static const char *encodings[] = {
563      "ISO-8859-1",
564      "UTF-8",
565      NULL
566    };
567    static int currentEncoding = -1;
568    const Evas_Modifier *mod = evas_key_modifier_get(e);
569    Eina_Bool ctrlPressed = evas_key_modifier_is_set(mod, "Control");
570    Eina_Bool altPressed = evas_key_modifier_is_set(mod, "Alt");
571    Eina_Bool shiftPressed = evas_key_modifier_is_set(mod, "Shift");
572
573    if (!strcmp(ev->key, "Left") && altPressed) {
574      INFO("Back (Alt+Left) was pressed");
575      if (!ewk_view_back(ewk_view))
576        INFO("Back ignored: No back history");
577    } else if (!strcmp(ev->key, "Right") && altPressed) {
578      INFO("Forward (Alt+Right) was pressed");
579      if (!ewk_view_forward(ewk_view))
580        INFO("Forward ignored: No forward history");
581    } else if (!strcmp(ev->key, "Home") && altPressed) {
582      INFO("Home (Alt+Home) was pressed");
583      ewk_view_url_set(window->ewk_view, DEFAULT_URL);
584    } else if (!strcmp(ev->key, "F3")) {
585      currentEncoding = (currentEncoding + 1) % (sizeof(encodings) / sizeof(encodings[0]));
586      INFO("Set encoding (F3) pressed. New encoding to %s", encodings[currentEncoding]);
587      ewk_view_custom_encoding_set(ewk_view, encodings[currentEncoding]);
588    } else if ((!strcmp(ev->key, "F5") && ctrlPressed) || (!strcmp(ev->key, "r") && (shiftPressed & ctrlPressed))) {
589      INFO("Reload ignoring cache (Ctrl+F5 or Ctrl+Shift+r) was pressed, reloading and bypassing cache...");
590      ewk_view_reload_bypass_cache(ewk_view);
591    } else if (!strcmp(ev->key, "F5") || (!strcmp(ev->key, "r") && ctrlPressed)) {
592      INFO("Reload (F5 or Ctrl+r) was pressed, reloading...");
593      ewk_view_reload(ewk_view);
594    } else if (!strcmp(ev->key, "F6")) {
595      INFO("Stop (F6) was pressed, stop loading.");
596      ewk_view_stop(ewk_view);
597    } else if (!strcmp(ev->key, "F7")) {
598      Ewk_Pagination_Mode mode =  ewk_view_pagination_mode_get(ewk_view);
599      mode = (mode + 1) % (EWK_PAGINATION_MODE_BOTTOM_TO_TOP + 1);
600      if (ewk_view_pagination_mode_set(ewk_view, mode))
601        INFO("Change Pagination Mode (F7) was pressed, changed to: %d", mode);
602      else
603        INFO("Change Pagination Mode (F7) was pressed, but NOT changed!");
604    } else if (!strcmp(ev->key, "F11")) {
605      INFO("Fullscreen (F11) was pressed, toggling window/fullscreen.");
606      toggle_window_fullscreen(window, !elm_win_fullscreen_get(window->elm_window));
607    } else if (!strcmp(ev->key, "n") && ctrlPressed) {
608      INFO("Create new window (Ctrl+n) was pressed.");
609      Browser_Window *window = window_create(configuration(), 0, 0);
610      ewk_view_url_set(window->ewk_view, DEFAULT_URL);
611      // 0 equals default width and height.
612      windows = eina_list_append(windows, window);
613    } else if (!strcmp(ev->key, "i") && ctrlPressed) {
614      INFO("Show Inspector (Ctrl+i) was pressed.");
615      ewk_view_inspector_show(ewk_view);
616    } else if (!strcmp(ev->key, "f") && ctrlPressed) {
617      INFO("Show Search Box (Ctrl+f) was pressed.");
618      const char get_data_script[] = "window.getSelection().toString();";
619      ewk_view_script_execute(ewk_view, get_data_script, script_execute_callback, (void*)(window));
620    } else if (!strcmp(ev->key, "Escape")) {
621      if (evas_object_visible_get(window->search.search_bar))
622        search_box_hide(window);
623      else if (evas_object_visible_get(window->history.history_box))
624        history_list_hide(window);
625      else if (elm_win_fullscreen_get(window->elm_window))
626        ewk_view_fullscreen_exit(ewk_view);
627      else
628        ewk_view_stop(ewk_view);
629    } else if (ctrlPressed && (!strcmp(ev->key, "minus") || !strcmp(ev->key, "KP_Subtract"))) {
630      if (zoom_level_set(ewk_view, window->current_zoom_level - 1))
631        window->current_zoom_level--;
632      INFO("Zoom out (Ctrl + '-') was pressed, zoom level became %.2f", zoomLevels[window->current_zoom_level]);
633    } else if (ctrlPressed && (!strcmp(ev->key, "equal") || !strcmp(ev->key, "KP_Add"))) {
634      if (zoom_level_set(ewk_view, window->current_zoom_level + 1))
635        window->current_zoom_level++;
636      INFO("Zoom in (Ctrl + '+') was pressed, zoom level became %.2f", zoomLevels[window->current_zoom_level]);
637    } else if (ctrlPressed && !strcmp(ev->key, "0")) {
638      if (zoom_level_set(ewk_view, DEFAULT_ZOOM_LEVEL))
639        window->current_zoom_level = DEFAULT_ZOOM_LEVEL;
640      INFO("Zoom to default (Ctrl + '0') was pressed, zoom level became %.2f", zoomLevels[window->current_zoom_level]);
641    } else if (ctrlPressed && !strcmp(ev->key, "s")) {
642      Eina_Strbuf *default_file = eina_strbuf_new();
643      const char *home_path = getenv("HOME");
644      const char *title = ewk_view_title_get(window->ewk_view);
645      eina_strbuf_append_printf(default_file, "%s/%s.mht", home_path ? home_path : "/home", title ? title : "title");
646      INFO("Pressed (CTRL + S) : Saving Current Page.");
647      Eina_Stringshare *save_file_name = _file_entry_dialog_show(window, "SAVE", eina_strbuf_string_get(default_file));
648      if (!save_file_name)
649        return;
650      ewk_view_page_contents_get(ewk_view, EWK_PAGE_CONTENTS_TYPE_MHTML, save_page_contents_callback, (void *)save_file_name);
651      eina_strbuf_free(default_file);
652    } else if (ctrlPressed && !strcmp(ev->key, "l")) {
653      const char *home_path =  getenv("HOME");
654      Eina_Stringshare *open_file_name = _file_entry_dialog_show(window, "LOAD", home_path ? home_path : "/home");
655      if (!open_file_name)
656        return;
657      Eina_Strbuf *uri_path = eina_strbuf_new();
658      eina_strbuf_append_printf(uri_path, "%s%s", FILE_SCHEME, open_file_name);
659      INFO("pressed (CTRL + L) : Loading Page %s", eina_strbuf_string_get(uri_path));
660      ewk_view_url_set(ewk_view, eina_strbuf_string_get(uri_path));
661      eina_strbuf_free(uri_path);
662      eina_stringshare_del(open_file_name);
663    }
664 }
665
666 static void
667 view_focus_set(Browser_Window *window, Eina_Bool focus)
668 {
669    /* We steal focus away from elm's focus model and start to do things
670     * manually here, so elm now has no clue what's up. Tell elm that its
671     * toplevel widget is to be unfocused so elm gives up the focus */
672    elm_object_focus_set(elm_object_top_widget_get(window->elm_window), EINA_FALSE);
673    evas_object_focus_set(window->ewk_view, focus);
674 }
675
676 static void
677 _mouse_down_cb(void *user_data, Evas *e, Evas_Object *ewk_view, void *event_info)
678 {
679    Browser_Window *window = (Browser_Window *)user_data;
680    Evas_Event_Mouse_Down *ev = (Evas_Event_Mouse_Down *)event_info;
681
682    /* Clear selection from the URL bar */
683    elm_entry_select_none(window->url_bar);
684
685    if (longpress_enabled)
686      history_list_hide(window);
687    if (ev->button == 1)
688      view_focus_set(window, EINA_TRUE);
689    else if (ev->button == 2)
690      view_focus_set(window, !evas_object_focus_get(ewk_view));
691 }
692
693 static void
694 title_set(Evas_Object *elm_window, const char *title, int progress)
695 {
696    Eina_Strbuf *buffer;
697
698    if (!title || !*title) {
699      elm_win_title_set(elm_window, APP_NAME);
700      return;
701    }
702
703    buffer = eina_strbuf_new();
704    if (progress < 100)
705      eina_strbuf_append_printf(buffer, "%s (%d%%) - %s", title, progress, APP_NAME);
706    else
707      eina_strbuf_append_printf(buffer, "%s - %s", title, APP_NAME);
708
709    elm_win_title_set(elm_window, eina_strbuf_string_get(buffer));
710    eina_strbuf_free(buffer);
711 }
712
713 static void
714 _title_changed_cb(void *user_data, Evas_Object *ewk_view, void *event_info)
715 {
716    Browser_Window *window = (Browser_Window *)user_data;
717    const char *title = (const char *)event_info;
718
719    title_set(window->elm_window, title, 100);
720 }
721
722 static void
723 _url_changed_cb(void *user_data, Evas_Object *ewk_view, void *event_info)
724 {
725    Browser_Window *window = (Browser_Window *)user_data;
726    const char *url = ewk_view_url_get(window->ewk_view);
727    char *converted_url = elm_entry_utf8_to_markup(url);
728    elm_entry_entry_set(window->url_bar, converted_url);
729
730    _icon_changed_cb(ewk_context_favicon_database_get(ewk_view_context_get(ewk_view)), url, user_data);
731
732    free(converted_url);
733
734    search_box_hide(window);
735 }
736
737 static void
738 _back_forward_list_changed_cb(void *user_data, Evas_Object *ewk_view, void *event_info)
739 {
740    Browser_Window *window = (Browser_Window *)user_data;
741
742    /* Update navigation buttons state */
743    elm_object_disabled_set(window->back_button, !ewk_view_back_possible(ewk_view));
744    elm_object_disabled_set(window->forward_button, !ewk_view_forward_possible(ewk_view));
745 }
746
747 static void
748 _progress_cb(void *user_data, Evas_Object *ewk_view, void *event_info)
749 {
750    Browser_Window *window = (Browser_Window *)user_data;
751    double progress = *(double *)event_info;
752
753    title_set(window->elm_window, ewk_view_title_get(window->ewk_view), progress * 100);
754 }
755
756 static void
757 _error_cb(void *user_data, Evas_Object *ewk_view, void *event_info)
758 {
759    Eina_Strbuf *buffer;
760    const Ewk_Error *error = (const Ewk_Error *)event_info;
761
762    /* This is a cancellation, do not display the error page */
763    if (ewk_error_cancellation_get(error))
764      return;
765
766    buffer = eina_strbuf_new();
767    eina_strbuf_append_printf(buffer,
768      "<html><body><div style=\"color:#ff0000\">ERROR!</div><br><div>Code: %d<br>Description: %s<br>URL: %s</div></body</html>",
769      ewk_error_code_get(error), ewk_error_description_get(error), ewk_error_url_get(error));
770
771    ewk_view_html_string_load(ewk_view, eina_strbuf_string_get(buffer), 0, ewk_error_url_get(error));
772    eina_strbuf_free(buffer);
773 }
774
775 static void
776 _download_request_cb(Ewk_Download_Job *download, void *user_data)
777 {
778    Browser_Window *window = (Browser_Window *)user_data;
779
780    Eina_Strbuf *destination_path = eina_strbuf_new();
781
782    const char *home_path = getenv("HOME");
783    Eina_Stringshare *save_file_path = _file_entry_dialog_show(window, "DOWNLOAD", home_path ? home_path : "/tmp");
784
785    if (save_file_path)
786      eina_strbuf_append_printf(destination_path, "%s", save_file_path);
787    else
788      eina_strbuf_append(destination_path, "/tmp");
789
790    const char *suggested_name = ewk_download_job_suggested_filename_get(download);
791    if (suggested_name && *suggested_name)
792      eina_strbuf_append_printf(destination_path, "/%s", suggested_name);
793    else {
794      // Generate a unique file name since no name was suggested.
795      eina_strbuf_append(destination_path, "/downloaded-file.XXXXXX");
796      char *url = NULL;
797      url = eina_strbuf_string_steal(destination_path);
798      if (mkstemp(url) == -1) {
799        ERROR("Could not generate a unique file name.");
800        return;
801      }
802      eina_strbuf_append(destination_path, url);
803    }
804
805    ewk_download_job_destination_set(download, eina_strbuf_string_get(destination_path));
806    INFO("Downloading: %s", eina_strbuf_string_get(destination_path));
807    eina_strbuf_free(destination_path);
808    eina_stringshare_del(save_file_path);
809 }
810
811 static void _filepicker_parent_deletion_cb(void *user_data, Evas *evas, Evas_Object *elm_window, void *event);
812
813 static void close_file_picker(File_Selector_Data *fs_data)
814 {
815    evas_object_event_callback_del(fs_data->parent->elm_window, EVAS_CALLBACK_DEL, _filepicker_parent_deletion_cb);
816    evas_object_del(fs_data->elm_window);
817    ewk_object_unref(fs_data->request);
818    free(fs_data);
819 }
820
821 static void
822 _filepicker_parent_deletion_cb(void *user_data, Evas *evas, Evas_Object *elm_window, void *event)
823 {
824    close_file_picker((File_Selector_Data *)user_data);
825 }
826
827 static void
828 _filepicker_deletion_cb(void *user_data, Evas_Object *elm_window, void *event_info)
829 {
830    close_file_picker((File_Selector_Data *)user_data);
831 }
832
833 static void
834 _fileselector_done_cb(void *user_data, Evas_Object *file_selector, void *event_info)
835 {
836    File_Selector_Data *fs_data = (File_Selector_Data *)user_data;
837
838    const char *selected = (const char *)event_info;
839    if (selected && *selected)
840      ewk_file_chooser_request_file_choose(fs_data->request, selected);
841
842    close_file_picker(fs_data);
843 }
844
845 static void
846 _file_chooser_request_cb(void *user_data, Evas_Object *ewk_view, void *event_info)
847 {
848    Evas_Object *bg;
849    Browser_Window *window = (Browser_Window *)user_data;
850    Ewk_File_Chooser_Request *request = (Ewk_File_Chooser_Request *)event_info;
851
852    // Show basic file picker which does not currently support multiple files
853    // or MIME type filtering.
854    Evas_Object *elm_window = elm_win_add(window->elm_window, "file-picker-window", ELM_WIN_DIALOG_BASIC);
855    elm_win_title_set(elm_window, "File picker");
856    elm_win_modal_set(elm_window, EINA_TRUE);
857
858    bg = elm_bg_add(elm_window);
859    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
860    elm_win_resize_object_add(elm_window, bg);
861    evas_object_show(bg);
862
863    File_Selector_Data *fs_data = (File_Selector_Data *)malloc(sizeof(File_Selector_Data));
864    fs_data->parent = window;
865    fs_data->elm_window = elm_window;
866    fs_data->request = ewk_object_ref(request);
867    evas_object_smart_callback_add(elm_window, "delete,request", _filepicker_deletion_cb, fs_data);
868    evas_object_event_callback_add(window->elm_window, EVAS_CALLBACK_DEL, _filepicker_parent_deletion_cb, fs_data);
869
870    Evas_Object *file_selector = elm_fileselector_add(elm_window);
871    const char *home_path = getenv("HOME");
872    elm_fileselector_path_set(file_selector, home_path ? home_path : "/home");
873    evas_object_size_hint_weight_set(file_selector, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
874    elm_win_resize_object_add(elm_window, file_selector);
875    evas_object_show(file_selector);
876
877    evas_object_smart_callback_add(file_selector, "done", _fileselector_done_cb, fs_data);
878
879    int x, y, width, height;
880    evas_object_geometry_get(window->elm_window, &x, &y, &width, &height);
881
882    int picker_x = x + width / 2 - color_picker_width / 2;
883    int picker_y = y + height / 2 - color_picker_height / 2;
884    evas_object_geometry_set(window->color_selector.elm_selector_window, picker_x, picker_y,
885      color_picker_width, color_picker_height);
886 }
887
888 static void
889 _download_finished_cb(Ewk_Download_Job *download, void *user_data)
890 {
891    INFO("Download finished: %s",  ewk_download_job_destination_get(download));
892 }
893
894 static void
895 _download_failed_cb(Ewk_Download_Job_Error *download_error, void *user_data)
896 {
897    Ewk_Error *error = download_error->error;
898
899    INFO("Download failed! Error code: %d, Error description: %s, Error URL: %s", ewk_error_code_get(error), ewk_error_description_get(error), ewk_error_url_get(error));
900 }
901
902 static void
903 _color_changed_cb(void *data, Evas_Object *obj, void *event_info)
904 {
905    int r, g, b, a;
906
907    elm_colorselector_color_get(obj, &r, &g, &b, &a);
908    evas_object_color_set(data, r, g, b, a);
909 }
910
911 static void
912 _color_item_selected_cb(void *data, Evas_Object *obj, void *event_info)
913 {
914    int r, g, b, a;
915    Elm_Object_Item *color_item = (Elm_Object_Item *)event_info;
916
917    elm_colorselector_palette_item_color_get(color_item, &r, &g, &b, &a);
918    evas_object_color_set(data, r, g, b, a);
919 }
920
921 static void
922 _color_picker_ok_clicked_cb(void *data, Evas_Object *obj, void *event_info)
923 {
924    int r, g, b, a;
925    Color_Selector *color_selector = (Color_Selector *)data;
926
927    elm_colorselector_color_get(color_selector->elm_selector, &r, &g, &b, &a);
928    ewk_color_picker_color_set(color_selector->ewk_picker, r, g, b, a);
929 }
930
931 static void
932 _color_picker_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info)
933 {
934    int r, g, b, a;
935
936    ewk_color_picker_color_get(data, &r, &g, &b, &a);
937    ewk_color_picker_color_set(data, r, g, b, a);
938 }
939
940 static Eina_Bool
941 _color_picker_dismiss_cb(Ewk_View_Smart_Data *sd)
942 {
943    Browser_Window *window = window_find_with_ewk_view(sd->self);
944
945    evas_object_del(window->color_selector.elm_selector_window);
946    window->color_selector.elm_selector_window = NULL;
947
948    return EINA_TRUE;
949 }
950
951 static Eina_Bool
952 _color_picker_request_cb(Ewk_View_Smart_Data *sd, Ewk_Color_Picker *color_picker)
953 {
954    int r, g, b, a;
955    Evas_Object *background, *rect, *box, *button_box, *rect_frame, *cs_frame, *ok_button, *cancel_button;
956
957    Browser_Window *window = window_find_with_ewk_view(sd->self);
958    window->color_selector.elm_selector_window = elm_win_add(window->elm_window, "color selector", ELM_WIN_BASIC);
959    window->color_selector.ewk_picker = color_picker;
960
961    elm_win_title_set(window->color_selector.elm_selector_window, "Color selector");
962
963    /* Show color view */
964    background = elm_bg_add(window->color_selector.elm_selector_window);
965    evas_object_size_hint_weight_set(background, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
966    elm_win_resize_object_add(window->color_selector.elm_selector_window, background);
967    evas_object_show(background);
968
969    box = elm_box_add(window->color_selector.elm_selector_window);
970    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
971    elm_win_resize_object_add(window->color_selector.elm_selector_window, box);
972    evas_object_show(box);
973
974    rect_frame = elm_frame_add(window->color_selector.elm_selector_window);
975    evas_object_size_hint_weight_set(rect_frame, EVAS_HINT_EXPAND, 0.3);
976    evas_object_size_hint_align_set(rect_frame, EVAS_HINT_FILL, EVAS_HINT_FILL);
977    elm_object_text_set(rect_frame, "Color View");
978    elm_box_pack_end(box, rect_frame);
979    evas_object_show(rect_frame);
980
981    rect = evas_object_rectangle_add(evas_object_evas_get(window->color_selector.elm_selector_window));
982    elm_object_content_set(rect_frame, rect);
983    ewk_color_picker_color_get(window->color_selector.ewk_picker, &r, &g, &b, &a);
984    evas_object_color_set(rect, r, g, b, a);
985    evas_object_show(rect);
986
987    /* Show color selector */
988    cs_frame = elm_frame_add(window->color_selector.elm_selector_window);
989    evas_object_size_hint_weight_set(cs_frame, EVAS_HINT_EXPAND, 0.7);
990    evas_object_size_hint_align_set(cs_frame, EVAS_HINT_FILL, EVAS_HINT_FILL);
991    elm_object_text_set(cs_frame, "Color Selector");
992    elm_box_pack_end(box, cs_frame);
993    evas_object_show(cs_frame);
994
995    window->color_selector.elm_selector = elm_colorselector_add(window->color_selector.elm_selector_window);
996    elm_object_content_set(cs_frame, window->color_selector.elm_selector);
997    evas_object_show(window->color_selector.elm_selector);
998
999    /* OK, Cancel Buttons */
1000    button_box = elm_box_add(window->color_selector.elm_selector_window);
1001    elm_box_horizontal_set(button_box, EINA_TRUE);
1002    evas_object_size_hint_min_set(button_box, 200, 50);
1003    elm_box_pack_end(box, button_box);
1004    evas_object_show(button_box);
1005
1006    ok_button = elm_button_add(window->color_selector.elm_selector_window);
1007    elm_object_text_set(ok_button, "OK");
1008    elm_box_pack_end(button_box, ok_button);
1009    evas_object_show(ok_button);
1010
1011    cancel_button = elm_button_add(window->color_selector.elm_selector_window);
1012    elm_object_text_set(cancel_button, "Cancel");
1013    elm_box_pack_end(button_box, cancel_button);
1014    evas_object_show(cancel_button);
1015
1016    evas_object_smart_callback_add(ok_button, "clicked", _color_picker_ok_clicked_cb, &(window->color_selector));
1017    evas_object_smart_callback_add(cancel_button, "clicked", _color_picker_cancel_clicked_cb,
1018      window->color_selector.ewk_picker);
1019    evas_object_smart_callback_add(window->color_selector.elm_selector_window, "delete,request",
1020      _color_picker_cancel_clicked_cb, window->color_selector.ewk_picker);
1021    evas_object_smart_callback_add(window->color_selector.elm_selector, "changed", _color_changed_cb, rect);
1022    evas_object_smart_callback_add(window->color_selector.elm_selector, "color,item,selected", _color_item_selected_cb,
1023      rect);
1024
1025    int x, y, width, height;
1026    evas_object_geometry_get(window->elm_window, &x, &y, &width, &height);
1027
1028    elm_win_center(window->color_selector.elm_selector_window, EINA_TRUE, EINA_TRUE);
1029    evas_object_resize(window->color_selector.elm_selector_window, 350, 500);
1030    evas_object_show(window->color_selector.elm_selector_window);
1031
1032    return EINA_TRUE;
1033 }
1034
1035 static int
1036 quit(Eina_Bool success, const char *msg)
1037 {
1038    if (msg)
1039      success ? INFO("%s", msg) : ERROR("%s", msg);
1040
1041    eina_log_domain_unregister(_log_domain_id);
1042    ewk_object_unref(configuration());
1043    ewk_shutdown();
1044    elm_shutdown();
1045
1046    if (!success)
1047      return EXIT_FAILURE;
1048
1049    return EXIT_SUCCESS;
1050 }
1051
1052 static Eina_Bool
1053 has_scheme(const char *url)
1054 {
1055    return !!strstr(url, "://");
1056 }
1057
1058 static char *
1059 url_from_user_input(const char *arg)
1060 {
1061    /* If it is already a URL, return the argument as is. */
1062    if (has_scheme(arg) || eina_str_has_prefix(arg, JAVASCRIPT_SCHEME) || !strcasecmp(arg, "about:blank"))
1063      return strdup(arg);
1064
1065    Eina_Strbuf *buf = eina_strbuf_manage_new(eina_file_path_sanitize(arg));
1066
1067    /* Check if the path exists. */
1068    if (ecore_file_exists(eina_strbuf_string_get(buf))) {
1069      /* File exists, convert local path to a URL. */
1070      eina_strbuf_prepend(buf, FILE_SCHEME);
1071    } else {
1072      /* The path does not exist, convert it to a URL by
1073         prepending http:// scheme:
1074         www.google.com -> http://www.google.com */
1075      eina_strbuf_string_free(buf);
1076      eina_strbuf_append_printf(buf, "%s%s", HTTP_SCHEME, arg);
1077    }
1078    char *url = eina_strbuf_string_steal(buf);
1079    eina_strbuf_free(buf);
1080
1081    return url;
1082 }
1083
1084 static Eina_Bool
1085 url_load_from_user_input(Evas_Object *ewk_view, const char *url)
1086 {
1087    if (!ewk_view || !url)
1088      return EINA_FALSE;
1089
1090    if (eina_str_has_prefix(url, JAVASCRIPT_SCHEME))
1091      return ewk_view_script_execute(ewk_view, strstr(url, JAVASCRIPT_SCHEME), 0, 0);
1092
1093    return ewk_view_url_set(ewk_view, url);
1094 }
1095
1096 static void
1097 _url_bar_activated_cb(void *user_data, Evas_Object *url_bar, void *event_info)
1098 {
1099    Browser_Window *window = (Browser_Window *)user_data;
1100
1101    const char *markup_url = elm_entry_entry_get(url_bar);
1102    char *user_url = elm_entry_markup_to_utf8(markup_url);
1103    char *url = url_from_user_input(user_url);
1104    url_load_from_user_input(window->ewk_view, url);
1105
1106    free(user_url);
1107    free(url);
1108
1109    /* Give focus back to the view */
1110    view_focus_set(window, EINA_TRUE);
1111 }
1112
1113 static void
1114 _url_bar_clicked_cb(void *user_data, Evas_Object *url_bar, void *event_info)
1115 {
1116    Browser_Window *window = (Browser_Window *)user_data;
1117
1118    /* Grab focus from the view */
1119    evas_object_focus_set(window->ewk_view, EINA_FALSE);
1120    elm_object_focus_set(url_bar, EINA_TRUE);
1121 }
1122
1123 static void
1124 _search_field_aborted_cb(void *user_data, Evas_Object *search_field, void *event_info)
1125 {
1126    Browser_Window *window = (Browser_Window *)user_data;
1127    search_box_hide(window);
1128
1129    /* Give focus back to the view */
1130    view_focus_set(window, EINA_TRUE);
1131 }
1132
1133 static void
1134 _search_field_activated_cb(void *user_data, Evas_Object *search_field, void *event_info)
1135 {
1136    Browser_Window *window = (Browser_Window *)user_data;
1137
1138    const char *markup_text = elm_entry_entry_get(search_field);
1139    char *text = elm_entry_markup_to_utf8(markup_text);
1140    ewk_view_text_find(window->ewk_view, text, search_flags, MAX_SEARCH_COUNT);
1141    free(text);
1142
1143    /* Grab focus from the view */
1144    evas_object_focus_set(window->ewk_view, EINA_FALSE);
1145    elm_object_focus_set(search_field, EINA_TRUE);
1146 }
1147
1148 static void
1149 _search_field_clicked_cb(void *user_data, Evas_Object *search_field, void *event_info)
1150 {
1151    Browser_Window *window = (Browser_Window *)user_data;
1152
1153    /* Grab focus from the view */
1154    evas_object_focus_set(window->ewk_view, EINA_FALSE);
1155    elm_object_focus_set(search_field, EINA_TRUE);
1156 }
1157
1158 static void
1159 _back_button_clicked_cb(void *user_data, Evas_Object *back_button, void *event_info)
1160 {
1161    if (longpress_enabled)
1162      return;
1163
1164    Browser_Window *window = (Browser_Window *)user_data;
1165
1166    ewk_view_back(window->ewk_view);
1167    /* Update back button state */
1168    elm_object_disabled_set(back_button, !ewk_view_back_possible(window->ewk_view));
1169 }
1170
1171 static void
1172 _forward_button_clicked_cb(void *user_data, Evas_Object *forward_button, void *event_info)
1173 {
1174    if (longpress_enabled)
1175      return;
1176
1177    Browser_Window *window = (Browser_Window *)user_data;
1178
1179    ewk_view_forward(window->ewk_view);
1180    /* Update forward button state */
1181    elm_object_disabled_set(forward_button, !ewk_view_forward_possible(window->ewk_view));
1182 }
1183
1184 static void
1185 _search_backward_button_clicked_cb(void *user_data, Evas_Object *search_backward_button, void *event_info)
1186 {
1187    Browser_Window *window = (Browser_Window *)user_data;
1188
1189    char *text = elm_entry_markup_to_utf8(elm_entry_entry_get(window->search.search_field));
1190    ewk_view_text_find(window->ewk_view, text, search_flags | EWK_FIND_OPTIONS_BACKWARDS, MAX_SEARCH_COUNT);
1191    free(text);
1192 }
1193
1194 static void
1195 _search_forward_button_clicked_cb(void *user_data, Evas_Object *search_forward_button, void *event_info)
1196 {
1197    Browser_Window *window = (Browser_Window *)user_data;
1198
1199    char *text = elm_entry_markup_to_utf8(elm_entry_entry_get(window->search.search_field));
1200    ewk_view_text_find(window->ewk_view, text, search_flags, MAX_SEARCH_COUNT);
1201    free(text);
1202 }
1203
1204 static void
1205 _search_case_option_changed(void *user_data, Evas_Object *search_case_check_box, void *event_info)
1206 {
1207    Browser_Window *window = (Browser_Window *)user_data;
1208    char *text = elm_entry_markup_to_utf8(elm_entry_entry_get(window->search.search_field));
1209
1210    /* Bit toggle the case sensitive flag */
1211    search_flags = search_flags ^ EWK_FIND_OPTIONS_CASE_INSENSITIVE;
1212
1213    ewk_view_text_find(window->ewk_view, text, search_flags, MAX_SEARCH_COUNT);
1214    free(text);
1215 }
1216
1217 static void
1218 _search_word_start_option_changed_cb(void *user_data, Evas_Object *search_word_start_check_box, void *event_info)
1219 {
1220    Browser_Window *window = (Browser_Window *)user_data;
1221    char *text = elm_entry_markup_to_utf8(elm_entry_entry_get(window->search.search_field));
1222
1223    /* Bit toggle the word start flag */
1224    search_flags = search_flags ^ EWK_FIND_OPTIONS_AT_WORD_STARTS;
1225
1226    ewk_view_text_find(window->ewk_view, text, search_flags, MAX_SEARCH_COUNT);
1227    free(text);
1228 }
1229
1230 static void
1231 _search_close_button_clicked_cb(void *user_data, Evas_Object *search_close_button, void *event_info)
1232 {
1233    Browser_Window *window = (Browser_Window *)user_data;
1234
1235    search_box_hide(window);
1236 }
1237
1238 static void
1239 _refresh_button_clicked_cb(void *user_data, Evas_Object *refresh_button, void *event_info)
1240 {
1241    Browser_Window *window = (Browser_Window *)user_data;
1242
1243    Evas *evas = evas_object_evas_get(refresh_button);
1244    Eina_Bool ctrlPressed = evas_key_modifier_is_set(evas_key_modifier_get(evas), "Control");
1245    if (ctrlPressed) {
1246      INFO("Reloading and bypassing cache...");
1247      ewk_view_reload_bypass_cache(window->ewk_view);
1248    } else {
1249      INFO("Reloading...");
1250      ewk_view_reload(window->ewk_view);
1251    }
1252 }
1253
1254 static void
1255 _stop_button_clicked_cb(void *user_data, Evas_Object *stop_button, void *event_info)
1256 {
1257    Browser_Window *window = (Browser_Window *)user_data;
1258
1259    INFO("Stop was Pressed. Aborting load...");
1260    ewk_view_stop(window->ewk_view);
1261 }
1262
1263 static char *
1264 list_item_label_get(void *data, Evas_Object *obj, const char *part)
1265 {
1266    int len = strlen((char *)data);
1267    char *buf = (char *)malloc(sizeof(char) * (len + 1));
1268    snprintf(buf, len + 1, "%s", (char *)data);
1269    return buf;
1270 }
1271
1272 static void
1273 _list_item_select_cb(void *user_data, Evas_Object *obj, void *event_info)
1274 {
1275    Browser_Window *window = evas_object_data_get(obj, "Browser_Window");
1276    ewk_view_navigate_to(window->ewk_view, user_data);
1277    history_list_hide(window);
1278    evas_object_data_del(obj, "Browser_Window");
1279 }
1280
1281 static void
1282 navigation_button_longpress_process(void *user_data, Eina_Bool forward_navigation_enabled)
1283 {
1284    if (longpress_enabled)
1285      return;
1286
1287    longpress_enabled = EINA_TRUE;
1288    Browser_Window *window = (Browser_Window *)user_data;
1289
1290    Ewk_Back_Forward_List *list = ewk_view_back_forward_list_get(window->ewk_view);
1291    const Eina_List *l;
1292    void *data;
1293    static Elm_Genlist_Item_Class *list_item = NULL;
1294    const char *title = NULL;
1295    int item_count;
1296    int x;
1297    int y;
1298    int width;
1299    int height;
1300    size_t index;
1301
1302    evas_object_data_set(window->history.history_list, "Browser_Window", window);
1303
1304    if (forward_navigation_enabled)
1305      window->history.history_list_items = ewk_back_forward_list_forward_items_copy(list);
1306    else
1307      window->history.history_list_items = ewk_back_forward_list_back_items_copy(list);
1308
1309    if (!list_item) {
1310      list_item = elm_genlist_item_class_new();
1311      list_item->item_style = "default";
1312      list_item->func.text_get = list_item_label_get;
1313      list_item->func.content_get = NULL;
1314      list_item->func.state_get = NULL;
1315      list_item->func.del = NULL;
1316    }
1317
1318    item_count = eina_list_count(window->history.history_list_items);
1319    INFO("navigation_button_longpress_process : Item count = %d forward_navigation_enabled = %d", item_count, forward_navigation_enabled);
1320
1321    EINA_LIST_FOREACH(window->history.history_list_items, l, data) {
1322      title = ewk_back_forward_list_item_title_get(data);
1323      INFO(" title = %s", title);
1324      elm_genlist_item_append(window->history.history_list, list_item, (void *)(title), NULL, ELM_GENLIST_ITEM_NONE, _list_item_select_cb, data);
1325    }
1326
1327    if (item_count > 0) {
1328      evas_object_geometry_get(window->elm_window, &x, &y, &width, &height);
1329      elm_list_go(window->history.history_list);
1330      evas_object_resize(window->history.history_box , width / 3 , LIST_ITEM_HEIGHT * item_count);
1331
1332      if (forward_navigation_enabled) {
1333        evas_object_move(window->history.history_box , x + TOOL_BAR_BUTTON_SIZE + 1, y + TOOL_BAR_BUTTON_SIZE);
1334        evas_object_move(window->history.history_list , x + TOOL_BAR_BUTTON_SIZE + 1, y + TOOL_BAR_BUTTON_SIZE);
1335      } else {
1336        evas_object_move(window->history.history_box , x, y + TOOL_BAR_BUTTON_SIZE);
1337        evas_object_move(window->history.history_list , x, y + TOOL_BAR_BUTTON_SIZE);
1338      }
1339
1340      elm_genlist_mode_set(window->history.history_list, ELM_LIST_COMPRESS);
1341      evas_object_show(window->history.history_box);
1342      evas_object_show(window->history.history_list);
1343      evas_object_focus_set(window->ewk_view, EINA_FALSE);
1344      elm_object_focus_set(window->history.history_list, EINA_TRUE);
1345    } else
1346      longpress_enabled = EINA_FALSE;
1347 }
1348
1349 static void
1350 _forward_button_longpress_cb(void *user_data, Evas_Object *forward_button, void *event_info)
1351 {
1352    Browser_Window *window = (Browser_Window *)user_data;
1353
1354    navigation_button_longpress_process(user_data, EINA_TRUE);
1355    elm_object_disabled_set(forward_button, !ewk_view_back_possible(window->ewk_view));
1356 }
1357
1358 static void
1359 _back_button_longpress_cb(void *user_data, Evas_Object *back_button, void *event_info)
1360 {
1361    Browser_Window *window = (Browser_Window *)user_data;
1362
1363    navigation_button_longpress_process(user_data, EINA_FALSE);
1364    elm_object_disabled_set(back_button, !ewk_view_back_possible(window->ewk_view));
1365 }
1366
1367 static void
1368 _ok_clicked_cb(void *user_data, Evas_Object *obj, void *event_info)
1369 {
1370    Eina_Bool *confirmed = (Eina_Bool *)user_data;
1371    *confirmed = EINA_TRUE;
1372 }
1373
1374 static Eina_Stringshare *
1375 _file_entry_dialog_show(Browser_Window *window, const char *label_tag, const char *default_text)
1376 {
1377    Evas_Object *file_popup = elm_popup_add(window->elm_window);
1378    evas_object_size_hint_weight_set(file_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1379    evas_object_show(file_popup);
1380
1381    Evas_Object *vbox = elm_box_add(file_popup);
1382    evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1383    evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
1384    elm_object_content_set(file_popup, vbox);
1385    evas_object_show(vbox);
1386
1387    Evas_Object *label = elm_label_add(window->elm_window);
1388    elm_object_text_set(label, label_tag);
1389    evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
1390    evas_object_size_hint_align_set(label, EVAS_HINT_FILL, 0.5);
1391    evas_object_color_set(label, 23, 45, 67, 142);
1392    elm_box_pack_end(vbox, label);
1393    evas_object_show(label);
1394
1395    Evas_Object *fs_entry = elm_fileselector_entry_add(file_popup);
1396    elm_fileselector_is_save_set(fs_entry, EINA_TRUE);
1397    evas_object_size_hint_align_set(fs_entry, EVAS_HINT_FILL, 0);
1398    elm_fileselector_path_set(fs_entry, default_text);
1399    elm_object_text_set(fs_entry, "FileChooser");
1400    elm_box_pack_end(vbox, fs_entry);
1401    evas_object_show(fs_entry);
1402
1403    Evas_Object *hbox = elm_box_add(file_popup);
1404    evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1405    elm_box_horizontal_set(hbox, EINA_TRUE);
1406    evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
1407    elm_box_pack_end(vbox, hbox);
1408    evas_object_show(hbox);
1409
1410    Eina_Bool ok = EINA_FALSE;
1411    Evas_Object *ok_button = elm_button_add(file_popup);
1412    elm_object_text_set(ok_button, "OK");
1413    evas_object_smart_callback_add(ok_button, "clicked", _ok_clicked_cb, &ok);
1414    elm_box_pack_end(hbox, ok_button);
1415    evas_object_show(ok_button);
1416
1417    Eina_Bool cancel = EINA_FALSE;
1418    Evas_Object *cancel_button = elm_button_add(file_popup);
1419    elm_object_text_set(cancel_button, "Cancel");
1420    evas_object_smart_callback_add(cancel_button, "clicked", _ok_clicked_cb, &cancel);
1421    elm_box_pack_end(hbox, cancel_button);
1422    evas_object_show(cancel_button);
1423
1424    while (ok != EINA_TRUE && cancel != EINA_TRUE)
1425     ecore_main_loop_iterate();
1426
1427    Eina_Stringshare *file_path = ok ? eina_stringshare_add(elm_fileselector_path_get(fs_entry)) : NULL;
1428    evas_object_del(file_popup);
1429    return file_path;
1430 }
1431
1432 static void
1433 _javascript_alert_cb(Ewk_View_Smart_Data *smartData, const char *message)
1434 {
1435    Browser_Window *window = window_find_with_ewk_view(smartData->self);
1436
1437    Evas_Object *alert_popup = elm_popup_add(window->elm_window);
1438    evas_object_size_hint_weight_set(alert_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1439    elm_object_text_set(alert_popup, message);
1440    elm_object_part_text_set(alert_popup, "title,text", "Alert");
1441
1442    /* Popup buttons */
1443    Eina_Bool ok = EINA_FALSE;
1444    Evas_Object *button = elm_button_add(alert_popup);
1445    elm_object_text_set(button, "OK");
1446    elm_object_part_content_set(alert_popup, "button1", button);
1447    evas_object_smart_callback_add(button, "clicked", _ok_clicked_cb, &ok);
1448    elm_object_focus_set(button, EINA_TRUE);
1449    evas_object_show(alert_popup);
1450
1451    while (ok != EINA_TRUE)
1452       ecore_main_loop_iterate();
1453
1454    evas_object_del(alert_popup);
1455 }
1456
1457 static Eina_Bool
1458 _javascript_confirm_cb(Ewk_View_Smart_Data *smartData, const char *message)
1459 {
1460    Browser_Window *window = window_find_with_ewk_view(smartData->self);
1461
1462    Evas_Object *confirm_popup = elm_popup_add(window->elm_window);
1463    evas_object_size_hint_weight_set(confirm_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1464    elm_object_text_set(confirm_popup, message);
1465    elm_object_part_text_set(confirm_popup, "title,text", "Confirmation");
1466
1467    /* Popup buttons */
1468    Eina_Bool cancel = EINA_FALSE;
1469    Evas_Object *cancel_button = elm_button_add(confirm_popup);
1470    elm_object_text_set(cancel_button, "Cancel");
1471    elm_object_part_content_set(confirm_popup, "button1", cancel_button);
1472    evas_object_smart_callback_add(cancel_button, "clicked", _ok_clicked_cb, &cancel);
1473    Evas_Object *ok_button = elm_button_add(confirm_popup);
1474    Eina_Bool ok = EINA_FALSE;
1475    elm_object_text_set(ok_button, "OK");
1476    elm_object_part_content_set(confirm_popup, "button2", ok_button);
1477    evas_object_smart_callback_add(ok_button, "clicked", _ok_clicked_cb, &ok);
1478    elm_object_focus_set(ok_button, EINA_TRUE);
1479    evas_object_show(confirm_popup);
1480
1481    while (cancel != EINA_TRUE && ok != EINA_TRUE)
1482       ecore_main_loop_iterate();
1483
1484    evas_object_del(confirm_popup);
1485
1486    return ok;
1487 }
1488
1489 static const char *
1490 _javascript_prompt_cb(Ewk_View_Smart_Data *smartData, const char *message, const char *default_value)
1491 {
1492    Browser_Window *window = window_find_with_ewk_view(smartData->self);
1493
1494    Evas_Object *prompt_popup = elm_popup_add(window->elm_window);
1495    evas_object_size_hint_weight_set(prompt_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1496    elm_object_part_text_set(prompt_popup, "title,text", "Prompt");
1497
1498    /* Popup Content */
1499    Evas_Object *box = elm_box_add(window->elm_window);
1500    elm_box_padding_set(box, 0, 4);
1501    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1502    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
1503    evas_object_show(box);
1504
1505    Evas_Object *prompt = elm_label_add(window->elm_window);
1506    elm_object_text_set(prompt, message);
1507    evas_object_size_hint_weight_set(prompt, EVAS_HINT_EXPAND, 0.0);
1508    evas_object_size_hint_align_set(prompt, EVAS_HINT_FILL, 0.5);
1509    elm_box_pack_end(box, prompt);
1510    evas_object_show(prompt);
1511
1512    Evas_Object *entry = elm_entry_add(window->elm_window);
1513    elm_entry_scrollable_set(entry, EINA_TRUE);
1514    elm_entry_single_line_set(entry, EINA_TRUE);
1515    elm_entry_text_style_user_push(entry, "DEFAULT='font_size=18'");
1516    elm_entry_entry_set(entry, default_value ? default_value : "");
1517    elm_entry_select_all(entry);
1518    evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0);
1519    evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0.5);
1520    elm_box_pack_end(box, entry);
1521    elm_object_focus_set(entry, EINA_TRUE);
1522    evas_object_show(entry);
1523
1524    elm_object_content_set(prompt_popup, box);
1525
1526    /* Popup buttons */
1527    Eina_Bool cancel = EINA_FALSE;
1528    Evas_Object *cancel_button = elm_button_add(prompt_popup);
1529    elm_object_text_set(cancel_button, "Cancel");
1530    elm_object_part_content_set(prompt_popup, "button1", cancel_button);
1531    evas_object_smart_callback_add(cancel_button, "clicked", _ok_clicked_cb, &cancel);
1532    Eina_Bool ok = EINA_FALSE;
1533    Evas_Object *ok_button = elm_button_add(prompt_popup);
1534    elm_object_text_set(ok_button, "OK");
1535    elm_object_part_content_set(prompt_popup, "button2", ok_button);
1536    evas_object_smart_callback_add(ok_button, "clicked", _ok_clicked_cb, &ok);
1537    evas_object_show(prompt_popup);
1538
1539    while (cancel != EINA_TRUE && ok != EINA_TRUE)
1540       ecore_main_loop_iterate();
1541
1542    /* The return string need to be stringshared */
1543    const char *prompt_text = ok ? eina_stringshare_add(elm_entry_entry_get(entry)) : NULL;
1544    evas_object_del(prompt_popup);
1545
1546    return prompt_text;
1547 }
1548
1549 static Eina_Bool
1550 _javascript_before_unload_confirm_cb(Ewk_View_Smart_Data *smartData, const char *message)
1551 {
1552    return _javascript_confirm_cb(smartData, "Will you leave this page?");
1553 }
1554
1555 static void
1556 _popup_menu_item_clicked_cb(void *user_data, Evas_Object *obj, void *event_info)
1557 {
1558    Browser_Window *window = (Browser_Window *)user_data;
1559    Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1560
1561    INFO("Selected popup menu index: %u", elm_menu_item_index_get(item));
1562    ewk_popup_menu_selected_index_set(window->popup.ewk_menu, elm_menu_item_index_get(item));
1563
1564    // Close popup menu.
1565    ewk_popup_menu_close(window->popup.ewk_menu);
1566 }
1567
1568 static void
1569 popup_menu_populate(Evas_Object *elm_menu, Ewk_Popup_Menu *ewk_menu, void *user_data)
1570 {
1571    const Eina_List* ewk_items = ewk_popup_menu_items_get(ewk_menu);
1572
1573    void *data;
1574    const Eina_List *l;
1575    EINA_LIST_FOREACH(ewk_items, l, data) {
1576      Ewk_Popup_Menu_Item *ewk_item = (Ewk_Popup_Menu_Item *)data;
1577      switch (ewk_popup_menu_item_type_get(ewk_item)) {
1578      case EWK_POPUP_MENU_SEPARATOR:
1579        elm_menu_item_separator_add(elm_menu, NULL);
1580        break;
1581      case EWK_POPUP_MENU_ITEM:
1582        if (ewk_popup_menu_item_is_label_get(ewk_item)) {
1583          Elm_Object_Item *item = elm_menu_item_add(elm_menu, NULL, NULL, ewk_popup_menu_item_text_get(ewk_item), NULL, NULL);
1584          elm_object_item_disabled_set(item, EINA_TRUE);
1585        } else {
1586          Elm_Object_Item *item = elm_menu_item_add(elm_menu, NULL, NULL, ewk_popup_menu_item_text_get(ewk_item), _popup_menu_item_clicked_cb, user_data);
1587          const char *tooltip_text = ewk_popup_menu_item_tooltip_get(ewk_item);
1588          if (tooltip_text && tooltip_text[0] != '\0')
1589            elm_object_item_tooltip_text_set(item, tooltip_text);
1590          elm_object_item_disabled_set(item, !ewk_popup_menu_item_enabled_get(ewk_item));
1591          elm_menu_item_selected_set(item, ewk_popup_menu_item_selected_get(ewk_item));
1592        }
1593        break;
1594      default:
1595        INFO("Unrecognized popup menu item type!");
1596        break;
1597      }
1598    }
1599 }
1600
1601 static Eina_Bool
1602 _popup_menu_show(Ewk_View_Smart_Data *smartData, Eina_Rectangle rect, Ewk_Text_Direction text_direction, double page_scale_factor, Ewk_Popup_Menu *ewk_menu)
1603 {
1604    Browser_Window *window = window_find_with_ewk_view(smartData->self);
1605
1606    if (window->popup.elm_menu)
1607      evas_object_del(window->popup.elm_menu);
1608
1609    window->popup.elm_menu = elm_menu_add(window->elm_window);
1610    window->popup.ewk_menu = ewk_menu;
1611
1612    popup_menu_populate(window->popup.elm_menu, ewk_menu, window);
1613
1614    INFO("Showing popup menu at (%d, %d)", rect.x, rect.y);
1615    elm_menu_move(window->popup.elm_menu, rect.x, rect.y);
1616    evas_object_show(window->popup.elm_menu);
1617
1618    return EINA_TRUE;
1619 }
1620
1621 static Eina_Bool
1622 _popup_menu_hide(Ewk_View_Smart_Data *smartData)
1623 {
1624    Browser_Window *window = window_find_with_ewk_view(smartData->self);
1625
1626    if (!window->popup.elm_menu)
1627      return EINA_FALSE;
1628
1629    elm_menu_close(window->popup.elm_menu);
1630    window->popup.ewk_menu = NULL;
1631
1632    return EINA_TRUE;
1633 }
1634
1635 static Eina_Bool
1636 _window_geometry_get(Ewk_View_Smart_Data *sd, Evas_Coord *x, Evas_Coord *y, Evas_Coord *width, Evas_Coord *height)
1637 {
1638    Browser_Window *window = window_find_with_ewk_view(sd->self);
1639
1640    evas_object_geometry_get(window->elm_window, x, y, width, height);
1641
1642    return EINA_TRUE;
1643 }
1644
1645 static Eina_Bool
1646 _window_geometry_set(Ewk_View_Smart_Data *sd, Evas_Coord x, Evas_Coord y, Evas_Coord width, Evas_Coord height)
1647 {
1648    Browser_Window *window = window_find_with_ewk_view(sd->self);
1649
1650    evas_object_move(window->elm_window, x, y);
1651    evas_object_resize(window->elm_window, width, height);
1652
1653    return EINA_TRUE;
1654 }
1655
1656 typedef struct {
1657    Evas_Object *ewk_view;
1658    Evas_Object *permission_popup;
1659 } PermissionData;
1660
1661 static void
1662 _fullscreen_accept_cb(void *user_data, Evas_Object *obj, void *event_info)
1663 {
1664    PermissionData *permission_data = (PermissionData *)user_data;
1665    Browser_Window *window = window_find_with_ewk_view(permission_data->ewk_view);
1666
1667    elm_win_resize_object_del(window->elm_window, permission_data->permission_popup);
1668    evas_object_del(permission_data->permission_popup);
1669    evas_object_focus_set(permission_data->ewk_view, EINA_TRUE);
1670    free(permission_data);
1671 }
1672
1673 static void
1674 _fullscreen_deny_cb(void *user_data, Evas_Object *obj, void *event_info)
1675 {
1676    PermissionData *permission_data = (PermissionData *)user_data;
1677    Browser_Window *window = window_find_with_ewk_view(permission_data->ewk_view);
1678
1679    ewk_view_fullscreen_exit(permission_data->ewk_view);
1680    elm_win_resize_object_del(window->elm_window, permission_data->permission_popup);
1681    evas_object_del(permission_data->permission_popup);
1682    evas_object_focus_set(permission_data->ewk_view, EINA_TRUE);
1683    free(permission_data);
1684 }
1685
1686 static Eina_Bool
1687 _fullscreen_enter_cb(Ewk_View_Smart_Data *sd, Ewk_Security_Origin *origin)
1688 {
1689    Browser_Window *window = window_find_with_ewk_view(sd->self);
1690
1691    /* Go fullscreen */
1692    toggle_window_fullscreen(window, EINA_TRUE);
1693
1694    /* Show user popup */
1695    Evas_Object *permission_popup = elm_popup_add(window->elm_window);
1696    evas_object_size_hint_weight_set(permission_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1697
1698    Eina_Strbuf *message = eina_strbuf_new();
1699    eina_strbuf_append_printf(message, "%s is now fullscreen.<br>Press ESC at any time to exit fullscreen.<br>Allow fullscreen?", ewk_security_origin_host_get(origin));
1700    elm_object_text_set(permission_popup, eina_strbuf_string_get(message));
1701    eina_strbuf_free(message);
1702    elm_object_part_text_set(permission_popup, "title,text", "Fullscreen Permission");
1703
1704    /* Popup buttons */
1705    PermissionData *permission_data = (PermissionData *)malloc(sizeof(PermissionData));
1706    permission_data->ewk_view = window->ewk_view;
1707    permission_data->permission_popup = permission_popup;
1708    Evas_Object *accept_button = elm_button_add(permission_popup);
1709    elm_object_text_set(accept_button, "Accept");
1710    elm_object_part_content_set(permission_popup, "button1", accept_button);
1711    evas_object_smart_callback_add(accept_button, "clicked", _fullscreen_accept_cb, permission_data);
1712
1713    Evas_Object *deny_button = elm_button_add(permission_popup);
1714    elm_object_text_set(deny_button, "Deny");
1715    elm_object_part_content_set(permission_popup, "button2", deny_button);
1716    evas_object_smart_callback_add(deny_button, "clicked", _fullscreen_deny_cb, permission_data);
1717    elm_win_resize_object_add(window->elm_window, permission_popup);
1718    evas_object_show(permission_popup);
1719
1720    return EINA_TRUE;
1721 }
1722
1723 static Eina_Bool _fullscreen_exit_cb(Ewk_View_Smart_Data *sd)
1724 {
1725    Browser_Window *window = window_find_with_ewk_view(sd->self);
1726
1727    toggle_window_fullscreen(window, EINA_FALSE);
1728
1729    return EINA_TRUE;
1730 }
1731
1732 static Evas_Object *
1733 _window_create_cb(Ewk_View_Smart_Data *smartData, Ewk_View_Configuration* configuration, const Ewk_Window_Features *window_features)
1734 {
1735    int x = 0;
1736    int y = 0;
1737    int width = 0;
1738    int height = 0;
1739
1740    ewk_window_features_geometry_get(window_features, &x, &y, &width, &height);
1741
1742    if (!width)
1743      width = window_width;
1744
1745    if (!height)
1746      height = window_height;
1747
1748    Browser_Window *window = window_create(configuration, width, height);
1749    Evas_Object *new_view = window->ewk_view;
1750
1751    windows = eina_list_append(windows, window);
1752
1753    INFO("minibrowser: location(%d,%d) size=(%d,%d)", x, y, width, height);
1754
1755    return new_view;
1756 }
1757
1758 static void
1759 _window_close_cb(Ewk_View_Smart_Data *smartData)
1760 {
1761    Browser_Window *window = window_find_with_ewk_view(smartData->self);
1762    window_close(window);
1763 }
1764
1765 static void
1766 _context_menu_item_selected_cb(void *data, Evas_Object *obj, void *event_info)
1767 {
1768    if (!data) {
1769      ERROR("Context menu callback data is NULL.");
1770      return;
1771    }
1772
1773    Ewk_Context_Menu_Item *ewk_item = (Ewk_Context_Menu_Item *)data;
1774    INFO("Selected context menu item: %s.", ewk_context_menu_item_title_get(ewk_item));
1775    ewk_context_menu_item_select(ewk_context_menu_item_parent_menu_get(ewk_item), ewk_item);
1776    ewk_context_menu_hide(ewk_context_menu_item_parent_menu_get(ewk_item));
1777 }
1778
1779 static void
1780 context_menu_populate(Evas_Object* context_menu, Ewk_Context_Menu *ewk_menu, Elm_Object_Item *parent_item)
1781 {
1782    if (!context_menu || !ewk_menu) {
1783      ERROR("Necessary objects are NULL.");
1784      return;
1785    }
1786
1787    const Eina_List *list = ewk_context_menu_items_get(ewk_menu);
1788    const Eina_List *l;
1789    void *data;
1790
1791    Ewk_Context_Menu_Item *ewk_item;
1792    Elm_Object_Item *elm_menu_item;
1793    Evas_Object *elm_check_item;
1794
1795    EINA_LIST_FOREACH(list, l, data) {
1796      ewk_item = (Ewk_Context_Menu_Item *)data;
1797      switch (ewk_context_menu_item_type_get(ewk_item)) {
1798      case EWK_ACTION_TYPE:
1799        elm_menu_item = elm_menu_item_add(context_menu, parent_item, NULL, ewk_context_menu_item_title_get(ewk_item), _context_menu_item_selected_cb, ewk_item);
1800        break;
1801      case EWK_CHECKABLE_ACTION_TYPE:
1802        elm_check_item = elm_check_add(context_menu);
1803        elm_menu_item = elm_menu_item_add(context_menu, parent_item, NULL, ewk_context_menu_item_title_get(ewk_item), _context_menu_item_selected_cb, ewk_item);
1804        elm_object_item_content_set(elm_menu_item, elm_check_item);
1805        elm_check_state_set(elm_check_item, ewk_context_menu_item_checked_get(ewk_item));
1806        break;
1807      case EWK_SUBMENU_TYPE:
1808        elm_menu_item = elm_menu_item_add(context_menu, parent_item, NULL, ewk_context_menu_item_title_get(ewk_item), NULL, ewk_item);
1809        if (elm_menu_item)
1810          context_menu_populate(context_menu, ewk_context_menu_item_submenu_get(ewk_item), elm_menu_item);
1811        break;
1812      default:
1813        continue;
1814      }
1815      elm_object_item_disabled_set(elm_menu_item, !ewk_context_menu_item_enabled_get(ewk_item));
1816    }
1817 }
1818
1819 static Eina_Bool
1820 _context_menu_show(Ewk_View_Smart_Data *sd, Evas_Coord x, Evas_Coord y, Ewk_Context_Menu *menu)
1821 {
1822    Browser_Window *window = window_find_with_ewk_view(sd->self);
1823
1824    if (!window || !menu) {
1825      ERROR("Necessary objects are NULL.");
1826      return EINA_FALSE;
1827    }
1828
1829    window->context_menu.elm_menu = elm_menu_add(window->elm_window);
1830
1831    if (!window->context_menu.elm_menu) {
1832      ERROR("Could not create menu widget.");
1833      return EINA_FALSE;
1834    }
1835
1836    window->context_menu.ewk_menu = menu;
1837
1838    context_menu_populate(window->context_menu.elm_menu, menu, NULL);
1839
1840    INFO("Showing context menu at (%d, %d).", x, y);
1841    elm_menu_move(window->context_menu.elm_menu, x, y);
1842    evas_object_show(window->context_menu.elm_menu);
1843
1844    return EINA_TRUE;
1845 }
1846
1847 static Eina_Bool
1848 _context_menu_hide(Ewk_View_Smart_Data *sd)
1849 {
1850    Browser_Window *window = window_find_with_ewk_view(sd->self);
1851
1852    if (!window || !window->context_menu.elm_menu) {
1853      ERROR("Necessary objects are NULL.");
1854      return EINA_FALSE;
1855    }
1856
1857    elm_menu_close(window->context_menu.elm_menu);
1858    evas_object_del(window->context_menu.elm_menu);
1859    window->context_menu.elm_menu = NULL;
1860    window->context_menu.ewk_menu = NULL;
1861
1862    return EINA_TRUE;
1863 }
1864
1865 static void
1866 auth_popup_close(Auth_Data *auth_data)
1867 {
1868    ewk_object_unref(auth_data->request);
1869    evas_object_del(auth_data->popup);
1870    free(auth_data);
1871 }
1872
1873 static void
1874 _auth_cancel_cb(void *user_data, Evas_Object *obj, void *event_info)
1875 {
1876    Auth_Data *auth_data = (Auth_Data *)user_data;
1877
1878    ewk_auth_request_cancel(auth_data->request);
1879
1880    auth_popup_close(auth_data);
1881 }
1882
1883 static void
1884 _auth_ok_cb(void *user_data, Evas_Object *obj, void *event_info)
1885 {
1886    Auth_Data *auth_data = (Auth_Data *)user_data;
1887
1888    const char *username = elm_entry_entry_get(auth_data->username_entry);
1889    const char *password = elm_entry_entry_get(auth_data->password_entry);
1890    ewk_auth_request_authenticate(auth_data->request, username, password);
1891
1892    auth_popup_close(auth_data);
1893 }
1894
1895 static void
1896 _authentication_request_cb(void *user_data, Evas_Object *obj, void *event_info)
1897 {
1898    Browser_Window *window = (Browser_Window *)user_data;
1899    Ewk_Auth_Request *request = ewk_object_ref((Ewk_Auth_Request *)event_info);
1900
1901    Auth_Data *auth_data = (Auth_Data *)malloc(sizeof(Auth_Data));
1902    auth_data->request = request;
1903
1904    Evas_Object *auth_popup = elm_popup_add(window->elm_window);
1905    auth_data->popup = auth_popup;
1906    evas_object_size_hint_weight_set(auth_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1907    elm_object_part_text_set(auth_popup, "title,text", "Authentication Required");
1908
1909    /* Popup Content */
1910    Evas_Object *vbox = elm_box_add(auth_popup);
1911    elm_box_padding_set(vbox, 0, 4);
1912    evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1913    evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
1914    elm_object_content_set(auth_popup, vbox);
1915    evas_object_show(vbox);
1916
1917    /* Authentication message */
1918    Evas_Object *label = elm_label_add(auth_popup);
1919    elm_label_line_wrap_set(label, ELM_WRAP_WORD);
1920    Eina_Strbuf *auth_text = eina_strbuf_new();
1921    const char *host = ewk_auth_request_host_get(request);
1922    const char *realm = ewk_auth_request_realm_get(request);
1923    eina_strbuf_append_printf(auth_text, "A username and password are being requested by %s. The site says: \"%s\"", host, realm ? realm : "");
1924    elm_object_text_set(label, eina_strbuf_string_get(auth_text));
1925    eina_strbuf_free(auth_text);
1926    evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1927    evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
1928    elm_box_pack_end(vbox, label);
1929    evas_object_show(label);
1930
1931    /* Credential table */
1932    Evas_Object *table = elm_table_add(auth_popup);
1933    elm_table_padding_set(table, 2, 2);
1934    elm_table_homogeneous_set(table, EINA_TRUE);
1935    evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1936    evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
1937    elm_box_pack_end(vbox, table);
1938    evas_object_show(table);
1939
1940    /* Username row */
1941    Evas_Object *username_label = elm_label_add(auth_popup);
1942    elm_object_text_set(username_label, "Username:");
1943    evas_object_size_hint_weight_set(username_label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1944    evas_object_size_hint_align_set(username_label, 1, EVAS_HINT_FILL);
1945    elm_table_pack(table, username_label, 0, 0, 1, 1);
1946    evas_object_show(username_label);
1947
1948    Evas_Object *username_entry = elm_entry_add(auth_popup);
1949    auth_data->username_entry = username_entry;
1950    elm_entry_scrollable_set(username_entry, EINA_TRUE);
1951    elm_entry_single_line_set(username_entry, EINA_TRUE);
1952    elm_entry_text_style_user_push(username_entry, "DEFAULT='font_size=18'");
1953    const char *suggested_username = ewk_auth_request_suggested_username_get(request);
1954    elm_entry_entry_set(username_entry, suggested_username ? suggested_username : "");
1955    evas_object_size_hint_weight_set(username_entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1956    evas_object_size_hint_align_set(username_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
1957    elm_table_pack(table, username_entry, 1, 0, 2, 1);
1958    elm_object_focus_set(username_entry, EINA_TRUE);
1959    evas_object_show(username_entry);
1960
1961    /* Password row */
1962    Evas_Object *password_label = elm_label_add(auth_popup);
1963    elm_object_text_set(password_label, "Password:");
1964    evas_object_size_hint_weight_set(password_label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1965    evas_object_size_hint_align_set(password_label, 1, EVAS_HINT_FILL);
1966    elm_table_pack(table, password_label, 0, 1, 1, 1);
1967    evas_object_show(password_label);
1968
1969    Evas_Object *password_entry = elm_entry_add(auth_popup);
1970    auth_data->password_entry = password_entry;
1971    elm_entry_scrollable_set(password_entry, EINA_TRUE);
1972    elm_entry_single_line_set(password_entry, EINA_TRUE);
1973    elm_entry_password_set(password_entry, EINA_TRUE);
1974    elm_entry_text_style_user_push(password_entry, "DEFAULT='font_size=18'");
1975    evas_object_size_hint_weight_set(password_entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1976    evas_object_size_hint_align_set(password_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
1977    elm_table_pack(table, password_entry, 1, 1, 2, 1);
1978    evas_object_show(password_entry);
1979
1980    /* Popup buttons */
1981    Evas_Object *cancel_button = elm_button_add(auth_popup);
1982    elm_object_text_set(cancel_button, "Cancel");
1983    elm_object_part_content_set(auth_popup, "button1", cancel_button);
1984    evas_object_smart_callback_add(cancel_button, "clicked", _auth_cancel_cb, auth_data);
1985    Evas_Object *ok_button = elm_button_add(auth_popup);
1986    elm_object_text_set(ok_button, "OK");
1987    elm_object_part_content_set(auth_popup, "button2", ok_button);
1988    evas_object_smart_callback_add(ok_button, "clicked", _auth_ok_cb, auth_data);
1989    evas_object_show(auth_popup);
1990 }
1991
1992 static void
1993 _search_text_found_cb(void *user_data, Evas_Object *obj, void *event_info)
1994 {
1995    Browser_Window *window = (Browser_Window *)user_data;
1996
1997    const int *match_count = (const int *)(event_info);
1998
1999    if (*match_count) {
2000      Eina_Strbuf *search_text = eina_strbuf_new();
2001      eina_strbuf_append_printf(search_text, "  %d  Matches Found " , *match_count);
2002      elm_object_text_set(window->search.search_field_count, eina_strbuf_string_get(search_text));
2003      eina_strbuf_free(search_text);
2004    } else
2005      elm_object_text_set(window->search.search_field_count, " No Matches Found");
2006
2007    evas_object_focus_set(window->ewk_view, EINA_FALSE);
2008    elm_object_focus_set(window->search.search_field_count, EINA_FALSE);
2009    elm_object_focus_set(window->search.search_field, EINA_TRUE);
2010 }
2011
2012 static void
2013 _tooltip_text_set(void *user_data, Evas_Object *obj, void *event_info)
2014 {
2015    Browser_Window *window = (Browser_Window *)user_data;
2016    const char *message = (const char*)event_info;
2017
2018    elm_object_tooltip_text_set(window->elm_window, message);
2019    window->tooltip.text_set = EINA_TRUE;
2020    window_tooltip_update(window);
2021 }
2022
2023 static void
2024 _tooltip_text_unset(void *user_data, Evas_Object *obj, void *event_info)
2025 {
2026    Browser_Window *window = (Browser_Window *)user_data;
2027
2028    window_tooltip_hide(window);
2029    elm_object_tooltip_unset(window->elm_window);
2030    window->tooltip.text_set = EINA_FALSE;
2031 }
2032
2033 static void
2034 _navigation_policy_decision_cb(void *user_data, Evas_Object *obj, void *event_info)
2035 {
2036    Ewk_Navigation_Policy_Decision *decision = (Ewk_Navigation_Policy_Decision *)event_info;
2037
2038    if (ewk_navigation_policy_mouse_button_get(decision) == EWK_EVENT_MOUSE_BUTTON_MIDDLE) {
2039      Browser_Window *window = window_create(NULL, 0, 0);
2040      ewk_view_url_set(window->ewk_view, ewk_url_request_url_get(ewk_navigation_policy_request_get(decision)));
2041      windows = eina_list_append(windows, window);
2042      INFO("Mouse middle button pressed, open link in new window");
2043
2044      ewk_navigation_policy_decision_reject(decision);
2045    }
2046 }
2047
2048 static void
2049 _home_button_clicked_cb(void *user_data, Evas_Object *home_button, void *event_info)
2050 {
2051    Browser_Window *window = (Browser_Window *)user_data;
2052
2053    ewk_view_url_set(window->ewk_view, DEFAULT_URL);
2054 }
2055
2056 static void
2057 _window_deletion_cb(void *user_data, Evas_Object *elm_window, void *event_info)
2058 {
2059    Browser_Window *window = (Browser_Window *)user_data;
2060    ewk_view_try_close(window->ewk_view);
2061 }
2062
2063 static Evas_Object *
2064 create_toolbar_button(Evas_Object *elm_window, const char *icon_name)
2065 {
2066    Evas_Object *button = elm_button_add(elm_window);
2067
2068    Evas_Object *icon = elm_icon_add(elm_window);
2069    elm_icon_standard_set(icon, icon_name);
2070    evas_object_size_hint_max_set(icon, TOOL_BAR_ICON_SIZE, TOOL_BAR_ICON_SIZE);
2071    evas_object_color_set(icon, 44, 44, 102, 128);
2072    evas_object_show(icon);
2073    elm_object_part_content_set(button, "icon", icon);
2074    evas_object_size_hint_min_set(button, TOOL_BAR_BUTTON_SIZE, TOOL_BAR_BUTTON_SIZE);
2075
2076    return button;
2077 }
2078
2079 static Browser_Window *window_create(Ewk_View_Configuration* configuration, int width, int height)
2080 {
2081    Browser_Window *window = calloc(1, sizeof(Browser_Window));
2082    if (!window) {
2083      ERROR("Could not create browser window.");
2084      return NULL;
2085    }
2086
2087    /* Initialize tooltip information */
2088    window->tooltip.show_timer = NULL;
2089    window->tooltip.activated = EINA_FALSE;
2090    window->tooltip.text_set = EINA_FALSE;
2091    window->tooltip.shown = EINA_FALSE;
2092
2093    /* Create window */
2094    window->elm_window = elm_win_add(NULL, "minibrowser-window", ELM_WIN_BASIC);
2095    elm_win_title_set(window->elm_window, APP_NAME);
2096    evas_object_smart_callback_add(window->elm_window, "delete,request", _window_deletion_cb, window);
2097
2098    /* Create window background */
2099    Evas_Object *bg = elm_bg_add(window->elm_window);
2100    elm_bg_color_set(bg, 193, 192, 191);
2101    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2102    elm_win_resize_object_add(window->elm_window, bg);
2103    evas_object_show(bg);
2104
2105    /* Create conformant widget. */
2106    Evas_Object *conformant = elm_conformant_add(window->elm_window);
2107    evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2108    elm_win_resize_object_add(window->elm_window, conformant);
2109    evas_object_show(conformant);
2110
2111    /* Create vertical layout */
2112    window->vertical_layout = elm_box_add(window->elm_window);
2113    elm_object_content_set(conformant, window->vertical_layout);
2114    elm_box_padding_set(window->vertical_layout, 0, 2);
2115    evas_object_size_hint_weight_set(window->vertical_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2116    evas_object_show(window->vertical_layout);
2117
2118    /* Create horizontal layout for top bar */
2119    window->horizontal_layout = elm_box_add(window->elm_window);
2120    elm_box_horizontal_set(window->horizontal_layout, EINA_TRUE);
2121    evas_object_size_hint_weight_set(window->horizontal_layout, EVAS_HINT_EXPAND, 0.0);
2122    evas_object_size_hint_align_set(window->horizontal_layout, EVAS_HINT_FILL, 0.0);
2123    elm_box_pack_end(window->vertical_layout, window->horizontal_layout);
2124    evas_object_show(window->horizontal_layout);
2125
2126    /* Create Back button */
2127    window->back_button = create_toolbar_button(window->elm_window, "arrow_left");
2128    evas_object_smart_callback_add(window->back_button, "clicked", _back_button_clicked_cb, window);
2129    evas_object_smart_callback_add(window->back_button, "repeated", _back_button_longpress_cb, window);
2130    elm_object_tooltip_text_set(window->back_button, "Click to go back, longpress to see session history");
2131    elm_object_tooltip_window_mode_set(window->back_button, EINA_TRUE);
2132    elm_object_disabled_set(window->back_button, EINA_TRUE);
2133    evas_object_size_hint_weight_set(window->back_button, 0.0, EVAS_HINT_EXPAND);
2134    evas_object_size_hint_align_set(window->back_button, 0.0, 0.5);
2135    elm_box_pack_end(window->horizontal_layout, window->back_button);
2136    evas_object_show(window->back_button);
2137
2138    /* Create Forward button */
2139    window->forward_button = create_toolbar_button(window->elm_window, "arrow_right");
2140    evas_object_smart_callback_add(window->forward_button, "clicked", _forward_button_clicked_cb, window);
2141    evas_object_smart_callback_add(window->forward_button, "repeated", _forward_button_longpress_cb, window);
2142    elm_object_tooltip_text_set(window->forward_button, "Click to go forward, longpress to see session history");
2143    elm_object_tooltip_window_mode_set(window->forward_button, EINA_TRUE);
2144    elm_object_disabled_set(window->forward_button, EINA_TRUE);
2145    evas_object_size_hint_weight_set(window->forward_button, 0.0, EVAS_HINT_EXPAND);
2146    evas_object_size_hint_align_set(window->forward_button, 0.0, 0.5);
2147    elm_box_pack_end(window->horizontal_layout, window->forward_button);
2148    evas_object_show(window->forward_button);
2149
2150    /* Create URL bar */
2151    window->url_bar = elm_entry_add(window->elm_window);
2152    elm_entry_scrollable_set(window->url_bar, EINA_TRUE);
2153    elm_scroller_policy_set(window->url_bar, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
2154    elm_entry_single_line_set(window->url_bar, EINA_TRUE);
2155    elm_entry_cnp_mode_set(window->url_bar, ELM_CNP_MODE_PLAINTEXT);
2156    elm_entry_text_style_user_push(window->url_bar, "DEFAULT='font_size=18'");
2157    evas_object_smart_callback_add(window->url_bar, "activated", _url_bar_activated_cb, window);
2158    evas_object_smart_callback_add(window->url_bar, "clicked", _url_bar_clicked_cb, window);
2159    evas_object_size_hint_weight_set(window->url_bar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2160    evas_object_size_hint_align_set(window->url_bar, EVAS_HINT_FILL, EVAS_HINT_FILL);
2161    elm_box_pack_end(window->horizontal_layout, window->url_bar);
2162    evas_object_show(window->url_bar);
2163
2164    /* Create Refresh button */
2165    Evas_Object *refresh_button = create_toolbar_button(window->elm_window, "refresh");
2166    evas_object_smart_callback_add(refresh_button, "clicked", _refresh_button_clicked_cb, window);
2167    elm_object_tooltip_text_set(refresh_button, "Reload page");
2168    elm_object_tooltip_window_mode_set(refresh_button, EINA_TRUE);
2169    evas_object_size_hint_weight_set(refresh_button, 0.0, EVAS_HINT_EXPAND);
2170    evas_object_size_hint_align_set(refresh_button, 1.0, 0.5);
2171    elm_box_pack_end(window->horizontal_layout, refresh_button);
2172    evas_object_show(refresh_button);
2173
2174    /* Create Stop button */
2175    Evas_Object *stop_button = create_toolbar_button(window->elm_window, "close");
2176    evas_object_smart_callback_add(stop_button, "clicked", _stop_button_clicked_cb, window);
2177    elm_object_tooltip_text_set(stop_button, "Stop page load");
2178    elm_object_tooltip_window_mode_set(stop_button, EINA_TRUE);
2179    evas_object_size_hint_weight_set(stop_button, 0.0, EVAS_HINT_EXPAND);
2180    evas_object_size_hint_align_set(stop_button, 1.0, 0.5);
2181    elm_box_pack_end(window->horizontal_layout, stop_button);
2182    evas_object_show(stop_button);
2183
2184    /* Create Home button */
2185    Evas_Object *home_button = create_toolbar_button(window->elm_window, "home");
2186    evas_object_smart_callback_add(home_button, "clicked", _home_button_clicked_cb, window);
2187    elm_object_tooltip_text_set(home_button, "Home page");
2188    elm_object_tooltip_window_mode_set(home_button, EINA_TRUE);
2189    evas_object_size_hint_weight_set(home_button, 0.0, EVAS_HINT_EXPAND);
2190    evas_object_size_hint_align_set(home_button, 1.0, 0.5);
2191    elm_box_pack_end(window->horizontal_layout, home_button);
2192    evas_object_show(home_button);
2193
2194    /* Create Search bar */
2195    window->search.search_bar = elm_box_add(window->elm_window);
2196    elm_box_horizontal_set(window->search.search_bar, EINA_TRUE);
2197    evas_object_size_hint_min_set(window->search.search_bar, SEARCH_FIELD_SIZE + 2 * SEARCH_BUTTON_SIZE, 0);
2198    evas_object_size_hint_align_set(window->search.search_bar, EVAS_HINT_FILL, EVAS_HINT_FILL);
2199    elm_box_pack_end(window->vertical_layout, window->search.search_bar);
2200
2201    /* Create Search field */
2202    window->search.search_field = elm_entry_add(window->elm_window);
2203    elm_entry_scrollable_set(window->search.search_field, EINA_TRUE);
2204    elm_scroller_policy_set(window->search.search_field, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
2205    elm_entry_single_line_set(window->search.search_field, EINA_TRUE);
2206    elm_entry_cnp_mode_set(window->search.search_field, ELM_CNP_MODE_PLAINTEXT);
2207    elm_entry_text_style_user_push(window->search.search_field, "DEFAULT='font_size=14'");
2208    evas_object_smart_callback_add(window->search.search_field, "activated", _search_field_activated_cb, window);
2209    evas_object_smart_callback_add(window->search.search_field, "changed", _search_field_activated_cb, window);
2210    evas_object_smart_callback_add(window->search.search_field, "aborted", _search_field_aborted_cb, window);
2211    evas_object_smart_callback_add(window->search.search_field, "clicked", _search_field_clicked_cb, window);
2212    evas_object_size_hint_weight_set(window->search.search_field, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2213    evas_object_size_hint_align_set(window->search.search_field, EVAS_HINT_FILL, EVAS_HINT_FILL);
2214    elm_box_pack_end(window->search.search_bar, window->search.search_field);
2215
2216    /* Create Search backward button */
2217    window->search.backward_button = create_toolbar_button(window->elm_window, "arrow_up");
2218    evas_object_smart_callback_add(window->search.backward_button, "clicked", _search_backward_button_clicked_cb, window);
2219    elm_object_disabled_set(window->search.backward_button, EINA_FALSE);
2220    evas_object_size_hint_weight_set(window->search.backward_button, 0.0, EVAS_HINT_EXPAND);
2221    evas_object_size_hint_align_set(window->search.backward_button, 1.0, 0.5);
2222    evas_object_size_hint_min_set(window->search.backward_button, SEARCH_BUTTON_SIZE, SEARCH_BUTTON_SIZE);
2223    elm_box_pack_end(window->search.search_bar, window->search.backward_button);
2224
2225    /* Create Search forwardward button */
2226    window->search.forward_button = create_toolbar_button(window->elm_window, "arrow_down");
2227    evas_object_smart_callback_add(window->search.forward_button, "clicked", _search_forward_button_clicked_cb, window);
2228    elm_object_disabled_set(window->search.forward_button, EINA_FALSE);
2229    evas_object_size_hint_weight_set(window->search.forward_button, 0.0, EVAS_HINT_EXPAND);
2230    evas_object_size_hint_align_set(window->search.forward_button, 1.0, 0.5);
2231    evas_object_size_hint_min_set(window->search.forward_button, SEARCH_BUTTON_SIZE, SEARCH_BUTTON_SIZE);
2232    elm_box_pack_end(window->search.search_bar, window->search.forward_button);
2233
2234    /* Create Search count field */
2235    window->search.search_field_count = elm_label_add(window->elm_window);
2236    evas_object_size_hint_weight_set(window->search.search_field_count, 0.0, EVAS_HINT_EXPAND);
2237    evas_object_size_hint_align_set(window->search.search_field_count, EVAS_HINT_FILL, EVAS_HINT_FILL);
2238    elm_object_text_set(window->search.search_field_count, "");
2239    elm_box_pack_end(window->search.search_bar, window->search.search_field_count);
2240
2241    /* Create Search Case Sensitive Option check box */
2242    window->search.search_case_check_box = elm_check_add(window->elm_window);
2243    elm_object_text_set(window->search.search_case_check_box, "Case Sensitive");
2244    evas_object_smart_callback_add(window->search.search_case_check_box, "changed", _search_case_option_changed, window);
2245    elm_box_pack_end(window->search.search_bar, window->search.search_case_check_box);
2246
2247    /* Create Search Word Start Option check box */
2248    window->search.search_word_start_check_box = elm_check_add(window->elm_window);
2249    elm_object_text_set(window->search.search_word_start_check_box, "Only Word Start");
2250    evas_object_smart_callback_add(window->search.search_word_start_check_box, "changed", _search_word_start_option_changed_cb, window);
2251    elm_box_pack_end(window->search.search_bar, window->search.search_word_start_check_box);
2252
2253    /* Create Search close button */
2254    window->search.close_button = create_toolbar_button(window->elm_window, "close");
2255    evas_object_smart_callback_add(window->search.close_button, "clicked", _search_close_button_clicked_cb, window);
2256    elm_object_disabled_set(window->search.close_button, EINA_FALSE);
2257    evas_object_size_hint_weight_set(window->search.close_button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2258    evas_object_size_hint_align_set(window->search.close_button, 1.0, 0.5);
2259    evas_object_size_hint_min_set(window->search.close_button, SEARCH_BUTTON_SIZE, SEARCH_BUTTON_SIZE);
2260    elm_box_pack_end(window->search.search_bar, window->search.close_button);
2261
2262    /* Create history box */
2263    window->history.history_box = elm_box_add(window->elm_window);
2264    evas_object_size_hint_aspect_set(window->history.history_box, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
2265    evas_object_size_hint_weight_set(window->history.history_box, EVAS_HINT_EXPAND , EVAS_HINT_EXPAND);
2266
2267    /* Create history list */
2268    window->history.history_list = elm_genlist_add(window->elm_window);
2269    evas_object_size_hint_weight_set(window->history.history_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2270    evas_object_size_hint_align_set(window->history.history_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
2271    elm_win_resize_object_add(window->elm_window, window->history.history_box);
2272    elm_box_pack_end(window->history.history_box, window->history.history_list);
2273
2274    /* Create ewk_view */
2275    Ewk_View_Smart_Class *ewkViewClass = miniBrowserViewSmartClass();
2276    ewkViewClass->run_javascript_alert = _javascript_alert_cb;
2277    ewkViewClass->run_javascript_confirm = _javascript_confirm_cb;
2278    ewkViewClass->run_javascript_prompt = _javascript_prompt_cb;
2279    ewkViewClass->run_javascript_before_unload_confirm = _javascript_before_unload_confirm_cb;
2280    ewkViewClass->window_geometry_get = _window_geometry_get;
2281    ewkViewClass->window_geometry_set = _window_geometry_set;
2282    ewkViewClass->fullscreen_enter = _fullscreen_enter_cb;
2283    ewkViewClass->fullscreen_exit = _fullscreen_exit_cb;
2284    ewkViewClass->window_create = _window_create_cb;
2285    ewkViewClass->window_close = _window_close_cb;
2286    ewkViewClass->popup_menu_show = _popup_menu_show;
2287    ewkViewClass->popup_menu_hide = _popup_menu_hide;
2288    ewkViewClass->context_menu_show = _context_menu_show;
2289    ewkViewClass->context_menu_hide = _context_menu_hide;
2290    ewkViewClass->input_picker_color_request = _color_picker_request_cb;
2291    ewkViewClass->input_picker_color_dismiss = _color_picker_dismiss_cb;
2292
2293    Evas *evas = evas_object_evas_get(window->elm_window);
2294    Evas_Smart *smart = evas_smart_class_new(&ewkViewClass->sc);
2295    window->ewk_view = ewk_view_add_with_configuration(evas, smart, configuration);
2296
2297    Ewk_Context *context = ewk_view_context_get(window->ewk_view);
2298    ewk_favicon_database_icon_change_callback_add(ewk_context_favicon_database_get(context), _icon_changed_cb, window);
2299
2300    ewk_view_theme_set(window->ewk_view, DEFAULT_THEME_DIR "/default.edj");
2301    if (device_pixel_ratio)
2302      ewk_view_device_pixel_ratio_set(window->ewk_view, (float)device_pixel_ratio);
2303    ewk_view_user_agent_set(window->ewk_view, user_agent_string);
2304    ewk_view_layout_fixed_set(window->ewk_view, fixed_layout_enabled);
2305
2306    if (touch_events_enabled) {
2307      ewk_view_touch_events_enabled_set(window->ewk_view, EINA_TRUE);
2308      ewk_view_mouse_events_enabled_set(window->ewk_view, EINA_FALSE);
2309    }
2310
2311    if (background_color_string) {
2312      int red, green, blue, alpha;
2313
2314      if (sscanf(background_color_string, "%d:%d:%d:%d", &red, &green, &blue, &alpha))
2315        ewk_view_bg_color_set(window->ewk_view, red, green, blue, alpha);
2316    }
2317
2318    /* Set the zoom level to default */
2319    window->current_zoom_level = DEFAULT_ZOOM_LEVEL;
2320
2321    elm_win_fullscreen_set(window->elm_window, fullscreen_enabled);
2322
2323    evas_object_smart_callback_add(window->ewk_view, "authentication,request", _authentication_request_cb, window);
2324    evas_object_smart_callback_add(window->ewk_view, "file,chooser,request", _file_chooser_request_cb, window);
2325    evas_object_smart_callback_add(window->ewk_view, "load,error", _error_cb, window);
2326    evas_object_smart_callback_add(window->ewk_view, "load,provisional,failed", _error_cb, window);
2327    evas_object_smart_callback_add(window->ewk_view, "load,progress", _progress_cb, window);
2328    evas_object_smart_callback_add(window->ewk_view, "title,changed", _title_changed_cb, window);
2329    evas_object_smart_callback_add(window->ewk_view, "url,changed", _url_changed_cb, window);
2330    evas_object_smart_callback_add(window->ewk_view, "back,forward,list,changed", _back_forward_list_changed_cb, window);
2331    evas_object_smart_callback_add(window->ewk_view, "text,found", _search_text_found_cb, window);
2332    evas_object_smart_callback_add(window->ewk_view, "tooltip,text,set", _tooltip_text_set, window);
2333    evas_object_smart_callback_add(window->ewk_view, "tooltip,text,unset", _tooltip_text_unset, window);
2334    evas_object_smart_callback_add(window->ewk_view, "policy,decision,navigation", _navigation_policy_decision_cb, window);
2335
2336    evas_object_event_callback_add(window->ewk_view, EVAS_CALLBACK_KEY_DOWN, _key_down_cb, window);
2337    evas_object_event_callback_add(window->ewk_view, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down_cb, window);
2338
2339    evas_object_size_hint_weight_set(window->ewk_view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2340    evas_object_size_hint_align_set(window->ewk_view, EVAS_HINT_FILL, EVAS_HINT_FILL);
2341    elm_box_pack_before(window->vertical_layout, window->ewk_view, window->search.search_bar);
2342    evas_object_show(window->ewk_view);
2343
2344    evas_object_resize(window->elm_window, width ? width : window_width, height ? height : window_height);
2345    evas_object_show(window->elm_window);
2346    search_box_hide(window);
2347
2348    view_focus_set(window, EINA_TRUE);
2349    // Prevent window from stealing web view's focus on start up.
2350    elm_object_focus_allow_set(window->elm_window, EINA_FALSE);
2351
2352    evas_object_event_callback_add(window->ewk_view, EVAS_CALLBACK_MOUSE_IN, _mouse_in_cb, window);
2353    evas_object_event_callback_add(window->ewk_view, EVAS_CALLBACK_MOUSE_OUT, _mouse_out_cb, window);
2354    evas_object_event_callback_add(window->ewk_view, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move_cb, window);
2355    evas_object_event_callback_add(window->ewk_view, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, window);
2356    evas_object_event_callback_add(window->elm_window, EVAS_CALLBACK_RESIZE, _window_resize_cb, window);
2357
2358    elm_button_autorepeat_set(window->back_button, EINA_TRUE);
2359    elm_button_autorepeat_set(window->forward_button, EINA_TRUE);
2360    elm_button_autorepeat_initial_timeout_set(window->back_button, LONGPRESS_INTERVAL_SECONDS);
2361    elm_button_autorepeat_initial_timeout_set(window->forward_button, LONGPRESS_INTERVAL_SECONDS);
2362
2363    return window;
2364 }
2365
2366 static Ewk_View_Configuration* configuration()
2367 {
2368     static Ewk_View_Configuration* default_configuration = 0;
2369
2370     if (default_configuration)
2371       return default_configuration;
2372
2373     default_configuration = ewk_view_configuration_new();
2374
2375     Ewk_Settings* settings = ewk_view_configuration_settings_get(default_configuration);
2376     ewk_settings_file_access_from_file_urls_allowed_set(settings, EINA_TRUE);
2377     ewk_settings_encoding_detector_enabled_set(settings, encoding_detector_enabled);
2378     ewk_settings_frame_flattening_enabled_set(settings, frame_flattening_enabled);
2379     ewk_settings_local_storage_enabled_set(settings, local_storage_enabled);
2380     ewk_settings_offline_web_application_cache_enabled_set(settings, offline_web_application_cache_enabled);
2381     INFO("HTML5 local storage is %s for this view.", local_storage_enabled ? "enabled" : "disabled");
2382     ewk_settings_developer_extras_enabled_set(settings, EINA_TRUE);
2383     ewk_settings_preferred_minimum_contents_width_set(settings, 0);
2384     ewk_text_checker_continuous_spell_checking_enabled_set(spell_checking_enabled);
2385     ewk_settings_web_security_enabled_set(settings, web_security_enabled);
2386
2387     return default_configuration;
2388 }
2389
2390 static Ewk_Cookie_Accept_Policy
2391 parse_cookies_policy(const char *input_string)
2392 {
2393    if (!strcmp(input_string, "always"))
2394      return EWK_COOKIE_ACCEPT_POLICY_ALWAYS;
2395    if (!strcmp(input_string, "never"))
2396      return EWK_COOKIE_ACCEPT_POLICY_NEVER;
2397    if (strcmp(input_string, "no-third-party"))
2398      INFO("Unrecognized type for cookies policy: %s.", input_string);
2399    return EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY;
2400 }
2401
2402 static void
2403 parse_window_size(const char *input_string, int *width, int *height)
2404 {
2405    static const unsigned max_length = 4;
2406    int parsed_width;
2407    int parsed_height;
2408    char **arr;
2409    unsigned elements;
2410
2411    arr = eina_str_split_full(input_string, "x", 0, &elements);
2412
2413    if (elements == 2 && (strlen(arr[0]) <= max_length) && (strlen(arr[1]) <= max_length)) {
2414      parsed_width = atoi(arr[0]);
2415      if (width && parsed_width)
2416        *width = parsed_width;
2417
2418      parsed_height = atoi(arr[1]);
2419      if (height && parsed_height)
2420        *height = parsed_height;
2421    }
2422
2423    free(arr[0]);
2424    free(arr);
2425 }
2426
2427 EAPI_MAIN int
2428 elm_main(int argc, char *argv[])
2429 {
2430    int args = 1;
2431    unsigned char quitOption = 0;
2432    Browser_Window *window;
2433    char *window_size_string = NULL;
2434    char *cookies_policy_string = NULL;
2435
2436    Ecore_Getopt_Value values[] = {
2437      ECORE_GETOPT_VALUE_STR(evas_engine_name),
2438      ECORE_GETOPT_VALUE_STR(window_size_string),
2439      ECORE_GETOPT_VALUE_STR(user_agent_string),
2440      ECORE_GETOPT_VALUE_STR(extensions_path),
2441      ECORE_GETOPT_VALUE_DOUBLE(device_pixel_ratio),
2442      ECORE_GETOPT_VALUE_BOOL(quitOption),
2443      ECORE_GETOPT_VALUE_BOOL(encoding_detector_enabled),
2444      ECORE_GETOPT_VALUE_STR(background_color_string),
2445      ECORE_GETOPT_VALUE_BOOL(frame_flattening_enabled),
2446      ECORE_GETOPT_VALUE_BOOL(local_storage_enabled),
2447      ECORE_GETOPT_VALUE_BOOL(offline_web_application_cache_enabled),
2448      ECORE_GETOPT_VALUE_BOOL(fullscreen_enabled),
2449      ECORE_GETOPT_VALUE_BOOL(spell_checking_enabled),
2450      ECORE_GETOPT_VALUE_BOOL(touch_events_enabled),
2451      ECORE_GETOPT_VALUE_BOOL(fixed_layout_enabled),
2452      ECORE_GETOPT_VALUE_STR(cookies_policy_string),
2453      ECORE_GETOPT_VALUE_BOOL(web_security_enabled),
2454      ECORE_GETOPT_VALUE_BOOL(separated_process_enabled),
2455      ECORE_GETOPT_VALUE_BOOL(quitOption),
2456      ECORE_GETOPT_VALUE_BOOL(quitOption),
2457      ECORE_GETOPT_VALUE_BOOL(quitOption),
2458      ECORE_GETOPT_VALUE_NONE
2459    };
2460
2461    efreet_cache_update = 0;
2462
2463    if (!ewk_init())
2464      return EXIT_FAILURE;
2465
2466    _log_domain_id = eina_log_domain_register("minibrowser", EINA_COLOR_YELLOW);
2467
2468    ewk_view_smart_class_set(miniBrowserViewSmartClass());
2469
2470    ecore_app_args_set(argc, (const char **) argv);
2471    args = ecore_getopt_parse(&options, values, argc, argv);
2472
2473    if (args < 0)
2474      return quit(EINA_FALSE, "Could not parse options.");
2475
2476    if (quitOption)
2477      return quit(EINA_TRUE, NULL);
2478
2479    if (evas_engine_name)
2480      elm_config_accel_preference_set(evas_engine_name);
2481    else {
2482      evas_engine_name = "opengl:depth24:stencil8";
2483      elm_config_accel_preference_set(evas_engine_name);
2484    }
2485
2486    Ewk_Context *context = ewk_context_default_get();
2487
2488    if (separated_process_enabled)
2489      ewk_context_web_process_count_limit_set(context, 0);
2490
2491    // Enable favicon database.
2492    ewk_context_favicon_database_directory_set(context, NULL);
2493
2494    // Use a proper cache model.
2495    ewk_context_cache_model_set(context, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
2496
2497    if (cookies_policy_string) {
2498      Ewk_Cookie_Accept_Policy cookie_policy = parse_cookies_policy(cookies_policy_string);
2499      ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), cookie_policy);
2500
2501      if (cookie_policy == EWK_COOKIE_ACCEPT_POLICY_ALWAYS) {
2502        const char cookie_storage_directory[] = "/tmp/ewebkit2_minibrowser_cookie/";
2503        mkdir(cookie_storage_directory, S_IRWXU);
2504        char storage_name[64];
2505        snprintf(storage_name, sizeof(storage_name), "%stxt-cookie", cookie_storage_directory);
2506        ewk_cookie_manager_persistent_storage_set(ewk_context_cookie_manager_get(context), storage_name, EWK_COOKIE_PERSISTENT_STORAGE_TEXT);
2507      }
2508    }
2509
2510    if (window_size_string)
2511      parse_window_size(window_size_string, &window_width, &window_height);
2512
2513    window = window_create(configuration(), 0, 0);
2514    if (!window)
2515      return quit(EINA_FALSE, "Could not create browser window.");
2516
2517    // Set callbacks for download events.
2518    ewk_context_download_callbacks_set(context, _download_request_cb, _download_failed_cb, 0, _download_finished_cb, window);
2519
2520    if (args < argc) {
2521      char *url = url_from_user_input(argv[args]);
2522      url_load_from_user_input(window->ewk_view, url);
2523      free(url);
2524    } else
2525      ewk_view_url_set(window->ewk_view, DEFAULT_URL);
2526
2527    windows = eina_list_append(windows, window);
2528
2529    elm_run();
2530
2531    return quit(EINA_TRUE, NULL);
2532 }
2533 ELM_MAIN()
2534