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 definition of widget dao class.
19 * @file widget_dao.cpp
20 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
21 * @author Bartosz Janiak (b.janiak@samsung.com)
22 * @author Yang Jie (jie2.yang@samsung.com)
23 * @author Koeun Choi(koeun.choi@samsung.com)
24 * @author Pawel Sikorski(p.sikorski@samsung.com)
26 * @brief This file contains the definition of Configuration.
29 #include <dpl/wrt-dao-rw/widget_dao.h>
32 #include <dpl/log/log.h>
33 #include <dpl/foreach.h>
34 #include <dpl/wrt-dao-ro/webruntime_database.h>
35 #include <dpl/wrt-dao-rw/property_dao.h>
36 #include <orm_generator_wrt.h>
37 #include <dpl/wrt-dao-ro/WrtDatabase.h>
40 //TODO in current solution in each getter there exists a check
41 //"IsWidgetInstalled". Maybe it should be verified, if it could be done
42 //differently (check in WidgetDAO constructor)
44 #define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try
46 #define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \
47 Catch(DPL::DB::SqlConnection::Exception::Base) { \
49 ReThrowMsg(WidgetDAO::Exception::DatabaseError, \
53 WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
54 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
57 WidgetDAO::WidgetDAO(DPL::String tzAppId) :
58 WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(tzAppId))
61 WidgetDAO::WidgetDAO(DbWidgetHandle handle) :
62 WidgetDAOReadOnly(handle)
65 WidgetDAO::~WidgetDAO()
68 void WidgetDAO::setTizenAppId(const DPL::OptionalString& tzAppId)
70 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
72 using namespace DPL::DB::ORM;
73 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
75 if (!isWidgetInstalled(getHandle())) {
76 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
77 "Cannot find widget. Handle: " << getHandle());
80 wrt::WidgetInfo::Row row;
81 row.Set_tizen_appid(*tzAppId);
83 WRT_DB_UPDATE(update, wrt::WidgetInfo, &WrtDatabase::interface())
85 Equals<wrt::WidgetInfo::app_id>(getHandle()));
91 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
94 void WidgetDAO::setSecurityPopupUsage(const SettingsType value)
96 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
98 using namespace DPL::DB::ORM;
99 using namespace DPL::DB::ORM::wrt;
101 ScopedTransaction transaction(&WrtDatabase::interface());
102 if (!isWidgetInstalled(getHandle())) {
103 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
104 "Cannot find widget. Handle: " << getHandle());
107 WidgetSecuritySettings::Row row;
108 row.Set_security_popup_usage(value);
110 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
111 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
115 transaction.Commit();
117 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set security popup usage")
120 void WidgetDAO::setGeolocationUsage(const SettingsType value)
122 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
124 using namespace DPL::DB::ORM;
125 using namespace DPL::DB::ORM::wrt;
127 ScopedTransaction transaction(&WrtDatabase::interface());
128 if (!isWidgetInstalled(getHandle())) {
129 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
130 "Cannot find widget. Handle: " << getHandle());
133 WidgetSecuritySettings::Row row;
134 row.Set_geolocation_usage(value);
136 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
137 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
141 transaction.Commit();
143 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set geolocation usage")
146 void WidgetDAO::setWebNotificationUsage(const SettingsType value)
148 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
150 using namespace DPL::DB::ORM;
151 using namespace DPL::DB::ORM::wrt;
153 ScopedTransaction transaction(&WrtDatabase::interface());
154 if (!isWidgetInstalled(getHandle())) {
155 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
156 "Cannot find widget. Handle: " << getHandle());
159 WidgetSecuritySettings::Row row;
160 row.Set_web_notification_usage(value);
162 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
163 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
167 transaction.Commit();
169 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web notification usage")
172 void WidgetDAO::setWebDatabaseUsage(const SettingsType value)
174 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
176 using namespace DPL::DB::ORM;
177 using namespace DPL::DB::ORM::wrt;
179 ScopedTransaction transaction(&WrtDatabase::interface());
180 if (!isWidgetInstalled(getHandle())) {
181 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
182 "Cannot find widget. Handle: " << getHandle());
185 WidgetSecuritySettings::Row row;
186 row.Set_web_database_usage(value);
188 WRT_DB_UPDATE(update, WidgetSecuritySettings, &WrtDatabase::interface())
189 update->Where(Equals<WidgetSecuritySettings::app_id>(getHandle()));
193 transaction.Commit();
195 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to set web database usage")
198 void WidgetDAO::registerWidget(
199 const TizenAppId & tzAppId,
200 const WidgetRegisterInfo &widgetRegInfo,
201 const IWidgetSecurity &widgetSecurity)
203 LogDebug("Registering widget");
204 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
206 DPL::DB::ORM::wrt::ScopedTransaction transaction(
207 &WrtDatabase::interface());
208 registerWidgetInternal(tzAppId, widgetRegInfo, widgetSecurity);
209 transaction.Commit();
211 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
214 DbWidgetHandle WidgetDAO::registerWidget(
215 const WidgetRegisterInfo &pWidgetRegisterInfo,
216 const IWidgetSecurity &widgetSecurity)
218 //make it more precise due to very fast tests
220 gettimeofday(&tv, NULL);
221 DbWidgetHandle widgetHandle;
222 unsigned int seed = time(NULL);
224 widgetHandle = rand_r(&seed);
225 } while (isWidgetInstalled(widgetHandle));
227 registerWidget(*pWidgetRegisterInfo.configInfo.tizenAppId,
233 TizenAppId WidgetDAO::registerWidgetGeneratePkgId(
234 const WidgetRegisterInfo &pWidgetRegisterInfo,
235 const IWidgetSecurity &widgetSecurity)
237 TizenAppId tzAppId = generatePkgId();
238 registerWidget(tzAppId, pWidgetRegisterInfo, widgetSecurity);
242 void WidgetDAO::updateTizenAppId(
243 const TizenAppId & fromAppId,
244 const TizenAppId & toAppId)
246 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
248 using namespace DPL::DB::ORM;
249 using namespace DPL::DB::ORM::wrt;
251 ScopedTransaction transaction(&WrtDatabase::interface());
252 if (!isWidgetInstalled(fromAppId)) {
253 ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist,
254 "Cannot find widget. tzAppId: " << fromAppId);
257 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
258 select->Where(Equals<WidgetInfo::tizen_appid>(fromAppId));
260 WidgetInfo::Row row = select->GetSingleRow();
262 //WidgetInfo::Row row;
263 row.Set_tizen_appid(toAppId);
265 WRT_DB_UPDATE(update, WidgetInfo, &WrtDatabase::interface())
266 update->Where(Equals<WidgetInfo::tizen_appid>(fromAppId));
270 transaction.Commit();
272 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to update appid")
275 void WidgetDAO::registerWidgetInternal(
276 const TizenAppId & tzAppId,
277 const WidgetRegisterInfo &widgetRegInfo,
278 const IWidgetSecurity &widgetSecurity,
279 const DPL::Optional<DbWidgetHandle> handle)
281 //Register into WidgetInfo has to be first
282 //as all other tables depend upon that
283 DbWidgetHandle widgetHandle = registerWidgetInfo(tzAppId,
288 registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
290 registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
292 registerWidgetIcons(widgetHandle, widgetRegInfo);
294 registerWidgetStartFile(widgetHandle, widgetRegInfo);
296 PropertyDAO::RegisterProperties(widgetHandle, tzAppId, widgetRegInfo);
298 registerWidgetFeatures(widgetHandle, widgetRegInfo);
300 registerWidgetPrivilege(widgetHandle, widgetRegInfo);
302 registerWidgetWindowModes(widgetHandle, widgetRegInfo);
304 registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
306 registerWidgetAllowNavigationInfo(widgetHandle, widgetRegInfo);
308 registerWidgetCertificates(widgetHandle, widgetSecurity);
310 CertificateChainList list;
311 widgetSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
312 registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
315 widgetSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
316 registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
318 registerWidgetSettings(widgetHandle, widgetRegInfo);
320 registerAppControl(widgetHandle, widgetRegInfo);
322 registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
324 registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
326 registerWidgetSecuritySettings(widgetHandle);
329 #define DO_INSERT(row, table) \
331 WRT_DB_INSERT(insert, table, &WrtDatabase::interface()) \
332 insert->Values(row); \
336 void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
337 const WidgetRegisterInfo ®Info)
339 //Try and transaction not needed
340 using namespace DPL::DB::ORM;
341 using namespace DPL::DB::ORM::wrt;
343 WidgetExtendedInfo::Row row;
344 row.Set_app_id(widgetHandle);
345 // row.Set_share_href (DPL::FromUTF8String(regInfo.shareHref));
346 row.Set_signature_type(regInfo.signatureType);
347 row.Set_install_time(regInfo.installedTime);
348 row.Set_splash_img_src(regInfo.configInfo.splashImgSrc);
349 row.Set_background_page(regInfo.configInfo.backgroundPage);
350 row.Set_installed_path(regInfo.widgetInstalledPath);
352 DO_INSERT(row, WidgetExtendedInfo)
355 DbWidgetHandle WidgetDAO::registerWidgetInfo(
356 const TizenAppId & tzAppId,
357 const WidgetRegisterInfo ®Info,
358 const IWidgetSecurity &widgetSecurity,
359 const DPL::Optional<DbWidgetHandle> handle)
361 using namespace DPL::DB::ORM;
362 using namespace DPL::DB::ORM::wrt;
363 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
365 // TODO in wrt_db all Columns in WidgetInfo have DEFAULT VALUE set.
366 // Because of that, "Optional" is not used there
370 row.Set_app_id(*handle);
373 row.Set_widget_type(regInfo.webAppType.appType);
375 row.Set_widget_id(widgetConfigurationInfo.widget_id);
376 row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
377 row.Set_widget_version(widgetConfigurationInfo.version);
378 row.Set_widget_width(widgetConfigurationInfo.width);
379 row.Set_widget_height(widgetConfigurationInfo.height);
380 row.Set_author_name(widgetConfigurationInfo.authorName);
381 row.Set_author_email(widgetConfigurationInfo.authorEmail);
382 row.Set_author_href(widgetConfigurationInfo.authorHref);
383 row.Set_csp_policy(widgetConfigurationInfo.cspPolicy);
384 row.Set_csp_policy_report_only(widgetConfigurationInfo.cspPolicyReportOnly);
385 row.Set_base_folder(DPL::FromUTF8String(regInfo.baseFolder));
386 row.Set_webkit_plugins_required(widgetConfigurationInfo.flashNeeded);
387 row.Set_recognized(widgetSecurity.isRecognized());
388 row.Set_distributor_signed(widgetSecurity.isDistributorSigned());
389 row.Set_tizen_appid(tzAppId);
390 row.Set_tizen_pkgid(regInfo.tzPkgid);
392 std::stringstream tmp;
393 tmp << regInfo.minVersion;
394 row.Set_min_version(DPL::FromUTF8String(tmp.str()));
396 row.Set_back_supported(widgetConfigurationInfo.backSupported);
397 row.Set_access_network(widgetConfigurationInfo.accessNetwork);
398 row.Set_pkg_type(regInfo.packagingType.pkgType);
399 row.Set_security_model_version(
400 static_cast<int>(widgetConfigurationInfo.securityModelVersion));
404 DO_INSERT(row, WidgetInfo);
406 Catch(DPL::DB::SqlConnection::Exception::Base)
408 ReThrowMsg(WidgetDAO::Exception::DatabaseError,
409 "Failed to register widget info.");
413 //get autoincremented value of widgetHandle
414 WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
415 select->Where(Equals<WidgetInfo::tizen_appid>(tzAppId));
416 return select->GetSingleValue<WidgetInfo::app_id>();
422 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
423 const WidgetRegisterInfo ®Info)
425 using namespace DPL::DB::ORM;
426 using namespace DPL::DB::ORM::wrt;
428 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
430 FOREACH(it, widgetConfigurationInfo.localizedDataSet)
432 const DPL::String& locale = it->first;
433 const ConfigParserData::LocalizedData& data = it->second;
435 LocalizedWidgetInfo::Row row;
436 row.Set_app_id(widgetHandle);
437 row.Set_widget_locale(locale);
438 row.Set_widget_name(data.name);
439 row.Set_widget_shortname(data.shortName);
440 row.Set_widget_description(data.description);
441 row.Set_widget_license(data.license);
442 row.Set_widget_license_file(data.licenseFile);
443 row.Set_widget_license_href(data.licenseHref);
445 DO_INSERT(row, LocalizedWidgetInfo)
449 void WidgetDAO::registerWidgetIcons(DbWidgetHandle widgetHandle,
450 const WidgetRegisterInfo ®Info)
452 using namespace DPL::DB::ORM;
453 using namespace DPL::DB::ORM::wrt;
455 FOREACH(i, regInfo.localizationData.icons)
457 wrt::WidgetIcon::icon_id::ColumnType icon_id;
459 wrt::WidgetIcon::Row row;
460 row.Set_app_id(widgetHandle);
461 row.Set_icon_src(i->src);
462 row.Set_icon_width(i->width);
463 row.Set_icon_height(i->height);
465 WRT_DB_INSERT(insert, wrt::WidgetIcon, &WrtDatabase::interface())
467 icon_id = static_cast<int>(insert->Execute());
470 FOREACH(j, i->availableLocales)
472 WidgetLocalizedIcon::Row row;
473 row.Set_app_id(widgetHandle);
474 row.Set_icon_id(icon_id);
475 row.Set_widget_locale(*j);
476 DO_INSERT(row, WidgetLocalizedIcon)
481 void WidgetDAO::registerWidgetStartFile(DbWidgetHandle widgetHandle,
482 const WidgetRegisterInfo ®Info)
484 using namespace DPL::DB::ORM;
485 using namespace DPL::DB::ORM::wrt;
487 FOREACH(i, regInfo.localizationData.startFiles)
489 WidgetStartFile::start_file_id::ColumnType startFileID;
491 WidgetStartFile::Row row;
492 row.Set_app_id(widgetHandle);
493 row.Set_src(i->path);
495 WRT_DB_INSERT(insert, WidgetStartFile, &WrtDatabase::interface())
497 startFileID = static_cast<int>(insert->Execute());
500 FOREACH(j, i->propertiesForLocales)
502 WidgetLocalizedStartFile::Row row;
503 row.Set_app_id(widgetHandle);
504 row.Set_start_file_id(startFileID);
505 row.Set_widget_locale(j->first);
506 row.Set_type(j->second.type);
507 row.Set_encoding(j->second.encoding);
509 DO_INSERT(row, WidgetLocalizedStartFile)
514 void WidgetDAO::registerWidgetFeatures(DbWidgetHandle widgetHandle,
515 const WidgetRegisterInfo ®Info)
517 using namespace DPL::DB::ORM;
518 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
520 FOREACH(pWidgetFeature, widgetConfigurationInfo.featuresList)
522 wrt::WidgetFeature::Row widgetFeature;
523 widgetFeature.Set_app_id(widgetHandle);
524 widgetFeature.Set_name(pWidgetFeature->name);
525 widgetFeature.Set_rejected(false);
527 DO_INSERT(widgetFeature, wrt::WidgetFeature)
531 void WidgetDAO::registerWidgetPrivilege(DbWidgetHandle widgetHandle,
532 const WidgetRegisterInfo ®Info)
534 using namespace DPL::DB::ORM;
535 using namespace DPL::DB::ORM::wrt;
536 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
538 FOREACH(it, widgetConfigurationInfo.privilegeList)
540 WidgetPrivilege::Row widgetPrivilege;
541 widgetPrivilege.Set_app_id(widgetHandle);
542 widgetPrivilege.Set_name(it->name);
544 DO_INSERT(widgetPrivilege, WidgetPrivilege)
548 void WidgetDAO::updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature)
550 // This function could be merged with registerWidgetFeature but it requires
552 // 1. Check "ace step" in installer must be done before "update database
555 // ConfigurationParserData shouldn't be called "ParserData" any more.
556 using namespace DPL::DB::ORM;
558 wrt::ScopedTransaction transaction(&WrtDatabase::interface());
559 WRT_DB_SELECT(select, wrt::WidgetFeature, &WrtDatabase::interface())
560 select->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
561 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
563 auto row = select->GetSingleRow();
564 row.Set_rejected(widgetFeature.rejected);
566 WRT_DB_UPDATE(update, wrt::WidgetFeature, &WrtDatabase::interface())
567 update->Where(And(Equals<wrt::WidgetFeature::app_id>(m_widgetHandle),
568 Equals<wrt::WidgetFeature::name>(widgetFeature.name)));
571 transaction.Commit();
574 void WidgetDAO::registerWidgetWindowModes(DbWidgetHandle widgetHandle,
575 const WidgetRegisterInfo ®Info)
577 using namespace DPL::DB::ORM;
578 using namespace DPL::DB::ORM::wrt;
579 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
581 FOREACH(i, widgetConfigurationInfo.windowModes)
583 wrt::WidgetWindowModes::Row windowMode;
584 windowMode.Set_app_id(widgetHandle);
585 windowMode.Set_window_mode(*i);
587 DO_INSERT(windowMode, wrt::WidgetWindowModes)
591 void WidgetDAO::registerWidgetWarpInfo(DbWidgetHandle widgetHandle,
592 const WidgetRegisterInfo ®Info)
594 using namespace DPL::DB::ORM;
595 using namespace DPL::DB::ORM::wrt;
596 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
598 FOREACH(AccIt, widgetConfigurationInfo.accessInfoSet)
600 WidgetWARPInfo::Row row;
601 row.Set_app_id(widgetHandle);
602 row.Set_iri(AccIt->m_strIRI);
603 row.Set_subdomain_access(static_cast <int>(
604 AccIt->m_bSubDomainAccess));
606 DO_INSERT(row, WidgetWARPInfo)
610 void WidgetDAO::registerWidgetAllowNavigationInfo(DbWidgetHandle widgetHandle,
611 const WidgetRegisterInfo ®Info)
613 using namespace DPL::DB::ORM;
614 using namespace DPL::DB::ORM::wrt;
615 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
617 FOREACH(allowNaviIt, widgetConfigurationInfo.allowNavigationInfoList)
619 WidgetAllowNavigation::Row row;
620 row.Set_app_id(widgetHandle);
621 row.Set_scheme(allowNaviIt->m_scheme);
622 row.Set_host(allowNaviIt->m_host);
623 DO_INSERT(row, WidgetAllowNavigation)
627 void WidgetDAO::registerWidgetCertificates(DbWidgetHandle widgetHandle,
628 const IWidgetSecurity &widgetSecurity)
630 using namespace DPL::DB::ORM;
631 using namespace DPL::DB::ORM::wrt;
633 FOREACH(it, widgetSecurity.getCertificateList())
635 WidgetCertificateFingerprint::Row row;
636 row.Set_app_id(widgetHandle);
637 row.Set_owner(it->owner);
638 row.Set_chainid(it->chainId);
639 row.Set_type(it->type);
640 row.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
641 row.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
642 row.Set_common_name(it->strCommonName);
644 DO_INSERT(row, WidgetCertificateFingerprint)
648 void WidgetDAO::registerCertificatesChains(
649 DbWidgetHandle widgetHandle,
650 CertificateSource certificateSource,
651 const CertificateChainList &
652 certificateChainList)
654 using namespace DPL::DB::ORM;
655 using namespace DPL::DB::ORM::wrt;
656 FOREACH(certChain, certificateChainList)
658 WidgetCertificate::Row row;
659 row.Set_app_id(widgetHandle);
660 row.Set_cert_source(certificateSource);
661 row.Set_encoded_chain(DPL::FromASCIIString(*certChain));
663 DO_INSERT(row, WidgetCertificate);
667 void WidgetDAO::registerWidgetSettings(DbWidgetHandle widgetHandle,
668 const WidgetRegisterInfo ®Info)
670 using namespace DPL::DB::ORM;
671 using namespace DPL::DB::ORM::wrt;
673 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
675 FOREACH(pWidgetSetting, widgetConfigurationInfo.settingsList)
677 SettingsList::Row row;
678 row.Set_appId(widgetHandle);
679 row.Set_settingName(pWidgetSetting->m_name);
680 row.Set_settingValue(pWidgetSetting->m_value);
682 DO_INSERT(row, SettingsList)
686 void WidgetDAO::insertAppControlInfo(DbWidgetHandle handle,
688 DPL::String operation,
692 unsigned disposition)
694 using namespace DPL::DB::ORM;
695 using namespace DPL::DB::ORM::wrt;
697 AppControlInfo::Row row;
699 row.Set_app_id(handle);
700 row.Set_execute_index(index);
702 row.Set_operation(operation);
705 row.Set_disposition(disposition);
707 DO_INSERT(row, AppControlInfo);
710 void WidgetDAO::registerAppControl(DbWidgetHandle widgetHandle,
711 const WidgetRegisterInfo ®Info)
713 using namespace DPL::DB::ORM;
714 using namespace DPL::DB::ORM::wrt;
715 const ConfigParserData& widgetConfigurationInfo = regInfo.configInfo;
718 FOREACH(appControl_it, widgetConfigurationInfo.appControlList)
720 DPL::String src = appControl_it->m_src;
721 DPL::String operation = appControl_it->m_operation;
722 unsigned index = appControl_it->m_index;
723 unsigned disposition = appControl_it->m_disposition ==
724 ConfigParserData::AppControlInfo::Disposition::INLINE ? 1 : 0;
726 if (!appControl_it->m_uriList.empty())
728 FOREACH(uri_it, appControl_it->m_uriList)
730 DPL::String uri = *uri_it;
732 if (!appControl_it->m_mimeList.empty())
734 FOREACH(mime_it, appControl_it->m_mimeList)
736 DPL::String mime = *mime_it;
738 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
743 DPL::String mime = L"";
745 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
751 DPL::String uri = L"";
753 if (!appControl_it->m_mimeList.empty())
755 FOREACH(mime_it, appControl_it->m_mimeList)
757 DPL::String mime = *mime_it;
759 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
764 DPL::String mime = L"";
766 insertAppControlInfo(widgetHandle, src, operation, uri, mime, index, disposition);
772 void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
773 const WidgetRegisterInfo ®Info)
775 using namespace DPL::DB::ORM;
776 using namespace DPL::DB::ORM::wrt;
778 FOREACH(it, regInfo.encryptedFiles)
780 EncryptedResourceList::Row row;
781 row.Set_app_id(widgetHandle);
782 row.Set_resource(it->fileName);
783 row.Set_size(it->fileSize);
785 DO_INSERT(row, EncryptedResourceList)
789 void WidgetDAO::registerExternalLocations(
790 DbWidgetHandle widgetHandle,
791 const ExternalLocationList &
794 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
796 using namespace DPL::DB::ORM;
797 using namespace DPL::DB::ORM::wrt;
798 DPL::DB::ORM::wrt::ScopedTransaction transaction(
799 &WrtDatabase::interface());
800 LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
801 FOREACH(it, externals)
803 WidgetExternalLocations::Row row;
804 row.Set_app_id(widgetHandle);
805 row.Set_path(DPL::FromUTF8String(*it));
807 DO_INSERT(row, WidgetExternalLocations)
809 transaction.Commit();
811 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register external files");
814 void WidgetDAO::registerWidgetSecuritySettings(DbWidgetHandle widgetHandle)
816 using namespace DPL::DB::ORM;
817 using namespace DPL::DB::ORM::wrt;
818 WidgetSecuritySettings::Row row;
819 row.Set_app_id(widgetHandle);
820 row.Set_security_popup_usage(SETTINGS_TYPE_ON);
821 row.Set_geolocation_usage(SETTINGS_TYPE_ON);
822 row.Set_web_notification_usage(SETTINGS_TYPE_ON);
823 row.Set_web_database_usage(SETTINGS_TYPE_ON);
825 DO_INSERT(row, WidgetSecuritySettings)
828 void WidgetDAO::unregisterAllExternalLocations()
830 using namespace DPL::DB::ORM;
831 using namespace DPL::DB::ORM::wrt;
832 LogDebug("Deleting external files for widgetHandle: " << m_widgetHandle);
833 WRT_DB_DELETE(del, WidgetExternalLocations, &WrtDatabase::interface());
834 del->Where(Equals<WidgetExternalLocations::app_id>(m_widgetHandle));
838 void WidgetDAO::unregisterWidget(const TizenAppId & tzAppId)
840 LogDebug("Unregistering widget from DB. tzAppId: " << tzAppId);
841 SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
843 DPL::DB::ORM::wrt::ScopedTransaction transaction(
844 &WrtDatabase::interface());
845 unregisterWidgetInternal(tzAppId);
846 transaction.Commit();
848 SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
851 void WidgetDAO::unregisterWidgetInternal(
852 const TizenAppId & tzAppId)
854 using namespace DPL::DB::ORM;
855 using namespace DPL::DB::ORM::wrt;
857 DbWidgetHandle handle = getHandle(tzAppId);
859 // Delete from table Widget Info
860 WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
861 del->Where(Equals<WidgetInfo::app_id>(handle));
864 // Deleting in other tables is done via "delete cascade" in SQL
869 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
870 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END