Prepare wrt to handle csp policy rules.
[platform/framework/web/wrt.git] / src / domain / widget_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_model.cpp
18  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for widget model
21  */
22 #include <widget_model.h>
23 #include <dpl/sstream.h>
24 #include <dpl/event/model_bind_to_dao.h>
25 #include <dpl/wrt-dao-ro/global_config.h>
26 #include <dpl/wrt-dao-ro/widget_config.h>
27 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
28
29 #include <dpl/utils/folder_size.h>
30
31 using namespace WrtDB;
32
33 template <typename RetType, RetType(WidgetDAOReadOnly::*extFun) () const >
34 struct BindToWidgetDAO :
35     DPL::Event::BindToDAO<WidgetModel,
36                           RetType,
37                           DPL::String,
38                           WidgetDAOReadOnly,
39                           &WidgetModel::getTizenId,
40                           extFun>
41 {};
42
43 template <typename RetType, RetType(*extFun) (DPL::String)>
44 struct BindToWidgetDAOStatic :
45     DPL::Event::BindToDAO_Static<WidgetModel,
46                                  RetType,
47                                  DPL::String,
48                                  &WidgetModel::getTizenId,
49                                  extFun>
50 {};
51
52 WidgetModel::WidgetModel(const std::string &tizenId) :
53     TizenId(DPL::FromASCIIString(tizenId)),
54     TzPkgId(this, &BindToWidgetDAO<WrtDB::TizenPkgId,
55                                    &WidgetDAOReadOnly::getTizenPkgId>::Get),
56     Type(this, &BindToWidgetDAO<WidgetType,
57                                 &WidgetDAOReadOnly::getWidgetType>::Get),
58     CspPolicy(this, &BindToWidgetDAO<DPL::OptionalString,
59                                      &WidgetDAOReadOnly::getCspPolicy>::Get),
60     ActualSize(this),
61     PreferredSize(this,
62                   &BindToWidgetDAO<WidgetSize,
63                                    &WidgetDAOReadOnly::getPreferredSize>::Get),
64     StartURL(this),
65     //localized, so not binded
66     StartFileInfo(this),
67     //localized, so not binded
68     // file:// + / : without "/" path, webkit return security error
69     PrefixURL(this, L"file:///"),
70     InstallPath(
71         this,
72         &BindToWidgetDAO<DPL::String, &WidgetDAOReadOnly::getFullPath>::Get),
73     PersistentStoragePath(this,
74                           DPL::FromUTF8String(
75                               WidgetConfig::GetWidgetPersistentStoragePath(
76                                   this->TizenId))
77                           ),
78     // use of multiple widget model
79     TemporaryStoragePath(this,
80                          DPL::FromUTF8String(
81                              WidgetConfig::GetWidgetTemporaryStoragePath(
82                                  this->TizenId + getTimestamp()))
83                          ),
84     defaultlocale(
85         this,
86         &BindToWidgetDAO<DPL::OptionalString,
87                          &WidgetDAOReadOnly::getDefaultlocale>::Get),
88     Name(this),
89     //localized, so not binded
90     ShortName(this),
91     //localized, so not binded
92     Description(this),
93     //localized, so not binded
94     License(this),
95     //localized, so not binded
96     LicenseHref(this),
97     //localized, so not binded
98     Icon(this),
99     SplashImg(
100         this,
101         &BindToWidgetDAO<DPL::OptionalString,
102                          &WidgetDAOReadOnly::getSplashImgSrc>::Get),
103     WindowModes(
104         this,
105         &BindToWidgetDAO<WindowModeList,
106                          &WidgetDAOReadOnly::getWindowModes>::Get),
107     //localized, so not binded
108     //    AccessNetwork(this, false),
109     //    WarpDefinitionEmpty(this),
110     BackSupported(
111         this,
112         //TODO this type has to be here now, as Property constructor is wrongly
113         //chosen
114         (DPL::Event::Property<bool,
115                               DPL::Event::PropertyReadOnly,
116                               DPL::Event::PropertyStorageDynamicCached>::
117              ReadDelegateType) &
118         BindToWidgetDAO<bool, &WidgetDAOReadOnly::getBackSupported>::Get),
119     AccessList(this),
120     IsTestWidget(
121         this,
122         //TODO this type has to be here now, as Property constructor is wrongly
123         //chosen
124         (DPL::Event::Property<bool,
125                               DPL::Event::PropertyReadOnly,
126                               DPL::Event::PropertyStorageDynamicCached>::
127              ReadDelegateType) &
128         BindToWidgetDAO<bool, &WidgetDAOReadOnly::isTestWidget>::Get),
129
130     SettingList(this),
131     AppServiceList(this)
132 {}
133
134 DPL::String WidgetModel::getTizenId() const
135 {
136     return TizenId;
137 }
138
139 DPL::String WidgetModel::getTimestamp()
140 {
141     struct timeval tv;
142     char buff[128];
143
144     gettimeofday(&tv, NULL);
145     sprintf(buff, "%lf", (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f);
146     LogInfo("timestamp: " << buff);
147     DPL::String timeString = DPL::FromUTF8String(std::string(buff));
148     return timeString;
149 }