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;
106 typedef std::list<std::string> ExternalLocationList;
110 * A structure to hold widget's information needed to be registered.
111 * @see WidgetConfigurationInfo
113 struct WidgetRegisterInfo
115 struct LocalizedIcon : public ConfigParserData::Icon
117 LocalizedIcon(const ConfigParserData::Icon& icon,
118 const LocaleSet& _availableLocales) :
119 ConfigParserData::Icon(icon),
120 availableLocales(_availableLocales)
124 LocaleSet availableLocales;
127 struct StartFileProperties
129 DPL::String encoding;
133 typedef std::map<Locale,
134 StartFileProperties> StartFilePropertiesForLocalesMap;
135 struct LocalizedStartFile
138 StartFilePropertiesForLocalesMap propertiesForLocales;
141 typedef std::list<LocalizedIcon> LocalizedIconList;
142 typedef std::list<LocalizedStartFile> LocalizedStartFileList;
143 struct LocalizationData
145 LocalizedIconList icons;
146 LocalizedStartFileList startFiles;
158 WidgetRegisterInfo() :
159 webAppType(APP_TYPE_UNKNOWN),
160 signatureType(SIGNATURE_TYPE_UNIDENTIFIED),
163 packagingType(PKG_TYPE_UNKNOWN)
167 WidgetType webAppType;
168 WidgetType type; // TODO : This type will be removed.
169 DPL::OptionalString guid;
170 DPL::OptionalString version;
171 DPL::OptionalString minVersion;
172 std::string shareHref;
173 std::string baseFolder;
174 WidgetSignatureType signatureType;
176 ConfigParserData configInfo;
177 LocalizationData localizationData;
179 DPL::OptionalString pkgname;
180 WidgetPkgName pkgName;
184 time_t installedTime;
185 PackagingType packagingType;
186 EncryptedFileList encryptedFiles;
187 ExternalLocationList externalLocations;
188 DPL::OptionalString widgetInstalledPath;
191 typedef std::list<std::string> CertificateChainList;
195 virtual ~IWacSecurity();
197 virtual const WidgetCertificateDataList& getCertificateList() const = 0;
199 virtual bool isRecognized() const = 0;
201 virtual bool isDistributorSigned() const = 0;
203 virtual bool isWacSigned() const = 0;
205 virtual void getCertificateChainList(CertificateChainList& list,
206 CertificateSource source) const = 0;
211 * Structure to hold the information of widget's author.
213 struct WidgetAuthorInfo
215 DPL::OptionalString name;
216 DPL::OptionalString email;
217 DPL::OptionalString href;
221 * Widget update policy
223 enum WidgetUpdatePolicy
225 WIDGET_UPDATE_MONTHLY = 0, //< monthly update
226 WIDGET_UPDATE_WEEKLY, //< weekly update
227 WIDGET_UPDATE_DAILY, //< daily update
228 WIDGET_UPDATE_STARTUP, //< update when cell phone boots
229 WIDGET_UPDATE_NEVER //< never update
232 typedef std::list <std::string> WidgetCertificateCNList;
233 typedef std::list<DPL::String> LanguageTagList;
234 typedef std::list<std::string> HostList;
235 typedef std::list<std::string> FingerPrintList;
236 typedef std::list<std::string> ResourceAttributeList;
238 class WidgetDAOReadOnly
242 * WidgetDAO Exception classes
247 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
248 DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
249 DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty)
250 DECLARE_EXCEPTION_TYPE(Base, GUIDisNull)
251 DECLARE_EXCEPTION_TYPE(Base, UnexpectedEmptyResult)
252 DECLARE_EXCEPTION_TYPE(Base, WidgetNotExist)
253 DECLARE_EXCEPTION_TYPE(Base, AlreadyRegistered)
257 DbWidgetHandle m_widgetHandle;
260 struct WidgetLocalizedIconRow
264 DPL::String widgetLocale;
266 typedef std::list<WidgetLocalizedIconRow> WidgetLocalizedIconList;
273 DPL::OptionalInt iconWidth;
274 DPL::OptionalInt iconHeight;
276 typedef std::list<WidgetIconRow> WidgetIconList;
278 struct WidgetStartFileRow
284 typedef std::list<WidgetStartFileRow> WidgetStartFileList;
286 struct WidgetLocalizedStartFileRow
290 DPL::String widgetLocale;
292 DPL::String encoding;
294 typedef std::list<WidgetLocalizedStartFileRow> LocalizedStartFileList;
297 * This is a constructor.
299 * @param[in] widgetHandle application id of widget.
301 WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
302 WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
303 WidgetDAOReadOnly(DPL::String tzAppid);
308 virtual ~WidgetDAOReadOnly();
311 * This method returns widget handle(m_widgetHandle).
313 * @return widget handle(m_widgetHandle).
314 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
315 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
317 DbWidgetHandle getHandle() const;
318 static DbWidgetHandle getHandle(const WidgetGUID GUID);
319 static DbWidgetHandle getHandle(const DPL::String pkgName);
322 * Returns tizenAppId for the specified widget
325 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
326 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
329 TizenAppId getTzAppId() const;
330 static TizenAppId getTzAppId(const WidgetGUID GUID);
331 static TizenAppId getTzAppId(const DbWidgetHandle handle);
334 * Returns WidgetPkgName for the specified widget
337 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
338 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
341 WidgetPkgName getPkgName() const;
342 static WidgetPkgName getPkgName(const WidgetGUID GUID);
343 static WidgetPkgName getPkgName(const DbWidgetHandle handle);
346 * This method returns the root directory of widget resource.
348 * @return path name of root directory.
349 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
350 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
353 DPL::String getPath() const;
355 DPL::String getFullPath() const;
358 * This method returns the preferred size of the widget,
359 * including width and height.
362 * @return An structure type variable to hold widget's size.
363 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
364 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
367 DbWidgetSize getPreferredSize() const;
370 * This method returns the type of the widget.
373 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
374 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
377 WidgetType getWidgetType() const;
380 * This method returns the id of the widget.
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
387 WidgetGUID getGUID() const;
391 * This method returns the App id of the widget.
394 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
395 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
397 DPL::OptionalString getTizenAppId() const;
400 * This method returns the defaultlocale for the widget.
402 * @return defaultlocale
403 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
404 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
407 DPL::OptionalString getDefaultlocale() const;
410 * This method returns list of localized icons files;
412 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
413 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
416 WidgetLocalizedIconList getLocalizedIconList() const;
419 * This method returns list of icons files;
421 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
422 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
425 WidgetIconList getIconList() const;
428 * This method returns list of localized start files;
430 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
431 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
434 LocalizedStartFileList getLocalizedStartFileList() const;
437 * This method returns list of start files;
439 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
440 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
443 WidgetStartFileList getStartFileList() const;
446 * @param[out] outAccessInfoList list filled with access info structures
448 void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
452 * @return recognized status
454 bool isRecognized() const;
460 bool isWacSigned() const;
466 bool isDistributorSigned() const;
470 * @return trusted status
472 bool isTrusted() const;
476 * @return is WAC test widget
478 bool isTestWidget() const;
481 * This method returns window mode of widget.
483 * @return window modes of widget
484 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
485 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
488 WindowModeList getWindowModes() const;
491 * This method returns the version of the widget.
493 * @return version of widget
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
498 DPL::OptionalString getVersion() const;
501 * This method is used as a getter for csp policy of widget. It should be
502 * provided in configuration file.
503 * @return global csp policy for widget
505 DPL::OptionalString getCspPolicy() const;
508 * This method returns list filed with Common Name entries from certificate.
510 * @return Common Name of Distribuotor End Entity certificate.
511 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
512 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
515 WidgetCertificateCNList getKeyCommonNameList(
516 WidgetCertificateData::Owner owner,
517 WidgetCertificateData::Type type) const;
520 * given a certificate owner (author / distributor) and type of certificate
522 * function returns list of matching fingerprints
524 FingerPrintList getKeyFingerprints(
525 WidgetCertificateData::Owner owner,
526 WidgetCertificateData::Type type) const;
529 * This method gets certificate data list for a widget from database.
531 WidgetCertificateDataList getCertificateDataList() const;
534 * This method returns a list of widget features.
537 * @see FreeFeatureList()
538 * @return list of widget features, type of list element is structure
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
544 DbWidgetFeatureSet getFeaturesList() const;
546 static WidgetParamMap getFeatureParams(int widgetFeatureId);
548 * This method checks whether widget has specified feature.
550 * @return true if has, false if has not
551 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
553 bool hasFeature(const std::string& featureName) const;
556 * This method gets host list that widget can connect to.
558 * @return See above comment
559 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
561 HostList getAccessHostList() const;
564 * This method gets widget's access on network: true or false.
566 * @return true: widget can access network; false: widget can not access
568 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
569 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
572 bool getAccessNetworkMode() const;
575 * This method gets if widget needs webkit plugins enabled
577 * @return true: widget needs webkit plugins enabled
578 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
579 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
582 bool getWebkitPluginsRequired() const;
585 * This method returns a list of all the installed widgets' app id.
587 * @return list of installed widgets' app id.
588 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
589 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
592 static DbWidgetHandleList getHandleList();
595 * This method returns list of pkgname of installed packages
596 * @return list of pkgname of installed packages
598 static TizenAppIdList getTizenAppidList();
599 static WidgetPkgNameList getPkgnameList();
602 * This method returns a list of all the installed widgets.
604 * @return list of installed widgets.
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
609 static DbWidgetDAOReadOnlyList getWidgetList();
612 * This method removes a widget's information from EmDB.
614 * @see RegisterWidget()
615 * @param[in] widgetHandle widget's app id
616 * @return true if succeed, false if fail.
618 static void unregisterWidget(DbWidgetHandle widgetHandle);
621 * This method gets author's infomation of a widget which is parsed from
622 * configiration document.
624 * @see WidgetAuthorInfo
625 * @param[out] pAuthorInfo
626 * @return true if succeed, false if fail.
628 WidgetAuthorInfo getAuthorInfo() const;
631 * This method gets author's name of a widget which is parsed from
632 * configiration document.
634 * @param[out] pAuthorInfo
635 * @return author's name.
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
640 DPL::OptionalString getAuthorName() const;
643 * This method gets author's email of a widget which is parsed from
644 * configiration document.
646 * @param[out] pAuthorInfo
647 * @return author's email.
648 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
649 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
652 DPL::OptionalString getAuthorEmail() const;
655 * This method gets author's email of a widget which is parsed from
656 * configiration document.
658 * @param[out] pAuthorInfo
659 * @return author's email.
660 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
661 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
664 DPL::OptionalString getAuthorHref() const;
667 * This method returns minimum version of WAC that WRT has to be compliant
668 * to to run this widget
670 * @return Minimum version
671 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
672 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
675 DPL::OptionalString getMinimumWacVersion() const;
677 /* This method get widget' share href.
679 * @return widget's share href
681 std::string getShareHref() const;
684 * This method get widget installed time
686 * @return time_t : return widget's install time
688 time_t getInstallTime() const;
691 * This method gets widget base folder.
693 * @return widget base folder.
694 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
695 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
698 std::string getBaseFolder() const;
700 /* This method gets the parameter list for resource.
702 ResourceAttributeList getResourceAttribute(
703 const std::string &resourceId) const;
705 /* This method checks read only flag for given property
707 DPL::OptionalInt checkPropertyReadFlag(
708 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
710 /* This method gets widget property key list
712 PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
714 /* This method gets widget property list
716 PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
718 /* This method get widget property value
720 PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
721 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
723 LanguageTagList getLanguageTags() const;
724 LanguageTagList getIconLanguageTags() const;
728 WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
729 std::string getCookieDatabasePath() const;
731 std::string getPrivateLocalStoragePath() const;
733 bool getBackSupported() const;
735 static bool isWidgetInstalled(DbWidgetHandle handle);
736 static bool isWidgetInstalled(const TizenAppId & tzAppId);
738 /* This method get path of the splash image.
740 * @return path of the widget's splash image
742 DPL::OptionalString getSplashImgSrc() const;
744 ExternalLocationList getWidgetExternalLocations() const;
747 * Default value is required to keep compatibility with
748 * wrt-installer and wrt.
750 CertificateChainList getWidgetCertificate(
751 CertificateSource source = SIGNATURE_DISTRIBUTOR) const;
753 void getWidgetSettings(WidgetSettings& outWidgetSettings) const;
756 * This method gets application service list that define AUL value
758 * @return See above comment
759 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
761 void getAppServiceList(
762 WidgetApplicationServiceList& outAppServiceList) const;
765 * This method returns the type of the package.
767 * @return PackagingType
768 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
769 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
772 PackagingType getPackagingType() const;
774 void getEncryptedFileList(EncryptedFileList& filesList) const;
777 * This method returns widget's background page filename.
779 * @return Name of file containing background page
781 DPL::OptionalString getBackgroundPage() const;
784 * @brief generateTizenId generates new package id
786 * If widget do not supplies it's own tizen package id, this method can be used,
787 * although it should be removed in future.
789 * @return new tizen package id
791 static TizenPkgId generatePkgId();
792 static TizenPkgId generateTizenId() {
793 return generatePkgId();
797 * @brief This method return each value for security setting
799 * @return SettingsType
800 * SETTINGS_TYPE_UNKNOWN : unknow value
801 * SETTINGS_TYPE_ON : enable
802 * SETTINGS_TYPE_ALWAYS_ASK : ask by popup
803 * SETTINGS_TYPE_OFF : disable
805 SettingsType getSecurityPopupUsage() const;
806 SettingsType getGeolocationUsage() const;
807 SettingsType getWebNotificationUsage() const;
808 SettingsType getWebDatabaseUsage() const;
809 SettingsType getFileSystemUsage() const;
812 * This method returns widget's installed path
814 * @return path of widget installed
816 DPL::OptionalString getWidgetInstalledPath() const;
819 * This method returns tizen package id
821 * @return tizen package id
823 TizenPkgId getTizenPkgId() const;
828 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_