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 WidgetType type; // TODO : This type will be removed.
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;
177 DPL::OptionalString pkgname;
178 WidgetPkgName pkgName;
182 time_t installedTime;
183 PackagingType packagingType;
184 EncryptedFileList encryptedFiles;
185 ExternalLocationList externalLocations;
186 DPL::OptionalString widgetInstalledPath;
189 typedef std::list<std::string> CertificateChainList;
193 virtual ~IWacSecurity();
195 virtual const WidgetCertificateDataList& getCertificateList() const = 0;
197 virtual bool isRecognized() const = 0;
199 virtual bool isDistributorSigned() const = 0;
201 virtual bool isWacSigned() const = 0;
203 virtual void getCertificateChainList(CertificateChainList& list,
204 CertificateSource source) const = 0;
209 * Structure to hold the information of widget's author.
211 struct WidgetAuthorInfo
213 DPL::OptionalString name;
214 DPL::OptionalString email;
215 DPL::OptionalString href;
219 * Widget update policy
221 enum WidgetUpdatePolicy
223 WIDGET_UPDATE_MONTHLY = 0, //< monthly update
224 WIDGET_UPDATE_WEEKLY, //< weekly update
225 WIDGET_UPDATE_DAILY, //< daily update
226 WIDGET_UPDATE_STARTUP, //< update when cell phone boots
227 WIDGET_UPDATE_NEVER //< never update
230 typedef std::list <std::string> WidgetCertificateCNList;
231 typedef std::list<DPL::String> LanguageTagList;
232 typedef std::list<std::string> HostList;
233 typedef std::list<std::string> FingerPrintList;
234 typedef std::list<std::string> ResourceAttributeList;
236 class WidgetDAOReadOnly
240 * WidgetDAO Exception classes
245 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
246 DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
247 DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty)
248 DECLARE_EXCEPTION_TYPE(Base, GUIDisNull)
249 DECLARE_EXCEPTION_TYPE(Base, UnexpectedEmptyResult)
250 DECLARE_EXCEPTION_TYPE(Base, WidgetNotExist)
251 DECLARE_EXCEPTION_TYPE(Base, AlreadyRegistered)
255 DbWidgetHandle m_widgetHandle;
258 struct WidgetLocalizedIconRow
262 DPL::String widgetLocale;
264 typedef std::list<WidgetLocalizedIconRow> WidgetLocalizedIconList;
271 DPL::OptionalInt iconWidth;
272 DPL::OptionalInt iconHeight;
274 typedef std::list<WidgetIconRow> WidgetIconList;
276 struct WidgetStartFileRow
282 typedef std::list<WidgetStartFileRow> WidgetStartFileList;
284 struct WidgetLocalizedStartFileRow
288 DPL::String widgetLocale;
290 DPL::String encoding;
292 typedef std::list<WidgetLocalizedStartFileRow> LocalizedStartFileList;
295 * This is a constructor.
297 * @param[in] widgetHandle application id of widget.
299 WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
300 WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
301 WidgetDAOReadOnly(DPL::String tzAppid);
306 virtual ~WidgetDAOReadOnly();
309 * This method returns widget handle(m_widgetHandle).
311 * @return widget handle(m_widgetHandle).
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
316 DbWidgetHandle getHandle() const;
317 static DbWidgetHandle getHandle(const WidgetGUID GUID);
318 static DbWidgetHandle getHandle(const DPL::String pkgName);
321 * Returns tizenAppId for the specified widget
324 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
325 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
329 TizenAppId getTzAppId() const;
330 static TizenAppId getTzAppId(const WidgetGUID GUID);
331 static TizenAppId getTzAppId(const DbWidgetHandle handle);
332 static TizenAppId getTzAppId(const TizenPkgId tzPkgid);
335 * Returns WidgetPkgName for the specified widget
338 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
339 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
343 WidgetPkgName getPkgName() const;
344 static WidgetPkgName getPkgName(const WidgetGUID GUID);
345 static WidgetPkgName getPkgName(const DbWidgetHandle handle);
348 * This method returns the root directory of widget resource.
350 * @return path name of root directory.
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 DPL::String getPath() const;
357 DPL::String getFullPath() const;
360 * This method returns the preferred size of the widget,
361 * including width and height.
364 * @return An structure type variable to hold widget's size.
365 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
366 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
369 DbWidgetSize getPreferredSize() const;
372 * This method returns the type of the widget.
375 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
376 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
377 * records in DB table.
379 WidgetType getWidgetType() const;
382 * This method returns the id of the widget.
385 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
386 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
389 WidgetGUID getGUID() const;
392 * This method returns the App id of the widget.
395 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
396 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
399 DPL::OptionalString getTizenAppId() const;
402 * This method returns the defaultlocale for the widget.
404 * @return defaultlocale
405 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
406 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
409 DPL::OptionalString getDefaultlocale() const;
412 * This method returns list of localized icons files;
414 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
415 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
418 WidgetLocalizedIconList getLocalizedIconList() const;
421 * This method returns list of icons files;
423 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
424 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
427 WidgetIconList getIconList() const;
430 * This method returns list of localized start files;
432 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
433 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
436 LocalizedStartFileList getLocalizedStartFileList() const;
439 * This method returns list of start files;
441 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
442 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
445 WidgetStartFileList getStartFileList() const;
448 * @param[out] outAccessInfoList list filled with access info structures
450 void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
454 * @return recognized status
456 bool isRecognized() const;
462 bool isWacSigned() const;
468 bool isDistributorSigned() const;
472 * @return trusted status
474 bool isTrusted() const;
478 * @return is WAC test widget
480 bool isTestWidget() const;
483 * This method returns window mode of widget.
485 * @return window modes of widget
486 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
487 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
490 WindowModeList getWindowModes() const;
493 * This method returns the version of the widget.
495 * @return version of widget
496 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
497 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
500 DPL::OptionalString getVersion() const;
503 * This method is used as a getter for csp policy of widget. It should be
504 * provided in configuration file.
505 * @return global csp policy for widget
507 DPL::OptionalString getCspPolicy() const;
510 * This method returns list filed with Common Name entries from certificate.
512 * @return Common Name of Distribuotor End Entity certificate.
513 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
514 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
517 WidgetCertificateCNList getKeyCommonNameList(
518 WidgetCertificateData::Owner owner,
519 WidgetCertificateData::Type type) const;
522 * given a certificate owner (author / distributor) and type of certificate
524 * function returns list of matching fingerprints
526 FingerPrintList getKeyFingerprints(
527 WidgetCertificateData::Owner owner,
528 WidgetCertificateData::Type type) const;
531 * This method gets certificate data list for a widget from database.
533 WidgetCertificateDataList getCertificateDataList() const;
536 * This method returns a list of widget features.
539 * @see FreeFeatureList()
540 * @return list of widget features, type of list element is structure
542 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
543 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
546 DbWidgetFeatureSet getFeaturesList() const;
548 static WidgetParamMap getFeatureParams(int widgetFeatureId);
550 * This method checks whether widget has specified feature.
552 * @return true if has, false if has not
553 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
555 bool hasFeature(const std::string& featureName) const;
558 * This method gets host list that widget can connect to.
560 * @return See above comment
561 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
563 HostList getAccessHostList() const;
566 * This method gets widget's access on network: true or false.
568 * @return true: widget can access network; false: widget can not access
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
574 bool getAccessNetworkMode() const;
577 * This method gets if widget needs webkit plugins enabled
579 * @return true: widget needs webkit plugins enabled
580 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
581 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
584 bool getWebkitPluginsRequired() const;
587 * This method returns a list of all the installed widgets' app id.
589 * @return list of installed widgets' app id.
590 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
591 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
594 static DbWidgetHandleList getHandleList();
597 * This method returns list of pkgname of installed packages
598 * @return list of pkgname of installed packages
600 static TizenAppIdList getTizenAppidList();
601 static WidgetPkgNameList getPkgnameList();
604 * This method returns a list of all the installed widgets.
606 * @return list of installed widgets.
607 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
608 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
611 static DbWidgetDAOReadOnlyList getWidgetList();
614 * This method removes a widget's information from EmDB.
616 * @see RegisterWidget()
617 * @param[in] widgetHandle widget's app id
618 * @return true if succeed, false if fail.
620 static void unregisterWidget(DbWidgetHandle widgetHandle);
623 * This method gets author's infomation of a widget which is parsed from
624 * configiration document.
626 * @see WidgetAuthorInfo
627 * @param[out] pAuthorInfo
628 * @return true if succeed, false if fail.
630 WidgetAuthorInfo getAuthorInfo() const;
633 * This method gets author's name of a widget which is parsed from
634 * configiration document.
636 * @param[out] pAuthorInfo
637 * @return author's name.
638 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
639 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
642 DPL::OptionalString getAuthorName() const;
645 * This method gets author's email of a widget which is parsed from
646 * configiration document.
648 * @param[out] pAuthorInfo
649 * @return author's email.
650 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
651 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
654 DPL::OptionalString getAuthorEmail() const;
657 * This method gets author's email of a widget which is parsed from
658 * configiration document.
660 * @param[out] pAuthorInfo
661 * @return author's email.
662 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
663 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
666 DPL::OptionalString getAuthorHref() const;
669 * This method returns minimum version of WAC that WRT has to be compliant
670 * to to run this widget
672 * @return Minimum version
673 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
674 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
677 DPL::OptionalString getMinimumWacVersion() const;
679 /* This method get widget' share href.
681 * @return widget's share href
683 std::string getShareHref() const;
686 * This method get widget installed time
688 * @return time_t : return widget's install time
690 time_t getInstallTime() const;
693 * This method gets widget base folder.
695 * @return widget base folder.
696 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
697 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
700 std::string getBaseFolder() const;
702 /* This method gets the parameter list for resource.
704 ResourceAttributeList getResourceAttribute(
705 const std::string &resourceId) const;
707 /* This method checks read only flag for given property
709 DPL::OptionalInt checkPropertyReadFlag(
710 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
712 /* This method gets widget property key list
714 PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
716 /* This method gets widget property list
718 PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
720 /* This method get widget property value
722 PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
723 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
725 LanguageTagList getLanguageTags() const;
726 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
770 * records in DB table.
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
788 * although it should be removed in future.
790 * @return new tizen package id
792 static TizenPkgId generatePkgId();
793 static TizenPkgId generateTizenId()
795 return generatePkgId();
799 * @brief This method return each value for security setting
801 * @return SettingsType
802 * SETTINGS_TYPE_UNKNOWN : unknow value
803 * SETTINGS_TYPE_ON : enable
804 * SETTINGS_TYPE_ALWAYS_ASK : ask by popup
805 * SETTINGS_TYPE_OFF : disable
807 SettingsType getSecurityPopupUsage() const;
808 SettingsType getGeolocationUsage() const;
809 SettingsType getWebNotificationUsage() const;
810 SettingsType getWebDatabaseUsage() const;
811 SettingsType getFileSystemUsage() const;
814 * This method returns widget's installed path
816 * @return path of widget installed
818 DPL::OptionalString getWidgetInstalledPath() const;
821 * This method returns tizen package id
823 * @return tizen package id
825 TizenPkgId getTizenPkgId() const;
829 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_