2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file view_logic_geolocation_support.cpp
18 * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
21 #include "view_logic_geolocation_support.h"
25 #include <dpl/log/log.h>
26 #include <dpl/assert.h>
27 #include <wrt-commons/security-origin-dao/security_origin_dao_types.h>
28 #include <wrt-commons/security-origin-dao/security_origin_dao.h>
30 #include <widget_string.h>
31 #include <common/view_logic_security_origin_support.h>
32 #include <Elementary.h>
35 namespace ViewModule {
36 namespace GeolocationSupport {
37 using namespace SecurityOriginDB;
38 using namespace ViewModule::SecurityOriginSupportUtil;
42 void askUserForGeolocationPermission(
44 PermissionData* data);
45 static void popupCallback(void* data, Evas_Object* obj, void* eventInfo);
47 void askUserForGeolocationPermission(
51 LogDebug("askUserForGeolocationPermission called");
52 std::string origin = DPL::ToUTF8String(data->m_originData.origin.host);
58 if (app_get_name(&name) == APP_ERROR_NONE) {
62 appname = "application";
66 WrtText::replacePS({WRT_POP_GEOLOCATION_PERMISSION, appname, origin});
67 Evas_Object* popup = createPopup(window,
69 WRT_BODY_REMEMBER_PREFERENCE,
74 LogError("Fail to create popup object");
78 evas_object_show(popup);
82 void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/)
84 LogDebug("popupCallback");
86 PermissionData* permData = static_cast<PermissionData*>(data);
87 Ewk_Geolocation_Permission_Request* permissionRequest =
88 static_cast<Ewk_Geolocation_Permission_Request*>(permData->m_data);
90 Evas_Object* popup = getPopup(obj);
91 Result result = getResult(obj);
93 if (result != RESULT_UNKNOWN) {
94 permData->m_originDao->setSecurityOriginData(permData->m_originData,
98 (result == RESULT_ALLOW_ALWAYS || result == RESULT_ALLOW_ONCE) ?
99 EINA_TRUE : EINA_FALSE;
100 ewk_geolocation_permission_request_set(permissionRequest, ret);
102 evas_object_hide(popup);
103 evas_object_del(popup);
107 void geolocationPermissionRequest(
109 SecurityOriginDB::SecurityOriginDAO* securityOriginDAO,
112 LogDebug("geolocationPermissionRequest called");
113 Assert(securityOriginDAO);
115 Ewk_Geolocation_Permission_Request* permissionRequest =
116 static_cast<Ewk_Geolocation_Permission_Request*>(data);
117 const Ewk_Security_Origin* ewkOrigin =
118 ewk_geolocation_permission_request_origin_get(
122 SecurityOriginData securityOriginData(
123 WrtDB::FEATURE_GEOLOCATION,
125 DPL::FromUTF8String(ewk_security_origin_protocol_get(ewkOrigin)),
126 DPL::FromUTF8String(ewk_security_origin_host_get(ewkOrigin)),
127 ewk_security_origin_port_get(ewkOrigin)));
129 // check cache database
130 Result result = securityOriginDAO->getResult(securityOriginData);
131 if (RESULT_ALLOW_ONCE == result || RESULT_ALLOW_ALWAYS == result) {
133 ewk_geolocation_permission_request_set(permissionRequest, EINA_TRUE);
135 } else if (RESULT_DENY_ONCE == result || RESULT_DENY_ALWAYS == result) {
137 ewk_geolocation_permission_request_set(permissionRequest, EINA_FALSE);
141 ewk_geolocation_permission_request_suspend(permissionRequest);
144 PermissionData* permissionData =
145 new PermissionData(securityOriginDAO,
148 askUserForGeolocationPermission(window, permissionData);
151 } // namespace GeolocationSupport
152 } // namespace ViewModule