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>
43 * Widget's signature enum.
44 * This enumerates signature type of widget.
46 enum WidgetSignatureType
48 SIGNATURE_TYPE_CARRIER = 0,
49 SIGNATURE_TYPE_IDENTIFIED,
50 SIGNATURE_TYPE_UNIDENTIFIED
53 enum CertificateSource {
54 SIGNATURE_DISTRIBUTOR = 0,
58 typedef std::list<DPL::String> StringList;
60 struct WidgetLocalizedInfo
62 DPL::OptionalString name;
63 DPL::OptionalString shortName;
64 DPL::OptionalString description;
65 DPL::OptionalString license;
66 DPL::OptionalString licenseHref;
71 * A structure to hold certificate fingerprints.
73 struct WidgetCertificateData
75 enum Owner { AUTHOR, DISTRIBUTOR, UNKNOWN };
76 enum Type { ROOT, ENDENTITY };
78 // type of signature: author/distributor
80 // indicates whether this is ca certificate
83 // chain id number: relative BASE, where BASE is signatureBASE.xml
85 // certificate fingerprint digested by md5
86 std::string strMD5Fingerprint;
87 // certificate fingerprint digestef by sha1
88 std::string strSHA1Fingerprint;
89 // Common name field in certificate
90 DPL::String strCommonName;
92 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)
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 webAppType(APP_TYPE_UNKNOWN),
159 signatureType(SIGNATURE_TYPE_UNIDENTIFIED),
162 packagingType(PKG_TYPE_UNKNOWN)
165 WidgetType webAppType;
166 DPL::OptionalString guid;
167 DPL::OptionalString version;
168 DPL::OptionalString minVersion;
169 std::string shareHref;
170 std::string baseFolder;
171 WidgetSignatureType signatureType;
173 ConfigParserData configInfo;
174 LocalizationData localizationData;
179 time_t installedTime;
180 PackagingType packagingType;
181 EncryptedFileList encryptedFiles;
182 ExternalLocationList externalLocations;
183 DPL::OptionalString widgetInstalledPath;
186 typedef std::list<std::string> CertificateChainList;
190 virtual ~IWacSecurity();
192 virtual const WidgetCertificateDataList& getCertificateList() const = 0;
194 virtual bool isRecognized() const = 0;
196 virtual bool isDistributorSigned() const = 0;
198 virtual bool isWacSigned() const = 0;
200 virtual void getCertificateChainList(CertificateChainList& list,
201 CertificateSource source) const = 0;
206 * Structure to hold the information of widget's author.
208 struct WidgetAuthorInfo
210 DPL::OptionalString name;
211 DPL::OptionalString email;
212 DPL::OptionalString href;
216 * Widget update policy
218 enum WidgetUpdatePolicy
220 WIDGET_UPDATE_MONTHLY = 0, //< monthly update
221 WIDGET_UPDATE_WEEKLY, //< weekly update
222 WIDGET_UPDATE_DAILY, //< daily update
223 WIDGET_UPDATE_STARTUP, //< update when cell phone boots
224 WIDGET_UPDATE_NEVER //< never update
227 typedef std::list <std::string> WidgetCertificateCNList;
228 typedef std::list<DPL::String> LanguageTagList;
229 typedef std::list<std::string> HostList;
230 typedef std::list<std::string> FingerPrintList;
231 typedef std::list<std::string> ResourceAttributeList;
233 class WidgetDAOReadOnly
237 * WidgetDAO Exception classes
242 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
243 DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
244 DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty)
245 DECLARE_EXCEPTION_TYPE(Base, GUIDisNull)
246 DECLARE_EXCEPTION_TYPE(Base, UnexpectedEmptyResult)
247 DECLARE_EXCEPTION_TYPE(Base, WidgetNotExist)
248 DECLARE_EXCEPTION_TYPE(Base, AlreadyRegistered)
252 DbWidgetHandle m_widgetHandle;
255 struct WidgetLocalizedIconRow
259 DPL::String widgetLocale;
261 typedef std::list<WidgetLocalizedIconRow> WidgetLocalizedIconList;
268 DPL::OptionalInt iconWidth;
269 DPL::OptionalInt iconHeight;
271 typedef std::list<WidgetIconRow> WidgetIconList;
273 struct WidgetStartFileRow
279 typedef std::list<WidgetStartFileRow> WidgetStartFileList;
281 struct WidgetLocalizedStartFileRow
285 DPL::String widgetLocale;
287 DPL::String encoding;
289 typedef std::list<WidgetLocalizedStartFileRow> LocalizedStartFileList;
292 * This is a constructor.
294 * @param[in] widgetHandle application id of widget.
296 WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
297 WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
298 WidgetDAOReadOnly(DPL::String tzAppid);
303 virtual ~WidgetDAOReadOnly();
306 * This method returns widget handle(m_widgetHandle).
308 * @return widget handle(m_widgetHandle).
309 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
310 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
313 DbWidgetHandle getHandle() const;
314 static DbWidgetHandle getHandle(const WidgetGUID GUID);
315 static DbWidgetHandle getHandle(const DPL::String pkgName);
318 * Returns tizenAppId for the specified widget
321 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
322 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
326 TizenAppId getTzAppId() const;
327 static TizenAppId getTzAppId(const WidgetGUID GUID);
328 static TizenAppId getTzAppId(const DbWidgetHandle handle);
329 static TizenAppId getTzAppId(const TizenPkgId tzPkgid);
332 * Returns WidgetPkgName for the specified widget
335 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
336 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
340 WidgetPkgName getPkgName() const;
341 static WidgetPkgName getPkgName(const WidgetGUID GUID);
342 static WidgetPkgName getPkgName(const DbWidgetHandle handle);
345 * This method returns the root directory of widget resource.
347 * @return path name of root directory.
348 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
349 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
352 virtual DPL::String getPath() const;
354 DPL::String getFullPath() const;
357 * This method returns the preferred size of the widget,
358 * including width and height.
361 * @return An structure type variable to hold widget's size.
362 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
363 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
366 DbWidgetSize getPreferredSize() const;
369 * This method returns the type of the widget.
372 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
373 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
374 * records in DB table.
376 WidgetType getWidgetType() const;
379 * This method returns the id of the widget.
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
386 WidgetGUID getGUID() const;
389 * This method returns the App id of the widget.
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
396 DPL::OptionalString getTizenAppId() const;
399 * This method returns the defaultlocale for the widget.
401 * @return defaultlocale
402 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
403 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
406 DPL::OptionalString getDefaultlocale() const;
409 * This method returns list of localized icons files;
411 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
412 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
415 WidgetLocalizedIconList getLocalizedIconList() const;
418 * This method returns list of icons files;
420 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
421 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
424 WidgetIconList getIconList() const;
427 * This method returns list of localized start files;
429 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
430 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
433 LocalizedStartFileList getLocalizedStartFileList() const;
436 * This method returns list of start files;
438 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
439 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
442 WidgetStartFileList getStartFileList() const;
445 * @param[out] outAccessInfoList list filled with access info structures
447 void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
451 * @return recognized status
453 bool isRecognized() const;
459 bool isWacSigned() const;
465 bool isDistributorSigned() const;
469 * @return trusted status
471 bool isTrusted() const;
475 * @return is WAC test widget
477 bool isTestWidget() const;
480 * This method returns window mode of widget.
482 * @return window modes of widget
483 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
484 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
487 WindowModeList getWindowModes() const;
490 * This method returns the version of the widget.
492 * @return version of widget
493 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
494 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
497 DPL::OptionalString getVersion() const;
500 * This method is used as a getter for csp policy of widget. It should be
501 * provided in configuration file.
502 * @return global csp policy for widget
504 DPL::OptionalString getCspPolicy() const;
507 * This method is used as a getter for report only csp policy of widget.
508 * It may be provided in configuration file.
509 * @return global csp report only policy for widget
511 DPL::OptionalString getCspPolicyReportOnly() const;
514 * This method returns list filed with Common Name entries from certificate.
516 * @return Common Name of Distribuotor End Entity certificate.
517 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
518 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
521 WidgetCertificateCNList getKeyCommonNameList(
522 WidgetCertificateData::Owner owner,
523 WidgetCertificateData::Type type) const;
526 * given a certificate owner (author / distributor) and type of certificate
528 * function returns list of matching fingerprints
530 FingerPrintList getKeyFingerprints(
531 WidgetCertificateData::Owner owner,
532 WidgetCertificateData::Type type) const;
535 * This method gets certificate data list for a widget from database.
537 WidgetCertificateDataList getCertificateDataList() const;
540 * This method returns a list of widget features.
543 * @see FreeFeatureList()
544 * @return list of widget features, type of list element is structure
546 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
547 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
550 DbWidgetFeatureSet getFeaturesList() const;
552 static WidgetParamMap getFeatureParams(int widgetFeatureId);
554 * This method checks whether widget has specified feature.
556 * @return true if has, false if has not
557 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
559 bool hasFeature(const std::string& featureName) const;
562 * This method gets host list that widget can connect to.
564 * @return See above comment
565 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
567 HostList getAccessHostList() const;
570 * This method gets widget's access on network: true or false.
572 * @return true: widget can access network; false: widget can not access
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
578 bool getAccessNetworkMode() const;
581 * This method gets if widget needs webkit plugins enabled
583 * @return true: widget needs webkit plugins enabled
584 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
585 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
588 bool getWebkitPluginsRequired() const;
591 * This method returns a list of all the installed widgets' app id.
593 * @return list of installed widgets' app id.
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
598 static DbWidgetHandleList getHandleList();
601 * This method returns list of pkgname of installed packages
602 * @return list of pkgname of installed packages
604 static TizenAppIdList getTizenAppidList();
605 static WidgetPkgNameList getPkgnameList();
608 * This method returns a list of all the installed widgets.
610 * @return list of installed widgets.
611 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
612 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
615 static DbWidgetDAOReadOnlyList getWidgetList();
618 * This method removes a widget's information from EmDB.
620 * @see RegisterWidget()
621 * @param[in] widgetHandle widget's app id
622 * @return true if succeed, false if fail.
624 static void unregisterWidget(DbWidgetHandle widgetHandle);
627 * This method gets author's infomation of a widget which is parsed from
628 * configiration document.
630 * @see WidgetAuthorInfo
631 * @param[out] pAuthorInfo
632 * @return true if succeed, false if fail.
634 WidgetAuthorInfo getAuthorInfo() const;
637 * This method gets author's name of a widget which is parsed from
638 * configiration document.
640 * @param[out] pAuthorInfo
641 * @return author's name.
642 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
643 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
646 DPL::OptionalString getAuthorName() const;
649 * This method gets author's email of a widget which is parsed from
650 * configiration document.
652 * @param[out] pAuthorInfo
653 * @return author's email.
654 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
655 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
658 DPL::OptionalString getAuthorEmail() const;
661 * This method gets author's email of a widget which is parsed from
662 * configiration document.
664 * @param[out] pAuthorInfo
665 * @return author's email.
666 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
667 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
670 DPL::OptionalString getAuthorHref() const;
673 * This method returns minimum version of WAC that WRT has to be compliant
674 * to to run this widget
676 * @return Minimum version
677 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
678 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
681 DPL::OptionalString getMinimumWacVersion() const;
683 /* This method get widget' share href.
685 * @return widget's share href
687 std::string getShareHref() const;
690 * This method get widget installed time
692 * @return time_t : return widget's install time
694 time_t getInstallTime() const;
697 * This method gets widget base folder.
699 * @return widget base folder.
700 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
701 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
704 std::string getBaseFolder() const;
706 /* This method gets the parameter list for resource.
708 ResourceAttributeList getResourceAttribute(
709 const std::string &resourceId) const;
711 /* This method checks read only flag for given property
713 DPL::OptionalInt checkPropertyReadFlag(
714 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
716 /* This method gets widget property key list
718 PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
720 /* This method gets widget property list
722 PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
724 /* This method get widget property value
726 PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
727 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
729 LanguageTagList getLanguageTags() const;
730 LanguageTagList getIconLanguageTags() const;
732 WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
733 std::string getCookieDatabasePath() const;
735 std::string getPrivateLocalStoragePath() const;
737 bool getBackSupported() const;
739 static bool isWidgetInstalled(DbWidgetHandle handle);
740 static bool isWidgetInstalled(const TizenAppId & tzAppId);
742 /* This method get path of the splash image.
744 * @return path of the widget's splash image
746 DPL::OptionalString getSplashImgSrc() const;
748 ExternalLocationList getWidgetExternalLocations() const;
751 * Default value is required to keep compatibility with
752 * wrt-installer and wrt.
754 CertificateChainList getWidgetCertificate(
755 CertificateSource source = SIGNATURE_DISTRIBUTOR) const;
757 void getWidgetSettings(WidgetSettings& outWidgetSettings) const;
760 * This method gets application service list that define AUL value
762 * @return See above comment
763 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
765 void getAppServiceList(
766 WidgetApplicationServiceList& outAppServiceList) const;
769 * This method returns the type of the package.
771 * @return PackagingType
772 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
773 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
774 * records in DB table.
776 PackagingType getPackagingType() const;
778 void getEncryptedFileList(EncryptedFileList& filesList) const;
781 * This method returns widget's background page filename.
783 * @return Name of file containing background page
785 DPL::OptionalString getBackgroundPage() const;
788 * @brief generateTizenId generates new package id
790 * If widget do not supplies it's own tizen package id, this method can be
792 * although it should be removed in future.
794 * @return new tizen package id
796 static TizenPkgId generatePkgId();
797 static TizenPkgId generateTizenId()
799 return generatePkgId();
803 * @brief This method return each value for security setting
805 * @return SettingsType
806 * SETTINGS_TYPE_UNKNOWN : unknow value
807 * SETTINGS_TYPE_ON : enable
808 * SETTINGS_TYPE_ALWAYS_ASK : ask by popup
809 * SETTINGS_TYPE_OFF : disable
811 SettingsType getSecurityPopupUsage() const;
812 SettingsType getGeolocationUsage() const;
813 SettingsType getWebNotificationUsage() const;
814 SettingsType getWebDatabaseUsage() const;
815 SettingsType getFileSystemUsage() const;
818 * This method returns widget's installed path
820 * @return path of widget installed
822 DPL::OptionalString getWidgetInstalledPath() const;
825 * This method returns tizen package id
827 * @return tizen package id
829 TizenPkgId getTizenPkgId() const;
833 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_