[Engine] patch for normal support of pkgmgr signal and thread problem
[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/string.h>
34 #include <dpl/exception.h>
35 #include <dpl/db/orm.h>
36 #include <dpl/optional_typedefs.h>
37 #include <dpl/wrt-dao-ro/config_parser_data.h>
38 #include <dpl/wrt-dao-ro/property_dao_read_only.h>
39 #include <dpl/wrt-dao-ro/common_dao_types.h>
40
41 namespace WrtDB {
42
43 /**
44  * Widget's signature enum.
45  * This enumerates signature type of widget.
46  */
47 enum WidgetSignatureType
48 {
49     SIGNATURE_TYPE_CARRIER = 0,
50     SIGNATURE_TYPE_IDENTIFIED,
51     SIGNATURE_TYPE_UNIDENTIFIED
52 };
53
54 typedef std::list<DPL::String> StringList;
55
56 struct WidgetLocalizedInfo
57 {
58     DPL::OptionalString name;
59     DPL::OptionalString shortName;
60     DPL::OptionalString description;
61     DPL::OptionalString license;
62     DPL::OptionalString licenseHref;
63 };
64
65 /**
66  * CertificateData
67  * A structure to hold certificate fingerprints.
68  */
69 struct WidgetCertificateData
70 {
71     enum Owner { AUTHOR, DISTRIBUTOR, UNKNOWN };
72     enum Type { ROOT, ENDENTITY };
73
74     // type of signature: author/distributor
75     Owner owner;
76     // indicates whether this is ca certificate
77     Type type;
78
79     // chain id number: relative BASE, where BASE is signatureBASE.xml
80     int chainId;
81     // certificate fingerprint digested by md5
82     std::string strMD5Fingerprint;
83     // certificate fingerprint digestef by sha1
84     std::string strSHA1Fingerprint;
85     // Common name field in certificate
86     DPL::String strCommonName;
87
88     bool operator== (const WidgetCertificateData& certData) const {
89         return certData.chainId == chainId &&
90            certData.owner == owner &&
91            certData.strCommonName == strCommonName &&
92            certData.strMD5Fingerprint == strMD5Fingerprint &&
93            certData.strSHA1Fingerprint == strSHA1Fingerprint;
94     }
95 };
96
97 typedef std::list<WidgetCertificateData> WidgetCertificateDataList;
98
99 typedef DPL::String Locale;
100 typedef std::set<Locale> LocaleSet;
101
102 /**
103  * WidgetRegisterInfo
104  * A structure to hold widget's information needed to be registered.
105  * @see WidgetConfigurationInfo
106  */
107 struct WidgetRegisterInfo
108 {
109     struct LocalizedIcon : public ConfigParserData::Icon
110     {
111         LocalizedIcon(const ConfigParserData::Icon& icon,
112                 const LocaleSet& _availableLocales) :
113             ConfigParserData::Icon(icon),
114             availableLocales(_availableLocales)
115         {
116         }
117
118         LocaleSet availableLocales;
119     };
120
121     struct StartFileProperties
122     {
123         DPL::String encoding;
124         DPL::String type;
125     };
126
127     typedef std::map<Locale,
128                      StartFileProperties> StartFilePropertiesForLocalesMap;
129     struct LocalizedStartFile
130     {
131         DPL::String path;
132         StartFilePropertiesForLocalesMap propertiesForLocales;
133     };
134
135     typedef std::list<LocalizedIcon> LocalizedIconList;
136     typedef std::list<LocalizedStartFile> LocalizedStartFileList;
137     struct LocalizationData
138     {
139         LocalizedIconList icons;
140         LocalizedStartFileList startFiles;
141     };
142
143     enum SecurityDomain
144     {
145         Untrusted,
146         Trusted,
147         Operator,
148         None
149     };
150
151     //Constructor
152     WidgetRegisterInfo() :
153         type(APP_TYPE_UNKNOWN),
154         signatureType(SIGNATURE_TYPE_UNIDENTIFIED),
155         isFactoryWidget(0),
156         isTestWidget(0),
157         configInfo()
158     {
159     }
160
161     WidgetType type;
162     DPL::OptionalString guid;
163     DPL::OptionalString version;
164     DPL::OptionalString minVersion;
165     std::string shareHref;
166     std::string baseFolder;
167     WidgetSignatureType signatureType;
168     int isFactoryWidget;
169     int isTestWidget;
170     ConfigParserData configInfo;
171     LocalizationData localizationData;
172     DPL::OptionalString pkgname;
173     time_t installedTime;
174 };
175
176 typedef std::list<std::string> CertificateChainList;
177 class IWacSecurity
178 {
179   public:
180     virtual ~IWacSecurity();
181
182     virtual const WidgetCertificateDataList& getCertificateList() const = 0;
183
184     virtual bool isRecognized() const = 0;
185
186     virtual bool isDistributorSigned() const = 0;
187
188     virtual bool isWacSigned() const = 0;
189
190     virtual void getCertificateChainList(CertificateChainList& list) const = 0;
191 };
192
193 /**
194  * WidgetAuthorInfo.
195  * Structure to hold the information of widget's author.
196  */
197 struct WidgetAuthorInfo
198 {
199     DPL::OptionalString name;
200     DPL::OptionalString email;
201     DPL::OptionalString href;
202 };
203
204 /**
205  * Widget update policy
206  */
207 enum WidgetUpdatePolicy
208 {
209     WIDGET_UPDATE_MONTHLY = 0,  //< monthly update
210     WIDGET_UPDATE_WEEKLY,       //< weekly update
211     WIDGET_UPDATE_DAILY,        //< daily update
212     WIDGET_UPDATE_STARTUP,      //< update when cell phone boots
213     WIDGET_UPDATE_NEVER         //< never update
214 };
215
216 typedef std::list <std::string> WidgetCertificateCNList;
217 typedef std::list<DPL::String> LanguageTagList;
218 typedef std::list<std::string> HostList;
219 typedef std::list<std::string> FingerPrintList;
220 typedef std::list<std::string> ResourceAttributeList;
221
222 class WidgetDAOReadOnly
223 {
224   public:
225     /**
226      * WidgetDAO Exception classes
227      */
228     class Exception
229     {
230       public:
231         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
232         DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
233         DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty)
234         DECLARE_EXCEPTION_TYPE(Base, GUIDisNull)
235         DECLARE_EXCEPTION_TYPE(Base, UnexpectedEmptyResult)
236         DECLARE_EXCEPTION_TYPE(Base, WidgetNotExist)
237         DECLARE_EXCEPTION_TYPE(Base, AlreadyRegistered)
238     };
239
240   protected:
241     DbWidgetHandle m_widgetHandle;
242
243   public:
244     struct WidgetLocalizedIconRow
245     {
246         int appId;
247         int iconId;
248         DPL::String widgetLocale;
249     };
250     typedef std::list<WidgetLocalizedIconRow> WidgetLocalizedIconList;
251
252     struct WidgetIconRow
253     {
254         int iconId;
255         int appId;
256         DPL::String iconSrc;
257         DPL::OptionalInt iconWidth;
258         DPL::OptionalInt iconHeight;
259     };
260     typedef std::list<WidgetIconRow> WidgetIconList;
261
262     struct WidgetStartFileRow
263     {
264         int startFileId;
265         int appId;
266         DPL::String src;
267     };
268     typedef std::list<WidgetStartFileRow> WidgetStartFileList;
269
270     struct WidgetLocalizedStartFileRow
271     {
272         int startFileId;
273         int appId;
274         DPL::String widgetLocale;
275         DPL::String type;
276         DPL::String encoding;
277     };
278     typedef std::list<WidgetLocalizedStartFileRow> LocalizedStartFileList;
279
280
281     /**
282      * This is a constructor.
283      *
284      * @param[in] widgetHandle application id of widget.
285      */
286     WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
287     WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
288
289     /**
290      * Destructor
291      */
292     virtual ~WidgetDAOReadOnly();
293
294     /**
295      * This method returns widget handle(m_widgetHandle).
296      *
297      * @return widget handle(m_widgetHandle).
298      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
299      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
300      */
301     DbWidgetHandle getHandle() const;
302     static DbWidgetHandle getHandle(const WidgetGUID GUID);
303     static DbWidgetHandle getHandle(const DPL::String pkgName);
304
305     /**
306      * This method returns the root directory of widget resource.
307      *
308      * @return path name of root directory.
309      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
310      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
311      * DB table.
312      */
313     DPL::String getPath() const;
314
315     DPL::String getFullPath() const;
316
317     /**
318      * This method returns the preferred size of the widget,
319      * including width and height.
320      *
321      * @see DbWidgetSize
322      * @return An structure type variable to hold widget's size.
323      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
324      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
325      *                                          DB table.
326      */
327     DbWidgetSize getPreferredSize() const;
328
329     /**
330      * This method returns the type of the widget.
331      *
332      * @return WidgetType
333      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
334      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
335                                                 records in DB table.
336      */
337     WidgetType getWidgetType() const;
338
339     /**
340      * This method returns the id of the widget.
341      *
342      * @return widget id
343      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
344      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
345      *  DB table.
346      */
347     WidgetGUID getGUID() const;
348
349     /**
350      * This method returns the Package name of the widget.
351      *
352      * @return pkgname
353      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
354      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
355      */
356     DPL::OptionalString getPkgname() const;
357
358     /**
359      * This method returns the defaultlocale for the widget.
360      *
361      * @return defaultlocale
362      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
363      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
364      *  DB table.
365      */
366     DPL::OptionalString getDefaultlocale() const;
367
368     /**
369      * This method returns list of localized icons files;
370      *
371      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
372      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
373      *  DB table.
374      */
375     WidgetLocalizedIconList getLocalizedIconList() const;
376
377     /**
378      * This method returns list of icons files;
379      *
380      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
381      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
382      *  DB table.
383      */
384     WidgetIconList getIconList() const;
385
386     /**
387      * This method returns list of localized start files;
388      *
389      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
390      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
391      *  DB table.
392      */
393     LocalizedStartFileList getLocalizedStartFileList() const;
394
395     /**
396      * This method returns list of start files;
397      *
398      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
399      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
400      *  DB table.
401      */
402     WidgetStartFileList getStartFileList() const;
403
404     /**
405      * @param[out] outAccessInfoList list filled with access info structures
406      */
407     void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
408
409     /**
410      * WAC 2.0 extension
411      * @return recognized status
412      */
413     bool isRecognized() const;
414
415     /**
416      * WAC 2.0 extension
417      * @return
418      */
419     bool isWacSigned() const;
420
421     /**
422      * WAC 2.0 extension
423      * @return
424      */
425     bool isDistributorSigned() const;
426
427     /**
428      * WAC 2.0 extension
429      * @return trusted status
430      */
431     bool isTrusted() const;
432
433     /**
434      * WAC 2.0 extension
435      * @return is WAC test widget
436      */
437     bool isTestWidget() const;
438
439     /**
440      * This method returns window mode of widget.
441      *
442      * @return window modes of widget
443      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
444      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
445      *  DB table.
446      */
447     WindowModeList getWindowModes() const;
448
449     /**
450      * This method returns the version of the widget.
451      *
452      * @return version of widget
453      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
454      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
455      *  DB table.
456      */
457     DPL::OptionalString getVersion() const;
458
459     /**
460      * This method returns list filed with Common Name entries from certificate.
461      *
462      * @return Common Name of Distribuotor End Entity certificate.
463      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
464      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
465      *  DB table.
466      */
467     WidgetCertificateCNList getKeyCommonNameList(
468             WidgetCertificateData::Owner owner,
469             WidgetCertificateData::Type type) const;
470
471     /**
472      * given a certificate owner (author / distributor) and type of certificate
473      * (end entity / ca)
474      * function returns list of matching fingerprints
475      */
476     FingerPrintList getKeyFingerprints(
477             WidgetCertificateData::Owner owner,
478             WidgetCertificateData::Type type) const;
479
480     /*
481      *  This method gets certificate data list for a widget from database.
482      */
483     WidgetCertificateDataList getCertificateDataList() const;
484
485     /**
486      * This method returns a list of widget features.
487      *
488      * @see WidgetFeature
489      * @see FreeFeatureList()
490      * @return list of widget features, type of list element is structure
491      *  WidgetFeature
492      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
493      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
494      *  DB table.
495      */
496     DbWidgetFeatureSet getFeaturesList() const;
497
498     static WidgetParamMap getFeatureParams(int widgetFeatureId);
499     /**
500      * This method checks whether widget has specified feature.
501      *
502      * @return true if has, false if has not
503      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
504      */
505     bool hasFeature(const std::string& featureName) const;
506
507     /**
508      * This method gets host list that widget can connect to.
509      *
510      * @return See above comment
511      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
512      */
513     HostList getAccessHostList() const;
514
515     /**
516      * This method gets widget's access on network: true or false.
517      *
518      * @return true: widget can access network; false: widget can not access
519      *  network.
520      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
521      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
522      *  DB table.
523      */
524     bool getAccessNetworkMode() const;
525
526     /**
527      * This method gets if widget needs webkit plugins enabled
528      *
529      * @return true: widget needs webkit plugins enabled
530      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
531      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
532      *  DB table.
533      */
534     bool getWebkitPluginsRequired() const;
535
536     /**
537      * This method returns a list of all the installed widgets.
538      *
539      * @return list of installed widgets' app id.
540      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
541      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
542      *  DB table.
543      */
544     static DbWidgetHandleList getHandleList();
545
546    /**
547      * This method removes a widget's information from EmDB.
548      *
549      * @see RegisterWidget()
550      * @param[in] widgetHandle    widget's app id
551      * @return true if succeed, false if fail.
552      */
553     static void unregisterWidget(DbWidgetHandle widgetHandle);
554
555     /**
556      * This method gets author's infomation of a widget which is parsed from
557      *  configiration document.
558      *
559      * @see WidgetAuthorInfo
560      * @param[out] pAuthorInfo
561      * @return true if succeed, false if fail.
562      */
563     WidgetAuthorInfo getAuthorInfo() const;
564
565     /**
566      * This method gets author's name of a widget which is parsed from
567      *  configiration document.
568      *
569      * @param[out] pAuthorInfo
570      * @return author's name.
571      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
572      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
573      *  DB table.
574      */
575     DPL::OptionalString getAuthorName() const;
576
577     /**
578      * This method gets author's email of a widget which is parsed from
579      *  configiration document.
580      *
581      * @param[out] pAuthorInfo
582      * @return author's email.
583      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
584      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
585      *  DB table.
586      */
587     DPL::OptionalString getAuthorEmail() const;
588
589     /**
590      * This method gets author's email of a widget which is parsed from
591      *  configiration document.
592      *
593      * @param[out] pAuthorInfo
594      * @return author's email.
595      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
596      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
597      *  DB table.
598      */
599     DPL::OptionalString getAuthorHref() const;
600
601     /**
602      * This method returns minimum version of WAC that WRT has to be compliant
603      *  to to run this widget
604      *
605      * @return Minimum version
606      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
607      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
608      *  DB table.
609      */
610     DPL::OptionalString getMinimumWacVersion() const;
611
612     /* This method get widget' share href.
613      *
614      * @return widget's share href
615      */
616     std::string getShareHref() const;
617
618     /**
619      * This method checks whether specified widget is a factory widget.
620      *
621      * @param[in] widgetHandle    widget's app id
622      * @return true if yes, false if no.
623      */
624     bool isFactory() const;
625
626     /**
627      * This method get widget installed time
628      *
629      * @return time_t : return widget's install time
630      */
631     time_t getInstallTime() const;
632
633     /**
634      * This method gets widget base folder.
635      *
636      * @return widget base folder.
637      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
638      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
639      *  DB table.
640      */
641     std::string getBaseFolder() const;
642
643     /**
644      * This method gets deletable property of widget.
645      *
646      * @return true: can be deleted; false: can not be deleted
647      * @exception WRT_CONF_ERR_GCONF_FAILURE
648      * @exception WRT_CONF_ERR_EMDB_FAILURE
649      * @exception WRT_CONF_ERR_EMDB_NO_RECORD
650      */
651     bool isDeletable() const;
652
653     /* This method gets the parameter list for resource.
654      */
655     ResourceAttributeList getResourceAttribute(
656             const std::string &resourceId) const;
657
658     /* This method checks read only flag for given property
659      */
660     DPL::OptionalInt checkPropertyReadFlag(
661             const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
662
663     /* This method gets widget property key list
664      */
665     PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
666
667     /* This method gets widget property list
668      */
669     PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
670
671     /* This method get widget property value
672      */
673     PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
674             const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
675
676     LanguageTagList getLanguageTags() const;
677     LanguageTagList getIconLanguageTags() const;
678
679     WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
680     std::string getCookieDatabasePath() const;
681     // Local storage
682     std::string getPrivateLocalStoragePath() const;
683
684     bool getBackSupported() const;
685
686     static bool isWidgetInstalled(DbWidgetHandle handle);
687     static bool isWidgetInstalled(DPL::String pkgName);
688
689     CertificateChainList getWidgetCertificate() const;
690
691     void getWidgetSettings(WidgetSettings& outWidgetSettings) const;
692
693     /**
694      * This method gets application service list that define AUL value
695      *
696      * @return See above comment
697      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
698      */
699     void getAppServiceList(
700             WidgetApplicationServiceList& outAppServiceList) const;
701 };
702
703 } // namespace WrtDB
704
705 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_
706