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;
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 pkgName);
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 DB table.
312 DbWidgetHandle getHandle() const;
313 static DbWidgetHandle getHandle(const WidgetGUID GUID);
314 static DbWidgetHandle getHandle(const DPL::String pkgName);
317 * This method returns the root directory of widget resource.
319 * @return path name of root directory.
320 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
321 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
324 DPL::String getPath() const;
326 DPL::String getFullPath() const;
329 * This method returns the preferred size of the widget,
330 * including width and height.
333 * @return An structure type variable to hold widget's size.
334 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
335 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
338 DbWidgetSize getPreferredSize() const;
341 * This method returns the type of the widget.
344 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
345 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
348 WidgetType getWidgetType() const;
351 * This method returns the id of the widget.
354 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
355 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
358 WidgetGUID getGUID() const;
361 * This method returns the Package name of the widget.
364 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
365 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
367 DPL::OptionalString getPkgname() const;
370 * This method returns the defaultlocale for the widget.
372 * @return defaultlocale
373 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
374 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
377 DPL::OptionalString getDefaultlocale() const;
380 * This method returns list of localized icons files;
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 WidgetLocalizedIconList getLocalizedIconList() const;
389 * This method returns list of icons files;
391 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
392 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
395 WidgetIconList getIconList() const;
398 * This method returns list of localized start files;
400 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
401 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
404 LocalizedStartFileList getLocalizedStartFileList() const;
407 * This method returns list of start files;
409 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
410 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
413 WidgetStartFileList getStartFileList() const;
416 * @param[out] outAccessInfoList list filled with access info structures
418 void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
422 * @return recognized status
424 bool isRecognized() const;
430 bool isWacSigned() const;
436 bool isDistributorSigned() const;
440 * @return trusted status
442 bool isTrusted() const;
446 * @return is WAC test widget
448 bool isTestWidget() const;
451 * This method returns window mode of widget.
453 * @return window modes of widget
454 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
455 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
458 WindowModeList getWindowModes() const;
461 * This method returns the version of the widget.
463 * @return version of widget
464 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
465 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
468 DPL::OptionalString getVersion() const;
471 * This method returns list filed with Common Name entries from certificate.
473 * @return Common Name of Distribuotor End Entity certificate.
474 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
475 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
478 WidgetCertificateCNList getKeyCommonNameList(
479 WidgetCertificateData::Owner owner,
480 WidgetCertificateData::Type type) const;
483 * given a certificate owner (author / distributor) and type of certificate
485 * function returns list of matching fingerprints
487 FingerPrintList getKeyFingerprints(
488 WidgetCertificateData::Owner owner,
489 WidgetCertificateData::Type type) const;
492 * This method gets certificate data list for a widget from database.
494 WidgetCertificateDataList getCertificateDataList() const;
497 * This method returns a list of widget features.
500 * @see FreeFeatureList()
501 * @return list of widget features, type of list element is structure
503 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
504 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
507 DbWidgetFeatureSet getFeaturesList() const;
509 static WidgetParamMap getFeatureParams(int widgetFeatureId);
511 * This method checks whether widget has specified feature.
513 * @return true if has, false if has not
514 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
516 bool hasFeature(const std::string& featureName) const;
519 * This method gets host list that widget can connect to.
521 * @return See above comment
522 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
524 HostList getAccessHostList() const;
527 * This method gets widget's access on network: true or false.
529 * @return true: widget can access network; false: widget can not access
531 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
532 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
535 bool getAccessNetworkMode() const;
538 * This method gets if widget needs webkit plugins enabled
540 * @return true: widget needs webkit plugins enabled
541 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
542 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
545 bool getWebkitPluginsRequired() const;
548 * This method returns a list of all the installed widgets' app id.
550 * @return list of installed widgets' app id.
551 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
552 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
555 static DbWidgetHandleList getHandleList();
558 * This method returns list of pkgname of installed packages
559 * @return list of pkgname of installed packages
561 static WidgetPkgNameList getPkgnameList();
564 * This method returns a list of all the installed widgets.
566 * @return list of installed widgets.
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 static DbWidgetDAOReadOnlyList getWidgetList();
574 * This method removes a widget's information from EmDB.
576 * @see RegisterWidget()
577 * @param[in] widgetHandle widget's app id
578 * @return true if succeed, false if fail.
580 static void unregisterWidget(DbWidgetHandle widgetHandle);
583 * This method gets author's infomation of a widget which is parsed from
584 * configiration document.
586 * @see WidgetAuthorInfo
587 * @param[out] pAuthorInfo
588 * @return true if succeed, false if fail.
590 WidgetAuthorInfo getAuthorInfo() const;
593 * This method gets author's name of a widget which is parsed from
594 * configiration document.
596 * @param[out] pAuthorInfo
597 * @return author's name.
598 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
599 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
602 DPL::OptionalString getAuthorName() const;
605 * This method gets author's email of a widget which is parsed from
606 * configiration document.
608 * @param[out] pAuthorInfo
609 * @return author's email.
610 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
611 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
614 DPL::OptionalString getAuthorEmail() const;
617 * This method gets author's email of a widget which is parsed from
618 * configiration document.
620 * @param[out] pAuthorInfo
621 * @return author's email.
622 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
623 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
626 DPL::OptionalString getAuthorHref() const;
629 * This method returns minimum version of WAC that WRT has to be compliant
630 * to to run this widget
632 * @return Minimum version
633 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
634 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
637 DPL::OptionalString getMinimumWacVersion() const;
639 /* This method get widget' share href.
641 * @return widget's share href
643 std::string getShareHref() const;
646 * This method get widget installed time
648 * @return time_t : return widget's install time
650 time_t getInstallTime() const;
653 * This method gets widget base folder.
655 * @return widget base folder.
656 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
657 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
660 std::string getBaseFolder() const;
662 /* This method gets the parameter list for resource.
664 ResourceAttributeList getResourceAttribute(
665 const std::string &resourceId) const;
667 /* This method checks read only flag for given property
669 DPL::OptionalInt checkPropertyReadFlag(
670 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
672 /* This method gets widget property key list
674 PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
676 /* This method gets widget property list
678 PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
680 /* This method get widget property value
682 PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
683 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
685 LanguageTagList getLanguageTags() const;
686 LanguageTagList getIconLanguageTags() const;
690 WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
691 std::string getCookieDatabasePath() const;
693 std::string getPrivateLocalStoragePath() const;
695 bool getBackSupported() const;
697 static bool isWidgetInstalled(DbWidgetHandle handle);
698 static bool isWidgetInstalled(const WidgetPkgName & pkgName);
700 /* This method get path of the splash image.
702 * @return path of the widget's splash image
704 DPL::OptionalString getSplashImgSrc() const;
706 ExternalLocationList getWidgetExternalLocations() const;
709 * Default value is required to keep compatibility with
710 * wrt-installer and wrt.
712 CertificateChainList getWidgetCertificate(
713 CertificateSource source = SIGNATURE_DISTRIBUTOR) const;
715 void getWidgetSettings(WidgetSettings& outWidgetSettings) const;
718 * This method gets application service list that define AUL value
720 * @return See above comment
721 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
723 void getAppServiceList(
724 WidgetApplicationServiceList& outAppServiceList) const;
727 * This method returns the type of the package.
729 * @return PackagingType
730 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
731 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
734 PackagingType getPackagingType() const;
736 void getEncryptedFileList(EncryptedFileList& filesList) const;
739 * This method returns widget's background page filename.
741 * @return Name of file containing background page
743 DPL::OptionalString getBackgroundPage() const;
746 * @brief generateTizenId generates new tizen id
748 * If widget do not supplies it's own tizen id, this method can be used,
749 * although it should be removed in future.
751 * @return new tizen id
753 static WidgetPkgName generateTizenId();
756 * @brief This method return each value for security setting
758 * @return SettingsType
759 * SETTINGS_TYPE_UNKNOWN : unknow value
760 * SETTINGS_TYPE_ON : enable
761 * SETTINGS_TYPE_ALWAYS_ASK : ask by popup
762 * SETTINGS_TYPE_OFF : disable
764 SettingsType getSecurityPopupUsage() const;
765 SettingsType getGeolocationUsage() const;
766 SettingsType getWebNotificationUsage() const;
767 SettingsType getWebDatabaseUsage() const;
768 SettingsType getFileSystemUsage() const;
771 * This method returns widget's installed path
773 * @return path of widget installed
775 DPL::OptionalString getWidgetInstalledPath() const;
780 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_