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")
159 TizenPkgId getTizenPkgIdByHandle(const DbWidgetHandle handle)
161 LogDebug("Getting TizenPkgId by DbWidgetHandle: " << handle);
163 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
165 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
166 select->Where(Equals<WidgetInfo::app_id>(handle));
167 WidgetInfo::Select::RowList rowList = select->GetRowList();
169 if (rowList.empty()) {
170 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
171 "Failed to get widget by handle");
173 TizenPkgId tzPkgid = rowList.front().Get_tizen_pkgid();
177 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
181 IWidgetSecurity::~IWidgetSecurity()
184 WidgetDAOReadOnly::WidgetDAOReadOnly(DbWidgetHandle widgetHandle) :
185 m_widgetHandle(widgetHandle)
188 WidgetDAOReadOnly::WidgetDAOReadOnly(DPL::OptionalString widgetGUID) :
189 m_widgetHandle(WidgetDAOReadOnly::getHandle(widgetGUID))
192 WidgetDAOReadOnly::WidgetDAOReadOnly(TizenAppId tzAppid) :
193 m_widgetHandle(WidgetDAOReadOnly::getHandle(tzAppid))
196 WidgetDAOReadOnly::~WidgetDAOReadOnly()
199 DbWidgetHandle WidgetDAOReadOnly::getHandle() const
201 return m_widgetHandle;
204 DbWidgetHandle WidgetDAOReadOnly::getHandle(const WidgetGUID GUID)
206 LogDebug("Getting WidgetHandle by GUID [" << GUID << "]");
208 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
210 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
211 select->Where(Equals<WidgetInfo::widget_id>(GUID));
212 WidgetInfo::Select::RowList rowList = select->GetRowList();
214 if (rowList.empty()) {
215 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
216 "Failed to get widget by guid");
218 return rowList.front().Get_app_id();
220 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
223 DbWidgetHandle WidgetDAOReadOnly::getHandle(const DPL::String tzAppId)
225 LogDebug("Getting WidgetHandle by tizen app id [" << tzAppId << "]");
227 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
229 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
230 select->Where(Equals<WidgetInfo::tizen_appid>(tzAppId));
231 WidgetInfo::Select::RowList rowList = select->GetRowList();
233 if (rowList.empty()) {
234 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
235 "Failed to get widget by package name");
237 return rowList.front().Get_app_id();
239 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
242 TizenAppId WidgetDAOReadOnly::getTzAppId() const
244 return getTizenAppIdByHandle(m_widgetHandle);
247 TizenAppId WidgetDAOReadOnly::getTzAppId(const WidgetGUID GUID)
249 return getTizenAppIdByHandle(getHandle(GUID));
252 TizenAppId WidgetDAOReadOnly::getTzAppId(const DbWidgetHandle handle)
254 return getTizenAppIdByHandle(handle);
257 TizenAppId WidgetDAOReadOnly::getTzAppId(const TizenPkgId tzPkgid)
259 return getTizenAppIdByPkgId(tzPkgid);
262 TizenPkgId WidgetDAOReadOnly::getTzPkgId() const
264 return getTizenPkgIdByHandle(m_widgetHandle);
267 PropertyDAOReadOnly::WidgetPropertyKeyList
268 WidgetDAOReadOnly::getPropertyKeyList() const
270 return PropertyDAOReadOnly::GetPropertyKeyList(getTzAppId());
273 PropertyDAOReadOnly::WidgetPreferenceList
274 WidgetDAOReadOnly::getPropertyList() const
276 return PropertyDAOReadOnly::GetPropertyList(getTzAppId());
279 PropertyDAOReadOnly::WidgetPropertyValue WidgetDAOReadOnly::getPropertyValue(
280 const PropertyDAOReadOnly::WidgetPropertyKey &key) const
282 return PropertyDAOReadOnly::GetPropertyValue(getTzAppId(), key);
285 DPL::OptionalInt WidgetDAOReadOnly::checkPropertyReadFlag(
286 const PropertyDAOReadOnly::WidgetPropertyKey &key) const
288 return PropertyDAOReadOnly::CheckPropertyReadFlag(getTzAppId(), key);
291 DPL::String WidgetDAOReadOnly::getPath() const
293 DPL::String path = *getWidgetInstalledPath();
294 DPL::String srcPath = DPL::FromUTF8String(GlobalConfig::GetWidgetSrcPath());
296 path += srcPath + L"/";
301 DPL::String WidgetDAOReadOnly::getFullPath() const
303 return L"file://" + getPath();
307 WidgetDAOReadOnly::getLocalizedInfo(const DPL::String& languageTag)
310 LogDebug("Getting Localized Info. Handle: " << m_widgetHandle);
311 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
313 ScopedTransaction transaction(&WrtDatabase::interface());
314 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
316 WRT_DB_SELECT(select, LocalizedWidgetInfo, &WrtDatabase::interface())
318 And(Equals<LocalizedWidgetInfo::app_id>(m_widgetHandle),
319 Equals<LocalizedWidgetInfo::widget_locale>(languageTag)));
320 LocalizedWidgetInfo::Row info = select->GetSingleRow();
321 WidgetLocalizedInfo result;
323 result.name = info.Get_widget_name();
324 result.shortName = info.Get_widget_shortname();
325 result.description = info.Get_widget_description();
326 result.license = info.Get_widget_license();
327 result.licenseHref = info.Get_widget_license_href();
329 transaction.Commit();
332 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get localized info")
335 DbWidgetFeatureSet WidgetDAOReadOnly::getFeaturesList() const
337 LogDebug("Getting FeaturesList. Handle: " << m_widgetHandle);
338 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
340 ScopedTransaction transaction(&WrtDatabase::interface());
341 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
343 WRT_DB_SELECT(select, WidgetFeature, &WrtDatabase::interface())
344 select->Where(Equals<WidgetFeature::app_id>(m_widgetHandle));
346 DbWidgetFeatureSet resultSet;
347 typedef std::list<WidgetFeature::Row> RowList;
348 RowList list = select->GetRowList();
350 for (RowList::iterator i = list.begin(); i != list.end(); ++i) {
351 DbWidgetFeature feature;
352 feature.name = i->Get_name();
353 feature.rejected = i->Get_rejected();
354 FeatureDAOReadOnly featureDao(DPL::ToUTF8String(i->Get_name()));
355 feature.pluginId = featureDao.GetPluginHandle();
356 resultSet.insert(feature);
358 transaction.Commit();
361 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get features list")
364 bool WidgetDAOReadOnly::hasFeature(const std::string& featureName) const
367 "Checking if widget has feature: " << featureName << ". Handle: " <<
369 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
371 ScopedTransaction transaction(&WrtDatabase::interface());
372 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
374 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
375 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
376 Equals<wrt::WidgetFeature::name>(
377 DPL::FromUTF8String(featureName))));
379 wrt::WidgetFeature::Select::RowList rows = select->GetRowList();
380 transaction.Commit();
381 return !rows.empty();
383 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check for feature")
386 HostList WidgetDAOReadOnly::getAccessHostList() const
388 LogDebug("Getting AccessHostList. Handle: " << m_widgetHandle);
389 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
391 ScopedTransaction transaction(&WrtDatabase::interface());
392 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
394 WRT_DB_SELECT(select, WidgetAccessHost, &WrtDatabase::interface())
395 select->Where(Equals<WidgetAccessHost::app_id>(m_widgetHandle));
396 std::list<WidgetAccessHost::host::ColumnType> values =
397 select->GetValueList<WidgetAccessHost::host>();
400 ret.push_back(DPL::ToUTF8String(*it));
402 transaction.Commit();
405 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get access host list")
408 bool WidgetDAOReadOnly::getAccessNetworkMode() const
410 //TODO there is no column access_network
411 //it was removed in "Widget localization overhaul
415 DbWidgetHandleList WidgetDAOReadOnly::getHandleList()
417 LogDebug("Getting DbWidgetHandle List");
418 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
420 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
421 return select->GetValueList<WidgetInfo::app_id>();
423 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get handle list")
426 TizenAppIdList WidgetDAOReadOnly::getTizenAppidList()
428 LogDebug("Getting Pkgname List ");
429 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
431 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
432 return select->GetValueList<WidgetInfo::tizen_appid>();
434 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get Pkgname list")
437 TizenPkgIdList WidgetDAOReadOnly::getTizenPkgidList()
439 LogDebug("Getting Pkgid List ");
440 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
442 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
443 return select->GetValueList<WidgetInfo::tizen_pkgid>();
445 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get Pkgid list")
448 DbWidgetDAOReadOnlyList WidgetDAOReadOnly::getWidgetList()
450 LogDebug("Getting DbWidget List");
451 DbWidgetDAOReadOnlyList list;
452 FOREACH(iterator, getHandleList()) {
453 list.push_back(WidgetDAOReadOnlyPtr(new WidgetDAOReadOnly(*iterator)));
458 bool WidgetDAOReadOnly::isWidgetInstalled(DbWidgetHandle handle)
460 LogDebug("Checking if widget exist. Handle: " << handle);
461 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
463 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
464 select->Where(Equals<WidgetInfo::app_id>(handle));
466 WidgetInfo::Select::RowList rows = select->GetRowList();
468 return !rows.empty();
470 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check if widget exist")
473 bool WidgetDAOReadOnly::isWidgetInstalled(const TizenAppId &tzAppId)
475 LogDebug("Checking if widget exist. tizen app id" << tzAppId);
476 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
478 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
479 select->Where(Equals<WidgetInfo::tizen_appid>(tzAppId));
481 WidgetInfo::Select::RowList rows = select->GetRowList();
483 return !rows.empty();
485 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check if widget exist")
488 ExternalLocationList WidgetDAOReadOnly::getWidgetExternalLocations() const
490 LogDebug("Getting WidgetExtranalFiles List");
491 ExternalLocationList result;
492 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
494 WRT_DB_SELECT(select, WidgetExternalLocations, &WrtDatabase::interface());
495 select->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
496 WidgetExternalLocations::Select::RowList rows = select->GetRowList();
499 result.push_back(DPL::ToUTF8String(it->Get_path()));
502 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get handle list")
506 CertificateChainList WidgetDAOReadOnly::getWidgetCertificate(
507 CertificateSource source) const
509 WRT_DB_SELECT(select, WidgetCertificate, &WrtDatabase::interface())
512 Equals<WidgetCertificate::app_id>(m_widgetHandle),
513 Equals<WidgetCertificate::cert_source>(source)));
515 std::list<WidgetCertificate::Row> chainList = select->GetRowList();
517 CertificateChainList result;
519 FOREACH(iter, chainList)
520 result.push_back(DPL::ToUTF8String(iter->Get_encoded_chain()));
524 DbWidgetSize WidgetDAOReadOnly::getPreferredSize() const
526 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
529 size.width = row.Get_widget_width();
530 size.height = row.Get_widget_height();
532 LogDebug("Return size wxh = " <<
533 (!!size.width ? *size.width : -1) << " x " <<
534 (!!size.height ? *size.height : -1));
539 WidgetType WidgetDAOReadOnly::getWidgetType() const
541 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
542 DPL::OptionalInt result = row.Get_widget_type();
543 return WidgetType(static_cast<AppType>(*result));
546 WidgetGUID WidgetDAOReadOnly::getGUID() const
548 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
549 return row.Get_widget_id();
552 DPL::OptionalString WidgetDAOReadOnly::getTizenAppId() const
554 return DPL::OptionalString(getTzAppId());
557 DPL::OptionalString WidgetDAOReadOnly::getDefaultlocale() const
559 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
560 return row.Get_defaultlocale();
563 DPL::Optional<DPL::String> WidgetDAOReadOnly::getVersion() const
565 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
566 return row.Get_widget_version();
569 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorName() const
571 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
572 return row.Get_author_name();
575 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorEmail() const
577 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
578 return row.Get_author_email();
581 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorHref() const
583 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
584 return row.Get_author_href();
587 DPL::Optional<DPL::String> WidgetDAOReadOnly::getMinimumWacVersion() const
589 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
590 return row.Get_min_version();
593 std::string WidgetDAOReadOnly::getShareHref() const
595 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
597 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
598 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
599 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
602 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
603 "Cannot find widget. Handle: " << m_widgetHandle);
606 DPL::Optional<DPL::String> value = rows.front().Get_share_href();
607 std::string ret = "";
608 if (!value.IsNull()) {
609 ret = DPL::ToUTF8String(*value);
613 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get share HREF")
616 bool WidgetDAOReadOnly::getBackSupported() const
618 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
619 return row.Get_back_supported();
622 bool WidgetDAOReadOnly::isRecognized() const
624 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
625 DPL::OptionalInt result = row.Get_recognized();
626 if (result.IsNull()) {
629 return static_cast<bool>(*result);
632 bool WidgetDAOReadOnly::isDistributorSigned() const
634 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
635 DPL::OptionalInt result = row.Get_distributor_signed();
636 if (result.IsNull()) {
639 return static_cast<bool>(*result);
642 bool WidgetDAOReadOnly::isTrusted() const
645 // widget with verified distributor signature is trusted
646 return isDistributorSigned();
649 DPL::OptionalString WidgetDAOReadOnly::getCspPolicy() const
651 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
652 return row.Get_csp_policy();
655 DPL::OptionalString WidgetDAOReadOnly::getCspPolicyReportOnly() const
657 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
658 return row.Get_csp_policy_report_only();
661 bool WidgetDAOReadOnly::getWebkitPluginsRequired() const
663 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
664 DPL::OptionalInt ret = row.Get_webkit_plugins_required();
666 if (ret.IsNull() || *ret == 0) {
668 } else { return true;
672 time_t WidgetDAOReadOnly::getInstallTime() const
674 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
676 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
677 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
679 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
681 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
682 "Cannot find widget. Handle: " << m_widgetHandle);
685 return static_cast<time_t>(*rows.front().Get_install_time());
687 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get widdget install time")
690 DPL::OptionalString WidgetDAOReadOnly::getSplashImgSrc() const
692 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
694 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
695 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
697 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
699 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
700 "Cannot find widget. Handle: " << m_widgetHandle);
703 DPL::OptionalString value = rows.front().Get_splash_img_src();
704 if (value.IsNull()) {
705 return DPL::OptionalString::Null;
708 return DPL::OptionalString(getPath() + *value);
710 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get splash image path")
713 WidgetDAOReadOnly::WidgetLocalizedIconList WidgetDAOReadOnly::
714 getLocalizedIconList() const
716 //TODO check widget existance??
717 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
719 WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
720 select->Where(Equals<WidgetLocalizedIcon::app_id>(m_widgetHandle));
722 std::list<WidgetLocalizedIcon::Row> list =
723 select->GetRowList();
724 WidgetLocalizedIconList ret;
727 WidgetLocalizedIconRow icon = { it->Get_app_id(),
729 it->Get_widget_locale() };
734 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get icon data")
737 WidgetDAOReadOnly::WidgetIconList WidgetDAOReadOnly::getIconList() const
739 //TODO check widget existance
740 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
742 WRT_DB_SELECT(select, wrt::WidgetIcon, &WrtDatabase::interface())
743 select->Where(Equals<wrt::WidgetIcon::app_id>(m_widgetHandle));
744 select->OrderBy(DPL::TypeListDecl<OrderingAscending<wrt::WidgetIcon::
747 std::list<WidgetIcon::Row> list =
748 select->GetRowList();
752 WidgetIconRow icon = { it->Get_icon_id(),
755 it->Get_icon_width(),
756 it->Get_icon_height() };
761 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get icon data")
764 WidgetDAOReadOnly::LocalizedStartFileList WidgetDAOReadOnly::
765 getLocalizedStartFileList() const
767 //TODO check widget existance
768 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
770 WRT_DB_SELECT(select, WidgetLocalizedStartFile, &WrtDatabase::interface())
771 select->Where(Equals<WidgetLocalizedStartFile::app_id>(
773 select->OrderBy("start_file_id ASC");
775 std::list<WidgetLocalizedStartFile::Row> list =
776 select->GetRowList();
777 LocalizedStartFileList ret;
780 WidgetLocalizedStartFileRow file = { it->Get_start_file_id(),
782 it->Get_widget_locale(),
784 it->Get_encoding() };
789 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get start file list data")
792 WidgetDAOReadOnly::WidgetStartFileList WidgetDAOReadOnly::getStartFileList()
795 //TODO check widget existance
796 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
798 WRT_DB_SELECT(select, WidgetStartFile, &WrtDatabase::interface())
799 select->Where(Equals<WidgetStartFile::app_id>(m_widgetHandle));
800 select->OrderBy("start_file_id ASC");
802 std::list<WidgetStartFile::Row> list =
803 select->GetRowList();
804 WidgetStartFileList ret;
807 WidgetStartFileRow file = { it->Get_start_file_id(),
814 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get start file list data")
817 WindowModeList WidgetDAOReadOnly::getWindowModes() const
819 //TODO check widget existance
820 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
822 WRT_DB_SELECT(select, WidgetWindowModes, &WrtDatabase::interface())
823 select->Where(Equals<WidgetWindowModes::app_id>(m_widgetHandle));
825 return select->GetValueList<WidgetWindowModes::window_mode>();
827 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get window modes")
830 std::string WidgetDAOReadOnly::getBaseFolder() const
832 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
833 DPL::Optional<DPL::String> ret = row.Get_base_folder();
834 std::string baseFolder;
836 baseFolder = DPL::ToUTF8String(*ret);
839 if (!baseFolder.empty()) {
846 WidgetCertificateDataList WidgetDAOReadOnly::getCertificateDataList() const
848 //TODO check widget existance
849 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
851 WRT_DB_SELECT(select,
852 WidgetCertificateFingerprint,
853 &WrtDatabase::interface())
854 select->Where(Equals<WidgetCertificateFingerprint::app_id>(
856 select->OrderBy("chainid");
857 WidgetCertificateFingerprint::Select::RowList rows =
858 select->GetRowList();
860 WidgetCertificateDataList outlCertificateData;
863 WidgetCertificateData data;
866 static_cast <WidgetCertificateData::Owner>(it->Get_owner());
868 static_cast <WidgetCertificateData::Type>(it->Get_type());
869 data.chainId = it->Get_chainid();
870 DPL::Optional<DPL::String> md5 = it->Get_md5_fingerprint();
871 data.strMD5Fingerprint =
872 md5.IsNull() ? "" : DPL::ToUTF8String(*md5);
873 DPL::Optional<DPL::String> sha1 = it->Get_sha1_fingerprint();
874 data.strSHA1Fingerprint =
875 sha1.IsNull() ? "" : DPL::ToUTF8String(*sha1);
876 DPL::Optional<DPL::String> cname = it->Get_common_name();
878 cname.IsNull() ? DPL::FromUTF8String("") : *cname;
880 outlCertificateData.push_back(data);
882 return outlCertificateData;
884 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get fingerprint list")
887 FingerPrintList WidgetDAOReadOnly::getKeyFingerprints(
888 WidgetCertificateData::Owner owner,
889 WidgetCertificateData::Type type) 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(And(And(
898 Equals<WidgetCertificateFingerprint::app_id>(
900 Equals<WidgetCertificateFingerprint::owner>(owner)),
901 Equals<WidgetCertificateFingerprint::type>(type)));
903 WidgetCertificateFingerprint::Select::RowList rows =
904 select->GetRowList();
906 FingerPrintList keys;
909 DPL::Optional<DPL::String> sha1 = it->Get_sha1_fingerprint();
910 if (!sha1.IsNull()) {
911 keys.push_back(DPL::ToUTF8String(*sha1));
913 DPL::Optional<DPL::String> md5 = it->Get_md5_fingerprint();
915 keys.push_back(DPL::ToUTF8String(*md5));
920 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get fingerprint list")
923 WidgetCertificateCNList WidgetDAOReadOnly::getKeyCommonNameList(
924 WidgetCertificateData::Owner owner,
925 WidgetCertificateData::Type type) const
927 //TODO check widget existance
928 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
930 WRT_DB_SELECT(select,
931 WidgetCertificateFingerprint,
932 &WrtDatabase::interface())
933 select->Where(And(And(
934 Equals<WidgetCertificateFingerprint::app_id>(
936 Equals<WidgetCertificateFingerprint::owner>(owner)),
937 Equals<WidgetCertificateFingerprint::type>(type)));
939 WidgetCertificateFingerprint::Select::RowList rows =
940 select->GetRowList();
942 WidgetCertificateCNList out;
945 DPL::Optional<DPL::String> cname = it->Get_common_name();
946 out.push_back(cname.IsNull() ? "" : DPL::ToUTF8String(*cname));
950 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get key common name")
953 void WidgetDAOReadOnly::getWidgetAccessInfo(
954 WidgetAccessInfoList& outAccessInfoList) const
956 //TODO check widget existance
957 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
959 WRT_DB_SELECT(select, WidgetWARPInfo, &WrtDatabase::interface())
960 select->Where(Equals<WidgetWARPInfo::app_id>(m_widgetHandle));
962 WidgetWARPInfo::Select::RowList rows = select->GetRowList();
966 WidgetAccessInfo info;
968 info.strIRI = it->Get_iri();
969 DPL::OptionalInt access = it->Get_subdomain_access();
970 if (access.IsNull() || 0 == *access) {
971 info.bSubDomains = false;
972 } else if (1 == *access) {
973 info.bSubDomains = true;
976 outAccessInfoList.push_back(info);
979 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get accessinfo list")
982 void WidgetDAOReadOnly::getWidgetAllowNavigationInfo(
983 WidgetAllowNavigationInfoList& allowNavigationList) const
985 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
987 WRT_DB_SELECT(select, WidgetAllowNavigation, &WrtDatabase::interface())
988 select->Where(Equals<WidgetAllowNavigation::app_id>(m_widgetHandle));
989 WidgetAllowNavigation::Select::RowList rows = select->GetRowList();
992 WidgetAllowNavigationInfo info;
993 info.scheme = it->Get_scheme();
994 info.host = it->Get_host();
995 allowNavigationList.push_back(info);
998 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get allow-navigation info list")
1001 LanguageTags WidgetDAOReadOnly::getLanguageTags() const
1003 //TODO check widget existance
1004 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1006 WRT_DB_SELECT(select, LocalizedWidgetInfo, &WrtDatabase::interface())
1007 select->Where(Equals<LocalizedWidgetInfo::app_id>(m_widgetHandle));
1008 return select->GetValueList<LocalizedWidgetInfo::widget_locale>();
1010 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get language tags")
1013 LanguageTags WidgetDAOReadOnly::getIconLanguageTags() const
1015 //TODO check widget existance
1016 WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
1017 select->Where(Equals<WidgetLocalizedIcon::app_id>(m_widgetHandle));
1019 return select->GetValueList<WidgetLocalizedIcon::widget_locale>();
1022 std::string WidgetDAOReadOnly::getCookieDatabasePath() const
1024 using namespace WrtDB::WidgetConfig;
1025 std::ostringstream path;
1027 TizenAppId tzAppId = getTzAppId();
1029 path << GetWidgetPersistentStoragePath(tzAppId);
1031 path << GlobalConfig::GetCookieDatabaseFile();
1036 std::string WidgetDAOReadOnly::getPrivateLocalStoragePath() const
1038 std::ostringstream path;
1039 TizenAppId tzPkgId = getTizenPkgId();
1040 path << WidgetConfig::GetWidgetWebLocalStoragePath(tzPkgId);
1046 void WidgetDAOReadOnly::getWidgetSettings(
1047 WidgetSettings& outWidgetSettings) const
1049 //TODO check widget existance
1050 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1052 WRT_DB_SELECT(select, SettingsList, &WrtDatabase::interface())
1053 select->Where(Equals<SettingsList::appId>(m_widgetHandle));
1055 SettingsList::Select::RowList rows = select->GetRowList();
1061 info.settingName = it->Get_settingName();
1062 info.settingValue = it->Get_settingValue();
1063 outWidgetSettings.push_back(info);
1066 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get settings list")
1069 void WidgetDAOReadOnly::getAppControlList(
1070 WidgetAppControlList& outAppControlList) const
1072 LogDebug("Getting getAppControlList. Handle: " << m_widgetHandle);
1073 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1075 ScopedTransaction transaction(&WrtDatabase::interface());
1076 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
1078 WRT_DB_SELECT(select, AppControlInfo, &WrtDatabase::interface())
1079 select->Where(Equals<AppControlInfo::app_id>(m_widgetHandle));
1081 AppControlInfo::Select::RowList rows = select->GetRowList();
1084 LogDebug("AppControl list is empty. Handle: " <<
1089 WidgetAppControl ret;
1090 ret.src = it->Get_src();
1091 ret.operation = it->Get_operation();
1092 ret.uri = it->Get_uri();
1093 ret.mime = it->Get_mime();
1094 ret.disposition = static_cast<WidgetAppControl::Disposition>(it->Get_disposition());
1095 ret.index = it->Get_execute_index();
1096 outAppControlList.push_back(ret);
1099 transaction.Commit();
1101 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get AppControl list")
1104 PackagingType WidgetDAOReadOnly::getPackagingType() const
1106 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
1107 DPL::OptionalInt result = row.Get_pkg_type();
1108 return PackagingType(static_cast<PkgType>(*result));
1111 void WidgetDAOReadOnly::getEncryptedFileList(EncryptedFileList& filesList)
1114 //TODO check widget existance
1115 WRT_DB_SELECT(select, EncryptedResourceList, &WrtDatabase::interface())
1116 select->Where(Equals<EncryptedResourceList::app_id>(m_widgetHandle));
1118 typedef std::list<EncryptedResourceList::Row> RowList;
1119 RowList list = select->GetRowList();
1122 EncryptedFileInfo info;
1123 info.fileName = it->Get_resource();
1124 info.fileSize = it->Get_size();
1125 filesList.insert(info);
1129 DPL::OptionalString WidgetDAOReadOnly::getBackgroundPage() const
1131 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1133 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
1134 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
1136 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
1138 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
1139 "Cannot find widget. Handle: " << m_widgetHandle);
1142 return rows.front().Get_background_page();
1144 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get background page")
1147 TizenPkgId WidgetDAOReadOnly::generatePkgId()
1149 std::string allowed("0123456789"
1150 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1151 "abcdefghijklmnopqrstuvwxyz");
1153 pkgId.resize(MAX_TIZENID_LENGTH);
1155 for (int i = 0; i < MAX_TIZENID_LENGTH; ++i) {
1156 pkgId[i] = allowed[rand_r(&seed) % allowed.length()];
1158 } while (isWidgetInstalled(pkgId));
1162 SettingsType WidgetDAOReadOnly::getSecurityPopupUsage(void) const
1164 WidgetSecuritySettingsRow row =
1165 getWidgetSecuritySettingsRow(m_widgetHandle);
1166 DPL::OptionalInt result = row.Get_security_popup_usage();
1167 return static_cast<SettingsType>(*result);
1170 SettingsType WidgetDAOReadOnly::getGeolocationUsage(void) const
1172 WidgetSecuritySettingsRow row =
1173 getWidgetSecuritySettingsRow(m_widgetHandle);
1174 DPL::OptionalInt result = row.Get_geolocation_usage();
1175 return static_cast<SettingsType>(*result);
1178 SettingsType WidgetDAOReadOnly::getWebNotificationUsage(void) const
1180 WidgetSecuritySettingsRow row =
1181 getWidgetSecuritySettingsRow(m_widgetHandle);
1182 DPL::OptionalInt result = row.Get_web_notification_usage();
1183 return static_cast<SettingsType>(*result);
1186 SettingsType WidgetDAOReadOnly::getWebDatabaseUsage(void) const
1188 WidgetSecuritySettingsRow row =
1189 getWidgetSecuritySettingsRow(m_widgetHandle);
1190 DPL::OptionalInt result = row.Get_web_database_usage();
1191 return static_cast<SettingsType>(*result);
1194 DPL::OptionalString WidgetDAOReadOnly::getWidgetInstalledPath() const
1196 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1198 using namespace DPL::DB::ORM;
1199 using namespace DPL::DB::ORM::wrt;
1200 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
1201 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
1203 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
1205 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
1206 "Cannot find widget. Handle: " << m_widgetHandle);
1209 return rows.front().Get_installed_path();
1211 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get widdget installed path")
1214 TizenPkgId WidgetDAOReadOnly::getTizenPkgId() const
1216 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
1217 return row.Get_tizen_pkgid();
1220 PrivilegeList WidgetDAOReadOnly::getWidgetPrivilege() const
1222 //TODO check widget existance
1223 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1225 WRT_DB_SELECT(select, WidgetPrivilege, &WrtDatabase::interface())
1226 select->Where(Equals<WidgetPrivilege::app_id>(m_widgetHandle));
1228 return select->GetValueList<WidgetPrivilege::name>();
1230 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get PrivilegeList")
1233 WidgetSecurityModelVersion WidgetDAOReadOnly::getSecurityModelVersion() const
1235 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
1236 DPL::OptionalInt result = row.Get_security_model_version();
1237 return static_cast<WidgetSecurityModelVersion>(*result);
1240 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1241 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END
1242 #undef CHECK_WIDGET_EXISTENCE
1243 } // namespace WrtDB