Create string tightly when retrive string from cbhm callback event
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_user_media.cpp
1 /*
2    Copyright (C) 2012 Samsung Electronics
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21 #include "ewk_user_media.h"
22
23 #if ENABLE(TIZEN_MEDIA_STREAM)
24 #include "WKAPICast.h"
25 #include "WKUserMediaPermissionRequest.h"
26 #include "WKRetainPtr.h"
27 #include "ewk_view_private.h"
28
29 struct _Ewk_User_Media_Permission_Request {
30     WKRetainPtr<WKUserMediaPermissionRequestRef> requestRef;
31     Evas_Object* ewkView;
32     bool isDecided;
33     bool isSuspended;
34
35     _Ewk_User_Media_Permission_Request(Evas_Object* ewkView, WKRetainPtr<WKUserMediaPermissionRequestRef> userMediaPermissionRequestRef)
36         : requestRef(userMediaPermissionRequestRef)
37         , ewkView(ewkView)
38         , isDecided(false)
39         , isSuspended(false)
40     { }
41 };
42
43 Ewk_User_Media_Permission_Request* ewkUserMediaPermissionRequestCreate(Evas_Object* ewkView, WKUserMediaPermissionRequestRef userMediaPermissionRequestRef)
44 {
45     return new Ewk_User_Media_Permission_Request(ewkView, userMediaPermissionRequestRef);
46 }
47
48 void ewkUserMediaDeletePermissionRequestList(Eina_List* requestList)
49 {
50     void* data = 0;
51     EINA_LIST_FREE(requestList, data)
52         delete (static_cast<Ewk_User_Media_Permission_Request*>(data));
53 }
54
55 bool ewkUserMediaPermissionRequestDecided(Ewk_User_Media_Permission_Request* permissionRequest)
56 {
57     return permissionRequest->isDecided;
58 }
59
60 bool ewkUserMediaPermissionRequestSuspended(Ewk_User_Media_Permission_Request* permissionRequest)
61 {
62     return permissionRequest->isSuspended;
63 }
64 #endif
65
66 Eina_Bool ewk_user_media_permission_request_suspend(Ewk_User_Media_Permission_Request* permissionRequest)
67 {
68 #if ENABLE(TIZEN_MEDIA_STREAM)
69     EINA_SAFETY_ON_NULL_RETURN_VAL(permissionRequest, false);
70     EINA_SAFETY_ON_NULL_RETURN_VAL(permissionRequest->requestRef, false);
71
72     permissionRequest->isSuspended = true;
73
74     return true;
75 #else
76     UNUSED_PARAM(permissionRequest);
77     return false;
78 #endif
79 }
80
81 void ewk_user_media_permission_request_set(Ewk_User_Media_Permission_Request* permissionRequest, Eina_Bool allowed)
82 {
83 #if ENABLE(TIZEN_MEDIA_STREAM)
84 #if ENABLE(TIZEN_DLOG_SUPPORT)
85     TIZEN_LOGI("Allowed : %d", allowed);
86 #endif
87     EINA_SAFETY_ON_NULL_RETURN(permissionRequest);
88
89     permissionRequest->isDecided = true;
90
91     if (allowed)
92         WKUserMediaPermissionRequestAllow(permissionRequest->requestRef.get());
93     else
94         WKUserMediaPermissionRequestDeny(permissionRequest->requestRef.get());
95
96     ewkViewDeleteUserMediaPermissionRequest(permissionRequest->ewkView, permissionRequest);
97     delete permissionRequest;
98 #else
99     UNUSED_PARAM(permissionRequest);
100     UNUSED_PARAM(allowed);
101 #endif
102 }