2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * This file contains the declaration of widget dao class.
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)
24 * @brief This file contains the declaration of widget dao
27 #ifndef _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_
28 #define _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_
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>
44 * Widget's signature enum.
45 * This enumerates signature type of widget.
47 enum WidgetSignatureType
49 SIGNATURE_TYPE_CARRIER = 0,
50 SIGNATURE_TYPE_IDENTIFIED,
51 SIGNATURE_TYPE_UNIDENTIFIED
54 enum CertificateSource {
55 SIGNATURE_DISTRIBUTOR = 0,
59 typedef std::list<DPL::String> StringList;
61 struct WidgetLocalizedInfo
63 DPL::OptionalString name;
64 DPL::OptionalString shortName;
65 DPL::OptionalString description;
66 DPL::OptionalString license;
67 DPL::OptionalString licenseHref;
72 * A structure to hold certificate fingerprints.
74 struct WidgetCertificateData
76 enum Owner { AUTHOR, DISTRIBUTOR, UNKNOWN };
77 enum Type { ROOT, ENDENTITY };
79 // type of signature: author/distributor
81 // indicates whether this is ca certificate
84 // chain id number: relative BASE, where BASE is signatureBASE.xml
86 // certificate fingerprint digested by md5
87 std::string strMD5Fingerprint;
88 // certificate fingerprint digestef by sha1
89 std::string strSHA1Fingerprint;
90 // Common name field in certificate
91 DPL::String strCommonName;
93 bool operator== (const WidgetCertificateData& certData) const {
94 return certData.chainId == chainId &&
95 certData.owner == owner &&
96 certData.strCommonName == strCommonName &&
97 certData.strMD5Fingerprint == strMD5Fingerprint &&
98 certData.strSHA1Fingerprint == strSHA1Fingerprint;
102 typedef std::list<WidgetCertificateData> WidgetCertificateDataList;
104 typedef DPL::String Locale;
105 typedef std::set<Locale> LocaleSet;
109 * A structure to hold widget's information needed to be registered.
110 * @see WidgetConfigurationInfo
112 struct WidgetRegisterInfo
114 struct LocalizedIcon : public ConfigParserData::Icon
116 LocalizedIcon(const ConfigParserData::Icon& icon,
117 const LocaleSet& _availableLocales) :
118 ConfigParserData::Icon(icon),
119 availableLocales(_availableLocales)
123 LocaleSet availableLocales;
126 struct StartFileProperties
128 DPL::String encoding;
132 typedef std::map<Locale,
133 StartFileProperties> StartFilePropertiesForLocalesMap;
134 struct LocalizedStartFile
137 StartFilePropertiesForLocalesMap propertiesForLocales;
140 typedef std::list<LocalizedIcon> LocalizedIconList;
141 typedef std::list<LocalizedStartFile> LocalizedStartFileList;
142 struct LocalizationData
144 LocalizedIconList icons;
145 LocalizedStartFileList startFiles;
157 WidgetRegisterInfo() :
158 type(APP_TYPE_UNKNOWN),
159 signatureType(SIGNATURE_TYPE_UNIDENTIFIED),
162 pType(PKG_TYPE_UNKNOWN)
167 DPL::OptionalString guid;
168 DPL::OptionalString version;
169 DPL::OptionalString minVersion;
170 std::string shareHref;
171 std::string baseFolder;
172 WidgetSignatureType signatureType;
174 ConfigParserData configInfo;
175 LocalizationData localizationData;
176 DPL::OptionalString pkgname;
177 time_t installedTime;
179 EncryptedFileList encryptedFiles;
182 typedef std::list<std::string> CertificateChainList;
186 virtual ~IWacSecurity();
188 virtual const WidgetCertificateDataList& getCertificateList() const = 0;
190 virtual bool isRecognized() const = 0;
192 virtual bool isDistributorSigned() const = 0;
194 virtual bool isWacSigned() const = 0;
196 virtual void getCertificateChainList(CertificateChainList& list,
197 CertificateSource source) const = 0;
202 * Structure to hold the information of widget's author.
204 struct WidgetAuthorInfo
206 DPL::OptionalString name;
207 DPL::OptionalString email;
208 DPL::OptionalString href;
212 * Widget update policy
214 enum WidgetUpdatePolicy
216 WIDGET_UPDATE_MONTHLY = 0, //< monthly update
217 WIDGET_UPDATE_WEEKLY, //< weekly update
218 WIDGET_UPDATE_DAILY, //< daily update
219 WIDGET_UPDATE_STARTUP, //< update when cell phone boots
220 WIDGET_UPDATE_NEVER //< never update
223 typedef std::list <std::string> WidgetCertificateCNList;
224 typedef std::list<DPL::String> LanguageTagList;
225 typedef std::list<std::string> HostList;
226 typedef std::list<std::string> FingerPrintList;
227 typedef std::list<std::string> ResourceAttributeList;
228 typedef std::list<std::string> ExternalLocationList; //TODO: if there will be many files registered std::set is better
230 class WidgetDAOReadOnly
234 * WidgetDAO Exception classes
239 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
240 DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
241 DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty)
242 DECLARE_EXCEPTION_TYPE(Base, GUIDisNull)
243 DECLARE_EXCEPTION_TYPE(Base, UnexpectedEmptyResult)
244 DECLARE_EXCEPTION_TYPE(Base, WidgetNotExist)
245 DECLARE_EXCEPTION_TYPE(Base, AlreadyRegistered)
249 DbWidgetHandle m_widgetHandle;
252 struct WidgetLocalizedIconRow
256 DPL::String widgetLocale;
258 typedef std::list<WidgetLocalizedIconRow> WidgetLocalizedIconList;
265 DPL::OptionalInt iconWidth;
266 DPL::OptionalInt iconHeight;
268 typedef std::list<WidgetIconRow> WidgetIconList;
270 struct WidgetStartFileRow
276 typedef std::list<WidgetStartFileRow> WidgetStartFileList;
278 struct WidgetLocalizedStartFileRow
282 DPL::String widgetLocale;
284 DPL::String encoding;
286 typedef std::list<WidgetLocalizedStartFileRow> LocalizedStartFileList;
289 * This is a constructor.
291 * @param[in] widgetHandle application id of widget.
293 WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
294 WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
295 WidgetDAOReadOnly(DPL::String pkgName);
300 virtual ~WidgetDAOReadOnly();
303 * This method returns widget handle(m_widgetHandle).
305 * @return widget handle(m_widgetHandle).
306 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
307 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
309 DbWidgetHandle getHandle() const;
310 static DbWidgetHandle getHandle(const WidgetGUID GUID);
311 static DbWidgetHandle getHandle(const DPL::String pkgName);
314 * This method returns the root directory of widget resource.
316 * @return path name of root directory.
317 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
318 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
321 DPL::String getPath() const;
323 DPL::String getFullPath() const;
326 * This method returns the preferred size of the widget,
327 * including width and height.
330 * @return An structure type variable to hold widget's size.
331 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
332 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
335 DbWidgetSize getPreferredSize() const;
338 * This method returns the type of the widget.
341 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
342 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
345 WidgetType getWidgetType() const;
348 * This method returns the id of the widget.
351 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
352 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
355 WidgetGUID getGUID() const;
358 * This method returns the Package name of the widget.
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 DB table.
364 DPL::OptionalString getPkgname() const;
367 * This method returns the defaultlocale for the widget.
369 * @return defaultlocale
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
374 DPL::OptionalString getDefaultlocale() const;
377 * This method returns list of localized icons files;
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
383 WidgetLocalizedIconList getLocalizedIconList() const;
386 * This method returns list of icons files;
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
392 WidgetIconList getIconList() const;
395 * This method returns list of localized start files;
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
401 LocalizedStartFileList getLocalizedStartFileList() const;
404 * This method returns list of start files;
406 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
407 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
410 WidgetStartFileList getStartFileList() const;
413 * @param[out] outAccessInfoList list filled with access info structures
415 void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
419 * @return recognized status
421 bool isRecognized() const;
427 bool isWacSigned() const;
433 bool isDistributorSigned() const;
437 * @return trusted status
439 bool isTrusted() const;
443 * @return is WAC test widget
445 bool isTestWidget() const;
448 * This method returns window mode of widget.
450 * @return window modes of widget
451 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
452 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
455 WindowModeList getWindowModes() const;
458 * This method returns the version of the widget.
460 * @return version of widget
461 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
462 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
465 DPL::OptionalString getVersion() const;
468 * This method returns list filed with Common Name entries from certificate.
470 * @return Common Name of Distribuotor End Entity certificate.
471 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
472 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
475 WidgetCertificateCNList getKeyCommonNameList(
476 WidgetCertificateData::Owner owner,
477 WidgetCertificateData::Type type) const;
480 * given a certificate owner (author / distributor) and type of certificate
482 * function returns list of matching fingerprints
484 FingerPrintList getKeyFingerprints(
485 WidgetCertificateData::Owner owner,
486 WidgetCertificateData::Type type) const;
489 * This method gets certificate data list for a widget from database.
491 WidgetCertificateDataList getCertificateDataList() const;
494 * This method returns a list of widget features.
497 * @see FreeFeatureList()
498 * @return list of widget features, type of list element is structure
500 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
501 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
504 DbWidgetFeatureSet getFeaturesList() const;
506 static WidgetParamMap getFeatureParams(int widgetFeatureId);
508 * This method checks whether widget has specified feature.
510 * @return true if has, false if has not
511 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
513 bool hasFeature(const std::string& featureName) const;
516 * This method gets host list that widget can connect to.
518 * @return See above comment
519 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
521 HostList getAccessHostList() const;
524 * This method gets widget's access on network: true or false.
526 * @return true: widget can access network; false: widget can not access
528 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
529 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
532 bool getAccessNetworkMode() const;
535 * This method gets if widget needs webkit plugins enabled
537 * @return true: widget needs webkit plugins enabled
538 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
539 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
542 bool getWebkitPluginsRequired() const;
545 * This method returns a list of all the installed widgets' app id.
547 * @return list of installed widgets' app id.
548 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
549 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
552 static DbWidgetHandleList getHandleList();
555 * This method returns a list of all the installed widgets.
557 * @return list of installed widgets.
558 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
559 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
562 static DbWidgetDAOReadOnlyList getWidgetList();
565 * This method removes a widget's information from EmDB.
567 * @see RegisterWidget()
568 * @param[in] widgetHandle widget's app id
569 * @return true if succeed, false if fail.
571 static void unregisterWidget(DbWidgetHandle widgetHandle);
574 * This method gets author's infomation of a widget which is parsed from
575 * configiration document.
577 * @see WidgetAuthorInfo
578 * @param[out] pAuthorInfo
579 * @return true if succeed, false if fail.
581 WidgetAuthorInfo getAuthorInfo() const;
584 * This method gets author's name of a widget which is parsed from
585 * configiration document.
587 * @param[out] pAuthorInfo
588 * @return author's name.
589 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
590 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
593 DPL::OptionalString getAuthorName() const;
596 * This method gets author's email of a widget which is parsed from
597 * configiration document.
599 * @param[out] pAuthorInfo
600 * @return author's email.
601 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
602 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
605 DPL::OptionalString getAuthorEmail() const;
608 * This method gets author's email of a widget which is parsed from
609 * configiration document.
611 * @param[out] pAuthorInfo
612 * @return author's email.
613 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
614 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
617 DPL::OptionalString getAuthorHref() const;
620 * This method returns minimum version of WAC that WRT has to be compliant
621 * to to run this widget
623 * @return Minimum version
624 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
625 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
628 DPL::OptionalString getMinimumWacVersion() const;
630 /* This method get widget' share href.
632 * @return widget's share href
634 std::string getShareHref() const;
637 * This method get widget installed time
639 * @return time_t : return widget's install time
641 time_t getInstallTime() const;
644 * This method gets widget base folder.
646 * @return widget base folder.
647 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
648 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
651 std::string getBaseFolder() const;
653 /* This method gets the parameter list for resource.
655 ResourceAttributeList getResourceAttribute(
656 const std::string &resourceId) const;
658 /* This method checks read only flag for given property
660 DPL::OptionalInt checkPropertyReadFlag(
661 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
663 /* This method gets widget property key list
665 PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
667 /* This method gets widget property list
669 PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
671 /* This method get widget property value
673 PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
674 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
676 LanguageTagList getLanguageTags() const;
677 LanguageTagList getIconLanguageTags() const;
681 WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
682 std::string getCookieDatabasePath() const;
684 std::string getPrivateLocalStoragePath() const;
686 bool getBackSupported() const;
688 static bool isWidgetInstalled(DbWidgetHandle handle);
689 static bool isWidgetInstalled(DPL::String pkgName);
691 /* This method get path of the splash image.
693 * @return path of the widget's splash image
695 DPL::OptionalString getSplashImgSrc() const;
697 ExternalLocationList getWidgetExternalLocations() const;
700 * Default value is required to keep compatibility with
701 * wrt-installer and wrt.
703 CertificateChainList getWidgetCertificate(
704 CertificateSource source = SIGNATURE_DISTRIBUTOR) const;
706 void getWidgetSettings(WidgetSettings& outWidgetSettings) const;
709 * This method gets application service list that define AUL value
711 * @return See above comment
712 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
714 void getAppServiceList(
715 WidgetApplicationServiceList& outAppServiceList) const;
718 * This method returns the type of the package.
721 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
722 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
725 PkgType getPkgType() const;
727 void getEncryptedFileList(EncryptedFileList& filesList) const;
730 * This method returns widget's background page filename.
732 * @return Name of file containing background page
734 DPL::OptionalString getBackgroundPage() const;
739 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_