Update wrt-commons_0.2.53
[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         pType(PKG_TYPE_UNKNOWN)
159     {
160     }
161
162     WidgetType type;
163     DPL::OptionalString guid;
164     DPL::OptionalString version;
165     DPL::OptionalString minVersion;
166     std::string shareHref;
167     std::string baseFolder;
168     WidgetSignatureType signatureType;
169     int isFactoryWidget;
170     int isTestWidget;
171     ConfigParserData configInfo;
172     LocalizationData localizationData;
173     DPL::OptionalString pkgname;
174     time_t installedTime;
175     PkgType pType;
176 };
177
178 typedef std::list<std::string> CertificateChainList;
179 class IWacSecurity
180 {
181   public:
182     virtual ~IWacSecurity();
183
184     virtual const WidgetCertificateDataList& getCertificateList() const = 0;
185
186     virtual bool isRecognized() const = 0;
187
188     virtual bool isDistributorSigned() const = 0;
189
190     virtual bool isWacSigned() const = 0;
191
192     virtual void getCertificateChainList(CertificateChainList& list) const = 0;
193 };
194
195 /**
196  * WidgetAuthorInfo.
197  * Structure to hold the information of widget's author.
198  */
199 struct WidgetAuthorInfo
200 {
201     DPL::OptionalString name;
202     DPL::OptionalString email;
203     DPL::OptionalString href;
204 };
205
206 /**
207  * Widget update policy
208  */
209 enum WidgetUpdatePolicy
210 {
211     WIDGET_UPDATE_MONTHLY = 0,  //< monthly update
212     WIDGET_UPDATE_WEEKLY,       //< weekly update
213     WIDGET_UPDATE_DAILY,        //< daily update
214     WIDGET_UPDATE_STARTUP,      //< update when cell phone boots
215     WIDGET_UPDATE_NEVER         //< never update
216 };
217
218 typedef std::list <std::string> WidgetCertificateCNList;
219 typedef std::list<DPL::String> LanguageTagList;
220 typedef std::list<std::string> HostList;
221 typedef std::list<std::string> FingerPrintList;
222 typedef std::list<std::string> ResourceAttributeList;
223
224 class WidgetDAOReadOnly
225 {
226   public:
227     /**
228      * WidgetDAO Exception classes
229      */
230     class Exception
231     {
232       public:
233         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
234         DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
235         DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty)
236         DECLARE_EXCEPTION_TYPE(Base, GUIDisNull)
237         DECLARE_EXCEPTION_TYPE(Base, UnexpectedEmptyResult)
238         DECLARE_EXCEPTION_TYPE(Base, WidgetNotExist)
239         DECLARE_EXCEPTION_TYPE(Base, AlreadyRegistered)
240     };
241
242   protected:
243     DbWidgetHandle m_widgetHandle;
244
245   public:
246     struct WidgetLocalizedIconRow
247     {
248         int appId;
249         int iconId;
250         DPL::String widgetLocale;
251     };
252     typedef std::list<WidgetLocalizedIconRow> WidgetLocalizedIconList;
253
254     struct WidgetIconRow
255     {
256         int iconId;
257         int appId;
258         DPL::String iconSrc;
259         DPL::OptionalInt iconWidth;
260         DPL::OptionalInt iconHeight;
261     };
262     typedef std::list<WidgetIconRow> WidgetIconList;
263
264     struct WidgetStartFileRow
265     {
266         int startFileId;
267         int appId;
268         DPL::String src;
269     };
270     typedef std::list<WidgetStartFileRow> WidgetStartFileList;
271
272     struct WidgetLocalizedStartFileRow
273     {
274         int startFileId;
275         int appId;
276         DPL::String widgetLocale;
277         DPL::String type;
278         DPL::String encoding;
279     };
280     typedef std::list<WidgetLocalizedStartFileRow> LocalizedStartFileList;
281
282
283     /**
284      * This is a constructor.
285      *
286      * @param[in] widgetHandle application id of widget.
287      */
288     WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
289     WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
290
291     /**
292      * Destructor
293      */
294     virtual ~WidgetDAOReadOnly();
295
296     /**
297      * This method returns widget handle(m_widgetHandle).
298      *
299      * @return widget handle(m_widgetHandle).
300      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
301      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
302      */
303     DbWidgetHandle getHandle() const;
304     static DbWidgetHandle getHandle(const WidgetGUID GUID);
305     static DbWidgetHandle getHandle(const DPL::String pkgName);
306
307     /**
308      * This method returns the root directory of widget resource.
309      *
310      * @return path name of root directory.
311      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
312      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
313      * DB table.
314      */
315     DPL::String getPath() const;
316
317     DPL::String getFullPath() const;
318
319     /**
320      * This method returns the preferred size of the widget,
321      * including width and height.
322      *
323      * @see DbWidgetSize
324      * @return An structure type variable to hold widget's size.
325      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
326      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
327      *                                          DB table.
328      */
329     DbWidgetSize getPreferredSize() const;
330
331     /**
332      * This method returns the type of the widget.
333      *
334      * @return WidgetType
335      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
336      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
337                                                 records in DB table.
338      */
339     WidgetType getWidgetType() const;
340
341     /**
342      * This method returns the id of the widget.
343      *
344      * @return widget id
345      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
346      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
347      *  DB table.
348      */
349     WidgetGUID getGUID() const;
350
351     /**
352      * This method returns the Package name of the widget.
353      *
354      * @return pkgname
355      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
356      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
357      */
358     DPL::OptionalString getPkgname() const;
359
360     /**
361      * This method returns the defaultlocale for the widget.
362      *
363      * @return defaultlocale
364      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
365      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
366      *  DB table.
367      */
368     DPL::OptionalString getDefaultlocale() const;
369
370     /**
371      * This method returns list of localized icons files;
372      *
373      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
374      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
375      *  DB table.
376      */
377     WidgetLocalizedIconList getLocalizedIconList() const;
378
379     /**
380      * This method returns list of icons files;
381      *
382      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
383      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
384      *  DB table.
385      */
386     WidgetIconList getIconList() const;
387
388     /**
389      * This method returns list of localized start files;
390      *
391      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
392      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
393      *  DB table.
394      */
395     LocalizedStartFileList getLocalizedStartFileList() const;
396
397     /**
398      * This method returns list of start files;
399      *
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     WidgetStartFileList getStartFileList() const;
405
406     /**
407      * @param[out] outAccessInfoList list filled with access info structures
408      */
409     void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
410
411     /**
412      * WAC 2.0 extension
413      * @return recognized status
414      */
415     bool isRecognized() const;
416
417     /**
418      * WAC 2.0 extension
419      * @return
420      */
421     bool isWacSigned() const;
422
423     /**
424      * WAC 2.0 extension
425      * @return
426      */
427     bool isDistributorSigned() const;
428
429     /**
430      * WAC 2.0 extension
431      * @return trusted status
432      */
433     bool isTrusted() const;
434
435     /**
436      * WAC 2.0 extension
437      * @return is WAC test widget
438      */
439     bool isTestWidget() const;
440
441     /**
442      * This method returns window mode of widget.
443      *
444      * @return window modes of widget
445      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
446      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
447      *  DB table.
448      */
449     WindowModeList getWindowModes() const;
450
451     /**
452      * This method returns the version of the widget.
453      *
454      * @return version of widget
455      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
456      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
457      *  DB table.
458      */
459     DPL::OptionalString getVersion() const;
460
461     /**
462      * This method returns list filed with Common Name entries from certificate.
463      *
464      * @return Common Name of Distribuotor End Entity certificate.
465      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
466      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
467      *  DB table.
468      */
469     WidgetCertificateCNList getKeyCommonNameList(
470             WidgetCertificateData::Owner owner,
471             WidgetCertificateData::Type type) const;
472
473     /**
474      * given a certificate owner (author / distributor) and type of certificate
475      * (end entity / ca)
476      * function returns list of matching fingerprints
477      */
478     FingerPrintList getKeyFingerprints(
479             WidgetCertificateData::Owner owner,
480             WidgetCertificateData::Type type) const;
481
482     /*
483      *  This method gets certificate data list for a widget from database.
484      */
485     WidgetCertificateDataList getCertificateDataList() const;
486
487     /**
488      * This method returns a list of widget features.
489      *
490      * @see WidgetFeature
491      * @see FreeFeatureList()
492      * @return list of widget features, type of list element is structure
493      *  WidgetFeature
494      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
495      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
496      *  DB table.
497      */
498     DbWidgetFeatureSet getFeaturesList() const;
499
500     static WidgetParamMap getFeatureParams(int widgetFeatureId);
501     /**
502      * This method checks whether widget has specified feature.
503      *
504      * @return true if has, false if has not
505      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
506      */
507     bool hasFeature(const std::string& featureName) const;
508
509     /**
510      * This method gets host list that widget can connect to.
511      *
512      * @return See above comment
513      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
514      */
515     HostList getAccessHostList() const;
516
517     /**
518      * This method gets widget's access on network: true or false.
519      *
520      * @return true: widget can access network; false: widget can not access
521      *  network.
522      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
523      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
524      *  DB table.
525      */
526     bool getAccessNetworkMode() const;
527
528     /**
529      * This method gets if widget needs webkit plugins enabled
530      *
531      * @return true: widget needs webkit plugins enabled
532      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
533      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
534      *  DB table.
535      */
536     bool getWebkitPluginsRequired() const;
537
538     /**
539      * This method returns a list of all the installed widgets.
540      *
541      * @return list of installed widgets' app id.
542      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
543      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
544      *  DB table.
545      */
546     static DbWidgetHandleList getHandleList();
547
548    /**
549      * This method removes a widget's information from EmDB.
550      *
551      * @see RegisterWidget()
552      * @param[in] widgetHandle    widget's app id
553      * @return true if succeed, false if fail.
554      */
555     static void unregisterWidget(DbWidgetHandle widgetHandle);
556
557     /**
558      * This method gets author's infomation of a widget which is parsed from
559      *  configiration document.
560      *
561      * @see WidgetAuthorInfo
562      * @param[out] pAuthorInfo
563      * @return true if succeed, false if fail.
564      */
565     WidgetAuthorInfo getAuthorInfo() const;
566
567     /**
568      * This method gets author's name of a widget which is parsed from
569      *  configiration document.
570      *
571      * @param[out] pAuthorInfo
572      * @return author's name.
573      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
574      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
575      *  DB table.
576      */
577     DPL::OptionalString getAuthorName() const;
578
579     /**
580      * This method gets author's email of a widget which is parsed from
581      *  configiration document.
582      *
583      * @param[out] pAuthorInfo
584      * @return author's email.
585      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
586      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
587      *  DB table.
588      */
589     DPL::OptionalString getAuthorEmail() const;
590
591     /**
592      * This method gets author's email of a widget which is parsed from
593      *  configiration document.
594      *
595      * @param[out] pAuthorInfo
596      * @return author's email.
597      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
598      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
599      *  DB table.
600      */
601     DPL::OptionalString getAuthorHref() const;
602
603     /**
604      * This method returns minimum version of WAC that WRT has to be compliant
605      *  to to run this widget
606      *
607      * @return Minimum version
608      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
609      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
610      *  DB table.
611      */
612     DPL::OptionalString getMinimumWacVersion() const;
613
614     /* This method get widget' share href.
615      *
616      * @return widget's share href
617      */
618     std::string getShareHref() const;
619
620     /**
621      * This method checks whether specified widget is a factory widget.
622      *
623      * @param[in] widgetHandle    widget's app id
624      * @return true if yes, false if no.
625      */
626     bool isFactory() const;
627
628     /**
629      * This method get widget installed time
630      *
631      * @return time_t : return widget's install time
632      */
633     time_t getInstallTime() const;
634
635     /**
636      * This method gets widget base folder.
637      *
638      * @return widget base folder.
639      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
640      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
641      *  DB table.
642      */
643     std::string getBaseFolder() const;
644
645     /**
646      * This method gets deletable property of widget.
647      *
648      * @return true: can be deleted; false: can not be deleted
649      * @exception WRT_CONF_ERR_GCONF_FAILURE
650      * @exception WRT_CONF_ERR_EMDB_FAILURE
651      * @exception WRT_CONF_ERR_EMDB_NO_RECORD
652      */
653     bool isDeletable() const;
654
655     /* This method gets the parameter list for resource.
656      */
657     ResourceAttributeList getResourceAttribute(
658             const std::string &resourceId) const;
659
660     /* This method checks read only flag for given property
661      */
662     DPL::OptionalInt checkPropertyReadFlag(
663             const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
664
665     /* This method gets widget property key list
666      */
667     PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
668
669     /* This method gets widget property list
670      */
671     PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
672
673     /* This method get widget property value
674      */
675     PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
676             const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
677
678     LanguageTagList getLanguageTags() const;
679     LanguageTagList getIconLanguageTags() const;
680
681     WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
682     std::string getCookieDatabasePath() const;
683     // Local storage
684     std::string getPrivateLocalStoragePath() const;
685
686     bool getBackSupported() const;
687
688     static bool isWidgetInstalled(DbWidgetHandle handle);
689     static bool isWidgetInstalled(DPL::String pkgName);
690
691     /* This method get path of the splash image.
692      *
693      * @return path of the widget's splash image
694      */
695     DPL::OptionalString getSplashImgSrc() const;
696
697     CertificateChainList getWidgetCertificate() const;
698
699     void getWidgetSettings(WidgetSettings& outWidgetSettings) const;
700
701     /**
702      * This method gets application service list that define AUL value
703      *
704      * @return See above comment
705      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
706      */
707     void getAppServiceList(
708             WidgetApplicationServiceList& outAppServiceList) const;
709
710     /**
711      * This method returns the type of the package.
712      *
713      * @return PkgType
714      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
715      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
716                                                 records in DB table.
717      */
718     PkgType getPkgType() const;
719 };
720
721 } // namespace WrtDB
722
723 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_
724