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