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;
178 DPL::OptionalString pkgname;
179 time_t installedTime;
180 PackagingType packagingType;
181 EncryptedFileList encryptedFiles;
182 ExternalLocationList externalLocations;
185 typedef std::list<std::string> CertificateChainList;
189 virtual ~IWacSecurity();
191 virtual const WidgetCertificateDataList& getCertificateList() const = 0;
193 virtual bool isRecognized() const = 0;
195 virtual bool isDistributorSigned() const = 0;
197 virtual bool isWacSigned() const = 0;
199 virtual void getCertificateChainList(CertificateChainList& list,
200 CertificateSource source) const = 0;
205 * Structure to hold the information of widget's author.
207 struct WidgetAuthorInfo
209 DPL::OptionalString name;
210 DPL::OptionalString email;
211 DPL::OptionalString href;
215 * Widget update policy
217 enum WidgetUpdatePolicy
219 WIDGET_UPDATE_MONTHLY = 0, //< monthly update
220 WIDGET_UPDATE_WEEKLY, //< weekly update
221 WIDGET_UPDATE_DAILY, //< daily update
222 WIDGET_UPDATE_STARTUP, //< update when cell phone boots
223 WIDGET_UPDATE_NEVER //< never update
226 typedef std::list <std::string> WidgetCertificateCNList;
227 typedef std::list<DPL::String> LanguageTagList;
228 typedef std::list<std::string> HostList;
229 typedef std::list<std::string> FingerPrintList;
230 typedef std::list<std::string> ResourceAttributeList;
232 class WidgetDAOReadOnly
236 * WidgetDAO Exception classes
241 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
242 DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
243 DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty)
244 DECLARE_EXCEPTION_TYPE(Base, GUIDisNull)
245 DECLARE_EXCEPTION_TYPE(Base, UnexpectedEmptyResult)
246 DECLARE_EXCEPTION_TYPE(Base, WidgetNotExist)
247 DECLARE_EXCEPTION_TYPE(Base, AlreadyRegistered)
251 DbWidgetHandle m_widgetHandle;
254 struct WidgetLocalizedIconRow
258 DPL::String widgetLocale;
260 typedef std::list<WidgetLocalizedIconRow> WidgetLocalizedIconList;
267 DPL::OptionalInt iconWidth;
268 DPL::OptionalInt iconHeight;
270 typedef std::list<WidgetIconRow> WidgetIconList;
272 struct WidgetStartFileRow
278 typedef std::list<WidgetStartFileRow> WidgetStartFileList;
280 struct WidgetLocalizedStartFileRow
284 DPL::String widgetLocale;
286 DPL::String encoding;
288 typedef std::list<WidgetLocalizedStartFileRow> LocalizedStartFileList;
291 * This is a constructor.
293 * @param[in] widgetHandle application id of widget.
295 WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
296 WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
297 WidgetDAOReadOnly(DPL::String pkgName);
302 virtual ~WidgetDAOReadOnly();
305 * This method returns widget handle(m_widgetHandle).
307 * @return widget handle(m_widgetHandle).
308 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
309 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
311 DbWidgetHandle getHandle() const;
312 static DbWidgetHandle getHandle(const WidgetGUID GUID);
313 static DbWidgetHandle getHandle(const DPL::String pkgName);
316 * This method returns the root directory of widget resource.
318 * @return path name of root directory.
319 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
320 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
323 DPL::String getPath() const;
325 DPL::String getFullPath() const;
328 * This method returns the preferred size of the widget,
329 * including width and height.
332 * @return An structure type variable to hold widget's size.
333 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
334 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
337 DbWidgetSize getPreferredSize() const;
340 * This method returns the type of the widget.
343 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
344 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
347 WidgetType getWidgetType() const;
350 * This method returns the id of the widget.
353 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
354 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
357 WidgetGUID getGUID() const;
360 * This method returns the Package name of the widget.
363 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
364 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
366 DPL::OptionalString getPkgname() const;
369 * This method returns the defaultlocale for the widget.
371 * @return defaultlocale
372 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
373 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
376 DPL::OptionalString getDefaultlocale() const;
379 * This method returns list of localized icons files;
381 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
382 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
385 WidgetLocalizedIconList getLocalizedIconList() const;
388 * This method returns list of icons files;
390 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
391 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
394 WidgetIconList getIconList() const;
397 * This method returns list of localized start files;
399 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
400 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
403 LocalizedStartFileList getLocalizedStartFileList() const;
406 * This method returns list of start files;
408 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
409 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
412 WidgetStartFileList getStartFileList() const;
415 * @param[out] outAccessInfoList list filled with access info structures
417 void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
421 * @return recognized status
423 bool isRecognized() const;
429 bool isWacSigned() const;
435 bool isDistributorSigned() const;
439 * @return trusted status
441 bool isTrusted() const;
445 * @return is WAC test widget
447 bool isTestWidget() const;
450 * This method returns window mode of widget.
452 * @return window modes of widget
453 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
454 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
457 WindowModeList getWindowModes() const;
460 * This method returns the version of the widget.
462 * @return version of widget
463 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
464 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
467 DPL::OptionalString getVersion() const;
470 * This method returns list filed with Common Name entries from certificate.
472 * @return Common Name of Distribuotor End Entity certificate.
473 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
474 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
477 WidgetCertificateCNList getKeyCommonNameList(
478 WidgetCertificateData::Owner owner,
479 WidgetCertificateData::Type type) const;
482 * given a certificate owner (author / distributor) and type of certificate
484 * function returns list of matching fingerprints
486 FingerPrintList getKeyFingerprints(
487 WidgetCertificateData::Owner owner,
488 WidgetCertificateData::Type type) const;
491 * This method gets certificate data list for a widget from database.
493 WidgetCertificateDataList getCertificateDataList() const;
496 * This method returns a list of widget features.
499 * @see FreeFeatureList()
500 * @return list of widget features, type of list element is structure
502 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
503 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
506 DbWidgetFeatureSet getFeaturesList() const;
508 static WidgetParamMap getFeatureParams(int widgetFeatureId);
510 * This method checks whether widget has specified feature.
512 * @return true if has, false if has not
513 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
515 bool hasFeature(const std::string& featureName) const;
518 * This method gets host list that widget can connect to.
520 * @return See above comment
521 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
523 HostList getAccessHostList() const;
526 * This method gets widget's access on network: true or false.
528 * @return true: widget can access network; false: widget can not access
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 bool getAccessNetworkMode() const;
537 * This method gets if widget needs webkit plugins enabled
539 * @return true: widget needs webkit plugins enabled
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 bool getWebkitPluginsRequired() const;
547 * This method returns a list of all the installed widgets' app id.
549 * @return list of installed widgets' app id.
550 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
551 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
554 static DbWidgetHandleList getHandleList();
557 * This method returns list of pkgname of installed packages
558 * @return list of pkgname of installed packages
560 static WidgetPkgNameList getPkgnameList();
563 * This method returns a list of all the installed widgets.
565 * @return list of installed widgets.
566 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
567 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
570 static DbWidgetDAOReadOnlyList getWidgetList();
573 * This method removes a widget's information from EmDB.
575 * @see RegisterWidget()
576 * @param[in] widgetHandle widget's app id
577 * @return true if succeed, false if fail.
579 static void unregisterWidget(DbWidgetHandle widgetHandle);
582 * This method gets author's infomation of a widget which is parsed from
583 * configiration document.
585 * @see WidgetAuthorInfo
586 * @param[out] pAuthorInfo
587 * @return true if succeed, false if fail.
589 WidgetAuthorInfo getAuthorInfo() const;
592 * This method gets author's name of a widget which is parsed from
593 * configiration document.
595 * @param[out] pAuthorInfo
596 * @return author's name.
597 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
598 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
601 DPL::OptionalString getAuthorName() const;
604 * This method gets author's email of a widget which is parsed from
605 * configiration document.
607 * @param[out] pAuthorInfo
608 * @return author's email.
609 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
610 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
613 DPL::OptionalString getAuthorEmail() const;
616 * This method gets author's email of a widget which is parsed from
617 * configiration document.
619 * @param[out] pAuthorInfo
620 * @return author's email.
621 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
622 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
625 DPL::OptionalString getAuthorHref() const;
628 * This method returns minimum version of WAC that WRT has to be compliant
629 * to to run this widget
631 * @return Minimum version
632 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
633 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
636 DPL::OptionalString getMinimumWacVersion() const;
638 /* This method get widget' share href.
640 * @return widget's share href
642 std::string getShareHref() const;
645 * This method get widget installed time
647 * @return time_t : return widget's install time
649 time_t getInstallTime() const;
652 * This method gets widget base folder.
654 * @return widget base folder.
655 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
656 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
659 std::string getBaseFolder() const;
661 /* This method gets the parameter list for resource.
663 ResourceAttributeList getResourceAttribute(
664 const std::string &resourceId) const;
666 /* This method checks read only flag for given property
668 DPL::OptionalInt checkPropertyReadFlag(
669 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
671 /* This method gets widget property key list
673 PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
675 /* This method gets widget property list
677 PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
679 /* This method get widget property value
681 PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
682 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
684 LanguageTagList getLanguageTags() const;
685 LanguageTagList getIconLanguageTags() const;
689 WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
690 std::string getCookieDatabasePath() const;
692 std::string getPrivateLocalStoragePath() const;
694 bool getBackSupported() const;
696 static bool isWidgetInstalled(DbWidgetHandle handle);
697 static bool isWidgetInstalled(const WidgetPkgName & pkgName);
699 /* This method get path of the splash image.
701 * @return path of the widget's splash image
703 DPL::OptionalString getSplashImgSrc() const;
705 ExternalLocationList getWidgetExternalLocations() const;
708 * Default value is required to keep compatibility with
709 * wrt-installer and wrt.
711 CertificateChainList getWidgetCertificate(
712 CertificateSource source = SIGNATURE_DISTRIBUTOR) const;
714 void getWidgetSettings(WidgetSettings& outWidgetSettings) const;
717 * This method gets application service list that define AUL value
719 * @return See above comment
720 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
722 void getAppServiceList(
723 WidgetApplicationServiceList& outAppServiceList) const;
726 * This method returns the type of the package.
728 * @return PackagingType
729 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
730 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
733 PackagingType getPackagingType() const;
735 void getEncryptedFileList(EncryptedFileList& filesList) const;
738 * This method returns widget's background page filename.
740 * @return Name of file containing background page
742 DPL::OptionalString getBackgroundPage() const;
745 * @brief generateTizenId generates new tizen id
747 * If widget do not supplies it's own tizen id, this method can be used,
748 * although it should be removed in future.
750 * @return new tizen id
752 static WidgetPkgName generateTizenId();
755 * @brief This method return each value for security setting
757 * @return SettingsType
758 * SETTINGS_TYPE_UNKNOWN : unknow value
759 * SETTINGS_TYPE_ON : enable
760 * SETTINGS_TYPE_ALWAYS_ASK : ask by popup
761 * SETTINGS_TYPE_OFF : disable
763 SettingsType getSecurityPopupUsage() const;
764 SettingsType getGeolocationUsage() const;
765 SettingsType getWebNotificationUsage() const;
766 SettingsType getWebDatabaseUsage() const;
767 SettingsType getFileSystemUsage() const;
772 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_