0ea1df086f68b54c735f076fc70b938b4c39a832
[platform/framework/web/wrt.git] / src / view / common / view_logic_security_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_keys_support.cpp
18  * @author  Pawel Sikorski (p.sikorski@samsung.com)
19  * @brief   Implementation file of SecuritySupport API used by ViewLogic
20  */
21
22 #include "view_logic_security_support.h"
23 #include <string>
24 #include <dpl/string.h>
25 #include <dpl/log/log.h>
26 #include <dpl/wrt-dao-ro/global_dao_read_only.h>
27 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
28 #include <ace_api_client.h>
29 #include <dpl/utils/warp_iri.h>
30 #include <widget_data_types.h>
31
32 namespace ViewModule {
33 namespace SecuritySupport {
34
35 namespace {
36
37 const char *GEOLOCATION_DEV_CAP = "geolocation.position";
38 const char *GEOLOCATION_PARAM_NAME = "param:enableHighAccuracy";
39 const char *GEOLOCATION_PARAM_VALUE = "true";
40
41 bool simpleAceCheck(
42     const DPL::String& tizenId,
43     const char *devCap,
44     const char *paramName,
45     const char *paramValue)
46 {
47     WrtDB::WidgetDAOReadOnly dao(tizenId);
48     ace_request_t aceRequest;
49     aceRequest.widget_handle = dao.getHandle();
50     aceRequest.session_id = const_cast<const ace_string_t>("");
51     aceRequest.feature_list.count = 0;
52     aceRequest.dev_cap_list.count = 1;
53     aceRequest.dev_cap_list.items = new ace_dev_cap_t[1];
54     aceRequest.dev_cap_list.items[0].name =
55         const_cast<ace_string_t>(devCap);
56
57     aceRequest.dev_cap_list.items[0].param_list.count = paramName ? 1 : 0;
58     aceRequest.dev_cap_list.items[0].param_list.items = NULL;
59
60     if (paramName) {
61         aceRequest.dev_cap_list.items[0].param_list.items = new ace_param_t[1];
62         aceRequest.dev_cap_list.items[0].param_list.items[0].name =
63             const_cast<ace_string_t>(paramName);
64         aceRequest.dev_cap_list.items[0].param_list.items[0].value =
65             const_cast<ace_string_t>(paramValue);
66     }
67
68     LogDebug("Making ace check with new C-API");
69     ace_bool_t result = ACE_FALSE;
70     ace_return_t ret = ace_check_access(&aceRequest, &result);
71
72     LogDebug("Result is: " << static_cast<int>(result));
73
74     delete [] aceRequest.dev_cap_list.items[0].param_list.items;
75     delete [] aceRequest.dev_cap_list.items;
76
77     return ACE_OK == ret && ACE_TRUE == result;
78 }
79
80 } //TODO copied from view_logic.cpp
81
82 bool checkWhitelist(const char *url)
83 {
84     LogInfo("Check WhiteList");
85     // White List should be checked in only case of Tizen widget
86     if (WarpIRI::isIRISchemaIgnored(url)) {
87         // scheme is not supported by WARP
88         return true;
89     }
90
91     WidgetAccessList whiteURIList(WrtDB::GlobalDAOReadOnly::GetWhiteURIList());
92     return whiteURIList.isRequiredIRI(DPL::FromUTF8String(std::string(url)));
93 }
94
95 bool geolocationACECheck(const DPL::String& tizenId, bool highAccuracy) {
96     const char *paramName = NULL;
97     const char *paramValue = NULL;
98     if (highAccuracy) {
99         paramName = GEOLOCATION_PARAM_NAME;
100         paramValue = GEOLOCATION_PARAM_VALUE;
101     }
102     return simpleAceCheck(
103         tizenId,
104         GEOLOCATION_DEV_CAP,
105         paramName,
106         paramValue);
107 }
108
109 } // namespace SecuritySupport
110 } //namespace ViewModule