Change the chromium header from ewk_chromium.h to EWebKit.h/Ewebkit_internal.h
[platform/framework/web/crosswalk-tizen.git] / wrt-upgrade / wrt-upgrade-info.cc
1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #include "wrt-upgrade/wrt-upgrade-info.h"
7 #include "common/logger.h"
8
9 // #include <sstream>
10
11 namespace {
12 const std::string kSectionPrefix = "_SECT_";
13 const std::string kSectionSuffix = "_SECT_";
14
15 const std::string kDBPublicSection = "public";
16 const std::string kDBPrivateSection = "private";
17
18 const std::string kGeolocationPermissionPrefix = "__WRT_GEOPERM_";
19 const std::string kNotificationPermissionPrefix = "__WRT_NOTIPERM_";
20 const std::string kQuotaPermissionPrefix = "__WRT_QUOTAPERM_";
21 const std::string kCertificateAllowPrefix = "__WRT_CERTIPERM_";
22 const std::string kUsermediaPermissionPrefix = "__WRT_USERMEDIAPERM_";
23
24 const std::string kValueAllow = "allowed";
25 const std::string kValueDenied = "denied";
26 const std::string kValueUnknown = "unknown";
27
28 const std::string kAppDirectoryPrefix = "/opt/usr/home/owner/apps_rw/";
29 const std::string kAppSecurityOriginDBFile = "/data/.security_origin.db";
30 const std::string kAppCertificateDBFile = "/data/.certificate.db";
31
32 enum {
33   FEATURE_GEOLOCATION = 0,
34   FEATURE_WEB_NOTIFICATION,
35   FEATURE_USER_MEDIA,
36   FEATURE_FULLSCREEN_MODE,
37   FEATURE_WEB_DATABASE,
38   FEATURE_CAMERA,
39   FEATURE_AUDIO_RECORDER
40 };
41 enum {
42   RESULT_UNKNOWN = 0,
43   RESULT_ALLOW_ONCE,
44   RESULT_DENY_ONCE,
45   RESULT_ALLOW_ALWAYS,
46   RESULT_DENY_ALWAYS
47 };
48 }  // namespace
49
50 namespace upgrade {
51
52 PreferenceInfo::PreferenceInfo(std::string key, std::string value) {
53   m_section_ = kDBPublicSection;
54   m_key_ = key;
55   m_value_ = value;
56 }
57 SecurityOriginInfo::SecurityOriginInfo(
58         int feature,
59         std::string scheme,
60         std::string host,
61         int port,
62         int result) {
63   m_section_ = kDBPrivateSection;
64   m_key_ = translateKey(feature, scheme, host, port);
65   m_value_ = translateValue(result);
66 }
67 std::string SecurityOriginInfo::translateKey(
68     int feature,
69     std::string scheme,
70     std::string host,
71     int port) {
72
73   std::string key = "";
74
75   switch (feature) {
76   case FEATURE_GEOLOCATION :
77       key += kGeolocationPermissionPrefix;
78   break;
79   case FEATURE_WEB_NOTIFICATION :
80       key += kNotificationPermissionPrefix;
81   break;
82   case FEATURE_USER_MEDIA :
83       key += kUsermediaPermissionPrefix;
84   break;
85   case FEATURE_WEB_DATABASE :
86       key += kQuotaPermissionPrefix;
87   break;
88   default :
89   break;
90   }
91
92   key += scheme;
93   key += "://";
94   key += host;
95   key += ":";
96   key += std::to_string(port);
97
98   return key;
99 }
100 std::string SecurityOriginInfo::translateValue(int result) {
101   std::string value = "";
102
103   switch (result) {
104   case RESULT_ALLOW_ALWAYS :
105        value = kValueAllow;
106   break;
107   case RESULT_DENY_ALWAYS :
108       value = kValueDenied;
109   break;
110   case RESULT_UNKNOWN :
111   case RESULT_ALLOW_ONCE :
112   case RESULT_DENY_ONCE :
113   default :
114       value = kValueUnknown;
115   break;
116   }
117   return value;
118 }
119 CertificateInfo::CertificateInfo(
120         std::string pem,
121         int result) {
122   m_section_ = kDBPrivateSection;
123   m_key_ = translateKey(pem);
124   m_value_ = translateValue(result);
125 }
126 std::string CertificateInfo::translateKey(std::string pem) {
127   std::string key = "";
128   key = kCertificateAllowPrefix + pem;
129   return key;
130 }
131 std::string CertificateInfo::translateValue(int result) {
132   std::string value = "";
133
134   switch (result) {
135   case RESULT_ALLOW_ALWAYS :
136     value = kValueAllow;
137   break;
138   case RESULT_DENY_ALWAYS :
139     value = kValueDenied;
140   break;
141   case RESULT_UNKNOWN :
142   case RESULT_ALLOW_ONCE :
143   case RESULT_DENY_ONCE :
144   default :
145     value = kValueUnknown;
146   break;
147   }
148   return value;
149 }
150 WrtUpgradeInfo::WrtUpgradeInfo(std::string appid) {
151   app_id_ = appid;
152   pkg_id_ = appid.substr(0, appid.find_first_of('.'));
153   app_dir_ = kAppDirectoryPrefix + pkg_id_;
154 }
155 void WrtUpgradeInfo::addPreferenceInfo(PreferenceInfo preference) {
156   preference_info_list_.push_back(preference);
157 }
158 void WrtUpgradeInfo::addSecurityOriginInfo(SecurityOriginInfo security_origin) {
159   security_origin_info_list_.push_back(security_origin);
160 }
161 void WrtUpgradeInfo::addCertificateInfo(CertificateInfo certificate) {
162   certificate_info_list.push_back(certificate);
163 }
164
165 std::string WrtUpgradeInfo::getSecurityOriginDB() {
166   return app_dir_ + kAppSecurityOriginDBFile;
167 }
168 std::string WrtUpgradeInfo::getCertificateDB() {
169   return app_dir_ + kAppCertificateDBFile;
170 }
171 }  // namespace upgrade