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),
161 packagingType(PKG_TYPE_UNKNOWN)
164 WidgetType webAppType;
165 DPL::OptionalString guid;
166 DPL::OptionalString version;
167 DPL::OptionalString minVersion;
168 std::string shareHref;
169 std::string baseFolder;
170 WidgetSignatureType signatureType;
171 ConfigParserData configInfo;
172 LocalizationData localizationData;
177 time_t installedTime;
178 PackagingType packagingType;
179 EncryptedFileList encryptedFiles;
180 ExternalLocationList externalLocations;
181 DPL::OptionalString widgetInstalledPath;
184 typedef std::list<std::string> CertificateChainList;
185 class IWidgetSecurity
188 virtual ~IWidgetSecurity();
190 virtual const WidgetCertificateDataList& getCertificateList() const = 0;
192 virtual bool isRecognized() const = 0;
194 virtual bool isDistributorSigned() 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;
229 class WidgetDAOReadOnly
233 * WidgetDAO Exception classes
238 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
239 DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
240 DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty)
241 DECLARE_EXCEPTION_TYPE(Base, GUIDisNull)
242 DECLARE_EXCEPTION_TYPE(Base, UnexpectedEmptyResult)
243 DECLARE_EXCEPTION_TYPE(Base, WidgetNotExist)
244 DECLARE_EXCEPTION_TYPE(Base, AlreadyRegistered)
248 DbWidgetHandle m_widgetHandle;
251 struct WidgetLocalizedIconRow
255 DPL::String widgetLocale;
257 typedef std::list<WidgetLocalizedIconRow> WidgetLocalizedIconList;
264 DPL::OptionalInt iconWidth;
265 DPL::OptionalInt iconHeight;
267 typedef std::list<WidgetIconRow> WidgetIconList;
269 struct WidgetStartFileRow
275 typedef std::list<WidgetStartFileRow> WidgetStartFileList;
277 struct WidgetLocalizedStartFileRow
281 DPL::String widgetLocale;
283 DPL::String encoding;
285 typedef std::list<WidgetLocalizedStartFileRow> LocalizedStartFileList;
288 * This is a constructor.
290 * @param[in] widgetHandle application id of widget.
292 WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
293 WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
294 WidgetDAOReadOnly(WrtDB::TizenAppId tzAppid);
299 virtual ~WidgetDAOReadOnly();
302 * This method returns widget handle(m_widgetHandle).
304 * @return widget handle(m_widgetHandle).
305 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
306 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
309 DbWidgetHandle getHandle() const;
310 static DbWidgetHandle getHandle(const WidgetGUID GUID);
311 static DbWidgetHandle getHandle(const DPL::String pkgName);
314 * Returns tizenAppId for the specified widget
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
322 TizenAppId getTzAppId() const;
323 static TizenAppId getTzAppId(const WidgetGUID GUID);
324 static TizenAppId getTzAppId(const DbWidgetHandle handle);
325 static TizenAppId getTzAppId(const TizenPkgId tzPkgid);
328 * Returns TizenPkgId for the specified widget
330 * @return TizenPkgId;
331 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
332 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
336 TizenPkgId getTzPkgId() const;
339 * This method returns the root directory of widget resource.
341 * @return path name of root directory.
342 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
343 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
346 virtual DPL::String getPath() const;
348 DPL::String getFullPath() const;
351 * This method returns the preferred size of the widget,
352 * including width and height.
355 * @return An structure type variable to hold widget's size.
356 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
357 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
360 DbWidgetSize getPreferredSize() const;
363 * This method returns the type of the widget.
366 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
367 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
368 * records in DB table.
370 WidgetType getWidgetType() const;
373 * This method returns the id of the widget.
376 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
377 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
380 WidgetGUID getGUID() const;
383 * This method returns the App id of the widget.
386 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
387 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
390 DPL::OptionalString getTizenAppId() const;
393 * This method returns the defaultlocale for the widget.
395 * @return defaultlocale
396 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
397 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
400 DPL::OptionalString getDefaultlocale() const;
403 * This method returns list of localized icons files;
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 WidgetLocalizedIconList getLocalizedIconList() const;
412 * This method returns list of 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 WidgetIconList getIconList() const;
421 * This method returns list of localized start 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 LocalizedStartFileList getLocalizedStartFileList() const;
430 * This method returns list of 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 WidgetStartFileList getStartFileList() const;
439 * @param[out] outAccessInfoList list filled with access info structures
441 void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
442 void getWidgetAllowNavigationInfo(
443 WidgetAllowNavigationInfoList& allowNavigationInfoList) const;
447 * @return recognized status
449 bool isRecognized() const;
455 bool isDistributorSigned() const;
459 * @return trusted status
461 bool isTrusted() const;
464 * This method returns window mode of widget.
466 * @return window modes of widget
467 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
468 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
471 WindowModeList getWindowModes() const;
474 * This method returns the version of the widget.
476 * @return version of widget
477 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
478 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
481 DPL::OptionalString getVersion() const;
484 * This method is used as a getter for csp policy of widget. It should be
485 * provided in configuration file.
486 * @return global csp policy for widget
488 DPL::OptionalString getCspPolicy() const;
491 * This method is used as a getter for report only csp policy of widget.
492 * It may be provided in configuration file.
493 * @return global csp report only policy for widget
495 DPL::OptionalString getCspPolicyReportOnly() const;
498 * This method returns list filed with Common Name entries from certificate.
500 * @return Common Name of Distribuotor End Entity certificate.
501 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
502 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
505 WidgetCertificateCNList getKeyCommonNameList(
506 WidgetCertificateData::Owner owner,
507 WidgetCertificateData::Type type) const;
510 * given a certificate owner (author / distributor) and type of certificate
512 * function returns list of matching fingerprints
514 FingerPrintList getKeyFingerprints(
515 WidgetCertificateData::Owner owner,
516 WidgetCertificateData::Type type) const;
519 * This method gets certificate data list for a widget from database.
521 WidgetCertificateDataList getCertificateDataList() const;
524 * This method returns a list of widget features.
527 * @see FreeFeatureList()
528 * @return list of widget features, type of list element is structure
530 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
531 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
534 DbWidgetFeatureSet getFeaturesList() const;
537 * This method checks whether widget has specified feature.
539 * @return true if has, false if has not
540 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
542 bool hasFeature(const std::string& featureName) const;
545 * This method gets host list that widget can connect to.
547 * @return See above comment
548 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
550 HostList getAccessHostList() const;
553 * This method gets widget's access on network: true or false.
555 * @return true: widget can access network; false: widget can not access
557 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
558 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
561 bool getAccessNetworkMode() const;
564 * This method gets if widget needs webkit plugins enabled
566 * @return true: widget needs webkit plugins enabled
567 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
568 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
571 bool getWebkitPluginsRequired() const;
574 * This method returns a list of all the installed widgets' app id.
576 * @return list of installed widgets' app id.
577 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
578 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
581 static DbWidgetHandleList getHandleList();
584 * This method returns list of tizen application list of installed packages
585 * @return list of TizenAppIdList of installed packages
587 static TizenAppIdList getTizenAppidList();
590 * This method returns list of tizen package list of installed packages
591 * @return list of TizenPkgIdList of installed packages
593 static TizenPkgIdList getTizenPkgidList();
596 * This method returns a list of all the installed widgets.
598 * @return list of installed widgets.
599 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
600 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
603 static DbWidgetDAOReadOnlyList getWidgetList();
606 * This method removes a widget's information from EmDB.
608 * @see RegisterWidget()
609 * @param[in] widgetHandle widget's app id
610 * @return true if succeed, false if fail.
612 static void unregisterWidget(DbWidgetHandle widgetHandle);
615 * This method gets author's infomation of a widget which is parsed from
616 * configiration document.
618 * @see WidgetAuthorInfo
619 * @param[out] pAuthorInfo
620 * @return true if succeed, false if fail.
622 WidgetAuthorInfo getAuthorInfo() const;
625 * This method gets author's name of a widget which is parsed from
626 * configiration document.
628 * @param[out] pAuthorInfo
629 * @return author's name.
630 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
631 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
634 DPL::OptionalString getAuthorName() const;
637 * This method gets author's email of a widget which is parsed from
638 * configiration document.
640 * @param[out] pAuthorInfo
641 * @return author's email.
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 getAuthorEmail() 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 getAuthorHref() const;
661 * This method returns minimum version of WAC that WRT has to be compliant
662 * to to run this widget
664 * @return Minimum version
665 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
666 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
669 DPL::OptionalString getMinimumWacVersion() const;
671 /* This method get widget' share href.
673 * @return widget's share href
675 std::string getShareHref() const;
678 * This method get widget installed time
680 * @return time_t : return widget's install time
682 time_t getInstallTime() const;
685 * This method gets widget base folder.
687 * @return widget base folder.
688 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
689 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
692 std::string getBaseFolder() const;
694 /* This method checks read only flag for given property
696 DPL::OptionalInt checkPropertyReadFlag(
697 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
699 /* This method gets widget property key list
701 PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
703 /* This method gets widget property list
705 PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
707 /* This method get widget property value
709 PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
710 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
712 LanguageTagList getLanguageTags() const;
713 LanguageTagList getIconLanguageTags() const;
715 WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
716 std::string getCookieDatabasePath() const;
718 std::string getPrivateLocalStoragePath() const;
720 bool getBackSupported() const;
722 static bool isWidgetInstalled(DbWidgetHandle handle);
723 static bool isWidgetInstalled(const TizenAppId & tzAppId);
725 /* This method get path of the splash image.
727 * @return path of the widget's splash image
729 DPL::OptionalString getSplashImgSrc() const;
731 ExternalLocationList getWidgetExternalLocations() const;
734 * Default value is required to keep compatibility with
735 * wrt-installer and wrt.
737 CertificateChainList getWidgetCertificate(
738 CertificateSource source = SIGNATURE_DISTRIBUTOR) const;
740 void getWidgetSettings(WidgetSettings& outWidgetSettings) const;
743 * This method gets application control list that define AUL value
745 * @return See above comment
746 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
748 void getAppControlList(
749 WidgetAppControlList& outAppControlList) const;
752 * This method returns the type of the package.
754 * @return PackagingType
755 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
756 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
757 * records in DB table.
759 PackagingType getPackagingType() const;
761 void getEncryptedFileList(EncryptedFileList& filesList) const;
764 * This method returns widget's background page filename.
766 * @return Name of file containing background page
768 DPL::OptionalString getBackgroundPage() const;
771 * @brief generateTizenId generates new package id
773 * If widget do not supplies it's own tizen package id, this method can be
775 * although it should be removed in future.
777 * @return new tizen package id
779 static TizenPkgId generatePkgId();
780 static TizenPkgId generateTizenId()
782 return generatePkgId();
786 * @brief This method return each value for security setting
788 * @return SettingsType
789 * SETTINGS_TYPE_UNKNOWN : unknow value
790 * SETTINGS_TYPE_ON : enable
791 * SETTINGS_TYPE_ALWAYS_ASK : ask by popup
792 * SETTINGS_TYPE_OFF : disable
794 SettingsType getSecurityPopupUsage() const;
795 SettingsType getGeolocationUsage() const;
796 SettingsType getWebNotificationUsage() const;
797 SettingsType getWebDatabaseUsage() const;
800 * This method returns widget's installed path
802 * @return path of widget installed
804 DPL::OptionalString getWidgetInstalledPath() const;
807 * This method returns tizen package id
809 * @return tizen package id
811 TizenPkgId getTizenPkgId() const;
812 PrivilegeList getWidgetPrivilege() const;
813 WidgetSecurityModelVersion getSecurityModelVersion() const;
818 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_