197a1635e3535d84a1846f371f38272ca03c9aae
[profile/ivi/org.tizen.browser.git] / src / browser-common-view.cpp
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18
19 #include "browser-class.h"
20 #include "browser-common-view.h"
21 #include "browser-view.h"
22 #include "browser-window.h"
23
24 Browser_Data_Manager *Browser_Common_View::m_data_manager;
25 Evas_Object *Browser_Common_View::m_win;
26 Evas_Object *Browser_Common_View::m_navi_bar;
27 Evas_Object *Browser_Common_View::m_bg;
28 Browser_Class *Browser_Common_View::m_browser;
29
30 Browser_Common_View::Browser_Common_View(void)
31 :
32         m_selection_info(NULL)
33         ,m_selection_info_layout(NULL)
34         ,m_selinfo_layout(NULL)
35         ,m_popup(NULL)
36         ,m_ug(NULL)
37         ,m_share_popup(NULL)
38         ,m_share_list(NULL)
39         ,m_call_confirm_popup(NULL)
40         ,m_call_type(CALL_UNKNOWN)
41 {
42         BROWSER_LOGD("[%s]", __func__);
43 }
44
45 Browser_Common_View::~Browser_Common_View(void)
46 {
47         BROWSER_LOGD("[%s]", __func__);
48         if (m_selection_info_layout) {
49                 evas_object_del(m_selection_info_layout);
50                 m_selection_info_layout = NULL;
51         }
52         if (m_selection_info) {
53                 evas_object_del(m_selection_info);
54                 m_selection_info = NULL;
55         }
56         if (m_popup) {
57                 evas_object_del(m_popup);
58                 m_popup = NULL;
59         }
60         if (m_share_popup) {
61                 evas_object_del(m_share_popup);
62                 m_share_popup = NULL;
63         }
64         if (m_share_list) {
65                 evas_object_del(m_share_list);
66                 m_share_list = NULL;
67         }
68         if (m_ug) {
69                 ug_destroy(m_ug);
70                 m_ug = NULL;
71         }
72         if (m_call_confirm_popup) {
73                 evas_object_del(m_call_confirm_popup);
74                 m_call_confirm_popup = NULL;
75         }
76
77         m_sns_path_list.clear();
78         m_sns_name_list.clear();
79         m_sns_icon_list.clear();
80 }
81
82 void Browser_Common_View::show_msg_popup(const char *msg, int timeout)
83 {
84         BROWSER_LOGD("[%s]", __func__);
85         if (m_popup) {
86                 evas_object_del(m_popup);
87                 m_popup = NULL;
88         }
89
90         m_popup = elm_popup_add(m_navi_bar);
91         evas_object_size_hint_weight_set(m_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
92         elm_object_text_set(m_popup, msg);
93         elm_popup_timeout_set(m_popup, timeout);
94         evas_object_show(m_popup);
95 }
96
97 void Browser_Common_View::show_msg_popup(const char *title, const char *msg, int timeout)
98 {
99         BROWSER_LOGD("[%s]", __func__);
100         if (m_popup) {
101                 evas_object_del(m_popup);
102                 m_popup = NULL;
103         }
104
105         m_popup = elm_popup_add(m_navi_bar);
106         evas_object_size_hint_weight_set(m_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
107         elm_object_part_text_set(m_popup, "title,text", title);
108         elm_object_text_set(m_popup, msg);
109         elm_popup_timeout_set(m_popup, timeout);
110         evas_object_show(m_popup);
111 }
112
113 void Browser_Common_View::hide_notify_popup(void)
114 {
115         if (m_selection_info_layout) {
116                 evas_object_del(m_selection_info_layout);
117                 m_selection_info_layout = NULL;
118         }
119
120         if (m_selection_info) {
121                 evas_object_del(m_selection_info);
122                 m_selection_info = NULL;
123         }
124 }
125
126 void Browser_Common_View::show_notify_popup(const char *msg, int timeout, Eina_Bool has_control_bar)
127 {
128         if (m_selection_info_layout) {
129                 evas_object_del(m_selection_info_layout);
130                 m_selection_info_layout = NULL;
131         }
132
133         if (m_selection_info) {
134                 evas_object_del(m_selection_info);
135                 m_selection_info = NULL;
136         }
137
138         int angle = 0;
139         angle = elm_win_rotation_get(m_win);
140         m_selection_info = elm_notify_add(m_navi_bar);
141         if (!m_selection_info) {
142                 BROWSER_LOGD("elm_notify_add failed");
143                 return;
144         }
145         elm_notify_orient_set(m_selection_info, ELM_NOTIFY_ORIENT_BOTTOM);
146         evas_object_size_hint_weight_set(m_selection_info, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
147         evas_object_size_hint_align_set(m_selection_info, EVAS_HINT_FILL, EVAS_HINT_FILL);
148         m_selection_info_layout = elm_layout_add(m_selection_info);
149         if (!m_selection_info_layout) {
150                 BROWSER_LOGD("elm_layout_add failed");
151                 return;
152         }
153         evas_object_size_hint_weight_set(m_selection_info_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
154         evas_object_size_hint_align_set(m_selection_info_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
155
156         elm_object_content_set(m_selection_info, m_selection_info_layout);
157
158         if (has_control_bar) {
159                 if(angle == 0 || angle == 180)
160                    elm_layout_theme_set(m_selection_info_layout, "standard", "selectioninfo",
161                                                                 "vertical/bottom_64");
162                 else
163                    elm_layout_theme_set(m_selection_info_layout, "standard", "selectioninfo",
164                                                                 "horizontal/bottom_64");
165         } else {
166                 if(angle == 0 || angle == 180)
167                    elm_layout_theme_set(m_selection_info_layout, "standard", "selectioninfo",
168                                                                 "vertical/bottom_12");
169                 else
170                    elm_layout_theme_set(m_selection_info_layout, "standard", "selectioninfo",
171                                                                 "horizontal/bottom_12");
172         }
173         edje_object_part_text_set(elm_layout_edje_get(m_selection_info_layout), "elm.text", msg);
174
175         if (timeout)
176                 elm_notify_timeout_set(m_selection_info, timeout);
177
178         evas_object_show(m_selection_info);
179 }
180
181 void Browser_Common_View::show_notify_popup_layout(const char *msg, int timeout, Evas_Object *parent)
182 {
183         if (m_selinfo_layout) {
184                 evas_object_del(m_selinfo_layout);
185                 m_selinfo_layout = NULL;
186         }
187
188         m_selinfo_layout = elm_layout_add(parent);
189         if (!m_selinfo_layout) {
190                 BROWSER_LOGD("elm_layout_add failed");
191                 return;
192         }
193         elm_object_part_content_set(parent,
194                         "selinfo.swallow.contents",
195                         m_selinfo_layout);
196         evas_object_size_hint_weight_set(m_selinfo_layout,
197                         EVAS_HINT_EXPAND,
198                         EVAS_HINT_EXPAND);
199         evas_object_size_hint_align_set(m_selinfo_layout,
200                         EVAS_HINT_FILL,
201                         EVAS_HINT_FILL);
202
203         elm_object_content_set(m_selection_info, m_selection_info_layout);
204
205         /* Set the layout theme */
206         elm_layout_theme_set(m_selinfo_layout, "standard", "selectioninfo", "default");
207         /* Set the text */
208         elm_object_part_text_set(m_selinfo_layout, "elm.text", msg);
209         elm_object_signal_emit(parent, "show,selection,info", "elm");
210 }
211
212 void Browser_Common_View::hide_notify_popup_layout(Evas_Object *parent)
213 {
214         if (m_selinfo_layout) {
215                 evas_object_del(m_selinfo_layout);
216                 m_selinfo_layout = NULL;
217         }
218
219         elm_object_signal_emit(parent, "hide,selection,info", "elm");
220 }
221
222 Eina_Bool Browser_Common_View::find_word_with_text(const char *text_to_find)
223 {
224         BROWSER_LOGD("[%s], text_to_find[%s]", __func__, text_to_find);
225
226         if (!text_to_find)
227                 return EINA_FALSE;
228
229         Browser_View *browser_view = m_data_manager->get_browser_view();
230         return browser_view->launch_find_word_with_text(text_to_find);;
231 }
232
233 /* Capture snapshot with current focused ewk view. */
234 Evas_Object *Browser_Common_View::_capture_snapshot(Browser_Window *window, float scale)
235 {
236         BROWSER_LOGD("[%s]", __func__);
237
238         int focused_ewk_view_w = 0;
239         int focused_ewk_view_h = 0;
240         evas_object_geometry_get(window->m_ewk_view, NULL, NULL,
241                                                 &focused_ewk_view_w, &focused_ewk_view_h);
242
243         Evas_Object *rectangle = evas_object_rectangle_add(evas_object_evas_get(m_navi_bar));
244         evas_object_size_hint_min_set(rectangle, focused_ewk_view_w * scale, focused_ewk_view_h * scale);
245         evas_object_resize(rectangle, focused_ewk_view_w * scale, focused_ewk_view_h * scale);
246         evas_object_color_set(rectangle, 255, 255, 255, 255);
247         return rectangle;
248 }
249
250 void Browser_Common_View::__post_to_sns_cb(void *data, Evas_Object *obj, void *event_info)
251 {
252         if (!data)
253                 return;
254
255         Browser_Common_View *common_view = (Browser_Common_View *)data;
256
257         Elm_Object_Item *selected_item = elm_list_selected_item_get(common_view->m_share_list);
258         const char *sns_name = elm_object_item_text_get(selected_item);
259         BROWSER_LOGD("sns_name=[%s]", sns_name);
260
261         if (!common_view->_post_to_sns(std::string(sns_name), common_view->m_share_url))
262                 BROWSER_LOGE("_post_to_sns failed");
263
264         __popup_response_cb(common_view, NULL, NULL);
265 }
266
267 Eina_Bool Browser_Common_View::_post_to_sns(std::string sns_name, std::string url)
268 {
269         BROWSER_LOGD("sns_name=[%s],  url=[%s]", sns_name.c_str(), url.c_str());
270         if (url.empty() || sns_name.empty()) {
271                 show_msg_popup(BR_STRING_EMPTY);
272                 return EINA_FALSE;
273         }
274
275         int index = 0;
276         for (index = 0 ; index < m_sns_name_list.size() ; index++) {
277                 if (m_sns_name_list[index].find(sns_name) != string::npos)
278                         break;
279         }
280
281         if (m_sns_path_list[index].find("twitter") != string::npos
282             || m_sns_path_list[index].find("facebook") != string::npos) {
283
284                 int ret = 0;
285                 service_h service_handle = NULL;
286                 if (service_create(&service_handle) < 0) {
287                         BROWSER_LOGE("Fail to create service handle");
288                         return EINA_FALSE;
289                 }
290                 if (!service_handle) {
291                         BROWSER_LOGE("service handle is NULL");
292                         return EINA_FALSE;
293                 }
294                 if (service_set_operation(service_handle, SERVICE_OPERATION_SEND_TEXT) < 0) {
295                         BROWSER_LOGE("Fail to set service operation");
296                         service_destroy(service_handle);
297                         return EINA_FALSE;
298                 }
299                 if (service_add_extra_data(service_handle, SERVICE_DATA_TEXT, (char *)url.c_str()) < 0) {
300                         BROWSER_LOGE("Fail to set post data");
301                         service_destroy(service_handle);
302                         return EINA_FALSE;
303                 }
304                 if (service_set_package(service_handle, m_sns_path_list[index].c_str()) < 0) {
305                         BROWSER_LOGE("Fail to set SNS");
306                         service_destroy(service_handle);
307                         return EINA_FALSE;
308                 }
309                 if (service_send_launch_request(service_handle, NULL, NULL) < 0) {
310                         BROWSER_LOGE("Fail to launch service operation");
311                         service_destroy(service_handle);
312                         return EINA_FALSE;
313                 }
314                 service_destroy(service_handle);
315         }
316
317         return EINA_TRUE;
318 }
319
320 void Browser_Common_View::__send_via_message_cb(void *data, Evas_Object *obj, void *event_info)
321 {
322         if (!data)
323                 return;
324
325         Browser_Common_View *common_view = (Browser_Common_View *)data;
326         if (!common_view->_send_via_message(common_view->m_share_url, std::string()))
327                 BROWSER_LOGE("_send_via_message failed");
328
329         __popup_response_cb(common_view, NULL, NULL);
330 }
331
332 Eina_Bool Browser_Common_View::_send_via_message(std::string url, std::string to, Eina_Bool attach_file)
333 {
334         BROWSER_LOGD("[%s], url[%s], to[%s]", __func__, url.c_str(), to.c_str());
335         if (url.empty() && to.empty()) {
336                 show_msg_popup(BR_STRING_EMPTY);
337                 return EINA_FALSE;
338         }
339
340         service_h service_handle = NULL;
341         if (service_create(&service_handle) < 0) {
342                 BROWSER_LOGE("Fail to create service handle");
343                 return EINA_FALSE;
344         }
345
346         if (!service_handle) {
347                 BROWSER_LOGE("Fail to create service handle");
348                 return EINA_FALSE;
349         }
350
351         if (!url.empty()) {
352                 if (attach_file) {
353                         if (service_set_operation(service_handle, SERVICE_OPERATION_SEND) < 0) {
354                                 BROWSER_LOGE("Fail to set service operation");
355                                 service_destroy(service_handle);
356                                 return EINA_FALSE;
357                         }
358
359                         if (service_add_extra_data(service_handle, "ATTACHFILE", url.c_str())) {
360                                 BROWSER_LOGE("Fail to set extra data");
361                                 service_destroy(service_handle);
362                                 return EINA_FALSE;
363                         }
364                 } else {
365                         if (service_set_operation(service_handle, SERVICE_OPERATION_SEND_TEXT) < 0) {
366                                 BROWSER_LOGE("Fail to set service operation");
367                                 service_destroy(service_handle);
368                                 return EINA_FALSE;
369                         }
370
371                         if (service_add_extra_data(service_handle, SERVICE_DATA_TEXT, url.c_str()) < 0) {
372                                 BROWSER_LOGE("Fail to set extra data");
373                                 service_destroy(service_handle);
374                                 return EINA_FALSE;
375                         }
376                 }
377         }
378
379         if (!to.empty()) {
380                 if (url.empty()) {
381                         if (service_set_operation(service_handle, SERVICE_OPERATION_SEND_TEXT) < 0) {
382                                 BROWSER_LOGE("Fail to set service operation");
383                                 service_destroy(service_handle);
384                                 return EINA_FALSE;
385                         }
386                 }
387
388                 if (service_add_extra_data(service_handle, SERVICE_DATA_TO , to.c_str()) < 0) {
389                         BROWSER_LOGE("Fail to set extra data");
390                         service_destroy(service_handle);
391                         return EINA_FALSE;
392                 }
393         }
394
395         if (service_set_package(service_handle, SEC_MESSAGE) < 0) {//SEC_EMAIL
396                 BROWSER_LOGE("Fail to launch service operation");
397                 service_destroy(service_handle);
398                 return EINA_FALSE;
399         }
400
401         if (service_send_launch_request(service_handle, NULL, NULL) < 0) {
402                 BROWSER_LOGE("Fail to launch service operation");
403                 service_destroy(service_handle);
404                 return EINA_FALSE;
405         }
406         service_destroy(service_handle);
407
408         return EINA_TRUE;
409 }
410
411 void Browser_Common_View::__send_via_email_cb(void *data, Evas_Object *obj, void *event_info)
412 {
413         BROWSER_LOGD("%s", __func__);
414         if (!data)
415                 return;
416
417         Browser_Common_View *common_view = (Browser_Common_View *)data;
418         if (!common_view->_send_via_email(common_view->m_share_url))
419                 BROWSER_LOGE("_send_via_email failed");
420
421         __popup_response_cb(common_view, NULL, NULL);
422 }
423
424 void Browser_Common_View::__share_via_nfc_cb(void *data, Evas_Object *obj, void *event_info)
425 {
426         BROWSER_LOGD("%s", __func__);
427         if (!data)
428                 return;
429
430         Browser_Common_View *common_view = (Browser_Common_View *)data;
431         if (!common_view->_share_via_nfc(common_view->m_share_url))
432                 BROWSER_LOGE("_share_via_nfc failed");
433
434         __popup_response_cb(common_view, NULL, NULL);
435 }
436
437 Eina_Bool Browser_Common_View::_launch_streaming_player(const char *url, const char *cookie)
438 {
439         BROWSER_LOGD("%s", __func__);
440         if (!url || strlen(url) == 0) {
441                 BROWSER_LOGE("url is empty");
442                 return EINA_FALSE;
443         }
444
445         bool is_running = false;
446         if (app_manager_is_running(SEC_VT_CALL, &is_running) < 0) {
447                 BROWSER_LOGE("Fail to get app running information\n");
448                 return EINA_FALSE;
449         }
450         if (is_running) {
451                 BROWSER_LOGE("video-call is running......\n");
452                 show_msg_popup(BR_STRING_WARNING_VIDEO_PLAYER);
453                 return EINA_FALSE;
454         }
455
456         service_h service_handle = NULL;
457
458         if (service_create(&service_handle) < 0) {
459                 BROWSER_LOGE("Fail to create service handle");
460                 return EINA_FALSE;
461         }
462
463         if (!service_handle) {
464                 BROWSER_LOGE("service handle is NULL");
465                 return EINA_FALSE;
466         }
467
468         BROWSER_LOGD("url=[%s]", url);
469         if (service_add_extra_data(service_handle, "path", url) < 0) {
470                 BROWSER_LOGE("Fail to set extra data");
471                 service_destroy(service_handle);
472                 return EINA_FALSE;
473         }
474
475         if (cookie && strlen(cookie)) {
476                 if (service_add_extra_data(service_handle, "cookie", cookie) < 0) {
477                         BROWSER_LOGE("Fail to set extra data");
478                         service_destroy(service_handle);
479                         return EINA_FALSE;
480                 }
481         }
482
483         if (service_set_package(service_handle,SEC_STREAMING_PLAYER) < 0) {
484                 BROWSER_LOGE("Fail to set package");
485                 service_destroy(service_handle);
486                 return EINA_FALSE;
487         }
488
489         if (service_send_launch_request(service_handle, NULL, NULL) < 0) {
490                 BROWSER_LOGE("Fail to launch service operation");
491                 service_destroy(service_handle);
492                 return EINA_FALSE;
493         }
494
495         service_destroy(service_handle);
496
497         return EINA_TRUE;
498 }
499
500 Eina_Bool Browser_Common_View::_check_available_sns_account(void)
501 {
502         BROWSER_LOGD("%s", __func__);
503
504         int error_code = account_connect();
505         bool result = EINA_FALSE;
506
507         if(error_code != ACCOUNT_ERROR_NONE) {
508                 BROWSER_LOGD("account_connect failed with error_code[%d].\n", error_code);
509                 return EINA_FALSE;
510         }
511
512         if (account_query_account_by_package_name(__check_available_sns_account_cb,
513                                 "org.tizen.facebook", NULL) == ACCOUNT_ERROR_NONE) {
514                 BROWSER_LOGD("Account for Facebook was set\n");
515         } else if (account_query_account_by_package_name(__check_available_sns_account_cb,
516                                 "org.tizen.twitter", NULL) == ACCOUNT_ERROR_NONE) {
517                 BROWSER_LOGD("Account for Twitter was set\n");
518         } else {
519                 BROWSER_LOGD("Account Queried failed \n");
520                 error_code = account_disconnect();
521                 if(error_code != ACCOUNT_ERROR_NONE) {
522                         BROWSER_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, error_code);
523                         return EINA_FALSE;
524                 }
525         }
526
527         error_code = account_disconnect();
528         if(error_code != ACCOUNT_ERROR_NONE) {
529                 BROWSER_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, error_code);
530                 return EINA_FALSE;
531         }
532
533         return EINA_TRUE;
534 }
535
536 bool Browser_Common_View::__check_available_sns_account_cb(account_h handle, void *data)
537 {
538         BROWSER_LOGD("%s", __func__);
539
540         char *pkg_name = NULL;
541         account_get_package_name(handle, &pkg_name);
542         BROWSER_LOGD("pkg_name [%s]", pkg_name);
543
544         if (pkg_name)
545                 free(pkg_name);
546         pkg_name = NULL;
547
548         return true;
549 }
550
551 Eina_Bool Browser_Common_View::_get_available_sns_list(void)
552 {
553         BROWSER_LOGD("[%s]\n", __func__);
554
555         int  error_code = 0;
556         error_code = account_connect();
557
558         if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
559                 show_msg_popup(BR_STRING_ERROR, BR_STRING_NOT_FOUND_URL, 2);
560                 return EINA_FALSE;
561         } else if (error_code == ACCOUNT_ERROR_NONE) {
562                 error_code = account_foreach_account_from_db(__get_sns_list, this);
563                 error_code = account_disconnect();
564
565                 if (error_code !=ACCOUNT_ERROR_NONE) {
566                         BROWSER_LOGD("account_svc_disconnect failed with error code [%d]\n", error_code);
567                         return EINA_FALSE;
568                 }
569         } else {
570                 BROWSER_LOGD("account_connect failed with error code [%d]\n", error_code);
571                 return EINA_FALSE;
572         }
573
574         return EINA_TRUE;
575 }
576
577
578 bool Browser_Common_View::__get_sns_list(account_h account, void *data)
579 {
580         BROWSER_LOGD("[%s]\n", __func__);
581
582         if (!data)
583                 return false;
584
585         Browser_Common_View *common_view = (Browser_Common_View *)data;
586
587         int account_id = 0;
588         char *service_name = NULL;
589         char *lib_path = NULL;
590         char *icon_path = NULL;
591
592         Eina_Bool can_post = EINA_FALSE;
593
594         account_get_capability(account, __get_post_capability_cb, &can_post);
595         account_get_account_id(account, &account_id);
596         BROWSER_LOGD("account_id: %d\n", account_id);
597
598         account_get_domain_name(account, &service_name);
599         BROWSER_LOGD("service_name: %s\n", service_name);
600
601         if (!can_post) {
602                 BROWSER_LOGD("cannot post to : [%s] in browser\n", service_name);
603                 if (service_name)
604                         free(service_name);
605                 service_name = NULL;
606                 return false;
607         } else {
608                 account_get_package_name(account, &lib_path);
609                 BROWSER_LOGD("lib_path: %s\n", lib_path);
610
611                 account_get_icon_path(account, &icon_path);
612                 BROWSER_LOGD("icon_path: %s\n", icon_path);
613
614                 if (icon_path && strlen(icon_path) > 0) {
615                         BROWSER_LOGD("icon_path: %s\n", icon_path);
616                         Evas_Object *icon = elm_icon_add(common_view->m_share_popup);
617                         if (icon) {
618                                 elm_icon_file_set(icon, icon_path, NULL);
619                                 BROWSER_LOGD("icon_path: %s\n", icon_path);
620                                 common_view->m_sns_icon_list.push_back(icon);
621                         }
622                 }
623
624                 if (service_name && strlen(service_name) && lib_path && strlen(lib_path)) {
625                         common_view->m_sns_path_list.push_back(std::string(lib_path));
626                         common_view->m_sns_name_list.push_back(std::string(service_name));
627                 }
628         }
629         if (service_name)
630                 free(service_name);
631         service_name = NULL;
632
633         if (icon_path)
634                 free(icon_path);
635         icon_path = NULL;
636
637         if (lib_path)
638                 free(lib_path);
639         lib_path= NULL;
640
641         return true;
642 }
643
644 bool Browser_Common_View::__get_post_capability_cb(account_capability_type_e type,
645                                                 account_capability_state_e state, void *data)
646 {
647         Eina_Bool *can_post = (Eina_Bool *)data;
648         if (!can_post) {
649                 BROWSER_LOGD("unable to post");
650                 return false;
651         }
652
653         if (ACCOUNT_CAPABILITY_STATUS_POST != type)
654                 return true;
655
656         if (ACCOUNT_CAPABILITY_DISABLED == state)
657                 return true;
658
659         *can_post = EINA_TRUE;
660
661         return true;
662 }
663
664 Eina_Bool Browser_Common_View::_send_via_email(std::string url, Eina_Bool attach_file)
665 {
666         BROWSER_LOGD("[%s], url[%s]", __func__, url.c_str());
667         if (url.empty()) {
668                 show_msg_popup(BR_STRING_EMPTY);
669                 return EINA_FALSE;
670         }
671
672         service_h service_handle = NULL;
673         if (service_create(&service_handle) < 0) {
674                 BROWSER_LOGE("Fail to create service handle");
675                 return EINA_FALSE;
676         }
677
678         if (!service_handle) {
679                 BROWSER_LOGE("Fail to create service handle");
680                 return EINA_FALSE;
681         }
682
683         if (attach_file) {
684                 if (service_set_operation(service_handle, SERVICE_OPERATION_SEND) < 0) {
685                         BROWSER_LOGE("Fail to set service operation");
686                         service_destroy(service_handle);
687                 return EINA_FALSE;
688         }
689
690                 if (service_set_uri(service_handle, url.c_str()) < 0) {
691                         BROWSER_LOGE("Fail to set uri");
692                         service_destroy(service_handle);
693                         return EINA_FALSE;
694                 }
695         } else {
696                 if (service_set_operation(service_handle, SERVICE_OPERATION_SEND_TEXT) < 0) {
697                         BROWSER_LOGE("Fail to set service operation");
698                         service_destroy(service_handle);
699                         return EINA_FALSE;
700                 }
701
702                 if (strstr(url.c_str(), BROWSER_MAIL_TO_SCHEME)) {
703                         if (service_add_extra_data(service_handle, SERVICE_DATA_TO, url.c_str() + strlen(BROWSER_MAIL_TO_SCHEME)) < 0) {
704                                 BROWSER_LOGE("Fail to set mailto data");
705                                 service_destroy(service_handle);
706                                 return EINA_FALSE;
707                         }
708                 } else {
709                         if (service_add_extra_data(service_handle, SERVICE_DATA_TEXT, url.c_str()) < 0) {
710                                 BROWSER_LOGE("Fail to set extra data");
711                                 service_destroy(service_handle);
712                                 return EINA_FALSE;
713                         }
714                 }
715         }
716
717         if (service_set_package(service_handle, SEC_EMAIL) < 0) {
718                 BROWSER_LOGE("Fail to launch service operation");
719                 service_destroy(service_handle);
720                 return EINA_FALSE;
721         }
722
723         if (service_send_launch_request(service_handle, NULL, NULL) < 0) {
724                 BROWSER_LOGE("Fail to launch service operation");
725                 service_destroy(service_handle);
726                 return EINA_FALSE;
727         }
728         service_destroy(service_handle);
729
730         return EINA_TRUE;
731 }
732
733 Eina_Bool Browser_Common_View::_add_to_contact(std::string number)
734 {
735         if (number.empty()) {
736                 BROWSER_LOGE("number is null");
737                 return EINA_FALSE;
738         }
739         struct ug_cbs cbs = {0, };
740         cbs.layout_cb = __ug_layout_cb;
741         cbs.result_cb = NULL;//__ug_result_cb;
742         cbs.destroy_cb = __ug_destroy_cb;
743         cbs.priv = (void *)this;
744
745         char *phone_number = (char *)strdup(number.c_str());
746         if (!phone_number) {
747                 BROWSER_LOGE("strdup failed");
748                 return EINA_FALSE;
749         }
750
751         service_h data = NULL;
752         service_create(&data);
753         if (data == NULL) {
754                 BROWSER_LOGE("fail to service_create.");
755                 return EINA_FALSE;
756         }
757 /*
758 type.
759 CT_UG_REQUEST_ADD = 21,
760 CT_UG_REQUEST_ADD_WITH_NUM = 22,
761 CT_UG_REQUEST_ADD_WITH_EMAIL = 23,
762 CT_UG_REQUEST_ADD_WITH_WEB = 24,
763 */
764         if (service_add_extra_data(data, "type", "22")) {
765                 BROWSER_LOGE("service_add_extra_data is failed.");
766                 service_destroy(data);
767                 return EINA_FALSE;
768         }
769         if (service_add_extra_data(data, "ct_num", number.c_str())) {
770                 BROWSER_LOGE("service_add_extra_data is failed.");
771                 service_destroy(data);
772                 return EINA_FALSE;
773         }
774
775         if (!ug_create(NULL, "contacts-details-efl", UG_MODE_FULLVIEW, data, &cbs))
776                 BROWSER_LOGE("ug_create is failed.");
777
778         if (service_destroy(data))
779                 BROWSER_LOGE("service_destroy is failed.");
780
781         free(phone_number);
782 }
783
784 Eina_Bool Browser_Common_View::_share_via_nfc(std::string url)
785 {
786         BROWSER_LOGD("[%s]", __func__);
787         if (url.empty()) {
788                 show_msg_popup(BR_STRING_EMPTY);
789                 return EINA_FALSE;
790         }
791
792         struct ug_cbs cbs = {0, };
793         cbs.layout_cb = __ug_layout_cb;
794         cbs.result_cb = NULL;//__ug_result_cb;
795         cbs.destroy_cb = __ug_destroy_cb;
796         cbs.priv = (void *)this;
797
798         char *share_url = (char *)strdup(url.c_str());
799         if (!share_url) {
800                 BROWSER_LOGE("strdup failed");
801                 return EINA_FALSE;
802         }
803
804         service_h data = NULL;
805         service_create(&data);
806         if (data == NULL) {
807                 BROWSER_LOGE("fail to service_create.");
808                 return EINA_FALSE;
809         }
810         if (service_add_extra_data(data, "count", "1")) {
811                 BROWSER_LOGE("service_add_extra_data is failed.");
812                 service_destroy(data);
813                 return EINA_FALSE;
814         }
815         if (service_add_extra_data(data, "request_type", "data_buffer")) {
816                 BROWSER_LOGE("service_add_extra_data is failed.");
817                 service_destroy(data);
818                 return EINA_FALSE;
819         }
820         if (service_add_extra_data(data, "request_data", share_url)) {
821                 BROWSER_LOGE("service_add_extra_data is failed.");
822                 service_destroy(data);
823
824                 free(share_url);
825                 return EINA_FALSE;
826         }
827
828         if(!ug_create(NULL, "share-nfc-efl", UG_MODE_FULLVIEW, data, &cbs))
829                 BROWSER_LOGE("ug_create is failed.");
830
831         if (service_destroy(data))
832                 BROWSER_LOGE("service_destroy is failed.");
833
834         free(share_url);
835
836         return EINA_TRUE;
837 }
838
839 Eina_Bool Browser_Common_View::_show_share_popup(const char *url)
840 {
841         BROWSER_LOGE("url=[%s]", url);
842         if (!url || strlen(url) == 0) {
843                 BROWSER_LOGE("url is empty");
844                 return EINA_FALSE;
845         }
846
847         m_share_url = std::string(url);
848
849         m_sns_path_list.clear();
850         m_sns_name_list.clear();
851         m_sns_icon_list.clear();
852
853         m_share_popup = elm_popup_add(m_navi_bar);
854         if (!m_share_popup) {
855                 BROWSER_LOGE("elm_popup_add failed");
856                 return EINA_FALSE;
857         }
858         elm_object_style_set(m_share_popup, "menustyle");
859         elm_object_part_text_set(m_share_popup, "title,text", BR_STRING_SHARE);
860         evas_object_size_hint_weight_set(m_share_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
861
862         m_share_list = elm_list_add(m_share_popup);
863         if (!m_share_list) {
864                 BROWSER_LOGE("elm_list_add failed");
865                 return EINA_FALSE;
866         }
867         evas_object_size_hint_weight_set(m_share_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
868         evas_object_size_hint_align_set(m_share_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
869
870         elm_list_item_append(m_share_list, BR_STRING_MESSAGES, NULL, NULL, __send_via_message_cb, this);
871         elm_list_item_append(m_share_list, BR_STRING_EMAIL, NULL, NULL, __send_via_email_cb, this);
872
873         evas_object_show(m_share_list);
874
875         Evas_Object *cancel_button = elm_button_add(m_share_popup);
876         elm_object_text_set(cancel_button, BR_STRING_CANCEL);
877         elm_object_part_content_set(m_share_popup, "button1", cancel_button);
878         elm_object_style_set(cancel_button, "popup_button/default");
879         evas_object_smart_callback_add(cancel_button, "clicked", __popup_response_cb, this);
880
881         elm_object_content_set(m_share_popup, m_share_list);
882
883         evas_object_show(m_share_popup);
884
885         return EINA_TRUE;
886 }
887
888 void Browser_Common_View::__popup_response_cb(void* data, Evas_Object* obj, void* event_info)
889 {
890         BROWSER_LOGD("%s, event_info=%d", __func__, (int)event_info);
891
892         if (!data)
893                 return;
894
895         Browser_Common_View *common_view = (Browser_Common_View *)data;
896         if (common_view->m_share_popup) {
897                 evas_object_del(common_view->m_share_popup);
898                 common_view->m_share_popup = NULL;
899         }
900         if (common_view->m_share_list) {
901                 evas_object_del(common_view->m_share_list);
902                 common_view->m_share_list = NULL;
903         }
904
905         common_view->m_sns_name_list.clear();
906         common_view->m_sns_path_list.clear();
907
908 }
909
910 char *Browser_Common_View::_trim(char *str)
911 {
912         char *pos_bos = str;
913
914         while(*pos_bos == ' ')
915                 pos_bos++;
916
917         char *pos_eos = pos_bos + strlen(pos_bos) - 1;
918
919         while((pos_eos >= str) && (*pos_eos == ' ')) {
920                 *pos_eos = '\0';
921                 pos_eos--;
922         }
923
924         return pos_bos;
925 }
926
927 #if defined(HORIZONTAL_UI)
928 Eina_Bool Browser_Common_View::is_landscape(void)
929 {
930         int window_w = 0;
931         int window_h = 0;
932         evas_object_geometry_get(m_win, NULL, NULL, &window_w, &window_h);
933         if (window_h > window_w) {
934                 BROWSER_LOGD("portrait");
935                 return EINA_FALSE;
936         } else {
937                 BROWSER_LOGD("landscape");
938                 return EINA_TRUE;
939         }
940 }
941 #endif
942
943 /* set focus to edit field idler callback to show ime. */
944 Eina_Bool Browser_Common_View::__set_focus_editfield_idler_cb(void *edit_field)
945 {
946         BROWSER_LOGD("[%s]", __func__);
947         if (!edit_field)
948                 return ECORE_CALLBACK_CANCEL;
949         elm_object_focus_set((Evas_Object *)edit_field, EINA_TRUE);
950         elm_object_signal_emit((Evas_Object *)edit_field, "clicked", "elm");
951
952         Evas_Object *entry = br_elm_editfield_entry_get((Evas_Object *)edit_field);
953         elm_entry_cursor_end_set(entry);
954
955         return ECORE_CALLBACK_CANCEL;
956 }
957
958 Eina_Bool Browser_Common_View::_has_url_sheme(const char *url)
959 {
960         if (url && strlen(url)
961             && (strstr(url, BROWSER_URL_SCHEME_CHECK) || strstr(url, BROWSER_MAIL_TO_SCHEME)))
962                 return EINA_TRUE;
963         else
964                 return EINA_FALSE;
965 }
966
967 void Browser_Common_View::__ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
968 {
969         BROWSER_LOGD("[%s]", __func__);
970         if (!priv || !ug)
971                 return;
972
973         Browser_Common_View *common_view = (Browser_Common_View *)priv;
974         Evas_Object *base = (Evas_Object*)ug_get_layout(ug);
975         if (!base)
976                 return;
977
978         common_view->m_ug = ug;
979
980         Evas_Object *win = (Evas_Object *)ug_get_window();
981
982         switch (mode) {
983         case UG_MODE_FULLVIEW:
984                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);             
985                 elm_win_resize_object_add(win, base);
986                 evas_object_show(base);
987                 break;
988         default:
989                 break;
990         }
991 }
992
993 void Browser_Common_View::__ug_result_cb(ui_gadget_h ug, bundle *result, void *priv)
994 {
995         if (!priv || !ug)
996                 return;
997 }
998
999 void Browser_Common_View::__ug_destroy_cb(ui_gadget_h ug, void *priv)
1000 {
1001         if (!priv || !ug)
1002                 return;
1003
1004         if (ug_destroy(ug))
1005                 BROWSER_LOGD("ug_destroy is failed.\n");
1006 }
1007