445f7548254698de005bd8dac396d22b988c3800
[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
31 namespace {
32 const char* const USERMEDIA_USE_ASK_BODY =
33     "This application wants to use your media";
34
35 // function declare
36 void askUserForUsermediaPermission(Evas_Object* window, void* data);
37 Evas_Object* getPopup(Evas_Object* button);
38 static void popupCallback(void* data, Evas_Object* obj, void* eventInfo);
39
40 void askUserForUsermediaPermission(Evas_Object* window, void* data)
41 {
42     LogDebug("askUserForUsermediaPermission called");
43
44     Evas_Object* popup = elm_popup_add(window);
45     evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
46     elm_object_text_set(popup, USERMEDIA_USE_ASK_BODY);
47
48     Evas_Object* lButton = elm_button_add(popup);
49     elm_object_text_set(lButton, "Allow");
50     elm_object_part_content_set(popup, "button1", lButton);
51     evas_object_smart_callback_add(lButton, "clicked", popupCallback, data);
52
53     Evas_Object* rButton = elm_button_add(popup);
54     elm_object_text_set(rButton, "Deny");
55     elm_object_part_content_set(popup, "button2", rButton);
56     evas_object_smart_callback_add(rButton, "clicked", popupCallback, data);
57     evas_object_show(popup);
58 }
59
60 Evas_Object* getPopup(Evas_Object* button)
61 {
62     Assert(button);
63
64     Evas_Object* popup = button;
65     while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
66         popup = elm_object_parent_widget_get(popup);
67         if (!popup) {
68             return NULL;
69         }
70     }
71     return popup;
72 }
73
74 void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/)
75 {
76     LogDebug("popupCallback");
77     Assert(data);
78     Ewk_User_Media_Permission* usermediaPermission =
79         static_cast<Ewk_User_Media_Permission*>(data);
80
81     Assert(obj);
82     Evas_Object* popup = getPopup(obj);
83     Assert(popup);
84     bool allow = !strcmp("Allow", elm_object_text_get(obj));
85
86     Eina_Bool ret = allow ? EINA_TRUE : EINA_FALSE;
87     ewk_user_media_permission_set(usermediaPermission, ret);
88
89     evas_object_hide(popup);
90     evas_object_del(popup);
91 }
92 } // namespace
93
94 void UsermediaSupport::usermediaPermissionRequest(Evas_Object* window,
95                                                    void* data)
96 {
97     LogDebug("usermediaPermissionRequest called");
98     Assert(window);
99     Assert(data);
100     // ask to user
101     askUserForUsermediaPermission(window, data);
102     return;
103 }
104 } // namespace ViewModule