Crash Fix when Creating SecurityOrigin DB.
[platform/framework/web/wrt.git] / src / domain / widget_deserialize_model.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    widget_deserialize_model.h
18  * @author  Piotr Marcinkiewicz (p.marcinkiew@samsung.com)
19  * @version 1.0
20  * @brief   Widget deserialization creates WidgetModel from WidgetDAOReadOnly
21  */
22
23 #include "widget_model.h"
24
25 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
26 #include <dpl/log/log.h>
27 // to apply widget default locales instead of calling localizeWidgetModel()
28 #include <dpl/localization/LanguageTagsProvider.h>
29
30
31 namespace Domain {
32
33 std::shared_ptr<WidgetModel> deserializeWidgetModel(const std::string& tizenId)
34 {
35     std::shared_ptr<WidgetModel> model;
36     DPL::String dplTizenId(DPL::FromUTF8String(tizenId));
37     if (WrtDB::WidgetDAOReadOnly::isWidgetInstalled(dplTizenId)) {
38         LogDebug("Widget installed - creating model");
39         model.reset(new WidgetModel(tizenId));
40
41         WrtDB::WidgetDAOReadOnly dao(dplTizenId);
42         DPL::Optional<DPL::String> defloc = model->defaultlocale.Get();
43         if(!defloc.IsNull())
44         {
45             LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(*defloc);
46         }
47
48         WrtDB::WidgetAccessInfoList widgetAccessInfoList;
49         // widgetAccessInfoList is output parameter
50         dao.getWidgetAccessInfo(widgetAccessInfoList);
51         model->AccessList.Set(widgetAccessInfoList);
52
53         // Widget application service information data
54         WidgetApplicationServiceList widgetApplicationServiceList;
55         // widgetApplicationServiceList is output parameter
56         dao.getAppServiceList(widgetApplicationServiceList);
57         model->AppServiceList.Set(widgetApplicationServiceList);
58
59         // Set Widget Settings
60         WidgetSettings widgetSettings;
61         dao.getWidgetSettings(widgetSettings);
62         model->SettingList.Set(widgetSettings);
63     } else {
64         LogError("Widget is not installed - model not created");
65     }
66     return model;
67 }
68
69 } //Namespace Domain
70