tizen 2.4 release
[framework/web/wrt-commons.git] / modules / widget_dao / include / dpl / wrt-dao-ro / widget_dao_read_only.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_read_only.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
27 #ifndef _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_
28 #define _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_
29
30 #include <time.h>
31 #include <list>
32 #include <string>
33 #include <dpl/availability.h>
34 #include <dpl/string.h>
35 #include <dpl/exception.h>
36 #include <dpl/optional_typedefs.h>
37 #include <dpl/platform.h>
38 #include <dpl/wrt-dao-ro/property_dao_read_only.h>
39 #include <dpl/wrt-dao-ro/common_dao_types.h>
40 #include <dpl/wrt-dao-ro/widget_register_types.h>
41
42 namespace WrtDB {
43
44 class WidgetDAOReadOnly
45 {
46   public:
47     /**
48      * WidgetDAO Exception classes
49      */
50     class Exception
51     {
52       public:
53         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
54         DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
55         DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty)
56         DECLARE_EXCEPTION_TYPE(Base, GUIDisNull)
57         DECLARE_EXCEPTION_TYPE(Base, UnexpectedEmptyResult)
58         DECLARE_EXCEPTION_TYPE(Base, WidgetNotExist)
59         DECLARE_EXCEPTION_TYPE(Base, AlreadyRegistered)
60     };
61
62   protected:
63     DbWidgetHandle m_widgetHandle;
64
65   public:
66     struct WidgetLocalizedIconRow
67     {
68         int appId;
69         int iconId;
70         DPL::String widgetLocale;
71     };
72     typedef std::list<WidgetLocalizedIconRow> WidgetLocalizedIconList;
73
74     struct WidgetIconRow
75     {
76         int iconId;
77         int appId;
78         DPL::String iconSrc;
79         DPL::OptionalInt iconWidth;
80         DPL::OptionalInt iconHeight;
81     };
82     typedef std::list<WidgetIconRow> WidgetIconList;
83
84     struct WidgetStartFileRow
85     {
86         int startFileId;
87         int appId;
88         DPL::String src;
89     };
90     typedef std::list<WidgetStartFileRow> WidgetStartFileList;
91
92     struct WidgetLocalizedStartFileRow
93     {
94         int startFileId;
95         int appId;
96         DPL::String widgetLocale;
97         DPL::String type;
98         DPL::String encoding;
99     };
100     typedef std::list<WidgetLocalizedStartFileRow> LocalizedStartFileList;
101
102 #if USE(WEB_PROVIDER)
103     /*
104      * This List is to retrive liveBox(es)ID from wrt.db. List is required as
105      * there might be multiple app-widget tag in config.xml for one widget.
106      */
107     typedef std::list<DPL::OptionalString> LiveBoxIdList;
108 #endif
109
110     /**
111      * This is a constructor.
112      *
113      * @param[in] widgetHandle application id of widget.
114      */
115     WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
116     WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
117     WidgetDAOReadOnly(WrtDB::TizenAppId tzAppid);
118
119     /**
120      * Destructor
121      */
122     virtual ~WidgetDAOReadOnly();
123
124     /**
125      * This method returns widget handle(m_widgetHandle).
126      *
127      * @return widget handle(m_widgetHandle).
128      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
129      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
130      * DB table.
131      */
132     DbWidgetHandle getHandle() const;
133     static DbWidgetHandle getHandle(const WidgetGUID GUID);
134     static DbWidgetHandle getHandle(const DPL::String tzAppId);
135     static DbWidgetHandle getHandleByPkgId(const DPL::String pkgId);
136
137     /**
138      * This method Returns tizen application id for the specified web application
139      * @return TizenAppId
140      */
141     TizenAppId getTzAppId() const DPL_DEPRECATED_WITH_MESSAGE("Use getTizenAppId");
142     static TizenAppId getTzAppId(const WidgetGUID GUID) DPL_DEPRECATED_WITH_MESSAGE("Use getTizenAppId");
143     static TizenAppId getTzAppId(const DbWidgetHandle handle) DPL_DEPRECATED_WITH_MESSAGE("Use getTizenAppId");
144     static TizenAppId getTzAppId(const TizenPkgId tizenPkgId) DPL_DEPRECATED_WITH_MESSAGE("Use getTizenAppId");
145     TizenAppId getTizenAppId() const;
146     static TizenAppId getTizenAppId(const WidgetGUID GUID);
147     static TizenAppId getTizenAppId(const DbWidgetHandle handle);
148     static TizenAppId getTizenAppId(const TizenPkgId tizenPkgId);
149
150     /**
151      * This method returns list of installed tizen application id
152      * @return TizenAppIdList
153      */
154     static TizenAppIdList getTizenAppidList() DPL_DEPRECATED_WITH_MESSAGE("Use getTizenAppIdList");
155     static TizenAppIdList getTizenAppIdList();
156     static std::list<TizenAppId> getTzAppIdList(const TizenPkgId tzPkgid);
157
158     /**
159      * Returns tizen package id for the specified web application
160      * @return TizenPkgId
161      */
162     TizenPkgId getTizenPkgId() const;
163     static TizenPkgId getTizenPkgId(const DbWidgetHandle handle);
164     static TizenPkgId getTizenPkgId(const TizenAppId tzAppid);
165
166     /**
167      * This method returns list of tizen package list of installed web applications
168      * @return TizenPkgIdList
169      */
170     static TizenPkgIdList getTizenPkgIdList();
171
172     /**
173      * This method returns the root directory of widget resource.
174      *
175      * @return path name of root directory.
176      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
177      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
178      * DB table.
179      */
180     virtual DPL::String getPath() const;
181
182     DPL::String getFullPath() const;
183
184     /**
185      * This method returns the preferred size of the widget,
186      * including width and height.
187      *
188      * @see DbWidgetSize
189      * @return An structure type variable to hold widget's size.
190      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
191      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
192      *                                          DB table.
193      */
194     DbWidgetSize getPreferredSize() const;
195
196     /**
197      * This method returns the type of the widget.
198      *
199      * @return WidgetType
200      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
201      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
202      *                                          records in DB table.
203      */
204     WidgetType getWidgetType() const;
205
206     /**
207      * This method returns the id of the widget.
208      *
209      * @return widget id
210      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
211      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
212      *  DB table.
213      */
214     WidgetGUID getGUID() const;
215
216     /**
217      * This method returns the defaultlocale for the widget.
218      *
219      * @return defaultlocale
220      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
221      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
222      *  DB table.
223      */
224     DPL::OptionalString getDefaultlocale() const;
225
226     /**
227      * This method returns list of localized icons files;
228      *
229      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
230      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
231      *  DB table.
232      */
233     WidgetLocalizedIconList getLocalizedIconList() const;
234
235     /**
236      * This method returns list of icons files;
237      *
238      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
239      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
240      *  DB table.
241      */
242     WidgetIconList getIconList() const;
243
244     /**
245      * This method returns list of localized start files;
246      *
247      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
248      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
249      *  DB table.
250      */
251     LocalizedStartFileList getLocalizedStartFileList() const;
252
253     /**
254      * This method returns list of start files;
255      *
256      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
257      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
258      *  DB table.
259      */
260     WidgetStartFileList getStartFileList() const;
261
262     /**
263      * @param[out] outAccessInfoList list filled with access info structures
264      */
265     void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
266     void getWidgetAllowNavigationInfo(
267         WidgetAllowNavigationInfoList& allowNavigationInfoList) const;
268
269     /**
270      * This method returns window mode of widget.
271      *
272      * @return window modes of widget
273      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
274      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
275      *  DB table.
276      */
277     WindowModeList getWindowModes() const;
278
279     /**
280      * This method returns the version of the widget.
281      *
282      * @return version of widget
283      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
284      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
285      *  DB table.
286      */
287     DPL::OptionalString getVersion() const;
288
289     /**
290      * This method is used as a getter for csp policy of widget. It should be
291      * provided in configuration file.
292      * @return global csp policy for widget
293      */
294     DPL::OptionalString getCspPolicy() const;
295
296     /**
297      * This method is used as a getter for report only csp policy of widget.
298      * It may be provided in configuration file.
299      * @return global csp report only policy for widget
300      */
301     DPL::OptionalString getCspPolicyReportOnly() const;
302
303     /**
304      * This method returns list filed with Common Name entries from certificate.
305      *
306      * @return Common Name of Distribuotor End Entity certificate.
307      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
308      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
309      *  DB table.
310      */
311     WidgetCertificateCNList getKeyCommonNameList(
312         WidgetCertificateData::Owner owner,
313         WidgetCertificateData::Type type) const;
314
315     /**
316      * given a certificate owner (author / distributor) and type of certificate
317      * (end entity / ca)
318      * function returns list of matching fingerprints
319      */
320     FingerPrintList getKeyFingerprints(
321         WidgetCertificateData::Owner owner,
322         WidgetCertificateData::Type type) const;
323
324     /*
325      *  This method gets certificate data list for a widget from database.
326      */
327     WidgetCertificateDataList getCertificateDataList() const;
328
329     /**
330      * This method returns a list of widget features.
331      *
332      * @see WidgetFeature
333      * @see FreeFeatureList()
334      * @return list of widget features, type of list element is structure
335      *  WidgetFeature
336      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
337      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
338      *  DB table.
339      */
340     DbWidgetFeatureSet getFeaturesList() const;
341
342     /**
343      * This method checks whether widget has specified feature.
344      *
345      * @return true if has, false if has not
346      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
347      */
348     bool hasFeature(const std::string& featureName) const;
349
350     /**
351      * This method returns a list of all the installed widgets.
352      *
353      * @return list of installed widgets.
354      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
355      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
356      *  DB table.
357      */
358     static DbWidgetDAOReadOnlyList getWidgetList();
359
360     /**
361      * This method gets author's infomation of a widget which is parsed from
362      *  configiration document.
363      *
364      * @see WidgetAuthorInfo
365      * @param[out] pAuthorInfo
366      * @return true if succeed, false if fail.
367      */
368     WidgetAuthorInfo getAuthorInfo() const;
369
370     /**
371      * This method gets author's name of a widget which is parsed from
372      *  configiration document.
373      *
374      * @param[out] pAuthorInfo
375      * @return author's name.
376      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
377      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
378      *  DB table.
379      */
380     DPL::OptionalString getAuthorName() const;
381
382     /**
383      * This method gets author's email of a widget which is parsed from
384      *  configiration document.
385      *
386      * @param[out] pAuthorInfo
387      * @return author's email.
388      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
389      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
390      *  DB table.
391      */
392     DPL::OptionalString getAuthorEmail() const;
393
394     /**
395      * This method gets author's email of a widget which is parsed from
396      *  configiration document.
397      *
398      * @param[out] pAuthorInfo
399      * @return author's email.
400      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
401      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
402      *  DB table.
403      */
404     DPL::OptionalString getAuthorHref() const;
405
406     /**
407      * This method returns minimum version of WAC that WRT has to be compliant
408      *  to to run this widget
409      *
410      * @return Minimum version
411      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
412      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
413      *  DB table.
414      */
415     DPL::OptionalString getMinimumWacVersion() const;
416
417     /**
418      * This method get widget installed time
419      *
420      * @return time_t : return widget's install time
421      */
422     time_t getInstallTime() const;
423
424     /* This method checks read only flag for given property
425      */
426     DPL::OptionalInt checkPropertyReadFlag(
427         const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
428
429     /* This method gets widget property key list
430      */
431     PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
432
433     /* This method gets widget property list
434      */
435     PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
436
437     /* This method get widget property value
438      */
439     PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
440         const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
441
442     LanguageTagList getLanguageTags() const;
443     LanguageTagList getIconLanguageTags() const;
444
445     WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
446
447     bool getBackSupported() const;
448
449     static bool isWidgetInstalled(DbWidgetHandle handle);
450     static bool isWidgetInstalled(const TizenAppId & tzAppId);
451
452     /* This method get path of the splash image.
453      *
454      * @return path of the widget's splash image
455      */
456     DPL::OptionalString getSplashImgSrc() const;
457
458     ExternalLocationList getWidgetExternalLocations() const;
459
460     /*
461      * Default value is required to keep compatibility with
462      * wrt-installer and wrt.
463      */
464     CertificateChainList getWidgetCertificate(
465         CertificateSource source = SIGNATURE_DISTRIBUTOR) const;
466
467     void getWidgetSettings(WidgetSettings& outWidgetSettings) const;
468
469     /**
470      * This method gets application control list that define AUL value
471      *
472      * @return See above comment
473      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
474      */
475     void getAppControlList(
476         WidgetAppControlList& outAppControlList) const;
477
478     /**
479      * This method returns the type of the package.
480      *
481      * @return PackagingType
482      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
483      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
484      *                                          records in DB table.
485      */
486     PackagingType getPackagingType() const;
487
488     void getEncryptedFileList(EncryptedFileList& filesList) const;
489
490     /**
491      * This method returns widget's background page filename.
492      *
493      * @return Name of file containing background page
494      */
495     DPL::OptionalString getBackgroundPage() const;
496
497     /**
498      * @brief generateTizenId generates new package id
499      *
500      * If widget do not supplies it's own tizen package id, this method can be
501      * used,
502      * although it should be removed in future.
503      *
504      * @return new tizen package id
505      */
506     static TizenPkgId generatePkgId();
507     static TizenPkgId generateTizenId()
508     {
509         return generatePkgId();
510     }
511
512     /**
513      * This method returns widget's installed path
514      *
515      * @return path of widget installed
516      */
517     DPL::OptionalString getWidgetInstalledPath() const;
518     PrivilegeList getWidgetPrivilege() const;
519     WidgetSecurityModelVersion getSecurityModelVersion() const;
520
521 #if USE(WEB_PROVIDER)
522     /**
523      * @brief Gets list of liveBox(es) ID(s) for a particular widget.
524      * @param[out] out param to retrive livebox(es) ID(s) as a list of String
525      */
526     void getLiveBoxInfoList(LiveBoxIdList& outLiveBoxIdList) const;
527 #endif
528 };
529 } // namespace WrtDB
530
531 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_
532