7b220c1935430c079796b379658ca58f02e83d19
[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
288     /**
289      * Destructor
290      */
291     virtual ~WidgetDAOReadOnly();
292
293     /**
294      * This method returns widget handle(m_widgetHandle).
295      *
296      * @return widget handle(m_widgetHandle).
297      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
298      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
299      */
300     DbWidgetHandle getHandle() const;
301     static DbWidgetHandle getHandle(const WidgetGUID GUID);
302     static DbWidgetHandle getHandle(const DPL::String pkgName);
303
304     /**
305      * This method returns the root directory of widget resource.
306      *
307      * @return path name of root directory.
308      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
309      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
310      * DB table.
311      */
312     DPL::String getPath() const;
313
314     DPL::String getFullPath() const;
315
316     /**
317      * This method returns the preferred size of the widget,
318      * including width and height.
319      *
320      * @see DbWidgetSize
321      * @return An structure type variable to hold widget's size.
322      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
323      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
324      *                                          DB table.
325      */
326     DbWidgetSize getPreferredSize() const;
327
328     /**
329      * This method returns the type of the widget.
330      *
331      * @return WidgetType
332      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
333      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
334                                                 records in DB table.
335      */
336     WidgetType getWidgetType() const;
337
338     /**
339      * This method returns the id of the widget.
340      *
341      * @return widget id
342      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
343      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
344      *  DB table.
345      */
346     WidgetGUID getGUID() const;
347
348     /**
349      * This method returns the Package name of the widget.
350      *
351      * @return pkgname
352      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
353      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
354      */
355     DPL::OptionalString getPkgname() const;
356
357     /**
358      * This method returns the defaultlocale for the widget.
359      *
360      * @return defaultlocale
361      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
362      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
363      *  DB table.
364      */
365     DPL::OptionalString getDefaultlocale() const;
366
367     /**
368      * This method returns list of localized icons files;
369      *
370      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
371      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
372      *  DB table.
373      */
374     WidgetLocalizedIconList getLocalizedIconList() const;
375
376     /**
377      * This method returns list of icons files;
378      *
379      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
380      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
381      *  DB table.
382      */
383     WidgetIconList getIconList() const;
384
385     /**
386      * This method returns list of localized start files;
387      *
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     LocalizedStartFileList getLocalizedStartFileList() const;
393
394     /**
395      * This method returns list of start files;
396      *
397      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
398      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
399      *  DB table.
400      */
401     WidgetStartFileList getStartFileList() const;
402
403     /**
404      * @param[out] outAccessInfoList list filled with access info structures
405      */
406     void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
407
408     /**
409      * WAC 2.0 extension
410      * @return recognized status
411      */
412     bool isRecognized() const;
413
414     /**
415      * WAC 2.0 extension
416      * @return
417      */
418     bool isWacSigned() const;
419
420     /**
421      * WAC 2.0 extension
422      * @return
423      */
424     bool isDistributorSigned() const;
425
426     /**
427      * WAC 2.0 extension
428      * @return trusted status
429      */
430     bool isTrusted() const;
431
432     /**
433      * WAC 2.0 extension
434      * @return is WAC test widget
435      */
436     bool isTestWidget() const;
437
438     /**
439      * This method returns window mode of widget.
440      *
441      * @return window modes of widget
442      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
443      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
444      *  DB table.
445      */
446     WindowModeList getWindowModes() const;
447
448     /**
449      * This method returns the version of the widget.
450      *
451      * @return version of widget
452      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
453      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
454      *  DB table.
455      */
456     DPL::OptionalString getVersion() const;
457
458     /**
459      * This method returns list filed with Common Name entries from certificate.
460      *
461      * @return Common Name of Distribuotor End Entity certificate.
462      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
463      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
464      *  DB table.
465      */
466     WidgetCertificateCNList getKeyCommonNameList(
467             WidgetCertificateData::Owner owner,
468             WidgetCertificateData::Type type) const;
469
470     /**
471      * given a certificate owner (author / distributor) and type of certificate
472      * (end entity / ca)
473      * function returns list of matching fingerprints
474      */
475     FingerPrintList getKeyFingerprints(
476             WidgetCertificateData::Owner owner,
477             WidgetCertificateData::Type type) const;
478
479     /*
480      *  This method gets certificate data list for a widget from database.
481      */
482     WidgetCertificateDataList getCertificateDataList() const;
483
484     /**
485      * This method returns a list of widget features.
486      *
487      * @see WidgetFeature
488      * @see FreeFeatureList()
489      * @return list of widget features, type of list element is structure
490      *  WidgetFeature
491      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
492      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
493      *  DB table.
494      */
495     DbWidgetFeatureSet getFeaturesList() const;
496
497     static WidgetParamMap getFeatureParams(int widgetFeatureId);
498     /**
499      * This method checks whether widget has specified feature.
500      *
501      * @return true if has, false if has not
502      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
503      */
504     bool hasFeature(const std::string& featureName) const;
505
506     /**
507      * This method gets host list that widget can connect to.
508      *
509      * @return See above comment
510      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
511      */
512     HostList getAccessHostList() const;
513
514     /**
515      * This method gets widget's access on network: true or false.
516      *
517      * @return true: widget can access network; false: widget can not access
518      *  network.
519      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
520      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
521      *  DB table.
522      */
523     bool getAccessNetworkMode() const;
524
525     /**
526      * This method gets if widget needs webkit plugins enabled
527      *
528      * @return true: widget needs webkit plugins enabled
529      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
530      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
531      *  DB table.
532      */
533     bool getWebkitPluginsRequired() const;
534
535     /**
536      * This method returns a list of all the installed widgets.
537      *
538      * @return list of installed widgets' app id.
539      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
540      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
541      *  DB table.
542      */
543     static DbWidgetHandleList getHandleList();
544
545    /**
546      * This method removes a widget's information from EmDB.
547      *
548      * @see RegisterWidget()
549      * @param[in] widgetHandle    widget's app id
550      * @return true if succeed, false if fail.
551      */
552     static void unregisterWidget(DbWidgetHandle widgetHandle);
553
554     /**
555      * This method gets author's infomation of a widget which is parsed from
556      *  configiration document.
557      *
558      * @see WidgetAuthorInfo
559      * @param[out] pAuthorInfo
560      * @return true if succeed, false if fail.
561      */
562     WidgetAuthorInfo getAuthorInfo() const;
563
564     /**
565      * This method gets author's name of a widget which is parsed from
566      *  configiration document.
567      *
568      * @param[out] pAuthorInfo
569      * @return author's name.
570      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
571      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
572      *  DB table.
573      */
574     DPL::OptionalString getAuthorName() const;
575
576     /**
577      * This method gets author's email of a widget which is parsed from
578      *  configiration document.
579      *
580      * @param[out] pAuthorInfo
581      * @return author's email.
582      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
583      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
584      *  DB table.
585      */
586     DPL::OptionalString getAuthorEmail() const;
587
588     /**
589      * This method gets author's email of a widget which is parsed from
590      *  configiration document.
591      *
592      * @param[out] pAuthorInfo
593      * @return author's email.
594      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
595      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
596      *  DB table.
597      */
598     DPL::OptionalString getAuthorHref() const;
599
600     /**
601      * This method returns minimum version of WAC that WRT has to be compliant
602      *  to to run this widget
603      *
604      * @return Minimum version
605      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
606      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
607      *  DB table.
608      */
609     DPL::OptionalString getMinimumWacVersion() const;
610
611     /* This method get widget' share href.
612      *
613      * @return widget's share href
614      */
615     std::string getShareHref() const;
616
617     /**
618      * This method checks whether specified widget is a factory widget.
619      *
620      * @param[in] widgetHandle    widget's app id
621      * @return true if yes, false if no.
622      */
623     bool isFactory() const;
624
625     /**
626      * This method get widget installed time
627      *
628      * @return time_t : return widget's install time
629      */
630     time_t getInstallTime() const;
631
632     /**
633      * This method gets widget base folder.
634      *
635      * @return widget base folder.
636      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
637      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
638      *  DB table.
639      */
640     std::string getBaseFolder() const;
641
642     /**
643      * This method gets deletable property of widget.
644      *
645      * @return true: can be deleted; false: can not be deleted
646      * @exception WRT_CONF_ERR_GCONF_FAILURE
647      * @exception WRT_CONF_ERR_EMDB_FAILURE
648      * @exception WRT_CONF_ERR_EMDB_NO_RECORD
649      */
650     bool isDeletable() const;
651
652     /* This method gets the parameter list for resource.
653      */
654     ResourceAttributeList getResourceAttribute(
655             const std::string &resourceId) const;
656
657     /* This method checks read only flag for given property
658      */
659     DPL::OptionalInt checkPropertyReadFlag(
660             const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
661
662     /* This method gets widget property key list
663      */
664     PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
665
666     /* This method gets widget property list
667      */
668     PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
669
670     /* This method get widget property value
671      */
672     PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
673             const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
674
675     LanguageTagList getLanguageTags() const;
676     LanguageTagList getIconLanguageTags() const;
677
678     WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
679     std::string getCookieDatabasePath() const;
680     // Local storage
681     std::string getPrivateLocalStoragePath() const;
682
683     bool getBackSupported() const;
684
685     static bool isWidgetInstalled(DbWidgetHandle handle);
686     static bool isWidgetInstalled(DPL::String pkgName);
687
688     CertificateChainList getWidgetCertificate() const;
689
690     void getWidgetSettings(WidgetSettings& outWidgetSettings) const;
691
692     /**
693      * This method gets application service list that define AUL value
694      *
695      * @return See above comment
696      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
697      */
698     void getAppServiceList(
699             WidgetApplicationServiceList& outAppServiceList) const;
700 };
701
702 } // namespace WrtDB
703
704 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_
705