Source code formating unification
[platform/framework/web/wrt.git] / src / view / webkit / view_logic_usermedia_support.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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  * @file    view_logic_usermedia_support.cpp
18  * @author  Jihoon Chung (jihoon.chung@samsung.com)
19  */
20
21 #include "view_logic_usermedia_support.h"
22
23 #include <string>
24 #include <dpl/log/log.h>
25 #include <dpl/assert.h>
26 #include <Elementary.h>
27 #include <EWebKit2.h>
28
29 namespace ViewModule {
30 namespace {
31 const char* const USERMEDIA_USE_ASK_BODY =
32     "This application wants to use your media";
33
34 // function declare
35 void askUserForUsermediaPermission(Evas_Object* window, void* data);
36 Evas_Object* getPopup(Evas_Object* button);
37 static void popupCallback(void* data, Evas_Object* obj, void* eventInfo);
38
39 void askUserForUsermediaPermission(Evas_Object* window, void* data)
40 {
41     LogDebug("askUserForUsermediaPermission called");
42
43     Evas_Object* popup = elm_popup_add(window);
44     evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
45     elm_object_text_set(popup, USERMEDIA_USE_ASK_BODY);
46
47     Evas_Object* lButton = elm_button_add(popup);
48     elm_object_text_set(lButton, "Allow");
49     elm_object_part_content_set(popup, "button1", lButton);
50     evas_object_smart_callback_add(lButton, "clicked", popupCallback, data);
51
52     Evas_Object* rButton = elm_button_add(popup);
53     elm_object_text_set(rButton, "Deny");
54     elm_object_part_content_set(popup, "button2", rButton);
55     evas_object_smart_callback_add(rButton, "clicked", popupCallback, data);
56     evas_object_show(popup);
57 }
58
59 Evas_Object* getPopup(Evas_Object* button)
60 {
61     Assert(button);
62
63     Evas_Object* popup = button;
64     while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
65         popup = elm_object_parent_widget_get(popup);
66         if (!popup) {
67             return NULL;
68         }
69     }
70     return popup;
71 }
72
73 void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/)
74 {
75     LogDebug("popupCallback");
76     Assert(data);
77     Ewk_User_Media_Permission* usermediaPermission =
78         static_cast<Ewk_User_Media_Permission*>(data);
79
80     Assert(obj);
81     Evas_Object* popup = getPopup(obj);
82     Assert(popup);
83     bool allow = !strcmp("Allow", elm_object_text_get(obj));
84
85     Eina_Bool ret = allow ? EINA_TRUE : EINA_FALSE;
86     ewk_user_media_permission_set(usermediaPermission, ret);
87
88     evas_object_hide(popup);
89     evas_object_del(popup);
90 }
91 } // namespace
92
93 void UsermediaSupport::usermediaPermissionRequest(Evas_Object* window,
94                                                   void* data)
95 {
96     LogDebug("usermediaPermissionRequest called");
97     Assert(window);
98     Assert(data);
99     // ask to user
100     askUserForUsermediaPermission(window, data);
101     return;
102 }
103 } // namespace ViewModule