45475f61f773bd78406cb51fb603194a0efee3a6
[platform/framework/web/wrt.git] / src / view / common / view_logic_geolocation_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_geolocation_support.cpp
18  * @author  Grzegorz Krawczyk (g.krawczyk@samsung.com)
19  */
20
21 #include "view_logic_geolocation_support.h"
22
23 #include <dpl/log/log.h>
24 #include <dpl/wrt-dao-ro/global_config.h>
25 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
26 #include <dpl/wrt-dao-ro/common_dao_types.h>
27 #include <popup-runner/PopupInvoker.h>
28 #include <view_logic_security_support.h>
29
30 namespace {
31 const char * const GEOLOCATION_ASK_TITLE = "location info";
32 const char * const GEOLOCATION_ASK_MSG =
33     "Application requests your current location. Do you allow it?";
34 }
35
36 namespace ViewModule {
37 namespace GeolocationSupport {
38
39 bool askUserForPermission()
40 {
41     return Wrt::Popup::PopupInvoker().askYesNo(
42         GEOLOCATION_ASK_TITLE,
43         GEOLOCATION_ASK_MSG);
44 }
45
46 bool checkRequestedStateOfGeolocationFeature(WrtDB::WidgetDAOReadOnlyPtr dao)
47 {
48     WrtDB::DbWidgetFeature geolocationFeature;
49     geolocationFeature.name = DPL::FromASCIIString(
50         WrtDB::GlobalConfig::GetW3CGeolocationFeatureName() );
51
52     auto features = dao->getFeaturesList();
53
54     auto it = features.find(geolocationFeature);
55
56     if ( it != features.end() )
57     {
58         if(it->rejected){
59             LogInfo("Feature rejected by ACE");
60             return false;
61         }
62         return true;
63     }
64
65     return false;
66 }
67
68 bool getLocalizationState(const DPL::String& tizenId, bool enableHighAccuracy)
69 {
70     LogDebug ("Get localization state");
71
72     WrtDB::WidgetDAOReadOnlyPtr dao(new WrtDB::WidgetDAOReadOnly(tizenId));
73
74     if (dao->getWidgetType() == WrtDB::APP_TYPE_TIZENWEBAPP)
75     {
76         return askUserForPermission();
77     }
78
79     return checkRequestedStateOfGeolocationFeature(dao) &&
80         ViewModule::SecuritySupport::geolocationACECheck(tizenId,
81             enableHighAccuracy);
82 }
83
84 bool getGeolocationModuleState(const DPL::String& tizenId)
85 {
86     LogDebug ("Get geolocation state");
87
88     WrtDB::WidgetDAOReadOnlyPtr dao(new WrtDB::WidgetDAOReadOnly(tizenId));
89
90     if (dao->getWidgetType() == WrtDB::APP_TYPE_TIZENWEBAPP)
91     {
92         LogInfo("Geolocation enable for tizen app");
93         return true;
94     }
95
96     return checkRequestedStateOfGeolocationFeature(dao);
97 }
98
99 } // namespace GeolocationSupport
100 } // namespace ViewModule