upload tizen1.0 source
[framework/web/wrt-commons.git] / tests / localization / mockup_include / dpl / wrt-dao-ro / common_dao_types.h
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  *
18  * @file    common_dao_types.h
19  * @author  Michal Ciepielski (m.ciepielski@samsung.com)
20  * @version 1.0
21  * @brief   This file contains the declaration of common data types for wrtdb
22  */
23
24 #ifndef WRT_SRC_CONFIGURATION_COMMON_DAO_TYPES_H_
25 #define WRT_SRC_CONFIGURATION_COMMON_DAO_TYPES_H_
26
27 #include <set>
28 #include <string>
29 #include <map>
30 #include <vector>
31 #include <list>
32 #include <dpl/optional_typedefs.h>
33 #include <dpl/shared_ptr.h>
34
35 namespace WrtDB {
36 namespace Powder {
37
38 typedef std::set<DPL::String> StringSet;
39 //! Widget description
40 struct Description
41 {
42     //!Content level
43     typedef enum
44     {
45         Level0 = 0,
46         Level1,
47         Level2,
48         Level3,
49         Level4,
50         Level5,
51         LevelUnknown
52     } LevelEnum;
53     struct LevelEntry
54     {
55         LevelEnum level; //!< content level
56
57         typedef StringSet Context;
58
59         //! POWDER context
60         //! xa    This material appears in an artistic context
61         //! xb    This material appears in an educational context
62         //! xc    This material appears in a medical context
63         //! xd    This material appears in a sports context
64         //! xe    This material appears in a violent context
65         Context context;
66         explicit LevelEntry(LevelEnum level = LevelUnknown);
67         //! Function checks if context is valid
68         //! \param[in] level POWDER content level
69         //! \param[in] context POWDER context
70         bool isContextValid(LevelEnum level,
71                 const DPL::OptionalString& context) const;
72     };
73
74     struct CategoryEntry
75     {
76         //! Levels entries for POWDER description
77         typedef std::vector <LevelEntry> LevelsContainer;
78         LevelsContainer levels;
79         //! Function checks if context is valid
80         //! \param[out] reason set if context invalid
81         //! \param[in] level POWDER content level
82         //! \param[in] context POWDER context
83         bool isCategoryValid(LevelEntry& reason,
84                 LevelEnum level,
85                 const DPL::OptionalString& context) const;
86     };
87
88     //! POWDER Category -> Category entry map for Widget
89     //!
90     //! nu    Nudity
91     //! se    Sex
92     //! vi    Violence
93     //! la    Potentially offensive language
94     //! dr    Drug use
95     //! ga    Gambling
96     //! ha    Hate or harmful activities
97     //! ug    Use of user-generated content
98     typedef std::map<DPL::String, CategoryEntry> CategoryEntries;
99
100     CategoryEntries categories;
101
102     //! Age rating for widget
103     //! If Null not set
104     DPL::OptionalInt ageRating;
105 };
106 } // namespace Powder
107
108 namespace ChildProtection {
109
110 //! Blacklist with forbidden URLs
111 //! It should be stored in WidgetDAO
112 typedef std::vector<DPL::String> BlackList;
113
114 //! Widget Child protection record
115 //! Record should be stored in WingetDAO
116 struct Record
117 {
118     //! Child protection enabled
119     bool enabled;
120     explicit Record(bool enabled) :
121         enabled(enabled)
122     {
123     }
124 };
125
126 //! Powder processing
127 struct PowderRules
128 {
129     //! Rule set by parent about forbidden category
130     //! Powder category
131     //! nu    Nudity
132     //! se    Sex
133     //! vi    Violence
134     //! la    Potentially offensive language
135     //! dr    Drug use
136     //! ga    Gambling
137     //! ha    Hate or harmful activities
138     //! ug    Use of user-generated content
139     //! Powder context
140     //! xa    This material appears in an artistic conteaxt
141     //! xb    This material appears in an educational context
142     //! xc    This material appears in a medical context
143     //! xd    This material appears in a sports context
144     //! xe    This material appears in a violent context
145     struct CategoryRule
146     {
147         DPL::String category;
148         Powder::Description::LevelEnum level;
149         DPL::OptionalString context;
150         explicit CategoryRule(const DPL::String& category = DPL::String(),
151                 Powder::Description::LevelEnum level =
152                     Powder::Description::LevelUnknown,
153                 const DPL::OptionalString& context = DPL::OptionalString());
154     };
155
156     struct PowderResult
157     {
158         //! Reasoning outcome: part of POWDER description used to invalidate
159         Powder::Description::LevelEntry invalidDescription;
160         //! Reasoning outcome: rule set by parent not full filed by description
161         CategoryRule invalidRule;
162
163         //! Reasoning outcome: type of invalidity
164         enum InvalidReason
165         {
166             InvalidRule, //!< One of rules was not fulfilled
167             InvalidAge, //!< Age is invalid
168             AgeRatingNotSet, //!< Age rating for widget is not set
169             Valid //!< Description valid
170         };
171         InvalidReason reason;
172         explicit PowderResult(InvalidReason reason = Valid,
173                 const Powder::Description::LevelEntry& invalidDescription =
174                     Powder::Description::LevelEntry(),
175                 const CategoryRule& invalidRule = CategoryRule());
176     };
177
178     typedef std::pair<bool, PowderResult> ResultPair;
179
180     //! Function checks if rule is fulfilled by description
181     //! \param[in] rule checked rule
182     //! \param[in] description
183     //! \retval true rule is valid
184     //! \retval false rule is invalid
185     ResultPair isRuleValidForDescription(const CategoryRule& rule,
186             const Powder::Description& description) const;
187     //! Function checks if age limit is fulfilled by description
188     //! \param[in] description
189     //! \retval true age is valid
190     //! \retval false age is invalid
191     ResultPair isAgeValidForDescription(
192             const Powder::Description& description) const;
193
194     //! It is the maximum age rating valid for child
195     //! Uniform age is stored in WidgetDAO
196     DPL::OptionalInt ageLimit;
197
198     //! Set to true if age rating is required
199     //! If ageLimit is not set value is ignored
200     bool isAgeRatingRequired;
201
202     //! Set of rules configured by parent
203     //! Rules are stored in WidgetDAO and are uniform for all widgets
204     typedef std::vector<CategoryRule> RulesContainer;
205     RulesContainer rules;
206
207     //! Function check if Widget description is valid for ChildProtection
208     //! configuration
209     //! \param description widget description
210     //! \retval true widget is valid
211     //! \retval false widget is invalid
212     ResultPair isDescriptionValid(const Powder::Description& description)
213     const;
214
215     PowderRules() :
216         isAgeRatingRequired(false)
217     {
218     }
219 };
220 } // namespace ChildProtection
221
222 class PluginMetafileData
223 {
224   public:
225     struct Feature
226     {
227         std::string m_name;
228         std::set<std::string> m_deviceCapabilities;
229
230         bool operator< (const Feature& obj) const
231         {
232             return m_name < obj.m_name;
233         }
234     };
235     typedef std::set<Feature> FeatureContainer;
236
237   public:
238
239     PluginMetafileData()
240     {
241     }
242
243     std::string m_libraryName;
244     std::string m_featuresInstallURI;
245     std::string m_featuresKeyCN;
246     std::string m_featuresRootCN;
247     std::string m_featuresRootFingerprint;
248
249     FeatureContainer m_featureContainer;
250 };
251
252 class PluginObjectsDAO
253 {
254   public:
255     typedef std::set<std::string> Objects;
256     typedef DPL::SharedPtr<Objects> ObjectsPtr;
257
258   public:
259     explicit PluginObjectsDAO() {}
260
261   protected:
262     ObjectsPtr m_implemented;
263     ObjectsPtr m_dependent;
264 };
265
266 /**
267  * @brief Widget id describes web-runtime global widget identifier.
268  *
269  * Notice that only up to one widget can exist at the same time.
270  * DbWidgetHandle can be translated into corresponding WidgetModel by invoking
271  * FindWidgetModel routine.
272  */
273 typedef int DbWidgetHandle;
274
275 /**
276  * @brief Structure to hold the information of widget's size
277  */
278 struct DbWidgetSize
279 {
280     DPL::OptionalInt width;
281     DPL::OptionalInt height;
282
283     DbWidgetSize(DPL::OptionalInt w = DPL::OptionalInt::Null,
284             DPL::OptionalInt h = DPL::OptionalInt::Null) :
285         width(w),
286         height(h)
287     {
288     }
289 };
290
291 inline bool operator ==(const DbWidgetSize &objA, const DbWidgetSize &objB)
292 {
293     if (!objA.height || !objA.width || !objB.width || !objB.height) {
294         return false;
295     } else {
296         return *objA.height == *objB.height && *objA.width == *objB.width;
297     }
298 }
299
300 /**
301  * Widget [G]lobal [U]nique [ID]entifier
302  * Orginated from appstore ID
303  */
304 typedef DPL::OptionalString WidgetGUID;
305
306 struct WidgetAccessInfo
307 {
308     DPL::String strIRI;                /* origin iri */
309     bool bSubDomains;                  /* do we want access to subdomains ? */
310
311     bool operator ==(const WidgetAccessInfo& info) const
312     {
313         return info.strIRI == strIRI &&
314                info.bSubDomains == bSubDomains;
315     }
316 };
317
318 typedef std::list<WidgetAccessInfo> WidgetAccessInfoList;
319
320 typedef std::list<DPL::String> WindowModeList;
321
322 /**
323  * @brief Widget configuration parameter key
324  */
325 typedef DPL::String WidgetParamKey;
326
327 /**
328  * @brief Widget configuration parameter value
329  */
330 typedef DPL::String WidgetParamValue;
331
332 /**
333  * @brief A map of widget configuration parameters.
334  *
335  * Widget configuration parameters are read from database and are stored
336  * along with feature that they describe.
337  */
338 typedef std::multimap<WidgetParamKey, WidgetParamValue> WidgetParamMap;
339
340 /**
341  * @brief Widget feature host information about possible javascript extensions
342  *        that widget may use
343  *
344  * Widget features are declared in configuration file in widget installation
345  * package. Each declared special feature is contained in some wrt-plugin that
346  * declares to implement it. After widget launch wrt searches for proper plugin
347  * libraries and load needed features.
348  *
349  * Widget features can be required or optional. It is possible to start widget
350  * without missing feature. When required feature cannot be loaded widget will
351  * not start.
352  */
353
354 enum {
355     INVALID_PLUGIN_HANDLE = -1
356 };
357 typedef int DbPluginHandle;
358
359 struct DbWidgetFeature
360 {
361     DPL::String name;        /// Feature name
362     bool required;           /// Whether feature is required
363     DbPluginHandle pluginId;            /// Plugin id that implement this feature
364     WidgetParamMap params;   /// Widget's params
365
366     DbWidgetFeature() :
367         required(false),
368         pluginId(INVALID_PLUGIN_HANDLE)
369     {
370     }
371 };
372
373 inline bool operator < (const DbWidgetFeature &objA,
374         const DbWidgetFeature &objB)
375 {
376     return objA.name.compare(objB.name) < 0;
377 }
378
379 inline bool operator==(const DbWidgetFeature &featureA,
380         const DbWidgetFeature &featureB)
381 {
382     return featureA.name == featureB.name &&
383            featureA.required == featureB.required &&
384            featureA.pluginId == featureB.pluginId;
385 }
386
387 /**
388  * @brief Default container for features list
389  */
390 typedef std::multiset<DbWidgetFeature> DbWidgetFeatureSet;
391
392 /**
393  * @brief Default container with DbWidgetHandle's
394  */
395 typedef std::list<DbWidgetHandle> DbWidgetHandleList;
396
397 /**
398  * @brief Widget specific type
399  *
400  * Widget type describes belowed in WAC, TIZEN WebApp
401  */
402 enum AppType
403 {
404     APP_TYPE_UNKNOWN = 0, // unknown
405     APP_TYPE_WAC10, // WAC 1.0
406     APP_TYPE_WAC20, // WAC 2.0
407     APP_TYPE_TIZENWEBAPP, // slp webapp
408 };
409
410 class WidgetType
411 {
412   public:
413     WidgetType()
414     :appType(APP_TYPE_UNKNOWN)
415     {
416     }
417     WidgetType(const AppType type)
418     :appType(type)
419     {
420     }
421     bool operator== (const AppType& other) const
422     {
423         return appType == other;
424     }
425     std::string getApptypeToString()
426     {
427         switch (appType) {
428 #define X(x) case x: return #x;
429         X(APP_TYPE_UNKNOWN)
430         X(APP_TYPE_WAC10)
431         X(APP_TYPE_WAC20)
432         X(APP_TYPE_TIZENWEBAPP)
433 #undef X
434         default:
435             return "UNKNOWN";
436         }
437     }
438
439     AppType appType;
440 };
441
442 } // namespace WrtDB
443
444 struct WidgetSetting
445 {
446     DPL::String settingName;
447     DPL::String settingValue;
448
449     bool operator ==(const WidgetSetting& info) const
450     {
451         return (info.settingName == settingName &&
452                info.settingValue == settingValue);
453     }
454     bool operator !=(const WidgetSetting& info) const
455     {
456         return (info.settingName != settingName ||
457                info.settingValue != settingValue);
458     }
459 };
460
461 typedef std::list<WidgetSetting> WidgetSettings;
462
463 /**
464  * @brief Widget Application Service
465  *
466  * Application sercvice describes details of behaviour
467  * when widget receives aul bundle data.
468  */
469 struct WidgetApplicationService
470 {
471   public:
472     DPL::String src;       /* start uri */
473     DPL::String operation; /* service name */
474     DPL::String scheme;    /* scheme type*/
475     DPL::String mime;      /* mime type */
476
477     bool operator== (const WidgetApplicationService& other) const
478     {
479         return src == other.src &&
480         operation == other.operation &&
481         scheme == other.scheme &&
482         mime == other.mime;
483     }
484 };
485
486 typedef std::list<WidgetApplicationService> WidgetApplicationServiceList;
487 #endif /* WRT_SRC_CONFIGURATION_COMMON_DAO_TYPES_H_ */