Make permission request for geolocation check page
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_geolocation.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_geolocation.h"
22
23 #if ENABLE(TIZEN_GEOLOCATION)
24 #include "EwkViewImpl.h"
25 #include "WKAPICast.h"
26 #include "WKGeolocationManager.h"
27 #include "WKGeolocationPermissionRequest.h"
28 #include "WKGeolocationPosition.h"
29 #include "WKRetainPtr.h"
30 #include "ewk_context_private.h"
31 #include "ewk_geolocation_private.h"
32 #include "ewk_view_private.h"
33
34 #include <Evas.h>
35 #include <location/locations.h>
36 #include <wtf/text/CString.h>
37
38 using namespace WebKit;
39
40 struct _Ewk_Geolocation_Permission_Request {
41     WKRetainPtr<WKGeolocationPermissionRequestRef> requestRef;
42     WKPageRef page;
43     Ewk_Security_Origin* origin;
44     bool isDecided;
45     bool isSuspended;
46
47     _Ewk_Geolocation_Permission_Request(WKPageRef pageRef, WKRetainPtr<WKGeolocationPermissionRequestRef> geolocationPermissionRequestRef, WKSecurityOriginRef originRef)
48         : requestRef(geolocationPermissionRequestRef)
49         , page(pageRef)
50         , isDecided(false)
51         , isSuspended(false)
52     {
53         origin = createSecurityOrigin(originRef);
54     }
55
56     ~_Ewk_Geolocation_Permission_Request()
57     {
58         deleteSecurityOrigin(origin);
59     }
60 };
61
62 Ewk_Geolocation_Permission_Request* ewkGeolocationCreatePermissionRequest(WKPageRef pageRef, WKGeolocationPermissionRequestRef geolocationPermissionRequestRef, WKSecurityOriginRef originRef)
63 {
64     return new Ewk_Geolocation_Permission_Request(pageRef, geolocationPermissionRequestRef, originRef);
65 }
66
67 void ewkGeolocationDeletePermissionRequestList(Eina_List* requestList)
68 {
69     void* data = 0;
70     EINA_LIST_FREE(requestList, data)
71         delete (static_cast<Ewk_Geolocation_Permission_Request*>(data));
72 }
73
74 bool ewkGeolocationIsPermissionRequestSuspended(const Ewk_Geolocation_Permission_Request* permissionRequest)
75 {
76     return permissionRequest->isSuspended;
77 }
78
79 bool ewkGeolocationIsPermissionRequestDecided(const Ewk_Geolocation_Permission_Request* permissionRequest)
80 {
81     return permissionRequest->isDecided;
82 }
83 #endif
84
85 const Ewk_Security_Origin* ewk_geolocation_permission_request_origin_get(const Ewk_Geolocation_Permission_Request* permissionRequest)
86 {
87 #if ENABLE(TIZEN_GEOLOCATION)
88     EINA_SAFETY_ON_NULL_RETURN_VAL(permissionRequest, 0);
89
90     return permissionRequest->origin;
91 #else
92     UNUSED_PARAM(permissionRequest);
93     return 0;
94 #endif
95 }
96
97 Eina_Bool ewk_geolocation_permission_request_set(Ewk_Geolocation_Permission_Request* permissionRequest, Eina_Bool allow)
98 {
99 #if ENABLE(TIZEN_GEOLOCATION)
100     EINA_SAFETY_ON_NULL_RETURN_VAL(permissionRequest, false);
101     TIZEN_LOGI("allow(%d)", allow);
102
103     permissionRequest->isDecided = true;
104
105     Evas_Object* ewkView = const_cast<Evas_Object*>(EwkViewImpl::viewFromPageViewMap(permissionRequest->page));
106     if (ewkView) {
107         allow ? WKGeolocationPermissionRequestAllow(permissionRequest->requestRef.get()) : WKGeolocationPermissionRequestDeny(permissionRequest->requestRef.get());
108         ewkViewDeleteGeolocationPermission(ewkView, permissionRequest);
109     }
110     delete permissionRequest;
111
112     return true;
113 #else
114     UNUSED_PARAM(permissionRequest);
115     UNUSED_PARAM(allow);
116     return false;
117 #endif
118 }
119
120 void ewk_geolocation_permission_request_suspend(Ewk_Geolocation_Permission_Request* permissionRequest)
121 {
122 #if ENABLE(TIZEN_GEOLOCATION)
123     EINA_SAFETY_ON_NULL_RETURN(permissionRequest);
124     TIZEN_LOGI("request(%d) is suspended", permissionRequest);
125
126     permissionRequest->isSuspended = true;
127 #else
128     UNUSED_PARAM(permissionRequest);
129 #endif
130 }