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;
179 DPL::OptionalString pkgname;
180 WidgetPkgName pkgName;
184 time_t installedTime;
185 PackagingType packagingType;
186 EncryptedFileList encryptedFiles;
187 ExternalLocationList externalLocations;
188 DPL::OptionalString widgetInstalledPath;
191 typedef std::list<std::string> CertificateChainList;
195 virtual ~IWacSecurity();
197 virtual const WidgetCertificateDataList& getCertificateList() const = 0;
199 virtual bool isRecognized() const = 0;
201 virtual bool isDistributorSigned() const = 0;
203 virtual bool isWacSigned() const = 0;
205 virtual void getCertificateChainList(CertificateChainList& list,
206 CertificateSource source) const = 0;
211 * Structure to hold the information of widget's author.
213 struct WidgetAuthorInfo
215 DPL::OptionalString name;
216 DPL::OptionalString email;
217 DPL::OptionalString href;
221 * Widget update policy
223 enum WidgetUpdatePolicy
225 WIDGET_UPDATE_MONTHLY = 0, //< monthly update
226 WIDGET_UPDATE_WEEKLY, //< weekly update
227 WIDGET_UPDATE_DAILY, //< daily update
228 WIDGET_UPDATE_STARTUP, //< update when cell phone boots
229 WIDGET_UPDATE_NEVER //< never update
232 typedef std::list <std::string> WidgetCertificateCNList;
233 typedef std::list<DPL::String> LanguageTagList;
234 typedef std::list<std::string> HostList;
235 typedef std::list<std::string> FingerPrintList;
236 typedef std::list<std::string> ResourceAttributeList;
238 class WidgetDAOReadOnly
242 * WidgetDAO Exception classes
247 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
248 DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
249 DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty)
250 DECLARE_EXCEPTION_TYPE(Base, GUIDisNull)
251 DECLARE_EXCEPTION_TYPE(Base, UnexpectedEmptyResult)
252 DECLARE_EXCEPTION_TYPE(Base, WidgetNotExist)
253 DECLARE_EXCEPTION_TYPE(Base, AlreadyRegistered)
257 DbWidgetHandle m_widgetHandle;
260 struct WidgetLocalizedIconRow
264 DPL::String widgetLocale;
266 typedef std::list<WidgetLocalizedIconRow> WidgetLocalizedIconList;
273 DPL::OptionalInt iconWidth;
274 DPL::OptionalInt iconHeight;
276 typedef std::list<WidgetIconRow> WidgetIconList;
278 struct WidgetStartFileRow
284 typedef std::list<WidgetStartFileRow> WidgetStartFileList;
286 struct WidgetLocalizedStartFileRow
290 DPL::String widgetLocale;
292 DPL::String encoding;
294 typedef std::list<WidgetLocalizedStartFileRow> LocalizedStartFileList;
297 * This is a constructor.
299 * @param[in] widgetHandle application id of widget.
301 WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
302 WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
303 WidgetDAOReadOnly(DPL::String tzAppid);
308 virtual ~WidgetDAOReadOnly();
311 * This method returns widget handle(m_widgetHandle).
313 * @return widget handle(m_widgetHandle).
314 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
315 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
317 DbWidgetHandle getHandle() const;
318 static DbWidgetHandle getHandle(const WidgetGUID GUID);
319 static DbWidgetHandle getHandle(const DPL::String pkgName);
322 * Returns tizenAppId for the specified widget
325 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
326 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
329 TizenAppId getTzAppId() const;
330 static TizenAppId getTzAppId(const WidgetGUID GUID);
331 static TizenAppId getTzAppId(const DbWidgetHandle handle);
334 * Returns WidgetPkgName for the specified widget
337 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
338 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
341 WidgetPkgName getPkgName() const;
342 static WidgetPkgName getPkgName(const WidgetGUID GUID);
343 static WidgetPkgName getPkgName(const DbWidgetHandle handle);
346 * This method returns the root directory of widget resource.
348 * @return path name of root directory.
349 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
350 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
353 DPL::String getPath() const;
355 DPL::String getFullPath() const;
358 * This method returns the preferred size of the widget,
359 * including width and height.
362 * @return An structure type variable to hold widget's size.
363 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
364 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
367 DbWidgetSize getPreferredSize() const;
370 * This method returns the type of the widget.
373 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
374 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
377 WidgetType getWidgetType() const;
380 * This method returns the id of the widget.
383 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
384 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
387 WidgetGUID getGUID() const;
391 * This method returns the App id of the widget.
394 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
395 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
397 DPL::OptionalString getTizenAppId() const;
400 * This method returns the defaultlocale for the widget.
402 * @return defaultlocale
403 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
404 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
407 DPL::OptionalString getDefaultlocale() const;
410 * This method returns list of localized icons files;
412 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
413 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
416 WidgetLocalizedIconList getLocalizedIconList() const;
419 * This method returns list of icons files;
421 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
422 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
425 WidgetIconList getIconList() const;
428 * This method returns list of localized start files;
430 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
431 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
434 LocalizedStartFileList getLocalizedStartFileList() const;
437 * This method returns list of start files;
439 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
440 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
443 WidgetStartFileList getStartFileList() const;
446 * @param[out] outAccessInfoList list filled with access info structures
448 void getWidgetAccessInfo(WidgetAccessInfoList& outAccessInfoList) const;
452 * @return recognized status
454 bool isRecognized() const;
460 bool isWacSigned() const;
466 bool isDistributorSigned() const;
470 * @return trusted status
472 bool isTrusted() const;
476 * @return is WAC test widget
478 bool isTestWidget() const;
481 * This method returns window mode of widget.
483 * @return window modes of widget
484 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
485 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
488 WindowModeList getWindowModes() const;
491 * This method returns the version of the widget.
493 * @return version of widget
494 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
495 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
498 DPL::OptionalString getVersion() const;
501 * This method returns list filed with Common Name entries from certificate.
503 * @return Common Name of Distribuotor End Entity certificate.
504 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
505 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
508 WidgetCertificateCNList getKeyCommonNameList(
509 WidgetCertificateData::Owner owner,
510 WidgetCertificateData::Type type) const;
513 * given a certificate owner (author / distributor) and type of certificate
515 * function returns list of matching fingerprints
517 FingerPrintList getKeyFingerprints(
518 WidgetCertificateData::Owner owner,
519 WidgetCertificateData::Type type) const;
522 * This method gets certificate data list for a widget from database.
524 WidgetCertificateDataList getCertificateDataList() const;
527 * This method returns a list of widget features.
530 * @see FreeFeatureList()
531 * @return list of widget features, type of list element is structure
533 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
534 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
537 DbWidgetFeatureSet getFeaturesList() const;
539 static WidgetParamMap getFeatureParams(int widgetFeatureId);
541 * This method checks whether widget has specified feature.
543 * @return true if has, false if has not
544 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
546 bool hasFeature(const std::string& featureName) const;
549 * This method gets host list that widget can connect to.
551 * @return See above comment
552 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
554 HostList getAccessHostList() const;
557 * This method gets widget's access on network: true or false.
559 * @return true: widget can access network; false: widget can not access
561 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
562 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
565 bool getAccessNetworkMode() const;
568 * This method gets if widget needs webkit plugins enabled
570 * @return true: widget needs webkit plugins enabled
571 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
572 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
575 bool getWebkitPluginsRequired() const;
578 * This method returns a list of all the installed widgets' app id.
580 * @return list of installed widgets' app id.
581 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
582 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
585 static DbWidgetHandleList getHandleList();
588 * This method returns list of pkgname of installed packages
589 * @return list of pkgname of installed packages
591 static TizenAppIdList getTizenAppidList();
592 static WidgetPkgNameList getPkgnameList();
595 * This method returns a list of all the installed widgets.
597 * @return list of installed widgets.
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 static DbWidgetDAOReadOnlyList getWidgetList();
605 * This method removes a widget's information from EmDB.
607 * @see RegisterWidget()
608 * @param[in] widgetHandle widget's app id
609 * @return true if succeed, false if fail.
611 static void unregisterWidget(DbWidgetHandle widgetHandle);
614 * This method gets author's infomation of a widget which is parsed from
615 * configiration document.
617 * @see WidgetAuthorInfo
618 * @param[out] pAuthorInfo
619 * @return true if succeed, false if fail.
621 WidgetAuthorInfo getAuthorInfo() const;
624 * This method gets author's name of a widget which is parsed from
625 * configiration document.
627 * @param[out] pAuthorInfo
628 * @return author's name.
629 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
630 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
633 DPL::OptionalString getAuthorName() const;
636 * This method gets author's email of a widget which is parsed from
637 * configiration document.
639 * @param[out] pAuthorInfo
640 * @return author's email.
641 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
642 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
645 DPL::OptionalString getAuthorEmail() const;
648 * This method gets author's email of a widget which is parsed from
649 * configiration document.
651 * @param[out] pAuthorInfo
652 * @return author's email.
653 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
654 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
657 DPL::OptionalString getAuthorHref() const;
660 * This method returns minimum version of WAC that WRT has to be compliant
661 * to to run this widget
663 * @return Minimum version
664 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
665 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
668 DPL::OptionalString getMinimumWacVersion() const;
670 /* This method get widget' share href.
672 * @return widget's share href
674 std::string getShareHref() const;
677 * This method get widget installed time
679 * @return time_t : return widget's install time
681 time_t getInstallTime() const;
684 * This method gets widget base folder.
686 * @return widget base folder.
687 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
688 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
691 std::string getBaseFolder() const;
693 /* This method gets the parameter list for resource.
695 ResourceAttributeList getResourceAttribute(
696 const std::string &resourceId) const;
698 /* This method checks read only flag for given property
700 DPL::OptionalInt checkPropertyReadFlag(
701 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
703 /* This method gets widget property key list
705 PropertyDAOReadOnly::WidgetPropertyKeyList getPropertyKeyList() const;
707 /* This method gets widget property list
709 PropertyDAOReadOnly::WidgetPreferenceList getPropertyList() const;
711 /* This method get widget property value
713 PropertyDAOReadOnly::WidgetPropertyValue getPropertyValue(
714 const PropertyDAOReadOnly::WidgetPropertyKey &key) const;
716 LanguageTagList getLanguageTags() const;
717 LanguageTagList getIconLanguageTags() const;
721 WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
722 std::string getCookieDatabasePath() const;
724 std::string getPrivateLocalStoragePath() const;
726 bool getBackSupported() const;
728 static bool isWidgetInstalled(DbWidgetHandle handle);
729 static bool isWidgetInstalled(const TizenAppId & tzAppId);
731 /* This method get path of the splash image.
733 * @return path of the widget's splash image
735 DPL::OptionalString getSplashImgSrc() const;
737 ExternalLocationList getWidgetExternalLocations() const;
740 * Default value is required to keep compatibility with
741 * wrt-installer and wrt.
743 CertificateChainList getWidgetCertificate(
744 CertificateSource source = SIGNATURE_DISTRIBUTOR) const;
746 void getWidgetSettings(WidgetSettings& outWidgetSettings) const;
749 * This method gets application service list that define AUL value
751 * @return See above comment
752 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
754 void getAppServiceList(
755 WidgetApplicationServiceList& outAppServiceList) const;
758 * This method returns the type of the package.
760 * @return PackagingType
761 * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
762 * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching
765 PackagingType getPackagingType() const;
767 void getEncryptedFileList(EncryptedFileList& filesList) const;
770 * This method returns widget's background page filename.
772 * @return Name of file containing background page
774 DPL::OptionalString getBackgroundPage() const;
777 * @brief generateTizenId generates new package id
779 * If widget do not supplies it's own tizen package id, this method can be used,
780 * although it should be removed in future.
782 * @return new tizen package id
784 static TizenPkgId generatePkgId();
785 static TizenPkgId generateTizenId() {
786 return generatePkgId();
790 * @brief This method return each value for security setting
792 * @return SettingsType
793 * SETTINGS_TYPE_UNKNOWN : unknow value
794 * SETTINGS_TYPE_ON : enable
795 * SETTINGS_TYPE_ALWAYS_ASK : ask by popup
796 * SETTINGS_TYPE_OFF : disable
798 SettingsType getSecurityPopupUsage() const;
799 SettingsType getGeolocationUsage() const;
800 SettingsType getWebNotificationUsage() const;
801 SettingsType getWebDatabaseUsage() const;
802 SettingsType getFileSystemUsage() const;
805 * This method returns widget's installed path
807 * @return path of widget installed
809 DPL::OptionalString getWidgetInstalledPath() const;
812 * This method returns tizen package id
814 * @return tizen package id
816 TizenPkgId getTizenPkgId() const;
821 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_