d92197cbb53cf87a718467675c0463402f4b1fd4
[platform/framework/web/wrt.git] / src / domain / widget_data_types.cpp
1 /*
2  * Copyright (c) 2012 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  * This file  have been implemented in compliance with  W3C WARP SPEC.
18  * but there are some patent issue between  W3C WARP SPEC and APPLE.
19  * so if you want to use this file, refer to the README file in root directory
20  */
21 /**
22  * @file       widget_data_types.cpp
23  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
24  * @author     Tomasz Iwanek (t.iwanek@samsung.com) (implementation moved to cpp)
25  * @version    0.1
26  * @brief
27  */
28
29 #include <widget_data_types.h>
30
31 #include <dpl/foreach.h>
32
33 WidgetAccessList::WidgetAccessList() : m_isAccessAll(false)
34 {
35 }
36
37 WidgetAccessList::WidgetAccessList(const WrtDB::WidgetAccessInfoList &widgetAccessInfoList) :
38     m_isAccessAll(false)
39 {
40     FOREACH(it, widgetAccessInfoList)
41     {
42         if (DPL::FromUTF32String(L"*") == it->strIRI) {
43             m_isAccessAll = true;
44             m_warpIriList.clear();
45             return;
46         }
47
48         WarpIRI warpIri;
49
50         warpIri.set(DPL::ToUTF8String(it->strIRI).c_str(),
51                     it->bSubDomains);
52
53         if (warpIri.isAccessDefinition()) {
54             m_warpIriList.push_back(warpIri);
55         }
56     }
57 }
58
59 bool WidgetAccessList::getIsAccessAll() const
60 {
61     return m_isAccessAll;
62 }
63
64 const WarpIRIList* WidgetAccessList::getWarpIRIList() const
65 {
66     return &m_warpIriList;
67 }
68
69 bool WidgetAccessList::isRequiredIRI(const DPL::String &iri) const
70 {
71     if (m_isAccessAll) {
72         return true;
73     }
74
75     WarpIRI requestIri;
76     requestIri.set(iri.c_str(), false);
77
78     FOREACH(it, m_warpIriList)
79     {
80         if (it->isSubDomain(requestIri)) {
81             return true;
82         }
83     }
84
85     return false;
86 }
87
88 bool WidgetAccessList::operator ==(const WidgetAccessList& other) const
89 {
90     return m_warpIriList == other.m_warpIriList &&
91            m_isAccessAll == other.m_isAccessAll;
92 }
93
94 WidgetSettingList::WidgetSettingList() :
95     m_RotationLock(Screen_Portrait),
96     m_IndicatorPresence(Indicator_Enable),
97     m_BackButtonPresence(BackButton_Disable),
98     m_ContextMenu(ContextMenu_Enable),
99     m_Encryption(Encryption_Disable),
100     m_BackgroundSupport(BackgroundSupport_Disable)
101 {
102 }
103
104 WidgetSettingList::WidgetSettingList(WidgetSettings &widgetSettings)
105 {
106     m_RotationLock = Screen_Portrait;
107     m_IndicatorPresence = Indicator_Enable;
108     m_BackButtonPresence = BackButton_Disable;
109     m_ContextMenu = ContextMenu_Enable;
110     m_Encryption = Encryption_Disable;
111     m_BackgroundSupport = BackgroundSupport_Disable;
112
113     FOREACH(it, widgetSettings)
114     {
115         DPL::String name = it->settingName;
116         DPL::String value = it->settingValue;
117
118         if (name == SETTING_NAME_SCREEN_ORIENTATION) {
119             if (value == SETTING_VALUE_SCREEN_ORIENTATION_PORTRAIT) {
120                 m_RotationLock = Screen_Portrait;
121             } else if (value ==
122                        SETTING_VALUE_SCREEN_ORIENTATION_LANDSCAPE)
123             {
124                 m_RotationLock = Screen_Landscape;
125             } else {
126                 LogError("Invalid screen orientation value!! [" <<
127                          value << "]");
128                 m_RotationLock = Screen_Portrait;
129             }
130         } else if (name == SETTING_NAME_INDICATOR_PRESENCE) {
131             if (value == SETTING_VALUE_INDICATOR_PRESENCE_ENALBE) {
132                 m_IndicatorPresence = Indicator_Enable;
133             } else if (value == SETTING_VALUE_INDICATOR_PRESENCE_DISABLE) {
134                 m_IndicatorPresence = Indicator_Disable;
135             } else {
136                 LogError("Invalid indicator presence value!! [" <<
137                     value << "]");
138                 m_IndicatorPresence = Indicator_Enable;
139             }
140         } else if (name == SETTING_NAME_BACKBUTTON_PRESENCE) {
141             if (value == SETTING_VALUE_BACKBUTTON_PRESENCE_ENALBE) {
142                 m_BackButtonPresence = BackButton_Enable;
143             } else if (value ==
144                             SETTING_VALUE_BACKBUTTON_PRESENCE_DISABLE) {
145                 m_BackButtonPresence = BackButton_Disable;
146             } else {
147                 LogError("Invalid backbutton presence value!! [" <<
148                     value << "]");
149                 m_BackButtonPresence = BackButton_Disable;
150             }
151         } else if ( name == SETTING_NAME_CONTEXT_MENU
152 #ifndef DEPRECATED_SETTING_STRING
153                     || name == SETTING_NAME_CONTEXTMENU
154 #endif
155                   ) {
156             if (value == SETTING_VALUE_ENABLE) {
157                 m_ContextMenu = ContextMenu_Enable;
158             } else if (value == SETTING_VALUE_DISABLE) {
159                 m_ContextMenu = ContextMenu_Disable;
160             } else {
161                 LogError("Invalid contextmenu value!! [" <<
162                     value << "]");
163                 m_ContextMenu = ContextMenu_Enable;
164             }
165         } else if (name == SETTING_NAME_ENCRYPTION) {
166             if (value == SETTING_VALUE_ENCRYPTION_ENABLE) {
167                 m_Encryption = Encryption_Enable;
168             } else if (value ==
169                             SETTING_VALUE_ENCRYPTION_DISABLE) {
170                 m_Encryption = Encryption_Disable;
171             } else {
172                 LogError("Invalid encryption value!! [" <<
173                     value << "]");
174                 m_Encryption = Encryption_Disable;
175             }
176         } else if (name == SETTING_NAME_BACKGROUND_SUPPORT) {
177             if (value == SETTING_VALUE_ENABLE) {
178                 m_BackgroundSupport = BackgroundSupport_Enable;
179             } else if (value == SETTING_VALUE_DISABLE) {
180                 m_BackgroundSupport = BackgroundSupport_Disable;
181             } else {
182                 LogError("Invalid background-support value!! [" <<
183                     value << "]");
184                 m_BackgroundSupport = BackgroundSupport_Disable;
185             }
186         } else if (name == SETTING_NAME_USER_AGENT) {
187             DPL::OptionalString userAgent = value;
188             if (!userAgent.IsNull()) {
189                 m_UserAgent = DPL::ToUTF8String(*userAgent);
190             }
191         } else {
192             LogError("Invalid setting name!! [" << name << "]");
193         }
194     }
195     LogDebug("m_RotationLock: " << m_RotationLock);
196     LogDebug("m_IndicatorPresence: " << m_IndicatorPresence);
197     LogDebug("m_BackButtonPresence: " << m_BackButtonPresence);
198     LogDebug("m_ContextMenu: " << m_ContextMenu);
199     LogDebug("m_Encryption: " << m_Encryption);
200     LogDebug("m_BackgroundSupport: " << m_BackgroundSupport);
201 }
202
203 WidgetSettingScreenLock WidgetSettingList::getRotationValue() const
204 {
205     return m_RotationLock;
206 }
207
208 WidgetSettingIndicatorPresence WidgetSettingList::getIndicatorPresence() const
209 {
210     return m_IndicatorPresence;
211 }
212
213 WidgetSettingBackButtonPresence WidgetSettingList::getBackButtonPresence() const
214 {
215     return m_BackButtonPresence;
216 }
217
218 WidgetSettingContextMenu WidgetSettingList::getContextMenu() const
219 {
220     return m_ContextMenu;
221 }
222
223 WidgetSettingEncryption WidgetSettingList::getEncryption() const
224 {
225     return m_Encryption;
226 }
227
228 WidgetSettingBackgroundSupport WidgetSettingList::getBackgroundSupport() const
229 {
230     return m_BackgroundSupport;
231 }
232
233 bool WidgetSettingList::isEncrypted() const
234 {
235     if (m_Encryption == Encryption_Enable) {
236         return true;
237     }
238     return false;
239 }
240
241 std::string WidgetSettingList::getUserAgent() const
242 {
243     return m_UserAgent;
244 }
245
246 bool WidgetSettingList::operator ==(const WidgetSettingList& other) const
247 {
248     return m_RotationLock == other.m_RotationLock &&
249         m_IndicatorPresence == other.m_IndicatorPresence &&
250         m_BackButtonPresence == other.m_BackButtonPresence &&
251         m_ContextMenu == other.m_ContextMenu &&
252         m_Encryption == other.m_Encryption &&
253         m_BackgroundSupport == other.m_BackgroundSupport &&
254         m_UserAgent == other.m_UserAgent;
255 }