remove test2 text
[scm/test.git] / aegis_test.c
1 opyright 2012  Samsung Electronics Co., Ltd 
2  *          
3  * Licensed under the Flora License, Version 1.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.tizenopensource.org/license
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  */
16  
17
18 #include "browser-settings-class.h"
19 #include "browser-settings-website-setting.h"
20 #include "browser-view.h"
21
22 Browser_Settings_Website_Setting::Browser_Settings_Website_Setting(Browser_Settings_Main_View *main_view)
23 :
24         m_genlist(NULL)
25         ,m_details_genlist(NULL)
26         ,m_back_button(NULL)
27         ,m_back_button_details(NULL)
28         ,m_clear_confirm_popup(NULL)
29         ,m_delete_all_website_list_confirm_popup(NULL)
30         ,m_delete_all_details_list_confirm_popup(NULL)
31         ,m_bottom_control_bar(NULL)
32         ,m_details_bottom_control_bar(NULL)
33         ,m_delete_all_website_list_conbar_item(NULL)
34         ,m_delete_all_details_conbar_item(NULL)
35         ,m_current_website_item_data(NULL)
36         ,m_current_item_data(NULL)
37         ,m_is_called_appcache_cb_flag(false)
38         ,m_is_called_webstorage_cb_flag(false)
39         ,m_is_called_webdb_cb_flag(false)
40         ,m_main_view(main_view)
41 {
42         BROWSER_LOGD("[%s]", __func__);
43 }
44
45 Browser_Settings_Website_Setting::~Browser_Settings_Website_Setting(void)
46 {
47         BROWSER_LOGD("[%s]", __func__);
48
49         for (int i = 0 ; i < m_website_setting_list.size() ; i++) {
50                 if (m_website_setting_list[i])
51                         delete m_website_setting_list[i];
52         }
53         m_website_setting_list.clear();
54 }
55
56 Eina_Bool Browser_Settings_Website_Setting::init(void)
57 {
58         BROWSER_LOGD("[%s]", __func__);
59
60         if (!_create_main_layout()) {
61                 BROWSER_LOGE("_create_main_layout failed");
62                 return EINA_FALSE;
63         }
64
65         return EINA_TRUE;
66 }
67
68 Evas_Object *Browser_Settings_Website_Setting::__genlist_icon_get(void *data,
69                                                 Evas_Object *obj, const char *part)
70 {
71         if (!data)
72                 return NULL;
73
74         BROWSER_LOGD("part = [%s]", part);
75
76         Browser_Geolocation_DB::geolocation_info *info = (Browser_Geolocation_DB::geolocation_info *)data;
77
78         if (part && strlen(part) > 0) {
79                 if (!strncmp(part, "elm.icon.1", strlen("elm.icon.1"))) {
80                         Evas_Object *favicon = NULL;
81                         favicon = m_data_manager->get_browser_view()->get_favicon(info->url.c_str());
82                         if (favicon)
83                                 return favicon;
84                         else {
85                                 Evas_Object *default_icon = elm_icon_add(obj);
86                                 if (!default_icon)
87                                         return NULL;
88                                 if (!elm_icon_file_set(default_icon, BROWSER_IMAGE_DIR"/faviconDefault.png", NULL)) {
89                                         BROWSER_LOGE("elm_icon_file_set is failed.\n");
90                                         return NULL;
91                                 }
92                                 evas_object_size_hint_aspect_set(default_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
93                                 return default_icon;
94                         }
95                 } else if (!strncmp(part,"elm.icon.2", strlen("elm.icon.2"))) {
96                         Evas_Object *location_icon = elm_icon_add(obj);
97                         if (!location_icon)
98                                 return NULL;
99
100                         if (info->geolocation) {
101                                 if (info->allow) {
102                                         if (!elm_icon_file_set(location_icon, BROWSER_IMAGE_DIR"/I01_icon_location_allowed.png", NULL)) {
103                                                 BROWSER_LOGE("elm_icon_file_set is failed.\n");
104                                                 return NULL;
105                                         }
106                                         evas_object_size_hint_aspect_set(location_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
107                                         return location_icon;
108                                 } else {
109                                         if (!elm_icon_file_set(location_icon, BROWSER_IMAGE_DIR"/I01_icon_location_denied.png", NULL)) {
110                                                 BROWSER_LOGE("elm_icon_file_set is failed.\n");
111                                                 return NULL;
112                                         }
113                                         evas_object_size_hint_aspect_set(location_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
114                                         return location_icon;
115                                 }
116                         }
117                 } else if (!strncmp(part,"elm.icon.3", strlen("elm.icon.3"))) {
118                         Evas_Object *storage_icon = elm_icon_add(obj);
119                         if (!storage_icon)
120                                 return NULL;
121                         if (info->storage) {
122                                 if (!elm_icon_file_set(storage_icon, BROWSER_IMAGE_DIR"/I01_icon_web_storage.png", NULL)) {
123                                         BROWSER_LOGE("elm_icon_file_set is failed.\n");
124                                         return NULL;
125                                 }
126                                 evas_object_size_hint_aspect_set(storage_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
127                                 return storage_icon;
128                         }
129                 }
130         }
131
132         return NULL;
133 }
134
135 char *Browser_Settings_Website_Setting::__genlist_label_get(void *data,
136                                         Evas_Object *obj, const char *part)
137 {
138         if (!data)
139                 return NULL;
140
141         BROWSER_LOGD("part = [%s]", part);
142
143         Browser_Geolocation_DB::geolocation_info *info = (Browser_Geolocation_DB::geolocation_info *)data;
144         const char *url = info->url.c_str();
145
146         if (part && strlen(part) > 0) {
147                 if (!strncmp(part,"elm.text", strlen("elm.text"))) {
148                         if (url && strlen(url))
149                                 return strdup(url);
150                 }
151         }
152
153         return NULL;
154 }
155
156 Evas_Object *Browser_Settings_Website_Setting::__details_genlist_icon_get(void *data,
157                                                 Evas_Object *obj, const char *part)
158 {
159         if (!data)
160                 return NULL;
161
162         BROWSER_LOGD("part = [%s]", part);
163
164         genlist_callback_data *callback_data = (genlist_callback_data *)data;
165         Browser_Settings_Website_Setting::menu_type type = callback_data->type;
166         Browser_Settings_Website_Setting *website_setting = NULL;
167
168         Browser_Geolocation_DB::geolocation_info *info =
169                 (Browser_Geolocation_DB::geolocation_info *)(callback_data->user_data);
170
171         if (part && strlen(part) > 0) {
172                 if (!strncmp(part, "elm.icon", strlen("elm.icon"))) {
173                         if (type == BR_MENU_LOCATION) {
174                                 BROWSER_LOGD("location menu\n");
175                                 Evas_Object *location_icon = elm_icon_add(obj);
176                                 if (!location_icon)
177                                         return NULL;
178                                 if (info->geolocation) {
179                                         if (info->allow) {
180                                                 if (!elm_icon_file_set(location_icon, BROWSER_IMAGE_DIR"/I01_icon_location_allowed_small.png", NULL)) {
181                                                         BROWSER_LOGE("elm_icon_file_set is failed.\n");
182                                                         return NULL;
183                                                 }
184                                                 evas_object_size_hint_aspect_set(location_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
185                                                 return location_icon;
186                                         } else {
187                                                 if (!elm_icon_file_set(location_icon, BROWSER_IMAGE_DIR"/I01_icon_location_denied_small.png", NULL)) {
188                                                         BROWSER_LOGE("elm_icon_file_set is failed.\n");
189                                                         return NULL;
190                                                 }
191                                                 evas_object_size_hint_aspect_set(location_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
192                                                 return location_icon;
193                                         }
194                                 }
195                         } else if (type == BR_MENU_WEB_STORAGE) {
196                                 BROWSER_LOGD("web storage menu.\n");
197                                 Evas_Object *storage_icon = elm_icon_add(obj);
198                                 if (!storage_icon)
199                                         return NULL;
200                                 if (info->storage) {
201                                         if (!elm_icon_file_set(storage_icon, BROWSER_IMAGE_DIR"/I01_icon_web_storage_small.png", NULL)) {
202                                                 BROWSER_LOGE("elm_icon_file_set is failed.\n");
203                                                 return NULL;
204                                         }
205                                         evas_object_size_hint_aspect_set(storage_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
206                                         return storage_icon;
207                                 }
208                         }else {
209                                 BROWSER_LOGD("wrong menu index.\n");
210                                 return NULL;
211                         }
212                 }
213         }
214         return NULL;
215 }
216
217 char *Browser_Settings_Website_Setting::__details_genlist_label_get(void *data,
218                                         Evas_Object *obj, const char *part)
219 {
220         if (!data)
221                 return NULL;
222
223         BROWSER_LOGD("part = [%s]", part);
224         genlist_callback_data *callback_data = (genlist_callback_data *)data;
225         Browser_Settings_Website_Setting::menu_type type = callback_data->type;
226         Browser_Settings_Website_Setting *website_setting = NULL;
227
228         Browser_Geolocation_DB::geolocation_info *info =
229                 (Browser_Geolocation_DB::geolocation_info *)(callback_data->user_data);
230         const char *url = info->url.c_str();
231
232         if (part && strlen(part) > 0) {
233                 if (!strncmp(part,"elm.text", strlen("elm.text"))) {
234                         if (type == BR_MENU_LOCATION) {
235                                 BROWSER_LOGD("location menu.\n");
236                                 return strdup(BR_STRING_CLEAR_LOCATION_ACCESS);
237                         } else if (type == BR_MENU_WEB_STORAGE) {
238                                 BROWSER_LOGD("web storage menu.\n");
239                                 return strdup(BR_STRING_CLEAR_STORED_DATA);
240                         }else {
241                                 BROWSER_LOGD("wrong menu index.\n");
242                                 return NULL;
243                         }
244                 }
245         }
246         return NULL;
247 }
248
249 void Browser_Settings_Website_Setting::__item_selected_cb(void *data, Evas_Object *obj, void *event_info)
250 {
251         BROWSER_LOGD("[%s]", __func__);
252         if (!data)
253                 return;
254
255         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)data;
256         Elm_Object_Item *it = (Elm_Object_Item *)event_info;
257         website_setting->m_current_website_item_data = NULL;
258         website_setting->m_current_website_item_data = (website_setting_item *)elm_object_item_data_get(it);
259
260         website_setting->_show_details_list(website_setting->m_current_website_item_data);
261         elm_genlist_item_selected_set(it, EINA_FALSE);
262 }
263
264 void Browser_Settings_Website_Setting::__details_item_selected_cb(void *data, Evas_Object *obj, void *event_info)
265 {
266         BROWSER_LOGD("[%s]", __func__);
267         if (!data)
268                 return;
269
270         genlist_callback_data *callback_data = (genlist_callback_data *)data;
271         Browser_Settings_Website_Setting::menu_type type = callback_data->type;
272         Browser_Settings_Website_Setting *website_setting = NULL;
273         website_setting = (Browser_Settings_Website_Setting *)(callback_data->cp);
274
275         website_setting->m_current_item_data = (website_setting_item *)callback_data->user_data;
276         if (type == BR_MENU_LOCATION) {
277                 website_setting->_show_clear_location_confirm_popup();
278         } else if (type == BR_MENU_WEB_STORAGE) {
279                 website_setting->_show_clear_web_storage_confirm_popup();
280         }
281
282         elm_genlist_item_selected_set(callback_data->it, EINA_FALSE);
283 }
284
285 Eina_Bool Browser_Settings_Website_Setting::_show_clear_location_confirm_popup(void)
286 {
287         BROWSER_LOGD("[%s]", __func__);
288         if (m_clear_confirm_popup)
289                 evas_object_del(m_clear_confirm_popup);
290
291         m_clear_confirm_popup = elm_popup_add(m_details_genlist);
292         if (!m_clear_confirm_popup) {
293                 BROWSER_LOGE("elm_popup_add failed");
294                 return EINA_FALSE;
295         }
296
297         evas_object_size_hint_weight_set(m_clear_confirm_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
298
299         elm_object_text_set(m_clear_confirm_popup, BR_STRING_CLEAR_LOCATION_ACCESS_FOR_THIS_WEBSITE);
300
301         Evas_Object *ok_button = elm_button_add(m_clear_confirm_popup);
302         if (!ok_button) {
303                 BROWSER_LOGE("elm_button_add failed");
304                 return EINA_FALSE;
305         }
306         elm_object_text_set(ok_button, BR_STRING_YES);
307         elm_object_part_content_set(m_clear_confirm_popup, "button1", ok_button);
308         evas_object_smart_callback_add(ok_button, "clicked", __clear_location_confirm_response_cb, this);
309
310         Evas_Object *cancel_button = elm_button_add(m_clear_confirm_popup);
311         elm_object_text_set(cancel_button, BR_STRING_NO);
312         elm_object_part_content_set(m_clear_confirm_popup, "button2", cancel_button);
313         evas_object_smart_callback_add(cancel_button, "clicked", __cancel_clear_location_confirm_response_cb, this);
314
315         evas_object_show(m_clear_confirm_popup);
316
317         return EINA_TRUE;
318 }
319
320 Eina_Bool Browser_Settings_Website_Setting::_show_clear_web_storage_confirm_popup(void)
321 {
322         BROWSER_LOGD("[%s]", __func__);
323         if (m_clear_confirm_popup)
324                 evas_object_del(m_clear_confirm_popup);
325
326         m_clear_confirm_popup = elm_popup_add(m_details_genlist);
327         if (!m_clear_confirm_popup) {
328                 BROWSER_LOGE("elm_popup_add failed");
329                 return EINA_FALSE;
330         }
331
332         evas_object_size_hint_weight_set(m_clear_confirm_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
333
334         elm_object_text_set(m_clear_confirm_popup, BR_STRING_DELETE_ALL_STORED_DATA_BY_THIS_WEBSITE);
335
336         Evas_Object *ok_button = elm_button_add(m_clear_confirm_popup);
337         if (!ok_button) {
338                 BROWSER_LOGE("elm_button_add failed");
339                 return EINA_FALSE;
340         }
341         elm_object_text_set(ok_button, BR_STRING_YES);
342         elm_object_part_content_set(m_clear_confirm_popup, "button1", ok_button);
343         evas_object_smart_callback_add(ok_button, "clicked", __clear_web_storage_confirm_response_cb, this);
344
345         Evas_Object *cancel_button = elm_button_add(m_clear_confirm_popup);
346         elm_object_text_set(cancel_button, BR_STRING_NO);
347         elm_object_part_content_set(m_clear_confirm_popup, "button2", cancel_button);
348         evas_object_smart_callback_add(cancel_button, "clicked", __cancel_clear_web_storage_confirm_response_cb, this);
349
350         evas_object_show(m_clear_confirm_popup);
351
352         return EINA_TRUE;
353 }
354
355 Eina_Bool Browser_Settings_Website_Setting::_show_delete_all_website_list_confirm_popup(void)
356 {
357         BROWSER_LOGD("[%s]", __func__);
358         if (m_delete_all_website_list_confirm_popup)
359                 evas_object_del(m_delete_all_website_list_confirm_popup);
360
361         m_delete_all_website_list_confirm_popup = elm_popup_add(m_genlist);
362         if (!m_delete_all_website_list_confirm_popup) {
363                 BROWSER_LOGE("elm_popup_add failed");
364                 return EINA_FALSE;
365         }
366
367         evas_object_size_hint_weight_set(m_delete_all_website_list_confirm_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
368
369         elm_object_text_set(m_delete_all_website_list_confirm_popup, BR_STRING_DELETE_ALL_WEBSITE_DATA_AND_LOCATION_PERMISSIONS);
370
371         Evas_Object *ok_button = elm_button_add(m_delete_all_website_list_confirm_popup);
372         if (!ok_button) {
373                 BROWSER_LOGE("elm_button_add failed");
374                 return EINA_FALSE;
375         }
376         elm_object_text_set(ok_button, BR_STRING_YES);
377         elm_object_part_content_set(m_delete_all_website_list_confirm_popup, "button1", ok_button);
378         evas_object_smart_callback_add(ok_button, "clicked", __delete_all_website_list_confirm_response_cb, this);
379
380         Evas_Object *cancel_button = elm_button_add(m_delete_all_website_list_confirm_popup);
381         elm_object_text_set(cancel_button, BR_STRING_NO);
382         elm_object_part_content_set(m_delete_all_website_list_confirm_popup, "button2", cancel_button);
383         evas_object_smart_callback_add(cancel_button, "clicked", __cancel_delete_all_website_list_confirm_response_cb, this);
384
385         evas_object_show(m_delete_all_website_list_confirm_popup);
386
387         return EINA_TRUE;
388 }
389
390 Eina_Bool Browser_Settings_Website_Setting::_show_delete_all_details_list_confirm_popup(void)
391 {
392         BROWSER_LOGD("[%s]", __func__);
393         if (m_delete_all_details_list_confirm_popup)
394                 evas_object_del(m_delete_all_details_list_confirm_popup);
395
396         m_delete_all_details_list_confirm_popup = elm_popup_add(m_details_genlist);
397         if (!m_delete_all_details_list_confirm_popup) {
398                 BROWSER_LOGE("elm_popup_add failed");
399                 return EINA_FALSE;
400         }
401
402         evas_object_size_hint_weight_set(m_delete_all_details_list_confirm_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
403
404         elm_object_text_set(m_delete_all_details_list_confirm_popup, BR_STRING_DELETE_ALL_WEBSITE_DATA_AND_LOCATION_PERMISSIONS);
405
406         Evas_Object *ok_button = elm_button_add(m_delete_all_details_list_confirm_popup);
407         if (!ok_button) {
408                 BROWSER_LOGE("elm_button_add failed");
409                 return EINA_FALSE;
410         }
411         elm_object_text_set(ok_button, BR_STRING_YES);
412         elm_object_part_content_set(m_delete_all_details_list_confirm_popup, "button1", ok_button);
413         evas_object_smart_callback_add(ok_button, "clicked", __delete_all_details_list_confirm_response_cb, this);
414
415         Evas_Object *cancel_button = elm_button_add(m_delete_all_details_list_confirm_popup);
416         elm_object_text_set(cancel_button, BR_STRING_NO);
417         elm_object_part_content_set(m_delete_all_details_list_confirm_popup, "button2", cancel_button);
418         evas_object_smart_callback_add(cancel_button, "clicked", __cancel_delete_all_details_list_confirm_response_cb, this);
419
420         evas_object_show(m_delete_all_details_list_confirm_popup);
421
422         return EINA_TRUE;
423 }
424
425 void Browser_Settings_Website_Setting::__clear_location_confirm_response_cb(void *data, Evas_Object *obj, void *event_info)
426 {
427         BROWSER_LOGD("[%s]", __func__);
428         if (!data)
429                 return;
430
431         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)data;
432         if (website_setting->m_clear_confirm_popup) {
433                 evas_object_del(website_setting->m_clear_confirm_popup);
434                 website_setting->m_clear_confirm_popup = NULL;
435         }
436
437         Browser_Geolocation_DB geolocation_db;
438
439         geolocation_db.remove_geolocation_data(website_setting->m_current_item_data->url.c_str());
440         website_setting->m_current_item_data->geolocation = false;
441
442         if(website_setting->m_current_item_data->storage == false) {
443                 website_setting->__back_button_clicked_cb(NULL, NULL, NULL);
444                 website_setting->_refresh_website_list();
445         } else {
446                 website_setting->_refresh_details_list(website_setting->m_current_item_data);
447         }
448
449         website_setting->show_notify_popup(BR_STRING_DELETED, 3, EINA_TRUE);
450 }
451
452 void Browser_Settings_Website_Setting::__cancel_clear_location_confirm_response_cb(void *data, Evas_Object *obj, void *event_info)
453 {
454         BROWSER_LOGD("[%s]", __func__);
455         if (!data)
456                 return;
457
458         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)data;
459         if (website_setting->m_clear_confirm_popup) {
460                 evas_object_del(website_setting->m_clear_confirm_popup);
461                 website_setting->m_clear_confirm_popup = NULL;
462         }
463 }
464
465 void Browser_Settings_Website_Setting::__clear_web_storage_confirm_response_cb(void *data, Evas_Object *obj, void *event_info)
466 {
467         BROWSER_LOGD("[%s]", __func__);
468         if (!data)
469                 return;
470
471         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)data;
472         if (website_setting->m_clear_confirm_popup) {
473                 evas_object_del(website_setting->m_clear_confirm_popup);
474                 website_setting->m_clear_confirm_popup = NULL;
475         }
476
477         /* Clear cache */
478         Ewk_Context *ewk_context = ewk_context_default_get();
479         ewk_context_application_cache_delete(ewk_context, (Ewk_Security_Origin*)(website_setting->m_current_item_data->origin));
480         ewk_context_web_database_delete(ewk_context, (Ewk_Security_Origin*)(website_setting->m_current_item_data->origin));
481         ewk_context_web_storage_origin_delete(ewk_context, (Ewk_Security_Origin*)(website_setting->m_current_item_data->origin));
482         website_setting->m_current_item_data->storage = false;
483
484         if(website_setting->m_current_item_data->geolocation == false) {
485                 website_setting->__back_button_clicked_cb(NULL, NULL, NULL);
486                 website_setting->_refresh_website_list();
487         } else
488                 website_setting->_refresh_details_list(website_setting->m_current_item_data);
489
490         website_setting->show_notify_popup(BR_STRING_DELETED, 3, EINA_TRUE);
491 }
492
493 void Browser_Settings_Website_Setting::__cancel_clear_web_storage_confirm_response_cb(void *data, Evas_Object *obj, void *event_info)
494 {
495         BROWSER_LOGD("[%s]", __func__);
496         if (!data)
497                 return;
498
499         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)data;
500         if (website_setting->m_clear_confirm_popup) {
501                 evas_object_del(website_setting->m_clear_confirm_popup);
502                 website_setting->m_clear_confirm_popup = NULL;
503         }
504 }
505
506 void Browser_Settings_Website_Setting::__delete_all_website_list_confirm_response_cb(void *data, Evas_Object *obj, void *event_info)
507 {
508         BROWSER_LOGD("[%s]", __func__);
509         if (!data)
510                 return;
511
512         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)data;
513         if (website_setting->m_delete_all_website_list_confirm_popup) {
514                 evas_object_del(website_setting->m_delete_all_website_list_confirm_popup);
515                 website_setting->m_delete_all_website_list_confirm_popup = NULL;
516         }
517
518         /* Clear Geolocation */
519         Browser_Geolocation_DB geolocation_db;
520         geolocation_db.remove_all_geolocation_data();
521         /* Clear cache */
522         Ewk_Context *ewk_context = ewk_context_default_get();
523         ewk_context_cache_clear(ewk_context);
524         ewk_context_web_indexed_database_delete_all(ewk_context);
525         ewk_context_application_cache_delete_all(ewk_context);
526         ewk_context_web_storage_delete_all(ewk_context);
527         ewk_context_web_database_delete_all(ewk_context);
528
529         website_setting->_refresh_website_list();
530
531         website_setting->show_notify_popup(BR_STRING_DELETED, 3, EINA_TRUE);
532 }
533
534 void Browser_Settings_Website_Setting::__cancel_delete_all_website_list_confirm_response_cb(void *data, Evas_Object *obj, void *event_info)
535 {
536         BROWSER_LOGD("[%s]", __func__);
537         if (!data)
538                 return;
539
540         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)data;
541         if (website_setting->m_delete_all_website_list_confirm_popup) {
542                 evas_object_del(website_setting->m_delete_all_website_list_confirm_popup);
543                 website_setting->m_delete_all_website_list_confirm_popup = NULL;
544         }
545 }
546
547 void Browser_Settings_Website_Setting::__delete_all_details_list_confirm_response_cb(void *data, Evas_Object *obj, void *event_info)
548 {
549         BROWSER_LOGD("[%s]", __func__);
550         if (!data)
551                 return;
552
553         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)data;
554         if (website_setting->m_delete_all_details_list_confirm_popup) {
555                 evas_object_del(website_setting->m_delete_all_details_list_confirm_popup);
556                 website_setting->m_delete_all_details_list_confirm_popup = NULL;
557         }
558
559         website_setting_item *info = website_setting->m_current_website_item_data;
560         if (info->geolocation) {
561                 Browser_Geolocation_DB geolocation_db;
562                 geolocation_db.remove_geolocation_data(info->url.c_str());
563                 info->geolocation = false;
564         }
565
566         if (info->storage) {
567                 /* Clear cache */
568                 Ewk_Context *ewk_context = ewk_context_default_get();
569                 ewk_context_application_cache_delete(ewk_context,
570                         (Ewk_Security_Origin*)(info->origin));
571                 ewk_context_web_database_delete(ewk_context,
572                         (Ewk_Security_Origin*)(info->origin));
573                 ewk_context_web_storage_origin_delete(ewk_context,
574                         (Ewk_Security_Origin*)(info->origin));
575                 info->storage = false;
576         }
577
578         website_setting->__back_button_clicked_cb(NULL, NULL, NULL);
579         website_setting->_refresh_website_list();
580
581         website_setting->show_notify_popup(BR_STRING_DELETED, 3, EINA_TRUE);
582 }
583
584 void Browser_Settings_Website_Setting::__cancel_delete_all_details_list_confirm_response_cb(void *data, Evas_Object *obj, void *event_info)
585 {
586         BROWSER_LOGD("[%s]", __func__);
587         if (!data)
588                 return;
589
590         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)data;
591         if (website_setting->m_delete_all_details_list_confirm_popup) {
592                 evas_object_del(website_setting->m_delete_all_details_list_confirm_popup);
593                 website_setting->m_delete_all_details_list_confirm_popup = NULL;
594         }
595 }
596 void Browser_Settings_Website_Setting::_show_details_list(website_setting_item *item_info)
597 {
598         BROWSER_LOGD("[%s]", __func__);
599         if(!item_info)
600                 return;
601
602         m_details_genlist = elm_genlist_add(m_navi_bar);
603         if (!m_details_genlist) {
604                 BROWSER_LOGE("elm_genlist_add failed");
605                 return;
606         }
607
608         evas_object_show(m_details_genlist);
609
610         m_1_text_1_icon_item_class.item_style = "1text.1icon";
611         m_1_text_1_icon_item_class.func.text_get = __details_genlist_label_get;
612         m_1_text_1_icon_item_class.func.content_get = __details_genlist_icon_get;
613         m_1_text_1_icon_item_class.func.state_get = NULL;
614         m_1_text_1_icon_item_class.func.del = NULL;
615
616         if (item_info->geolocation) {
617                 m_location_item_callback_data.type = BR_MENU_LOCATION;
618                 m_location_item_callback_data.cp = this;
619                 m_location_item_callback_data.user_data = item_info;
620                 m_location_item_callback_data.it = elm_genlist_item_append(m_details_genlist,
621                         &m_1_text_1_icon_item_class, &m_location_item_callback_data, NULL, ELM_GENLIST_ITEM_NONE,
622                         __details_item_selected_cb, &m_location_item_callback_data);
623         }
624
625         if (item_info->storage) {
626                 m_web_storage_item_callback_data.type = BR_MENU_WEB_STORAGE;
627                 m_web_storage_item_callback_data.cp = this;
628                 m_web_storage_item_callback_data.user_data = item_info;
629                 m_web_storage_item_callback_data.it = elm_genlist_item_append(m_details_genlist,
630                                 &m_1_text_1_icon_item_class, &m_web_storage_item_callback_data, NULL, ELM_GENLIST_ITEM_NONE,
631                                 __details_item_selected_cb, &m_web_storage_item_callback_data);
632         }
633
634         m_back_button_details = elm_button_add(m_details_genlist);
635         if (!m_back_button_details) {
636                 BROWSER_LOGE("elm_button_add failed");
637                 return;
638         }
639         elm_object_style_set(m_back_button_details, "browser/bookmark_controlbar_back");
640         evas_object_show(m_back_button_details);
641         evas_object_smart_callback_add(m_back_button_details, "clicked", __back_button_clicked_cb, this);
642
643         Elm_Object_Item *navi_it = elm_naviframe_item_push(m_navi_bar, item_info->url.c_str(),
644                                                         m_back_button_details, NULL, m_details_genlist, "browser_titlebar");
645
646         m_details_bottom_control_bar = elm_toolbar_add(m_navi_bar);
647         if (!m_details_bottom_control_bar) {
648                 BROWSER_LOGE("elm_toolbar_add failed");
649                 return;
650         }
651         elm_object_style_set(m_details_bottom_control_bar, "browser/default");
652         elm_toolbar_shrink_mode_set(m_details_bottom_control_bar, ELM_TOOLBAR_SHRINK_EXPAND);
653
654         m_delete_all_details_conbar_item = elm_toolbar_item_append(m_details_bottom_control_bar,
655                                                         NULL, BR_STRING_DELETE_ALL,
656                                                         __delete_all_details_list_conbar_item_clicked_cb, this);
657         if (elm_genlist_items_count(m_details_genlist) == 0) {
658                 elm_object_item_disabled_set(m_delete_all_details_conbar_item, EINA_TRUE);
659         }
660
661         Elm_Object_Item *empty_item = elm_toolbar_item_append(m_details_bottom_control_bar, NULL, NULL, NULL, NULL);
662         elm_object_item_disabled_set(empty_item, EINA_TRUE);
663
664         empty_item = elm_toolbar_item_append(m_details_bottom_control_bar, NULL, NULL, NULL, NULL);
665         elm_object_item_disabled_set(empty_item, EINA_TRUE);
666
667         evas_object_show(m_details_bottom_control_bar);
668         elm_object_item_part_content_set(navi_it, ELM_NAVIFRAME_ITEM_CONTROLBAR, m_details_bottom_control_bar);
669 }
670
671 void Browser_Settings_Website_Setting::_refresh_details_list(website_setting_item *item_info)
672 {
673         elm_genlist_clear(m_details_genlist);
674
675         if (item_info->geolocation) {
676                 m_location_item_callback_data.type = BR_MENU_LOCATION;
677                 m_location_item_callback_data.cp = this;
678                 m_location_item_callback_data.user_data = item_info;
679                 m_location_item_callback_data.it = elm_genlist_item_append(m_details_genlist,
680                         &m_1_text_1_icon_item_class, &m_location_item_callback_data, NULL, ELM_GENLIST_ITEM_NONE,
681                         __details_item_selected_cb, &m_location_item_callback_data);
682         }
683
684         if (item_info->storage) {
685                 m_web_storage_item_callback_data.type = BR_MENU_WEB_STORAGE;
686                 m_web_storage_item_callback_data.cp = this;
687                 m_web_storage_item_callback_data.user_data = item_info;
688                 m_web_storage_item_callback_data.it = elm_genlist_item_append(m_details_genlist,
689                                 &m_1_text_1_icon_item_class, &m_web_storage_item_callback_data, NULL, ELM_GENLIST_ITEM_NONE,
690                                 __details_item_selected_cb, &m_web_storage_item_callback_data);
691         }
692 }
693
694 void Browser_Settings_Website_Setting::__back_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
695 {
696         BROWSER_LOGD("[%s]", __func__);
697
698         if (elm_naviframe_bottom_item_get(m_navi_bar)
699             != elm_naviframe_top_item_get(m_navi_bar))
700                 elm_naviframe_item_pop(m_navi_bar);
701 }
702
703 void Browser_Settings_Website_Setting::__delete_all_website_list_conbar_item_clicked_cb(void *data,
704                                                                 Evas_Object *obj, void *event_info)
705 {
706         BROWSER_LOGD("[%s]", __func__);
707         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)data;
708
709         website_setting->_show_delete_all_website_list_confirm_popup();
710 }
711
712 void Browser_Settings_Website_Setting::__delete_all_details_list_conbar_item_clicked_cb(void *data,
713                                                                 Evas_Object *obj, void *event_info)
714 {
715         BROWSER_LOGD("[%s]", __func__);
716         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)data;
717
718         website_setting->_show_delete_all_details_list_confirm_popup();
719 }
720
721 void Browser_Settings_Website_Setting::__application_cache_origin_get_cb(Eina_List* origins, void* user_data)
722 {
723         BROWSER_LOGD("[%s]", __func__);
724         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)user_data;
725
726         Eina_List *list = NULL;
727         void *list_data = NULL;
728
729         EINA_LIST_FOREACH(origins, list, list_data) {
730                 BROWSER_LOGD("list_data=%d", list_data);
731                 if (list_data) {
732                         Ewk_Security_Origin *origin = (Ewk_Security_Origin *)list_data;;
733                         BROWSER_LOGD("<<< host = [%s]", ewk_security_origin_host_get(origin));
734
735                         Eina_Bool duplicated = EINA_FALSE;
736                         for (int i = 0 ; i < website_setting->m_website_setting_list.size() ; i++) {
737                                 if (!website_setting->m_website_setting_list[i]->url.empty()
738                                     && !strcmp(website_setting->m_website_setting_list[i]->url.c_str(), ewk_security_origin_host_get(origin))) {
739                                         duplicated = EINA_TRUE;
740                                         website_setting->m_website_setting_list[i]->storage = EINA_TRUE;
741                                         website_setting->m_website_setting_list[i]->origin = origin;
742
743                                         elm_genlist_item_update((Elm_Object_Item *)(website_setting->m_website_setting_list[i]->user_data));
744                                         break;
745                                 }
746                         }
747
748                         if (!duplicated) {
749                                 website_setting_item *item = new(nothrow) website_setting_item;
750                                 item->allow = EINA_FALSE;
751                                 item->geolocation = EINA_FALSE;
752                                 item->storage = EINA_TRUE;
753                                 item->url = std::string(ewk_security_origin_host_get(origin));
754                                 item->origin = origin;
755
756                                 item->user_data = (void*)elm_genlist_item_append(website_setting->m_genlist, &website_setting->m_1_text_2_icon_item_class,
757                                                                                 item, NULL, ELM_GENLIST_ITEM_NONE,
758                                                                                 __item_selected_cb, website_setting);
759                                 website_setting->m_website_setting_list.push_back(item);
760                         }
761                 }
762         }
763
764         /* enable the deleteall button at every origin callback
765                 because these callbacks are invoked asyncronously*/
766         if (website_setting->m_website_setting_list.size() > 0) {
767                 if (website_setting->m_delete_all_website_list_conbar_item != NULL)
768                         elm_object_item_disabled_set(website_setting->m_delete_all_website_list_conbar_item, EINA_FALSE);
769         }
770
771         website_setting->m_is_called_appcache_cb_flag = true;
772         if ((website_setting->m_is_called_appcache_cb_flag == true)
773             && (website_setting->m_is_called_webstorage_cb_flag == true)
774             && (website_setting->m_is_called_webdb_cb_flag == true)) {
775                 if (website_setting->m_website_setting_list.size() == 0) {
776                         website_setting->__back_button_clicked_cb(NULL, NULL, NULL);
777                 }
778         }
779 }
780
781 void Browser_Settings_Website_Setting::__web_storage_origin_get_cb(Eina_List* origins, void* user_data)
782 {
783         BROWSER_LOGD("[%s]", __func__);
784         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)user_data;
785
786         Eina_List *list = NULL;
787         void *list_data = NULL;
788
789         EINA_LIST_FOREACH(origins, list, list_data) {
790                 BROWSER_LOGD("list_data=%d", list_data);
791                 if (list_data) {
792                         Ewk_Security_Origin *origin = (Ewk_Security_Origin *)list_data;;
793                         BROWSER_LOGD("<<< host = [%s]", ewk_security_origin_host_get(origin));
794
795                         Eina_Bool duplicated = EINA_FALSE;
796                         for (int i = 0 ; i < website_setting->m_website_setting_list.size() ; i++) {
797                                 if (!website_setting->m_website_setting_list[i]->url.empty()
798                                     && !strcmp(website_setting->m_website_setting_list[i]->url.c_str(), ewk_security_origin_host_get(origin))) {
799                                         duplicated = EINA_TRUE;
800                                         website_setting->m_website_setting_list[i]->storage = EINA_TRUE;
801                                         website_setting->m_website_setting_list[i]->origin = origin;
802
803                                         elm_genlist_item_update((Elm_Object_Item *)(website_setting->m_website_setting_list[i]->user_data));
804                                         break;
805                                 }
806                         }
807
808                         if (!duplicated) {
809                                 website_setting_item *item = new(nothrow) website_setting_item;
810                                 item->allow = EINA_FALSE;
811                                 item->geolocation = EINA_FALSE;
812                                 item->storage = EINA_TRUE;
813                                 item->url = std::string(ewk_security_origin_host_get(origin));
814                                 item->origin = origin;
815
816                                 item->user_data = (void*)elm_genlist_item_append(website_setting->m_genlist, &website_setting->m_1_text_2_icon_item_class,
817                                                                                 item, NULL, ELM_GENLIST_ITEM_NONE,
818                                                                                 __item_selected_cb, website_setting);
819                                 website_setting->m_website_setting_list.push_back(item);
820                         }
821                 }
822         }
823
824         /* enable the deleteall button at every origin callback
825                 because these callbacks are invoked asyncronously*/
826         if (website_setting->m_website_setting_list.size() > 0) {
827                 if (website_setting->m_delete_all_website_list_conbar_item != NULL)
828                         elm_object_item_disabled_set(website_setting->m_delete_all_website_list_conbar_item, EINA_FALSE);
829         }
830
831         website_setting->m_is_called_webstorage_cb_flag = true;
832         if ((website_setting->m_is_called_appcache_cb_flag == true)
833             && (website_setting->m_is_called_webstorage_cb_flag == true)
834             && (website_setting->m_is_called_webdb_cb_flag == true)) {
835                 if (website_setting->m_website_setting_list.size() == 0) {
836                         website_setting->__back_button_clicked_cb(NULL, NULL, NULL);
837                 }
838         }
839 }
840
841 void Browser_Settings_Website_Setting::__web_database_origin_get_cb(Eina_List* origins, void* user_data)
842 {
843         BROWSER_LOGD("[%s]", __func__);
844         Browser_Settings_Website_Setting *website_setting = (Browser_Settings_Website_Setting *)user_data;
845
846         Eina_List *list = NULL;
847         void *list_data = NULL;
848
849         EINA_LIST_FOREACH(origins, list, list_data) {
850                 BROWSER_LOGD("list_data=%d", list_data);
851                 if (list_data) {
852                         Ewk_Security_Origin *origin = (Ewk_Security_Origin *)list_data;
853                         BROWSER_LOGD("<<< host = [%s]", ewk_security_origin_host_get(origin));
854
855                         Eina_Bool duplicated = EINA_FALSE;
856                         for (int i = 0 ; i < website_setting->m_website_setting_list.size() ; i++) {
857                                 if (!website_setting->m_website_setting_list[i]->url.empty()
858                                     && !strcmp(website_setting->m_website_setting_list[i]->url.c_str(), ewk_security_origin_host_get(origin))) {
859                                         duplicated = EINA_TRUE;
860                                         website_setting->m_website_setting_list[i]->storage = EINA_TRUE;
861                                         website_setting->m_website_setting_list[i]->origin = origin;
862
863                                         elm_genlist_item_update((Elm_Object_Item *)(website_setting->m_website_setting_list[i]->user_data));
864                                         break;
865                                 }
866                         }
867
868                         if (!duplicated) {
869                                 website_setting_item *item = new(nothrow) website_setting_item;
870                                 item->allow = EINA_FALSE;
871                                 item->geolocation = EINA_FALSE;
872                                 item->storage = EINA_TRUE;
873                                 item->url = std::string(ewk_security_origin_host_get(origin));
874                                 item->origin = origin;
875
876                                 item->user_data = (void*)elm_genlist_item_append(website_setting->m_genlist, &website_setting->m_1_text_2_icon_item_class,
877                                                                                 item, NULL, ELM_GENLIST_ITEM_NONE,
878                                                                                 __item_selected_cb, website_setting);
879                                 website_setting->m_website_setting_list.push_back(item);
880
881                         }
882                 }
883         }
884
885         /* enable the deleteall button at every origin callback
886                 because these callbacks are invoked asyncronously*/
887         if (website_setting->m_website_setting_list.size() > 0) {
888                 if (website_setting->m_delete_all_website_list_conbar_item != NULL)
889                         elm_object_item_disabled_set(website_setting->m_delete_all_website_list_conbar_item, EINA_FALSE);
890         }
891
892         website_setting->m_is_called_webdb_cb_flag = true;
893         if ((website_setting->m_is_called_appcache_cb_flag == true)
894             && (website_setting->m_is_called_webstorage_cb_flag == true)
895             && (website_setting->m_is_called_webdb_cb_flag == true)) {
896                 if (website_setting->m_website_setting_list.size() == 0) {
897                         website_setting->__back_button_clicked_cb(NULL, NULL, NULL);
898                 }
899         }
900 }
901
902 void Browser_Settings_Website_Setting::_website_list_get(void)
903 {
904         BROWSER_LOGD("[%s]", __func__);
905         m_is_called_appcache_cb_flag = false;
906         m_is_called_webstorage_cb_flag = false;
907         m_is_called_webdb_cb_flag = false;
908         Ewk_Context *context = ewk_context_default_get();
909         ewk_context_application_cache_origins_get(context, __application_cache_origin_get_cb, this);
910         ewk_context_web_storage_origins_get(context, __web_storage_origin_get_cb, this);
911         ewk_context_web_database_origins_get(context, __web_database_origin_get_cb, this);
912
913         Browser_Geolocation_DB geolocation_db;
914
915         geolocation_db.get_geolocation_info_list(m_geolocation_list);
916
917         BROWSER_LOGD("geolocation_list size=%d", m_geolocation_list.size());
918
919         for (int i = 0 ; i < m_geolocation_list.size() ; i++) {
920                 m_geolocation_list[i]->user_data = (void* )elm_genlist_item_append(m_genlist, &m_1_text_2_icon_item_class,
921                                                                 m_geolocation_list[i], NULL, ELM_GENLIST_ITEM_NONE,
922                                                                 __item_selected_cb, this);
923
924                 m_website_setting_list.push_back((website_setting_item *)(m_geolocation_list[i]));
925         }
926 }
927
928 void Browser_Settings_Website_Setting::_refresh_website_list(void)
929 {
930         BROWSER_LOGD("[%s]", __func__);
931
932         for (int i = 0 ; i < m_website_setting_list.size() ; i++) {
933                 if (m_website_setting_list[i])
934                         delete m_website_setting_list[i];
935         }
936         m_website_setting_list.clear();
937         m_geolocation_list.clear();
938
939         elm_genlist_clear(m_genlist);
940
941         _website_list_get();
942
943         if (m_website_setting_list.size() == 0) {
944                 if (m_delete_all_website_list_conbar_item != NULL)
945                         elm_object_item_disabled_set(m_delete_all_website_list_conbar_item, EINA_TRUE);
946         }
947 }
948
949 Eina_Bool Browser_Settings_Website_Setting::_create_main_layout(void)
950 {
951         BROWSER_LOGD("[%s]", __func__);
952
953         m_genlist = elm_genlist_add(m_navi_bar);
954         if (!m_genlist) {
955                 BROWSER_LOGE("elm_genlist_add failed");
956                 return EINA_FALSE;
957         }
958
959         evas_object_show(m_genlist);
960
961         m_back_button = elm_button_add(m_genlist);
962         if (!m_back_button) {
963                 BROWSER_LOGE("elm_button_add failed");
964                 return EINA_FALSE;
965         }
966         elm_object_style_set(m_back_button, "browser/bookmark_controlbar_back");
967         evas_object_show(m_back_button);
968         evas_object_smart_callback_add(m_back_button, "clicked", __back_button_clicked_cb, this);
969
970         m_1_text_2_icon_item_class.item_style = "1text.3icon.2";
971         m_1_text_2_icon_item_class.func.text_get = __genlist_label_get;
972         m_1_text_2_icon_item_class.func.content_get = __genlist_icon_get;
973         m_1_text_2_icon_item_class.func.state_get = NULL;
974         m_1_text_2_icon_item_class.func.del = NULL;
975
976         _website_list_get();
977
978         Elm_Object_Item *navi_it = elm_naviframe_item_push(m_navi_bar, BR_STRING_WEBSITE_SETTINGS,
979                                                         m_back_button, NULL, m_genlist, "browser_titlebar");
980
981         m_bottom_control_bar = elm_toolbar_add(m_navi_bar);
982         if (!m_bottom_control_bar) {
983                 BROWSER_LOGE("elm_toolbar_add failed");
984                 return EINA_FALSE;
985         }
986         elm_object_style_set(m_bottom_control_bar, "browser/default");
987         elm_toolbar_shrink_mode_set(m_bottom_control_bar, ELM_TOOLBAR_SHRINK_EXPAND);
988
989         m_delete_all_website_list_conbar_item = elm_toolbar_item_append(m_bottom_control_bar,
990                                                         NULL, BR_STRING_DELETE_ALL,
991                                                         __delete_all_website_list_conbar_item_clicked_cb, this);
992
993         if (!m_delete_all_website_list_conbar_item) {
994                 BROWSER_LOGE("elm_toolbar_item_append failed");
995                 return EINA_FALSE;
996         }
997
998         if (m_website_setting_list.size() == 0) {
999                 elm_object_item_disabled_set(m_delete_all_website_list_conbar_item, EINA_TRUE);
1000         }
1001
1002         Elm_Object_Item *empty_item = elm_toolbar_item_append(m_bottom_control_bar, NULL, NULL, NULL, NULL);
1003         elm_object_item_disabled_set(empty_item, EINA_TRUE);
1004
1005         empty_item = elm_toolbar_item_append(m_bottom_control_bar, NULL, NULL, NULL, NULL);
1006         elm_object_item_disabled_set(empty_item, EINA_TRUE);
1007
1008         evas_object_show(m_bottom_control_bar);
1009         elm_object_item_part_content_set(navi_it, ELM_NAVIFRAME_ITEM_CONTROLBAR, m_bottom_control_bar);
1010
1011         return EINA_TRUE;
1012 }
1013
1014
1015