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>
42 //TODO in current solution in each getter there exists a check
43 //"IsWidgetInstalled". Maybe it should be verified, if it could be done
44 //differently (check in WidgetDAOReadOnly constructor)
46 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
48 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
49 Catch(DPL::DB::SqlConnection::Exception::Base) { \
51 ReThrowMsg(WidgetDAOReadOnly::Exception::DatabaseError, \
55 #define CHECK_WIDGET_EXISTENCE(macro_transaction, macro_handle) \
56 if (!WidgetDAOReadOnly::isWidgetInstalled(macro_handle)) \
58 macro_transaction.Commit(); \
59 LogWarning("Cannot find widget. Handle: " << macro_handle); \
60 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist, \
61 "Cannot find widget. Handle: " << macro_handle); \
65 typedef DPL::DB::ORM::wrt::WidgetInfo::Row WidgetInfoRow;
66 typedef DPL::DB::ORM::wrt::WidgetFeature::widget_feature_id::ColumnType
68 typedef DPL::DB::ORM::wrt::WidgetSecuritySettings::Row
69 WidgetSecuritySettingsRow;
73 using namespace DPL::DB::ORM;
74 using namespace DPL::DB::ORM::wrt;
76 WidgetInfoRow getWidgetInfoRow(int widgetHandle)
78 LogDebug("Getting WidgetInfo row. Handle: " << widgetHandle);
79 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
81 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
82 select->Where(Equals<WidgetInfo::app_id>(widgetHandle));
84 WidgetInfo::Select::RowList rows = select->GetRowList();
86 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
87 "Cannot find widget. Handle: " << widgetHandle);
91 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in GetWidgetInfoRow")
94 WidgetSecuritySettingsRow getWidgetSecuritySettingsRow(int widgetHandle)
96 LogDebug("Getting WidgetSecuritySettings row. Handle: " << widgetHandle);
97 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
99 using namespace DPL::DB::ORM;
100 using namespace DPL::DB::ORM::wrt;
101 WRT_DB_SELECT(select, WidgetSecuritySettings, &WrtDatabase::interface())
102 select->Where(Equals<WidgetSecuritySettings::app_id>(widgetHandle));
104 WidgetSecuritySettings::Select::RowList rows = select->GetRowList();
106 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
107 "Cannot find widget. Handle: " << widgetHandle);
111 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getWidgetSecuritySettingsRow")
114 const int MAX_TIZENID_LENGTH = 10;
116 WidgetPkgName getPkgNameByHandle(const DbWidgetHandle handle)
118 LogDebug("Getting WidgetPkgName by DbWidgetHandle: " << handle);
120 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
122 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
123 select->Where(Equals<WidgetInfo::app_id>(handle));
124 WidgetInfo::Select::RowList rowList = select->GetRowList();
126 if (rowList.empty()) {
127 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
128 "Failed to get widget by package name");
130 DPL::OptionalString pkgname = rowList.front().Get_pkgname();
131 if(pkgname.IsNull()){
132 ThrowMsg(WidgetDAOReadOnly::Exception::DatabaseError,
133 "PkgName is null for this widget");
138 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
140 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
141 "Failed to get widget by handle");
146 IWacSecurity::~IWacSecurity()
150 WidgetDAOReadOnly::WidgetDAOReadOnly(DbWidgetHandle widgetHandle) :
151 m_widgetHandle(widgetHandle)
155 WidgetDAOReadOnly::WidgetDAOReadOnly(DPL::OptionalString widgetGUID) :
156 m_widgetHandle(WidgetDAOReadOnly::getHandle(widgetGUID))
160 WidgetDAOReadOnly::WidgetDAOReadOnly(DPL::String pkgName) :
161 m_widgetHandle(WidgetDAOReadOnly::getHandle(pkgName))
166 WidgetDAOReadOnly::~WidgetDAOReadOnly()
170 DbWidgetHandle WidgetDAOReadOnly::getHandle() const
172 return m_widgetHandle;
175 DbWidgetHandle WidgetDAOReadOnly::getHandle(const WidgetGUID GUID)
177 LogDebug("Getting WidgetHandle by GUID [" << GUID << "]");
179 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
181 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
182 select->Where(Equals<WidgetInfo::widget_id>(GUID));
183 WidgetInfo::Select::RowList rowList = select->GetRowList();
185 if (rowList.empty()) {
186 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
187 "Failed to get widget by guid");
189 return rowList.front().Get_app_id();
191 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
193 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
194 "Failed to get widget by guid");
197 DbWidgetHandle WidgetDAOReadOnly::getHandle(const DPL::String pkgName)
199 LogDebug("Getting WidgetHandle by Package Name [" << pkgName << "]");
201 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
203 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
204 select->Where(Equals<WidgetInfo::pkgname>(pkgName));
205 WidgetInfo::Select::RowList rowList = select->GetRowList();
207 if (rowList.empty()) {
208 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
209 "Failed to get widget by package name");
211 return rowList.front().Get_app_id();
213 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle")
215 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
216 "Failed to get widget by package name");
219 WidgetPkgName WidgetDAOReadOnly::getPkgName() const
221 return getPkgNameByHandle(m_widgetHandle);
224 WidgetPkgName WidgetDAOReadOnly::getPkgName(const WidgetGUID GUID)
226 return getPkgNameByHandle(getHandle(GUID));
229 WidgetPkgName WidgetDAOReadOnly::getPkgName(const DbWidgetHandle handle)
231 return getPkgNameByHandle(handle);
234 PropertyDAOReadOnly::WidgetPropertyKeyList
235 WidgetDAOReadOnly::getPropertyKeyList() const
237 return PropertyDAOReadOnly::GetPropertyKeyList(getPkgName());
240 PropertyDAOReadOnly::WidgetPreferenceList
241 WidgetDAOReadOnly::getPropertyList() const
243 return PropertyDAOReadOnly::GetPropertyList(getPkgName());
246 PropertyDAOReadOnly::WidgetPropertyValue WidgetDAOReadOnly::getPropertyValue(
247 const PropertyDAOReadOnly::WidgetPropertyKey &key) const
249 return PropertyDAOReadOnly::GetPropertyValue(getPkgName(), key);
252 DPL::OptionalInt WidgetDAOReadOnly::checkPropertyReadFlag(
253 const PropertyDAOReadOnly::WidgetPropertyKey &key) const
255 return PropertyDAOReadOnly::CheckPropertyReadFlag(getPkgName(), key);
258 DPL::String WidgetDAOReadOnly::getPath() const
260 DPL::String path = *getWidgetInstalledPath();
261 DPL::String srcPath = DPL::FromUTF8String(GlobalConfig::GetWidgetSrcPath());
263 path += srcPath + L"/";
268 DPL::String WidgetDAOReadOnly::getFullPath() const
270 return L"file://" + getPath();
274 WidgetDAOReadOnly::getLocalizedInfo(const DPL::String& languageTag)
277 LogDebug("Getting Localized Info. Handle: " << m_widgetHandle);
278 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
280 ScopedTransaction transaction(&WrtDatabase::interface());
281 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
283 WRT_DB_SELECT(select, LocalizedWidgetInfo, &WrtDatabase::interface())
285 And(Equals<LocalizedWidgetInfo::app_id>(m_widgetHandle),
286 Equals<LocalizedWidgetInfo::widget_locale>(languageTag)));
287 LocalizedWidgetInfo::Row info = select->GetSingleRow();
288 WidgetLocalizedInfo result;
290 result.name = info.Get_widget_name();
291 result.shortName = info.Get_widget_shortname();
292 result.description = info.Get_widget_description();
293 result.license = info.Get_widget_license();
294 result.licenseHref = info.Get_widget_license_href();
296 transaction.Commit();
299 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get localized info")
302 DbWidgetFeatureSet WidgetDAOReadOnly::getFeaturesList() const
304 LogDebug("Getting FeaturesList. Handle: " << m_widgetHandle);
305 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
307 ScopedTransaction transaction(&WrtDatabase::interface());
308 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
310 WRT_DB_SELECT(select, WidgetFeature, &WrtDatabase::interface())
311 select->Where(Equals<WidgetFeature::app_id>(m_widgetHandle));
313 DbWidgetFeatureSet resultSet;
314 typedef std::list<WidgetFeature::Row> RowList;
315 RowList list = select->GetRowList();
317 for (RowList::iterator i = list.begin(); i != list.end(); ++i) {
318 DbWidgetFeature feature;
319 feature.name = i->Get_name();
320 feature.required = i->Get_required();
321 feature.rejected = i->Get_rejected();
322 feature.params = getFeatureParams(i->Get_widget_feature_id());
323 FeatureDAOReadOnly featureDao(DPL::ToUTF8String(i->Get_name()));
324 feature.pluginId = featureDao.GetPluginHandle();
325 resultSet.insert(feature);
327 transaction.Commit();
330 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get features list")
333 WidgetParamMap WidgetDAOReadOnly::getFeatureParams(int id)
335 WidgetFeatureId widgetFeatureId(id);
336 LogDebug("Getting feature Params. featureId: " << widgetFeatureId);
337 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
339 WRT_DB_SELECT(select, FeatureParam, &WrtDatabase::interface())
340 select->Where(Equals<FeatureParam::widget_feature_id>(
343 WidgetParamMap resultMap;
344 typedef std::list<FeatureParam::Row> RowList;
345 RowList list = select->GetRowList();
348 resultMap.insert(std::make_pair(i->Get_name(), i->Get_value()));
352 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get feature params")
355 bool WidgetDAOReadOnly::hasFeature(const std::string& featureName) const
358 "Checking if widget has feature: " << featureName << ". Handle: " <<
360 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
362 ScopedTransaction transaction(&WrtDatabase::interface());
363 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
365 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
366 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
367 Equals<wrt::WidgetFeature::name>(
368 DPL::FromUTF8String(featureName))));
370 wrt::WidgetFeature::Select::RowList rows = select->GetRowList();
371 transaction.Commit();
372 return !rows.empty();
374 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check for feature")
377 HostList WidgetDAOReadOnly::getAccessHostList() const
379 LogDebug("Getting AccessHostList. Handle: " << m_widgetHandle);
380 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
382 ScopedTransaction transaction(&WrtDatabase::interface());
383 CHECK_WIDGET_EXISTENCE(transaction, m_widgetHandle)
385 WRT_DB_SELECT(select, WidgetAccessHost, &WrtDatabase::interface())
386 select->Where(Equals<WidgetAccessHost::app_id>(m_widgetHandle));
387 std::list<WidgetAccessHost::host::ColumnType> values =
388 select->GetValueList<WidgetAccessHost::host>();
391 ret.push_back(DPL::ToUTF8String(*it));
393 transaction.Commit();
396 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get access host list")
399 bool WidgetDAOReadOnly::getAccessNetworkMode() const
401 //TODO there is no column access_network
402 //it was removed in "Widget localization overhaul
406 DbWidgetHandleList WidgetDAOReadOnly::getHandleList()
408 LogDebug("Getting DbWidgetHandle List");
409 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
411 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
412 return select->GetValueList<WidgetInfo::app_id>();
414 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get handle list")
417 WidgetPkgNameList WidgetDAOReadOnly::getPkgnameList()
419 LogDebug("Getting Pkgname List");
420 WidgetPkgNameList_TEMPORARY_API pkgnameList_TEMPORARY_API = getPkgnameList_TEMPORARY_API();
421 WidgetPkgNameList pkgnameList;
422 FOREACH(it,pkgnameList_TEMPORARY_API ){
423 pkgnameList.push_back(DPL::Optional<WidgetPkgName>(*it));
428 WidgetPkgNameList_TEMPORARY_API WidgetDAOReadOnly::getPkgnameList_TEMPORARY_API()
430 LogDebug("Getting Pkgname List ");
431 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
433 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
434 return select->GetValueList<WidgetInfo::pkgname>();
436 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get Pkgname list")
439 DbWidgetDAOReadOnlyList WidgetDAOReadOnly::getWidgetList()
441 LogDebug("Getting DbWidget List");
442 DbWidgetDAOReadOnlyList list;
443 FOREACH(iterator, getHandleList()) {
444 list.push_back(WidgetDAOReadOnlyPtr(new WidgetDAOReadOnly(*iterator)));
449 bool WidgetDAOReadOnly::isWidgetInstalled(DbWidgetHandle handle)
451 LogDebug("Checking if widget exist. Handle: " << handle);
452 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
454 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
455 select->Where(Equals<WidgetInfo::app_id>(handle));
457 WidgetInfo::Select::RowList rows = select->GetRowList();
459 return !rows.empty();
461 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check if widget exist")
464 bool WidgetDAOReadOnly::isWidgetInstalled(const WidgetPkgName & pkgName)
466 LogDebug("Checking if widget exist. package name " << pkgName);
467 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
469 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
470 select->Where(Equals<WidgetInfo::pkgname>(pkgName));
472 WidgetInfo::Select::RowList rows = select->GetRowList();
474 return !rows.empty();
476 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check if widget exist")
479 ExternalLocationList WidgetDAOReadOnly::getWidgetExternalLocations() const
481 LogDebug("Getting WidgetExtranalFiles List");
482 ExternalLocationList result;
483 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
485 WRT_DB_SELECT(select, WidgetExternalLocations, &WrtDatabase::interface());
486 select->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
487 WidgetExternalLocations::Select::RowList rows = select->GetRowList();
490 result.push_back(DPL::ToUTF8String(it->Get_path()));
493 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get handle list")
497 CertificateChainList WidgetDAOReadOnly::getWidgetCertificate(
498 CertificateSource source) const
500 WRT_DB_SELECT(select, WidgetCertificate, &WrtDatabase::interface())
503 Equals<WidgetCertificate::app_id>(m_widgetHandle),
504 Equals<WidgetCertificate::cert_source>(source)));
506 std::list<WidgetCertificate::Row> chainList = select->GetRowList();
508 CertificateChainList result;
510 FOREACH(iter, chainList)
511 result.push_back(DPL::ToUTF8String(iter->Get_encoded_chain()));
515 DbWidgetSize WidgetDAOReadOnly::getPreferredSize() const
517 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
520 size.width = row.Get_widget_width();
521 size.height = row.Get_widget_height();
523 LogDebug("Return size wxh = " <<
524 (!!size.width ? *size.width : -1) << " x " <<
525 (!!size.height ? *size.height : -1));
530 WidgetType WidgetDAOReadOnly::getWidgetType() const
532 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
533 DPL::OptionalInt result = row.Get_widget_type();
534 return WidgetType(static_cast<AppType>(*result));
537 WidgetGUID WidgetDAOReadOnly::getGUID() const
539 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
540 return row.Get_widget_id();
543 DPL::OptionalString WidgetDAOReadOnly::getPkgname() const
545 return DPL::OptionalString(getPkgname_TEMPORARY_API());
548 WidgetPkgName WidgetDAOReadOnly::getPkgname_TEMPORARY_API() const
550 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
551 return row.Get_pkgname();
554 DPL::OptionalString WidgetDAOReadOnly::getDefaultlocale() const
556 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
557 return row.Get_defaultlocale();
560 DPL::Optional<DPL::String> WidgetDAOReadOnly::getVersion() const
562 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
563 return row.Get_widget_version();
566 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorName() const
568 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
569 return row.Get_author_name();
572 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorEmail() const
574 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
575 return row.Get_author_email();
578 DPL::Optional<DPL::String> WidgetDAOReadOnly::getAuthorHref() const
580 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
581 return row.Get_author_href();
584 DPL::Optional<DPL::String> WidgetDAOReadOnly::getMinimumWacVersion() const
586 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
587 return row.Get_min_version();
590 std::string WidgetDAOReadOnly::getShareHref() const
592 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
594 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
595 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
596 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
599 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
600 "Cannot find widget. Handle: " << m_widgetHandle);
603 DPL::Optional<DPL::String> value = rows.front().Get_share_href();
604 std::string ret = "";
605 if (!value.IsNull()) {
606 ret = DPL::ToUTF8String(*value);
610 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get share HREF")
613 bool WidgetDAOReadOnly::getBackSupported() const
615 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
616 return row.Get_back_supported();
619 bool WidgetDAOReadOnly::isRecognized() const
621 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
622 DPL::OptionalInt result = row.Get_recognized();
623 if (result.IsNull()) {
626 return static_cast<bool>(*result);
629 bool WidgetDAOReadOnly::isWacSigned() const
631 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
632 DPL::OptionalInt result = row.Get_wac_signed();
633 if (result.IsNull()) {
636 return static_cast<bool>(*result);
639 bool WidgetDAOReadOnly::isDistributorSigned() const
641 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
642 DPL::OptionalInt result = row.Get_distributor_signed();
643 if (result.IsNull()) {
646 return static_cast<bool>(*result);
649 bool WidgetDAOReadOnly::isTrusted() const
652 // widget with verified distributor signature is trusted
653 return isDistributorSigned();
656 bool WidgetDAOReadOnly::isTestWidget() const
659 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
660 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
662 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
664 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
665 "Cannot find widget. Handle: " << m_widgetHandle);
668 return static_cast<bool>(rows.front().Get_test_widget());
670 Catch(DPL::DB::SqlConnection::Exception::Base){
671 ReThrowMsg(WidgetDAOReadOnly::Exception::DatabaseError,
672 "Failed to check IsTestWidget");
676 bool WidgetDAOReadOnly::getWebkitPluginsRequired() const
678 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
679 DPL::OptionalInt ret = row.Get_webkit_plugins_required();
681 if (ret.IsNull() || *ret == 0) { return false; } else { return true; }
684 time_t WidgetDAOReadOnly::getInstallTime() const
686 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
688 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
689 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
691 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
693 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
694 "Cannot find widget. Handle: " << m_widgetHandle);
697 return static_cast<time_t>(*rows.front().Get_install_time());
699 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get widdget install time")
702 DPL::OptionalString WidgetDAOReadOnly::getSplashImgSrc() const
704 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
706 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
707 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
709 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
711 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
712 "Cannot find widget. Handle: " << m_widgetHandle);
715 DPL::OptionalString value = rows.front().Get_splash_img_src();
716 if (value.IsNull()) {
717 return DPL::OptionalString::Null;
720 return DPL::OptionalString(getPath() + *value);
722 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get splash image path")
725 WidgetDAOReadOnly::WidgetLocalizedIconList WidgetDAOReadOnly::getLocalizedIconList() const
727 //TODO check widget existance??
728 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
730 WRT_DB_SELECT(select, WidgetLocalizedIcon, &WrtDatabase::interface())
731 select->Where(Equals<WidgetLocalizedIcon::app_id>(m_widgetHandle));
733 std::list<WidgetLocalizedIcon::Row> list =
734 select->GetRowList();
735 WidgetLocalizedIconList ret;
738 WidgetLocalizedIconRow icon = {it->Get_app_id(),
740 it->Get_widget_locale()};
745 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get icon data")
748 WidgetDAOReadOnly::WidgetIconList WidgetDAOReadOnly::getIconList() const
750 //TODO check widget existance
751 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
753 WRT_DB_SELECT(select, wrt::WidgetIcon, &WrtDatabase::interface())
754 select->Where(Equals<wrt::WidgetIcon::app_id>(m_widgetHandle));
756 std::list<WidgetIcon::Row> list =
757 select->GetRowList();
761 WidgetIconRow icon = {it->Get_icon_id(),
764 it->Get_icon_width(),
765 it->Get_icon_height()};
770 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get icon data")
773 WidgetDAOReadOnly::LocalizedStartFileList WidgetDAOReadOnly::getLocalizedStartFileList() const
775 //TODO check widget existance
776 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
778 WRT_DB_SELECT(select, WidgetLocalizedStartFile, &WrtDatabase::interface())
779 select->Where(Equals<WidgetLocalizedStartFile::app_id>(
781 select->OrderBy("start_file_id ASC");
783 std::list<WidgetLocalizedStartFile::Row> list =
784 select->GetRowList();
785 LocalizedStartFileList ret;
788 WidgetLocalizedStartFileRow file = {it->Get_start_file_id(),
790 it->Get_widget_locale(),
797 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get start file list data")
800 WidgetDAOReadOnly::WidgetStartFileList WidgetDAOReadOnly::getStartFileList() const
802 //TODO check widget existance
803 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
805 WRT_DB_SELECT(select, WidgetStartFile, &WrtDatabase::interface())
806 select->Where(Equals<WidgetStartFile::app_id>(m_widgetHandle));
807 select->OrderBy("start_file_id ASC");
809 std::list<WidgetStartFile::Row> list =
810 select->GetRowList();
811 WidgetStartFileList ret;
814 WidgetStartFileRow file = {it->Get_start_file_id(),
821 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get start file list data")
824 WindowModeList WidgetDAOReadOnly::getWindowModes() const
826 //TODO check widget existance
827 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
829 WRT_DB_SELECT(select, WidgetWindowModes, &WrtDatabase::interface())
830 select->Where(Equals<WidgetWindowModes::app_id>(m_widgetHandle));
832 return select->GetValueList<WidgetWindowModes::window_mode>();
834 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get window modes")
837 std::string WidgetDAOReadOnly::getBaseFolder() const
839 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
840 DPL::Optional<DPL::String> ret = row.Get_base_folder();
841 std::string baseFolder;
843 baseFolder = DPL::ToUTF8String(*ret);
846 if (!baseFolder.empty()) {
853 WidgetCertificateDataList WidgetDAOReadOnly::getCertificateDataList() const
855 //TODO check widget existance
856 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
858 WRT_DB_SELECT(select, WidgetCertificateFingerprint, &WrtDatabase::interface())
859 select->Where(Equals<WidgetCertificateFingerprint::app_id>(
861 select->OrderBy("chainid");
862 WidgetCertificateFingerprint::Select::RowList rows =
863 select->GetRowList();
865 WidgetCertificateDataList outlCertificateData;
868 WidgetCertificateData data;
871 static_cast <WidgetCertificateData::Owner>(it->Get_owner());
873 static_cast <WidgetCertificateData::Type>(it->Get_type());
874 data.chainId = it->Get_chainid();
875 DPL::Optional<DPL::String> md5 = it->Get_md5_fingerprint();
876 data.strMD5Fingerprint =
877 md5.IsNull() ? "" : DPL::ToUTF8String(*md5);
878 DPL::Optional<DPL::String> sha1 = it->Get_sha1_fingerprint();
879 data.strSHA1Fingerprint =
880 sha1.IsNull() ? "" : DPL::ToUTF8String(*sha1);
881 DPL::Optional<DPL::String> cname = it->Get_common_name();
883 cname.IsNull() ? DPL::FromUTF8String("") : *cname;
885 outlCertificateData.push_back(data);
887 return outlCertificateData;
889 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get fingerprint list")
892 FingerPrintList WidgetDAOReadOnly::getKeyFingerprints(
893 WidgetCertificateData::Owner owner,
894 WidgetCertificateData::Type type) const
896 //TODO check widget existance
897 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
899 WRT_DB_SELECT(select, WidgetCertificateFingerprint, &WrtDatabase::interface())
900 select->Where(And(And(
901 Equals<WidgetCertificateFingerprint::app_id>(m_widgetHandle),
902 Equals<WidgetCertificateFingerprint::owner>(owner)),
903 Equals<WidgetCertificateFingerprint::type>(type)));
905 WidgetCertificateFingerprint::Select::RowList rows =
906 select->GetRowList();
908 FingerPrintList keys;
911 DPL::Optional<DPL::String> sha1 = it->Get_sha1_fingerprint();
912 if (!sha1.IsNull()) {
913 keys.push_back(DPL::ToUTF8String(*sha1));
915 DPL::Optional<DPL::String> md5 = it->Get_md5_fingerprint();
917 keys.push_back(DPL::ToUTF8String(*md5));
922 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get fingerprint list")
925 WidgetCertificateCNList WidgetDAOReadOnly::getKeyCommonNameList(
926 WidgetCertificateData::Owner owner,
927 WidgetCertificateData::Type type) const
929 //TODO check widget existance
930 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
932 WRT_DB_SELECT(select, WidgetCertificateFingerprint, &WrtDatabase::interface())
933 select->Where(And(And(
934 Equals<WidgetCertificateFingerprint::app_id>(m_widgetHandle),
935 Equals<WidgetCertificateFingerprint::owner>(owner)),
936 Equals<WidgetCertificateFingerprint::type>(type)));
938 WidgetCertificateFingerprint::Select::RowList rows =
939 select->GetRowList();
941 WidgetCertificateCNList out;
944 DPL::Optional<DPL::String> cname = it->Get_common_name();
945 out.push_back(cname.IsNull() ? "" : DPL::ToUTF8String(*cname));
949 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get key common name")
952 ResourceAttributeList WidgetDAOReadOnly::getResourceAttribute(
953 const std::string &resourceId) const
955 WRT_DB_SELECT(select, WidgetFeature, &WrtDatabase::interface())
956 select->Where(And(Equals<WidgetFeature::app_id>(m_widgetHandle),
957 Equals<WidgetFeature::name>(
958 DPL::FromUTF8String(resourceId))));
960 std::list<WidgetFeature::Row> list = select->GetRowList();
961 ResourceAttributeList result;
963 int widgetFeatureId = list.begin()->Get_widget_feature_id();
964 WidgetParamMap map = getFeatureParams(widgetFeatureId);
967 result.push_back(DPL::ToUTF8String(i->first));
972 void WidgetDAOReadOnly::getWidgetAccessInfo(
973 WidgetAccessInfoList& outAccessInfoList) const
975 //TODO check widget existance
976 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
978 WRT_DB_SELECT(select, WidgetWARPInfo, &WrtDatabase::interface())
979 select->Where(Equals<WidgetWARPInfo::app_id>(m_widgetHandle));
981 WidgetWARPInfo::Select::RowList rows = select->GetRowList();
985 WidgetAccessInfo info;
987 info.strIRI = it->Get_iri();
988 DPL::OptionalInt access = it->Get_subdomain_access();
989 if (access.IsNull() || 0 == *access) {
990 info.bSubDomains = false;
991 } else if (1 == *access) {
992 info.bSubDomains = true;
995 outAccessInfoList.push_back(info);
998 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get accessinfo 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 WidgetPkgName pkgname = getPkgname_TEMPORARY_API();
1029 path << GetWidgetPersistentStoragePath(pkgname);
1031 path << GlobalConfig::GetCookieDatabaseFile();
1036 std::string WidgetDAOReadOnly::getPrivateLocalStoragePath() const
1038 std::ostringstream path;
1039 WidgetPkgName pkgname = getPkgname_TEMPORARY_API();
1040 path << WidgetConfig::GetWidgetWebLocalStoragePath(pkgname);
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::getAppServiceList(
1070 WidgetApplicationServiceList& outAppServiceList) const
1072 LogDebug("Getting getAppServiceList. 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, ApplicationServiceInfo, &WrtDatabase::interface())
1079 select->Where(Equals<ApplicationServiceInfo::app_id>(m_widgetHandle));
1081 ApplicationServiceInfo::Select::RowList rows = select->GetRowList();
1084 LogDebug("Application Service list is empty. Handle: " <<
1089 WidgetApplicationService ret;
1090 ret.src = it->Get_src();
1091 ret.operation = it->Get_operation();
1092 ret.scheme = it->Get_scheme();
1093 ret.mime = it->Get_mime();
1094 outAppServiceList.push_back(ret);
1097 transaction.Commit();
1099 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get access host list")
1102 PackagingType WidgetDAOReadOnly::getPackagingType() const
1104 WidgetInfoRow row = getWidgetInfoRow(m_widgetHandle);
1105 DPL::OptionalInt result = row.Get_pkg_type();
1106 return PackagingType(static_cast<PkgType>(*result));
1109 void WidgetDAOReadOnly::getEncryptedFileList(EncryptedFileList& filesList) const
1111 //TODO check widget existance
1112 WRT_DB_SELECT(select, EncryptedResourceList, &WrtDatabase::interface())
1113 select->Where(Equals<EncryptedResourceList::app_id>(m_widgetHandle));
1115 typedef std::list<EncryptedResourceList::Row> RowList;
1116 RowList list = select->GetRowList();
1119 EncryptedFileInfo info;
1120 info.fileName = it->Get_resource();
1121 info.fileSize = it->Get_size();
1122 filesList.insert(info);
1126 DPL::OptionalString WidgetDAOReadOnly::getBackgroundPage() const
1128 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1130 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
1131 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
1133 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
1135 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
1136 "Cannot find widget. Handle: " << m_widgetHandle);
1139 return rows.front().Get_background_page();
1141 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get background page")
1144 WidgetPkgName WidgetDAOReadOnly::generateTizenId() {
1145 std::string allowed("0123456789"
1146 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1147 "abcdefghijklmnopqrstuvwxyz");
1148 WidgetPkgName tizenId;
1149 tizenId.resize(MAX_TIZENID_LENGTH);
1151 for (int i = 0; i < MAX_TIZENID_LENGTH; ++i) {
1152 tizenId[i] = allowed[rand() % allowed.length()];
1154 } while (isWidgetInstalled(tizenId));
1158 SettingsType WidgetDAOReadOnly::getSecurityPopupUsage(void) const
1160 WidgetSecuritySettingsRow row =
1161 getWidgetSecuritySettingsRow(m_widgetHandle);
1162 DPL::OptionalInt result = row.Get_security_popup_usage();
1163 return static_cast<SettingsType>(*result);
1166 SettingsType WidgetDAOReadOnly::getGeolocationUsage(void) const
1168 WidgetSecuritySettingsRow row =
1169 getWidgetSecuritySettingsRow(m_widgetHandle);
1170 DPL::OptionalInt result = row.Get_geolocation_usage();
1171 return static_cast<SettingsType>(*result);
1174 SettingsType WidgetDAOReadOnly::getWebNotificationUsage(void) const
1176 WidgetSecuritySettingsRow row =
1177 getWidgetSecuritySettingsRow(m_widgetHandle);
1178 DPL::OptionalInt result = row.Get_web_notification_usage();
1179 return static_cast<SettingsType>(*result);
1182 SettingsType WidgetDAOReadOnly::getWebDatabaseUsage(void) const
1184 WidgetSecuritySettingsRow row =
1185 getWidgetSecuritySettingsRow(m_widgetHandle);
1186 DPL::OptionalInt result = row.Get_web_database_usage();
1187 return static_cast<SettingsType>(*result);
1190 SettingsType WidgetDAOReadOnly::getFileSystemUsage(void) const
1192 WidgetSecuritySettingsRow row =
1193 getWidgetSecuritySettingsRow(m_widgetHandle);
1194 DPL::OptionalInt result = row.Get_file_system_usage();
1195 return static_cast<SettingsType>(*result);
1198 DPL::OptionalString WidgetDAOReadOnly::getWidgetInstalledPath() const
1200 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1202 using namespace DPL::DB::ORM;
1203 using namespace DPL::DB::ORM::wrt;
1204 WRT_DB_SELECT(select, WidgetExtendedInfo, &WrtDatabase::interface())
1205 select->Where(Equals<WidgetExtendedInfo::app_id>(m_widgetHandle));
1207 WidgetExtendedInfo::Select::RowList rows = select->GetRowList();
1209 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
1210 "Cannot find widget. Handle: " << m_widgetHandle);
1213 return rows.front().Get_installed_path();
1215 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get widdget installed path")
1217 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
1218 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END
1219 #undef CHECK_WIDGET_EXISTENCE
1221 } // namespace WrtDB