[Release] wrt-commons_0.2.139
[framework/web/wrt-commons.git] / modules / widget_dao / include / dpl / wrt-dao-rw / widget_dao.h
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  * This file contains the declaration of widget dao class.
18  *
19  * @file    widget_dao.h
20  * @author  Yang Jie (jie2.yang@samsung.com)
21  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
22  * @author  Pawel Sikorski (p.sikorski@samsung.com)
23  * @version 1.0
24  * @brief   This file contains the declaration of widget dao
25  */
26 #ifndef WIDGET_DAO_H
27 #define WIDGET_DAO_H
28
29 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
30 #include <list>
31 #include <string>
32 #include <sys/time.h>
33 #include <ctime>
34 #include <cstdlib>
35 #include <dpl/exception.h>
36 #include <dpl/db/orm.h>
37 #include <dpl/wrt-dao-ro/config_parser_data.h>
38 #include <dpl/wrt-dao-rw/property_dao.h>
39
40 namespace WrtDB {
41 class WidgetDAO : public WidgetDAOReadOnly
42 {
43   public:
44     typedef std::list<DPL::String> LanguageTagsList;
45
46     WidgetDAO(DbWidgetHandle handle);
47     WidgetDAO(DPL::OptionalString widgetGUID);
48     WidgetDAO(DPL::String tzAppId);
49
50     /**
51      * Destructor
52      */
53     virtual ~WidgetDAO();
54
55     /**
56      * This method registers the widget information in the DB when it is
57      * installed.
58      *
59      * @see WidgetRegisterInfo
60      * @see UnRegisterWidget()
61      * @param[in] TizenAppId Widget app id that will be registered.
62      * @param[in] pWidgetRegisterInfo    Specified the widget's information
63      * needed to be registered.
64      * @param[in] widgetSecurity   Widget's security certificates.
65      */
66     static void registerWidget(
67         const TizenAppId& tzAppId,
68         const WidgetRegisterInfo &widgetRegInfo,
69         const IWidgetSecurity &widgetSecurity);
70
71     static DbWidgetHandle registerWidget(
72         const WidgetRegisterInfo &pWidgetRegisterInfo,
73         const IWidgetSecurity &widgetSecurity) __attribute__((deprecated));
74
75     /**
76      * @brief registerWidgetGenerateTizenId Registers widget with auto-generated
77      * tizen id
78      *
79      * This function is disadviced and should be used only in tests.
80      * Function is not thread-safe.
81      *
82      * @param pWidgetRegisterInfo registeration information
83      * @param widgetSecurity Widget's security certificates.
84      * @return tzAppId generated
85      */
86     static TizenAppId registerWidgetGeneratePkgId(
87         const WidgetRegisterInfo &pWidgetRegisterInfo,
88         const IWidgetSecurity &widgetSecurity);
89
90     /**
91      * This method re-registers the widget information to the DB when it is
92      * installed.
93      *
94      * It performs unregistration and new registration of widget in db in one
95      * transaction.
96      *
97      * @see WidgetRegisterInfo
98      * @param[in] tzAppId  Widget tizen app id that will be registered.
99      * @param[in] pWidgetRegisterInfo    Specified the widget's information
100      * needed to be registered.
101      * @param[in] widgetSecurity   Widget's security certificates.
102      */
103     static void registerOrUpdateWidget(
104         const TizenAppId & tzAppId,
105         const WidgetRegisterInfo &widgetRegInfo,
106         const IWidgetSecurity &widgetSecurity);
107
108     /* This method backup widget information and update new widget information
109      * for restore widget information
110      */
111     static void backupAndUpdateWidget(
112         const TizenAppId & oldAppId,
113         const TizenAppId & newAppId,
114         const WidgetRegisterInfo &widgetRegInfo,
115         const IWidgetSecurity &widgetSecurity);
116
117     static void restoreUpdateWidget(
118         const TizenAppId & oldAppId,
119         const TizenAppId & newAppId);
120
121     /**
122      * This method removes a widget's information from EmDB.
123      *
124      * @see RegisterWidget()
125      * @param[in] tzAppId widgets name to be unregistered
126      */
127     static void unregisterWidget(const TizenAppId & tzAppId);
128
129     static void unregisterWidget(WrtDB::DbWidgetHandle handle) __attribute__((
130                                                                                  deprecated));
131
132     /* This method removes widget property
133      */
134     void removeProperty(const PropertyDAOReadOnly::WidgetPropertyKey &key);
135
136     /**
137      * @brief registerExternalLocations Removes rows from
138      * WidgetExternalLocations
139      */
140     void unregisterAllExternalLocations();
141
142     /* This method sets widget property
143      */
144     void setProperty(const PropertyDAOReadOnly::WidgetPropertyKey &key,
145                      const PropertyDAOReadOnly::WidgetPropertyValue &value,
146                      bool readOnly = false);
147
148     /* set tzAppId
149      */
150     void setTizenAppId(const DPL::OptionalString& tzAppId);
151
152     /* This function will update of api-feature status.
153      * If status is true (feature rejected) plugin connected with this
154      * api feature mustn't be loaded durign widget launch.
155      */
156     void updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature);
157
158     /*
159      * This method change security settings value
160      */
161     void setSecurityPopupUsage(const SettingsType value);
162     void setGeolocationUsage(const SettingsType value);
163     void setWebNotificationUsage(const SettingsType value);
164     void setWebDatabaseUsage(const SettingsType value);
165
166   private:
167     //Methods used during widget registering
168     static DbWidgetHandle registerWidgetInfo(
169         const TizenAppId & widgetName,
170         const WidgetRegisterInfo &regInfo,
171         const IWidgetSecurity &widgetSecurity,
172         const DPL::Optional<DbWidgetHandle> handle =
173             DPL::Optional<DbWidgetHandle>());
174     static void registerWidgetExtendedInfo(
175         DbWidgetHandle widgetHandle,
176         const WidgetRegisterInfo &regInfo);
177     static void registerWidgetLocalizedInfo(
178         DbWidgetHandle widgetHandle,
179         const WidgetRegisterInfo &regInfo);
180     static void registerWidgetIcons(
181         DbWidgetHandle widgetHandle,
182         const WidgetRegisterInfo &regInfo);
183     static void registerWidgetStartFile(
184         DbWidgetHandle widgetHandle,
185         const WidgetRegisterInfo &regInfo);
186     static void registerWidgetPreferences(
187         DbWidgetHandle widgetHandle,
188         const WidgetRegisterInfo &regInfo);
189     static void registerWidgetFeatures(
190         DbWidgetHandle widgetHandle,
191         const WidgetRegisterInfo &regInfo);
192     static void registerWidgetPrivilege(
193         DbWidgetHandle widgetHandle,
194         const WidgetRegisterInfo &regInfo);
195     static void registerWidgetWindowModes(
196         DbWidgetHandle widgetHandle,
197         const WidgetRegisterInfo &regInfo);
198     static void registerWidgetWarpInfo(
199         DbWidgetHandle widgetHandle,
200         const WidgetRegisterInfo &regInfo);
201     static void registerWidgetAllowNavigationInfo(
202         DbWidgetHandle widgetHandle,
203         const WidgetRegisterInfo &regInfo);
204     static void registerWidgetCertificates(
205         DbWidgetHandle widgetHandle,
206         const IWidgetSecurity &widgetSecurity);
207     static void registerCertificatesChains(
208         DbWidgetHandle widgetHandle,
209         CertificateSource certificateSource,
210         const CertificateChainList &list);
211     static void registerWidgetSettings(
212         DbWidgetHandle widgetHandle,
213         const WidgetRegisterInfo &regInfo);
214     static void registerAppControl(
215         DbWidgetHandle widgetHandle,
216         const WidgetRegisterInfo &regInfo);
217     static void registerEncryptedResouceInfo(
218         DbWidgetHandle widgetHandle,
219         const WidgetRegisterInfo &regInfo);
220     /**
221      * @brief registerExternalLocations Inserts new rows to
222      * WidgetExternalLocations
223      * @param externals list of files
224      */
225     static void registerExternalLocations(
226         DbWidgetHandle widgetHandle,
227         const ExternalLocationList &
228         externals);
229     static void registerWidgetSecuritySettings(DbWidgetHandle widgetHandle);
230
231     static void registerWidgetInternal(
232         const TizenAppId & tzAppId,
233         const WidgetRegisterInfo &widgetRegInfo,
234         const IWidgetSecurity &widgetSecurity,
235         const DPL::Optional<DbWidgetHandle> handle =
236             DPL::Optional<DbWidgetHandle>());
237     static void unregisterWidgetInternal(
238         const TizenAppId & tzAppId);
239
240     static void updateWidgetAppIdInternal(
241         const TizenAppId & fromAppId,
242         const TizenAppId & toAppId);
243
244     static void insertAppControlInfo(DbWidgetHandle handle,
245                                              DPL::String src,
246                                              DPL::String operation,
247                                              DPL::String uri,
248                                              DPL::String mime,
249                                              unsigned index,
250                                              unsigned disposition);
251 };
252 } // namespace WrtDB
253
254 #endif // WIDGET_DAO_H