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.cpp
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 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
30 #include <dpl/foreach.h>
31 #include <dpl/sstream.h>
32 #include <dpl/wrt-dao-ro/global_config.h>
33 #include <dpl/wrt-dao-ro/webruntime_database.h>
34 #include <dpl/wrt-dao-ro/WrtDatabase.h>
35 #include <dpl/wrt-dao-ro/widget_config.h>
36 #include <dpl/wrt-dao-ro/feature_dao_read_only.h>
37 #include <orm_generator_wrt.h>
38 #include <LanguageTagsProvider.h>
41 unsigned int seed = time(NULL);
45 //TODO in current solution in each getter there exists a check
46 //"IsWidgetInstalled". Maybe it should be verified, if it could be done
47 //differently (check in WidgetDAOReadOnly constructor)
49 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
51 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
52 Catch(DPL::DB::SqlConnection::Exception::Base) { \
54 ReThrowMsg(WidgetDAOReadOnly::Exception::DatabaseError, \
58 #define CHECK_WIDGET_EXISTENCE(macro_transaction, macro_handle) \
59 if (!WidgetDAOReadOnly::isWidgetInstalled(macro_handle)) \
61 macro_transaction.Commit(); \
62 LogWarning("Cannot find widget. Handle: " << macro_handle); \
63 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist, \
64 "Cannot find widget. Handle: " << macro_handle); \
67 typedef DPL::DB::ORM::wrt::WidgetInfo::Row WidgetInfoRow;
68 typedef DPL::DB::ORM::wrt::WidgetFeature::widget_feature_id::ColumnType
70 typedef DPL::DB::ORM::wrt::WidgetSecuritySettings::Row
71 WidgetSecuritySettingsRow;
74 using namespace DPL::DB::ORM;
75 using namespace DPL::DB::ORM::wrt;
77 WidgetInfoRow getWidgetInfoRow(int widgetHandle)
79 LogDebug("Getting WidgetInfo row. Handle: " << widgetHandle);
80 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
82 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
83 select->Where(Equals<WidgetInfo::app_id>(widgetHandle));
85 WidgetInfo::Select::RowList rows = select->GetRowList();
87 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
88 "Cannot find widget. Handle: " << widgetHandle);
92 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in GetWidgetInfoRow")
95 WidgetSecuritySettingsRow getWidgetSecuritySettingsRow(int widgetHandle)
97 LogDebug("Getting WidgetSecuritySettings row. Handle: " << widgetHandle);
98 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
100 using namespace DPL::DB::ORM;
101 using namespace DPL::DB::ORM::wrt;
102 WRT_DB_SELECT(select, WidgetSecuritySettings, &WrtDatabase::interface())
103 select->Where(Equals<WidgetSecuritySettings::app_id>(widgetHandle));
105 WidgetSecuritySettings::Select::RowList rows = select->GetRowList();
107 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
108 "Cannot find widget. Handle: " << widgetHandle);
112 SQL_CONNECTION_EXCEPTION_HANDLER_END(
113 "Failed in getWidgetSecuritySettingsRow")
116 const int MAX_TIZENID_LENGTH = 10;
118 TizenAppId getTizenAppIdByHandle(const DbWidgetHandle handle)
120 LogDebug("Getting TizenAppId by DbWidgetHandle: " << handle);
122 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
124 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
125 select->Where(Equals<WidgetInfo::app_id>(handle));
126 WidgetInfo::Select::RowList rowList = select->GetRowList();
128 if (rowList.empty()) {
129 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
130 "Failed to get widget by handle");
132 TizenAppId tzAppid = rowList.front().Get_tizen_appid();
136 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
139 TizenAppId getTizenAppIdByPkgId(const TizenPkgId tzPkgid)
141 LogDebug("Getting TizenAppId by pkgid : " << tzPkgid);
142 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
144 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
145 select->Where(Equals<WidgetInfo::tizen_pkgid>(tzPkgid));
146 WidgetInfo::Select::RowList rowList = select->GetRowList();
148 if (rowList.empty()) {
149 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
150 "Failed to get widget by handle");
152 TizenAppId tzAppid = rowList.front().Get_tizen_appid();
156 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
160 IWacSecurity::~IWacSecurity()
163 WidgetDAOReadOnly::WidgetDAOReadOnly(DbWidgetHandle widgetHandle) :
164 m_widgetHandle(widgetHandle)
167 WidgetDAOReadOnly::WidgetDAOReadOnly(DPL::OptionalString widgetGUID) :
168 m_widgetHandle(WidgetDAOReadOnly::getHandle(widgetGUID))
171 WidgetDAOReadOnly::WidgetDAOReadOnly(DPL::String tzAppid) :
172 m_widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid))
175 WidgetDAOReadOnly::~WidgetDAOReadOnly()
178 DbWidgetHandle WidgetDAOReadOnly::getHandle() const
180 return m_widgetHandle;
183 DbWidgetHandle WidgetDAOReadOnly::getHandle(const WidgetGUID GUID)
185 LogDebug("Getting WidgetHandle by GUID [" << GUID << "]");
187 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
189 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
190 select->Where(Equals<WidgetInfo::widget_id>(GUID));
191 WidgetInfo::Select::RowList rowList = select->GetRowList();
193 if (rowList.empty()) {
194 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
195 "Failed to get widget by guid");
197 return rowList.front().Get_app_id();
199 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
202 DbWidgetHandle WidgetDAOReadOnly::getHandle(const DPL::String tzAppId)
204 LogDebug("Getting WidgetHandle by tizen app id [" << tzAppId << "]");
206 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
208 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
209 select->Where(Equals<WidgetInfo::tizen_appid>(tzAppId));
210 WidgetInfo::Select::RowList rowList = select->GetRowList();
212 if (rowList.empty()) {
213 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
214 "Failed to get widget by package name");
216 return rowList.front().Get_app_id();
218 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
221 WidgetPkgName WidgetDAOReadOnly::getPkgName() const
226 WidgetPkgName WidgetDAOReadOnly::getPkgName(const WidgetGUID GUID)
228 return getTzAppId(GUID);
231 WidgetPkgName WidgetDAOReadOnly::getPkgName(const DbWidgetHandle handle)
233 return getTzAppId(handle);
236 TizenAppId WidgetDAOReadOnly::getTzAppId() const
238 return getTizenAppIdByHandle(m_widgetHandle);
241 TizenAppId WidgetDAOReadOnly::getTzAppId(const WidgetGUID GUID)
243 return getTizenAppIdByHandle(getHandle(GUID));
246 TizenAppId WidgetDAOReadOnly::getTzAppId(const DbWidgetHandle handle)
248 return getTizenAppIdByHandle(handle);
251 TizenAppId WidgetDAOReadOnly::getTzAppId(const TizenPkgId tzPkgid)
253 return getTizenAppIdByPkgId(tzPkgid);
256 PropertyDAOReadOnly::WidgetPropertyKeyList
257 WidgetDAOReadOnly::getPropertyKeyList() const
259 return PropertyDAOReadOnly::GetPropertyKeyList(getTzAppId());
262 PropertyDAOReadOnly::WidgetPreferenceList
263 WidgetDAOReadOnly::getPropertyList() const
265 return PropertyDAOReadOnly::GetPropertyList(getTzAppId());
268 PropertyDAOReadOnly::WidgetPropertyValue WidgetDAOReadOnly::getPropertyValue(
269 const PropertyDAOReadOnly::WidgetPropertyKey &key) const
271 return PropertyDAOReadOnly::GetPropertyValue(getTzAppId(), key);
274 DPL::OptionalInt WidgetDAOReadOnly::checkPropertyReadFlag(
275 const PropertyDAOReadOnly::WidgetPropertyKey &key) const
277 return PropertyDAOReadOnly::CheckPropertyReadFlag(getTzAppId(), key);
280 DPL::String WidgetDAOReadOnly::getPath() const
282 DPL::String path = *getWidgetInstalledPath();
283 DPL::String srcPath = DPL::FromUTF8String(GlobalConfig::GetWidgetSrcPath());
285 path += srcPath + L"/";
290 DPL::String WidgetDAOReadOnly::getFullPath() const
292 return L"file://" + getPath();
296 WidgetDAOReadOnly::getLocalizedInfo(const DPL::String& languageTag)
299 LogDebug("Getting Localized Info. Handle: " << m_widgetHandle);
300 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
302 ScopedTransaction transaction(&WrtDatabase::interface());
303 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
305 WRT_DB_SELECT(select, LocalizedWidgetInfo, &WrtDatabase::interface())
307 And(Equals<LocalizedWidgetInfo::app_id>(m_widgetHandle),
308 Equals<LocalizedWidgetInfo::widget_locale>(languageTag)));
309 LocalizedWidgetInfo::Row info = select->GetSingleRow();
310 WidgetLocalizedInfo result;
312 result.name = info.Get_widget_name();
313 result.shortName = info.Get_widget_shortname();
314 result.description = info.Get_widget_description();
315 result.license = info.Get_widget_license();
316 result.licenseHref = info.Get_widget_license_href();
318 transaction.Commit();
321 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get localized info")
324 DbWidgetFeatureSet WidgetDAOReadOnly::getFeaturesList() const
326 LogDebug("Getting FeaturesList. Handle: " << m_widgetHandle);
327 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
329 ScopedTransaction transaction(&WrtDatabase::interface());
330 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
332 WRT_DB_SELECT(select, WidgetFeature, &WrtDatabase::interface())
333 select->Where(Equals<WidgetFeature::app_id>(m_widgetHandle));
335 DbWidgetFeatureSet resultSet;
336 typedef std::list<WidgetFeature::Row> RowList;
337 RowList list = select->GetRowList();
339 for (RowList::iterator i = list.begin(); i != list.end(); ++i) {
340 DbWidgetFeature feature;
341 feature.name = i->Get_name();
342 feature.required = i->Get_required();
343 feature.rejected = i->Get_rejected();
344 feature.params = getFeatureParams(i->Get_widget_feature_id());
345 FeatureDAOReadOnly featureDao(DPL::ToUTF8String(i->Get_name()));
346 feature.pluginId = featureDao.GetPluginHandle();
347 resultSet.insert(feature);
349 transaction.Commit();
352 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get features list")
355 WidgetParamMap WidgetDAOReadOnly::getFeatureParams(int id)
357 WidgetFeatureId widgetFeatureId(id);
358 LogDebug("Getting feature Params. featureId: " << widgetFeatureId);
359 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
361 WRT_DB_SELECT(select, FeatureParam, &WrtDatabase::interface())
362 select->Where(Equals<FeatureParam::widget_feature_id>(
365 WidgetParamMap resultMap;
366 typedef std::list<FeatureParam::Row> RowList;
367 RowList list = select->GetRowList();
370 resultMap.insert(std::make_pair(i->Get_name(), i->Get_value()));
374 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get feature params")
377 bool WidgetDAOReadOnly::hasFeature(const std::string& featureName) const
380 "Checking if widget has feature: " << featureName << ". Handle: " <<
382 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
384 ScopedTransaction transaction(&WrtDatabase::interface());
385 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
387 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
388 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
389 Equals<wrt::WidgetFeature::name>(
390 DPL::FromUTF8String(featureName))));
392 wrt::WidgetFeature::Select::RowList rows = select->GetRowList();
393 transaction.Commit();
394 return !rows.empty();
396 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check for feature")
399 HostList WidgetDAOReadOnly::getAccessHostList() const
401 LogDebug("Getting AccessHostList. Handle: " << m_widgetHandle);
402 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
404 ScopedTransaction transaction(&WrtDatabase::interface());
405 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
407 WRT_DB_SELECT(select, WidgetAccessHost, &WrtDatabase::interface())
408 select->Where(Equals<WidgetAccessHost::app_id>(m_widgetHandle));
409 std::list<WidgetAccessHost::host::ColumnType> values =
410 select->GetValueList<WidgetAccessHost::host>();
413 ret.push_back(DPL::ToUTF8String(*it));
415 transaction.Commit();
418 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get access host list")
421 bool WidgetDAOReadOnly::getAccessNetworkMode() const
423 //TODO there is no column access_network
424 //it was removed in "Widget localization overhaul
428 DbWidgetHandleList WidgetDAOReadOnly::getHandleList()
430 LogDebug("Getting DbWidgetHandle List");
431 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
433 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
434 return select->GetValueList<WidgetInfo::app_id>();
436 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get handle list")
439 WidgetPkgNameList WidgetDAOReadOnly::getPkgnameList()
441 LogDebug("Getting Pkgname List ");
442 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
444 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
445 return select->GetValueList<WidgetInfo::tizen_appid>();
447 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get Pkgname list")
450 TizenAppIdList WidgetDAOReadOnly::getTizenAppidList()
452 LogDebug("Getting Pkgname List ");
453 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
455 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
456 return select->GetValueList<WidgetInfo::tizen_appid>();
458 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get Pkgname list")
461 DbWidgetDAOReadOnlyList WidgetDAOReadOnly::getWidgetList()
463 LogDebug("Getting DbWidget List");
464 DbWidgetDAOReadOnlyList list;
465 FOREACH(iterator, getHandleList()) {
466 list.push_back(WidgetDAOReadOnlyPtr(new WidgetDAOReadOnly(*iterator)));
471 bool WidgetDAOReadOnly::isWidgetInstalled(DbWidgetHandle handle)
473 LogDebug("Checking if widget exist. Handle: " << handle);
474 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
476 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
477 select->Where(Equals<WidgetInfo::app_id>(handle));
479 WidgetInfo::Select::RowList rows = select->GetRowList();
481 return !rows.empty();
483 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check if widget exist")
486 bool WidgetDAOReadOnly::isWidgetInstalled(const TizenAppId &tzAppId)
488 LogDebug("Checking if widget exist. tizen app id" << tzAppId);
489 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
491 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
492 select->Where(Equals<WidgetInfo::tizen_appid>(tzAppId));
494 WidgetInfo::Select::RowList rows = select->GetRowList();
496 return !rows.empty();
498 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check if widget exist")
501 ExternalLocationList WidgetDAOReadOnly::getWidgetExternalLocations() const
503 LogDebug("Getting WidgetExtranalFiles List");
504 ExternalLocationList result;
505 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
507 WRT_DB_SELECT(select, WidgetExternalLocations, &WrtDatabase::interface());
508 select->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
509 WidgetExternalLocations::Select::RowList rows = select->GetRowList();
512 result.push_back(DPL::ToUTF8String(it->Get_path()));
515 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get handle list")
519 CertificateChainList WidgetDAOReadOnly::getWidgetCertificate(
520 CertificateSource source) const
522 WRT_DB_SELECT(select, WidgetCertificate, &WrtDatabase::interface())
525 Equals<WidgetCertificate::app_id>(m_widgetHandle),
526 Equals<WidgetCertificate::cert_source>(source)));
528 std::list<WidgetCertificate::Row> chainList = select->GetRowList();
530 CertificateChainList result;
532 FOREACH(iter, chainList)
533 result.push_back(DPL::ToUTF8String(iter->Get_encoded_chain()));
537 DbWidgetSize WidgetDAOReadOnly::getPreferredSize() const
539 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
542 size.width = row.Get_widget_width();
543 size.height = row.Get_widget_height();
545 LogDebug("Return size wxh = " <<
546 (!!size.width ? *size.width : -1) << " x " <<
547 (!!size.height ? *size.height : -1));
552 WidgetType WidgetDAOReadOnly::getWidgetType() const
554 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
555 DPL::OptionalInt result = row.Get_widget_type();
556 return WidgetType(static_cast<AppType>(*result));
559 WidgetGUID WidgetDAOReadOnly::getGUID() const
561 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
562 return row.Get_widget_id();
565 DPL::OptionalString WidgetDAOReadOnly::getTizenAppId() const
567 return DPL::OptionalString(getTzAppId());
570 DPL::OptionalString WidgetDAOReadOnly::getDefaultlocale() const
572 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
573 return row.Get_defaultlocale();
576 DPL::Optional<DPL::String> WidgetDAOReadOnly::getVersion() const
578 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
579 return row.Get_widget_version();
582 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorName() const
584 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
585 return row.Get_author_name();
588 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorEmail() const
590 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
591 return row.Get_author_email();
594 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorHref() const
596 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
597 return row.Get_author_href();
600 DPL::Optional<DPL::String> WidgetDAOReadOnly::getMinimumWacVersion() const
602 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
603 return row.Get_min_version();
606 std::string WidgetDAOReadOnly::getShareHref() const
608 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
610 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
611 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
612 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
615 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
616 "Cannot find widget. Handle: " << m_widgetHandle);
619 DPL::Optional<DPL::String> value = rows.front().Get_share_href();
620 std::string ret = "";
621 if (!value.IsNull()) {
622 ret = DPL::ToUTF8String(*value);
626 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get share HREF")
629 bool WidgetDAOReadOnly::getBackSupported() const
631 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
632 return row.Get_back_supported();
635 bool WidgetDAOReadOnly::isRecognized() const
637 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
638 DPL::OptionalInt result = row.Get_recognized();
639 if (result.IsNull()) {
642 return static_cast<bool>(*result);
645 bool WidgetDAOReadOnly::isWacSigned() const
647 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
648 DPL::OptionalInt result = row.Get_wac_signed();
649 if (result.IsNull()) {
652 return static_cast<bool>(*result);
655 bool WidgetDAOReadOnly::isDistributorSigned() const
657 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
658 DPL::OptionalInt result = row.Get_distributor_signed();
659 if (result.IsNull()) {
662 return static_cast<bool>(*result);
665 bool WidgetDAOReadOnly::isTrusted() const
668 // widget with verified distributor signature is trusted
669 return isDistributorSigned();
672 bool WidgetDAOReadOnly::isTestWidget() const
675 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
676 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
678 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
680 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
681 "Cannot find widget. Handle: " << m_widgetHandle);
684 return static_cast<bool>(rows.front().Get_test_widget());
686 Catch(DPL::DB::SqlConnection::Exception::Base){
687 ReThrowMsg(WidgetDAOReadOnly::Exception::DatabaseError,
688 "Failed to check IsTestWidget");
692 DPL::OptionalString WidgetDAOReadOnly::getCspPolicy() const
694 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
695 return row.Get_csp_policy();
698 DPL::OptionalString WidgetDAOReadOnly::getCspPolicyReportOnly() const
700 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
701 return row.Get_csp_policy_report_only();
704 bool WidgetDAOReadOnly::getWebkitPluginsRequired() const
706 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
707 DPL::OptionalInt ret = row.Get_webkit_plugins_required();
709 if (ret.IsNull() || *ret == 0) {
711 } else { return true;
715 time_t WidgetDAOReadOnly::getInstallTime() const
717 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
719 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
720 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
722 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
724 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
725 "Cannot find widget. Handle: " << m_widgetHandle);
728 return static_cast<time_t>(*rows.front().Get_install_time());
730 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get widdget install time")
733 DPL::OptionalString WidgetDAOReadOnly::getSplashImgSrc() const
735 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
737 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
738 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
740 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
742 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
743 "Cannot find widget. Handle: " << m_widgetHandle);
746 DPL::OptionalString value = rows.front().Get_splash_img_src();
747 if (value.IsNull()) {
748 return DPL::OptionalString::Null;
751 return DPL::OptionalString(getPath() + *value);
753 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get splash image path")
756 WidgetDAOReadOnly::WidgetLocalizedIconList WidgetDAOReadOnly::
757 getLocalizedIconList() const
759 //TODO check widget existance??
760 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
762 WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
763 select->Where(Equals<WidgetLocalizedIcon::app_id>(m_widgetHandle));
765 std::list<WidgetLocalizedIcon::Row> list =
766 select->GetRowList();
767 WidgetLocalizedIconList ret;
770 WidgetLocalizedIconRow icon = { it->Get_app_id(),
772 it->Get_widget_locale() };
777 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get icon data")
780 WidgetDAOReadOnly::WidgetIconList WidgetDAOReadOnly::getIconList() const
782 //TODO check widget existance
783 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
785 WRT_DB_SELECT(select, wrt::WidgetIcon, &WrtDatabase::interface())
786 select->Where(Equals<wrt::WidgetIcon::app_id>(m_widgetHandle));
787 select->OrderBy(DPL::TypeListDecl<OrderingAscending<wrt::WidgetIcon::
790 std::list<WidgetIcon::Row> list =
791 select->GetRowList();
795 WidgetIconRow icon = { it->Get_icon_id(),
798 it->Get_icon_width(),
799 it->Get_icon_height() };
804 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get icon data")
807 WidgetDAOReadOnly::LocalizedStartFileList WidgetDAOReadOnly::
808 getLocalizedStartFileList() const
810 //TODO check widget existance
811 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
813 WRT_DB_SELECT(select, WidgetLocalizedStartFile, &WrtDatabase::interface())
814 select->Where(Equals<WidgetLocalizedStartFile::app_id>(
816 select->OrderBy("start_file_id ASC");
818 std::list<WidgetLocalizedStartFile::Row> list =
819 select->GetRowList();
820 LocalizedStartFileList ret;
823 WidgetLocalizedStartFileRow file = { it->Get_start_file_id(),
825 it->Get_widget_locale(),
827 it->Get_encoding() };
832 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get start file list data")
835 WidgetDAOReadOnly::WidgetStartFileList WidgetDAOReadOnly::getStartFileList()
838 //TODO check widget existance
839 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
841 WRT_DB_SELECT(select, WidgetStartFile, &WrtDatabase::interface())
842 select->Where(Equals<WidgetStartFile::app_id>(m_widgetHandle));
843 select->OrderBy("start_file_id ASC");
845 std::list<WidgetStartFile::Row> list =
846 select->GetRowList();
847 WidgetStartFileList ret;
850 WidgetStartFileRow file = { it->Get_start_file_id(),
857 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get start file list data")
860 WindowModeList WidgetDAOReadOnly::getWindowModes() const
862 //TODO check widget existance
863 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
865 WRT_DB_SELECT(select, WidgetWindowModes, &WrtDatabase::interface())
866 select->Where(Equals<WidgetWindowModes::app_id>(m_widgetHandle));
868 return select->GetValueList<WidgetWindowModes::window_mode>();
870 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get window modes")
873 std::string WidgetDAOReadOnly::getBaseFolder() const
875 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
876 DPL::Optional<DPL::String> ret = row.Get_base_folder();
877 std::string baseFolder;
879 baseFolder = DPL::ToUTF8String(*ret);
882 if (!baseFolder.empty()) {
889 WidgetCertificateDataList WidgetDAOReadOnly::getCertificateDataList() const
891 //TODO check widget existance
892 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
894 WRT_DB_SELECT(select,
895 WidgetCertificateFingerprint,
896 &WrtDatabase::interface())
897 select->Where(Equals<WidgetCertificateFingerprint::app_id>(
899 select->OrderBy("chainid");
900 WidgetCertificateFingerprint::Select::RowList rows =
901 select->GetRowList();
903 WidgetCertificateDataList outlCertificateData;
906 WidgetCertificateData data;
909 static_cast <WidgetCertificateData::Owner>(it->Get_owner());
911 static_cast <WidgetCertificateData::Type>(it->Get_type());
912 data.chainId = it->Get_chainid();
913 DPL::Optional<DPL::String> md5 = it->Get_md5_fingerprint();
914 data.strMD5Fingerprint =
915 md5.IsNull() ? "" : DPL::ToUTF8String(*md5);
916 DPL::Optional<DPL::String> sha1 = it->Get_sha1_fingerprint();
917 data.strSHA1Fingerprint =
918 sha1.IsNull() ? "" : DPL::ToUTF8String(*sha1);
919 DPL::Optional<DPL::String> cname = it->Get_common_name();
921 cname.IsNull() ? DPL::FromUTF8String("") : *cname;
923 outlCertificateData.push_back(data);
925 return outlCertificateData;
927 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get fingerprint list")
930 FingerPrintList WidgetDAOReadOnly::getKeyFingerprints(
931 WidgetCertificateData::Owner owner,
932 WidgetCertificateData::Type type) const
934 //TODO check widget existance
935 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
937 WRT_DB_SELECT(select,
938 WidgetCertificateFingerprint,
939 &WrtDatabase::interface())
940 select->Where(And(And(
941 Equals<WidgetCertificateFingerprint::app_id>(
943 Equals<WidgetCertificateFingerprint::owner>(owner)),
944 Equals<WidgetCertificateFingerprint::type>(type)));
946 WidgetCertificateFingerprint::Select::RowList rows =
947 select->GetRowList();
949 FingerPrintList keys;
952 DPL::Optional<DPL::String> sha1 = it->Get_sha1_fingerprint();
953 if (!sha1.IsNull()) {
954 keys.push_back(DPL::ToUTF8String(*sha1));
956 DPL::Optional<DPL::String> md5 = it->Get_md5_fingerprint();
958 keys.push_back(DPL::ToUTF8String(*md5));
963 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get fingerprint list")
966 WidgetCertificateCNList WidgetDAOReadOnly::getKeyCommonNameList(
967 WidgetCertificateData::Owner owner,
968 WidgetCertificateData::Type type) const
970 //TODO check widget existance
971 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
973 WRT_DB_SELECT(select,
974 WidgetCertificateFingerprint,
975 &WrtDatabase::interface())
976 select->Where(And(And(
977 Equals<WidgetCertificateFingerprint::app_id>(
979 Equals<WidgetCertificateFingerprint::owner>(owner)),
980 Equals<WidgetCertificateFingerprint::type>(type)));
982 WidgetCertificateFingerprint::Select::RowList rows =
983 select->GetRowList();
985 WidgetCertificateCNList out;
988 DPL::Optional<DPL::String> cname = it->Get_common_name();
989 out.push_back(cname.IsNull() ? "" : DPL::ToUTF8String(*cname));
993 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get key common name")
996 ResourceAttributeList WidgetDAOReadOnly::getResourceAttribute(
997 const std::string &resourceId) const
999 WRT_DB_SELECT(select, WidgetFeature, &WrtDatabase::interface())
1000 select->Where(And(Equals<WidgetFeature::app_id>(m_widgetHandle),
1001 Equals<WidgetFeature::name>(
1002 DPL::FromUTF8String(resourceId))));
1004 std::list<WidgetFeature::Row> list = select->GetRowList();
1005 ResourceAttributeList result;
1006 if (!list.empty()) {
1007 int widgetFeatureId = list.begin()->Get_widget_feature_id();
1008 WidgetParamMap map = getFeatureParams(widgetFeatureId);
1011 result.push_back(DPL::ToUTF8String(i->first));
1016 void WidgetDAOReadOnly::getWidgetAccessInfo(
1017 WidgetAccessInfoList& outAccessInfoList) const
1019 //TODO check widget existance
1020 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1022 WRT_DB_SELECT(select, WidgetWARPInfo, &WrtDatabase::interface())
1023 select->Where(Equals<WidgetWARPInfo::app_id>(m_widgetHandle));
1025 WidgetWARPInfo::Select::RowList rows = select->GetRowList();
1029 WidgetAccessInfo info;
1031 info.strIRI = it->Get_iri();
1032 DPL::OptionalInt access = it->Get_subdomain_access();
1033 if (access.IsNull() || 0 == *access) {
1034 info.bSubDomains = false;
1035 } else if (1 == *access) {
1036 info.bSubDomains = true;
1039 outAccessInfoList.push_back(info);
1042 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get accessinfo list")
1045 LanguageTags WidgetDAOReadOnly::getLanguageTags() const
1047 //TODO check widget existance
1048 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1050 WRT_DB_SELECT(select, LocalizedWidgetInfo, &WrtDatabase::interface())
1051 select->Where(Equals<LocalizedWidgetInfo::app_id>(m_widgetHandle));
1052 return select->GetValueList<LocalizedWidgetInfo::widget_locale>();
1054 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get language tags")
1057 LanguageTags WidgetDAOReadOnly::getIconLanguageTags() const
1059 //TODO check widget existance
1060 WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
1061 select->Where(Equals<WidgetLocalizedIcon::app_id>(m_widgetHandle));
1063 return select->GetValueList<WidgetLocalizedIcon::widget_locale>();
1066 std::string WidgetDAOReadOnly::getCookieDatabasePath() const
1068 using namespace WrtDB::WidgetConfig;
1069 std::ostringstream path;
1071 TizenAppId tzAppId = getTzAppId();
1073 path << GetWidgetPersistentStoragePath(tzAppId);
1075 path << GlobalConfig::GetCookieDatabaseFile();
1080 std::string WidgetDAOReadOnly::getPrivateLocalStoragePath() const
1082 std::ostringstream path;
1083 TizenAppId tzAppId = getTzAppId();
1084 path << WidgetConfig::GetWidgetWebLocalStoragePath(tzAppId);
1090 void WidgetDAOReadOnly::getWidgetSettings(
1091 WidgetSettings& outWidgetSettings) const
1093 //TODO check widget existance
1094 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1096 WRT_DB_SELECT(select, SettingsList, &WrtDatabase::interface())
1097 select->Where(Equals<SettingsList::appId>(m_widgetHandle));
1099 SettingsList::Select::RowList rows = select->GetRowList();
1105 info.settingName = it->Get_settingName();
1106 info.settingValue = it->Get_settingValue();
1107 outWidgetSettings.push_back(info);
1110 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get settings list")
1113 void WidgetDAOReadOnly::getAppServiceList(
1114 WidgetApplicationServiceList& outAppServiceList) const
1116 LogDebug("Getting getAppServiceList. Handle: " << m_widgetHandle);
1117 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1119 ScopedTransaction transaction(&WrtDatabase::interface());
1120 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
1122 WRT_DB_SELECT(select, ApplicationServiceInfo, &WrtDatabase::interface())
1123 select->Where(Equals<ApplicationServiceInfo::app_id>(m_widgetHandle));
1125 ApplicationServiceInfo::Select::RowList rows = select->GetRowList();
1128 LogDebug("Application Service list is empty. Handle: " <<
1133 WidgetApplicationService ret;
1134 ret.src = it->Get_src();
1135 ret.operation = it->Get_operation();
1136 ret.scheme = it->Get_scheme();
1137 ret.mime = it->Get_mime();
1138 ret.disposition = static_cast<WidgetApplicationService::Disposition>(it->Get_disposition());
1139 outAppServiceList.push_back(ret);
1142 transaction.Commit();
1144 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get access host list")
1147 PackagingType WidgetDAOReadOnly::getPackagingType() const
1149 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
1150 DPL::OptionalInt result = row.Get_pkg_type();
1151 return PackagingType(static_cast<PkgType>(*result));
1154 void WidgetDAOReadOnly::getEncryptedFileList(EncryptedFileList& filesList)
1157 //TODO check widget existance
1158 WRT_DB_SELECT(select, EncryptedResourceList, &WrtDatabase::interface())
1159 select->Where(Equals<EncryptedResourceList::app_id>(m_widgetHandle));
1161 typedef std::list<EncryptedResourceList::Row> RowList;
1162 RowList list = select->GetRowList();
1165 EncryptedFileInfo info;
1166 info.fileName = it->Get_resource();
1167 info.fileSize = it->Get_size();
1168 filesList.insert(info);
1172 DPL::OptionalString WidgetDAOReadOnly::getBackgroundPage() const
1174 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1176 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
1177 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
1179 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
1181 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
1182 "Cannot find widget. Handle: " << m_widgetHandle);
1185 return rows.front().Get_background_page();
1187 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get background page")
1190 TizenPkgId WidgetDAOReadOnly::generatePkgId()
1192 std::string allowed("0123456789"
1193 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1194 "abcdefghijklmnopqrstuvwxyz");
1196 pkgId.resize(MAX_TIZENID_LENGTH);
1198 for (int i = 0; i < MAX_TIZENID_LENGTH; ++i) {
1199 pkgId[i] = allowed[rand_r(&seed) % allowed.length()];
1201 } while (isWidgetInstalled(pkgId));
1205 SettingsType WidgetDAOReadOnly::getSecurityPopupUsage(void) const
1207 WidgetSecuritySettingsRow row =
1208 getWidgetSecuritySettingsRow(m_widgetHandle);
1209 DPL::OptionalInt result = row.Get_security_popup_usage();
1210 return static_cast<SettingsType>(*result);
1213 SettingsType WidgetDAOReadOnly::getGeolocationUsage(void) const
1215 WidgetSecuritySettingsRow row =
1216 getWidgetSecuritySettingsRow(m_widgetHandle);
1217 DPL::OptionalInt result = row.Get_geolocation_usage();
1218 return static_cast<SettingsType>(*result);
1221 SettingsType WidgetDAOReadOnly::getWebNotificationUsage(void) const
1223 WidgetSecuritySettingsRow row =
1224 getWidgetSecuritySettingsRow(m_widgetHandle);
1225 DPL::OptionalInt result = row.Get_web_notification_usage();
1226 return static_cast<SettingsType>(*result);
1229 SettingsType WidgetDAOReadOnly::getWebDatabaseUsage(void) const
1231 WidgetSecuritySettingsRow row =
1232 getWidgetSecuritySettingsRow(m_widgetHandle);
1233 DPL::OptionalInt result = row.Get_web_database_usage();
1234 return static_cast<SettingsType>(*result);
1237 SettingsType WidgetDAOReadOnly::getFileSystemUsage(void) const
1239 WidgetSecuritySettingsRow row =
1240 getWidgetSecuritySettingsRow(m_widgetHandle);
1241 DPL::OptionalInt result = row.Get_file_system_usage();
1242 return static_cast<SettingsType>(*result);
1245 DPL::OptionalString WidgetDAOReadOnly::getWidgetInstalledPath() const
1247 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1249 using namespace DPL::DB::ORM;
1250 using namespace DPL::DB::ORM::wrt;
1251 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
1252 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
1254 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
1256 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
1257 "Cannot find widget. Handle: " << m_widgetHandle);
1260 return rows.front().Get_installed_path();
1262 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get widdget installed path")
1265 TizenPkgId WidgetDAOReadOnly::getTizenPkgId() const
1267 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
1268 return row.Get_tizen_pkgid();
1271 PrivilegeList WidgetDAOReadOnly::getWidgetPrivilege() const
1273 //TODO check widget existance
1274 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1276 WRT_DB_SELECT(select, WidgetPrivilege, &WrtDatabase::interface())
1277 select->Where(Equals<WidgetPrivilege::app_id>(m_widgetHandle));
1279 return select->GetValueList<WidgetPrivilege::name>();
1281 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get PrivilegeList")
1284 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1285 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END
1286 #undef CHECK_WIDGET_EXISTENCE
1287 } // namespace WrtDB