update wrt_0.8.107
[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 <ace_api_client.h>
28 #include <dpl/utils/warp_iri.h>
29 #include <widget_data_types.h>
30
31 namespace ViewModule {
32 namespace SecuritySupport {
33
34 namespace {
35
36 const char *SCHEME_TYPE_HTTP = "http";
37 const char *SCHEME_TYPE_HTTPS = "https";
38
39 const char *GEOLOCATION_DEV_CAP = "geolocation.position";
40 const char *GEOLOCATION_PARAM_NAME = "param:enableHighAccuracy";
41 const char *GEOLOCATION_PARAM_VALUE = "true";
42
43 bool simpleAceCheck(
44     WidgetHandle widgetHandle,
45     const char *devCap,
46     const char *paramName,
47     const char *paramValue)
48 {
49     ace_request_t aceRequest;
50     aceRequest.widget_handle = widgetHandle;
51     aceRequest.session_id = const_cast<const ace_string_t>("");
52     aceRequest.feature_list.count = 0;
53     aceRequest.dev_cap_list.count = 1;
54     aceRequest.dev_cap_list.items = new ace_dev_cap_t[1];
55     aceRequest.dev_cap_list.items[0].name =
56         const_cast<ace_string_t>(devCap);
57
58     aceRequest.dev_cap_list.items[0].param_list.count = paramName ? 1 : 0;
59     aceRequest.dev_cap_list.items[0].param_list.items = NULL;
60
61     if (paramName) {
62         aceRequest.dev_cap_list.items[0].param_list.items = new ace_param_t[1];
63         aceRequest.dev_cap_list.items[0].param_list.items[0].name =
64             const_cast<ace_string_t>(paramName);
65         aceRequest.dev_cap_list.items[0].param_list.items[0].value =
66             const_cast<ace_string_t>(paramValue);
67     }
68
69     LogDebug("Making ace check with new C-API");
70     ace_bool_t result = ACE_FALSE;
71     ace_return_t ret = ace_check_access(&aceRequest, &result);
72
73     LogDebug("Result is: " << static_cast<int>(result));
74
75     delete [] aceRequest.dev_cap_list.items[0].param_list.items;
76     delete [] aceRequest.dev_cap_list.items;
77
78     return ACE_OK == ret && ACE_TRUE == result;
79 }
80
81 } //TODO copied from view_logic.cpp
82
83 bool checkWhitelist(const char *url)
84 {
85     LogInfo("Check WhiteList");
86     // White List should be checked in only case of Tizen widget
87     if (WarpIRI::isIRISchemaIgnored(url)) {
88         // scheme is not supported by WARP
89         return true;
90     }
91
92     WidgetAccessList whiteURIList(WrtDB::GlobalDAOReadOnly::GetWhiteURIList());
93     return whiteURIList.isRequiredIRI(DPL::FromUTF8String(std::string(url)));
94 }
95
96 bool geolocationACECheck(WidgetHandle widgetHandle, bool highAccuracy) {
97     const char *paramName = NULL;
98     const char *paramValue = NULL;
99     if (highAccuracy) {
100         paramName = GEOLOCATION_PARAM_NAME;
101         paramValue = GEOLOCATION_PARAM_VALUE;
102     }
103     return simpleAceCheck(
104         widgetHandle,
105         GEOLOCATION_DEV_CAP,
106         paramName,
107         paramValue);
108 }
109
110 } // namespace SecuritySupport
111 } //namespace ViewModule