Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules_mobile / widget_dao / 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_WIDGET_DAO_COMMON_DAO_TYPES_H_
25 #define WRT_WIDGET_DAO_COMMON_DAO_TYPES_H_
26
27 #include <set>
28 #include <string>
29 #include <map>
30 #include <vector>
31 #include <list>
32 #include <memory>
33 #include <dpl/optional_typedefs.h>
34
35 namespace WrtDB {
36 class PluginMetafileData
37 {
38   public:
39     struct Feature
40     {
41         std::string m_name;
42         std::set<std::string> m_deviceCapabilities;
43
44         bool operator< (const Feature& obj) const
45         {
46             return m_name < obj.m_name;
47         }
48     };
49     typedef std::set<Feature> FeatureContainer;
50
51   public:
52
53     PluginMetafileData()
54     {}
55
56     std::string m_libraryName;
57     FeatureContainer m_featureContainer;
58 };
59
60 class PluginObjectsDAO
61 {
62   public:
63     typedef std::set<std::string> Objects;
64     typedef std::shared_ptr<Objects> ObjectsPtr;
65
66   public:
67     explicit PluginObjectsDAO() {}
68
69   protected:
70     ObjectsPtr m_implemented;
71     ObjectsPtr m_dependent;
72 };
73
74 /**
75  * @brief Widget id describes web-runtime global widget identifier.
76  *
77  * Notice that only up to one widget can exist at the same time.
78  * DbWidgetHandle can be translated into corresponding WidgetModel by invoking
79  * FindWidgetModel routine.
80  */
81 typedef int DbWidgetHandle;
82 typedef DPL::String TizenPkgId;
83 typedef DPL::String TizenAppId;
84
85 /**
86  * Value of invalid widget handle
87  */
88 enum {
89     INVALID_WIDGET_HANDLE = -1
90 };
91
92 /**
93  * @brief Structure to hold the information of widget's size
94  */
95 struct DbWidgetSize
96 {
97     DPL::OptionalInt width;
98     DPL::OptionalInt height;
99
100     DbWidgetSize(DPL::OptionalInt w = DPL::OptionalInt::Null,
101                  DPL::OptionalInt h = DPL::OptionalInt::Null) :
102         width(w),
103         height(h)
104     {}
105 };
106
107 inline bool operator ==(const DbWidgetSize &objA, const DbWidgetSize &objB)
108 {
109     if (!objA.height || !objA.width || !objB.width || !objB.height) {
110         return false;
111     } else {
112         return *objA.height == *objB.height && *objA.width == *objB.width;
113     }
114 }
115
116 /**
117  * Widget [G]lobal [U]nique [ID]entifier
118  * Orginated from appstore ID
119  */
120 typedef DPL::OptionalString WidgetGUID;
121
122 struct WidgetAccessInfo
123 {
124     DPL::String strIRI;                /* origin iri */
125     bool bSubDomains;                  /* do we want access to subdomains ? */
126
127     bool operator ==(const WidgetAccessInfo& info) const
128     {
129         return info.strIRI == strIRI &&
130                info.bSubDomains == bSubDomains;
131     }
132 };
133 typedef std::list<WidgetAccessInfo> WidgetAccessInfoList;
134
135 struct WidgetAllowNavigationInfo
136 {
137     DPL::String scheme;
138     DPL::String host;
139 };
140 typedef std::list<WidgetAllowNavigationInfo> WidgetAllowNavigationInfoList;
141
142 struct EncryptedFileInfo
143 {
144     DPL::String fileName;
145     int fileSize;
146
147     bool operator==(const EncryptedFileInfo& info) const
148     {
149         return fileName == info.fileName;
150     }
151
152     bool operator==(const DPL::String& file) const
153     {
154         return fileName == file;
155     }
156
157     bool operator< (const EncryptedFileInfo& info) const
158     {
159         return fileName < info.fileName;
160     }
161 };
162
163 typedef std::list<DPL::String> WindowModeList;
164
165 typedef std::list<DPL::String> PrivilegeList;
166
167 typedef std::set<EncryptedFileInfo> EncryptedFileList;
168
169 /**
170  * @brief Widget feature host information about possible javascript extensions
171  *        that widget may use
172  *
173  * Widget features are declared in configuration file in widget installation
174  * package. Each declared special feature is contained in some wrt-plugin that
175  * declares to implement it. After widget launch wrt searches for proper plugin
176  * libraries and load needed features.
177  *
178  * Widget features can be required or optional. It is possible to start widget
179  * without missing feature. When required feature cannot be loaded widget will
180  * not start.
181  */
182
183 enum {
184     INVALID_PLUGIN_HANDLE = -1
185 };
186 typedef int DbPluginHandle;
187
188 struct DbWidgetFeature
189 {
190     DPL::String name;        /// Feature name
191     bool rejected;           /// Api feature was rejected by ace
192     DbPluginHandle pluginId; /// Plugin id that implement this feature
193
194     DbWidgetFeature() :
195         pluginId(INVALID_PLUGIN_HANDLE)
196     {}
197 };
198
199 inline bool operator < (const DbWidgetFeature &objA,
200                         const DbWidgetFeature &objB)
201 {
202     return objA.name.compare(objB.name) < 0;
203 }
204
205 inline bool operator==(const DbWidgetFeature &featureA,
206                        const DbWidgetFeature &featureB)
207 {
208     return featureA.name == featureB.name &&
209            featureA.pluginId == featureB.pluginId;
210 }
211
212 /**
213  * @brief Default container for features list
214  */
215 typedef std::multiset<DbWidgetFeature> DbWidgetFeatureSet;
216
217 /**
218  * @brief Default container with DbWidgetHandle's
219  */
220 typedef std::list<DbWidgetHandle> DbWidgetHandleList;
221 typedef std::list<TizenAppId> TizenAppIdList;
222 typedef std::list<TizenPkgId> TizenPkgIdList;
223
224 class WidgetDAOReadOnly; //forward declaration
225 typedef std::shared_ptr<WidgetDAOReadOnly> WidgetDAOReadOnlyPtr;
226 /**
227  * @brief Default container with WidgetDAOReadOnly
228  */
229 typedef std::list<WidgetDAOReadOnlyPtr> DbWidgetDAOReadOnlyList;
230
231 /**
232  * @brief Widget specific type
233  *
234  * Widget type describes belowed in WAC, TIZEN WebApp
235  */
236 enum AppType
237 {
238     APP_TYPE_UNKNOWN = 0, // unknown
239     APP_TYPE_TIZENWEBAPP // Tizen webapp
240 };
241
242 class WidgetType
243 {
244   public:
245     WidgetType() :
246         appType(APP_TYPE_UNKNOWN)
247     {}
248     WidgetType(const AppType type) :
249         appType(type)
250     {}
251     bool operator== (const AppType& other) const
252     {
253         return appType == other;
254     }
255     bool operator!= (const AppType& other) const
256     {
257         return appType != other;
258     }
259     std::string getApptypeToString()
260     {
261         switch (appType) {
262 #define X(x) case x: return #x;
263             X(APP_TYPE_UNKNOWN)
264             X(APP_TYPE_TIZENWEBAPP)
265 #undef X
266         default:
267             return "UNKNOWN";
268         }
269     }
270
271     AppType appType;
272 };
273
274 /**
275  * @brief Package specific type
276  *
277  * Package type describes belowed in Tizen webapp, C++ service App
278  */
279 enum PkgType
280 {
281     PKG_TYPE_UNKNOWN = 0, // unknown
282     PKG_TYPE_NOMAL_WEB_APP,
283     PKG_TYPE_DIRECTORY_WEB_APP,
284     PKG_TYPE_HOSTED_WEB_APP,    // request from browser
285     PKG_TYPE_HYBRID_WEB_APP // Tizen webapp with C++ service app
286 };
287
288 class PackagingType
289 {
290   public:
291     PackagingType() :
292         pkgType(PKG_TYPE_UNKNOWN)
293     {}
294     PackagingType(const PkgType type) :
295         pkgType(type)
296     {}
297     bool operator== (const PkgType& other) const
298     {
299         return pkgType == other;
300     }
301     bool operator!= (const PkgType& other) const
302     {
303         return pkgType != other;
304     }
305     std::string getPkgtypeToString()
306     {
307         switch (pkgType) {
308 #define X(x) case x: return #x;
309             X(PKG_TYPE_UNKNOWN)
310             X(PKG_TYPE_NOMAL_WEB_APP)
311             X(PKG_TYPE_DIRECTORY_WEB_APP)
312             X(PKG_TYPE_HOSTED_WEB_APP)
313             X(PKG_TYPE_HYBRID_WEB_APP)
314 #undef X
315         default:
316             return "UNKNOWN";
317         }
318     }
319
320     PkgType pkgType;
321 };
322
323 enum SettingsType
324 {
325     SETTINGS_TYPE_UNKNOWN = 0,
326     SETTINGS_TYPE_ON,
327     SETTINGS_TYPE_ALWAYS_ASK,
328     SETTINGS_TYPE_OFF
329 };
330
331 struct WidgetSetting
332 {
333     DPL::String settingName;
334     DPL::String settingValue;
335
336     bool operator ==(const WidgetSetting& info) const
337     {
338         return (info.settingName == settingName &&
339                 info.settingValue == settingValue);
340     }
341     bool operator !=(const WidgetSetting& info) const
342     {
343         return (info.settingName != settingName ||
344                 info.settingValue != settingValue);
345     }
346 };
347
348 typedef std::list<WidgetSetting> WidgetSettings;
349
350 /**
351  * @brief Widget AppControl
352  *
353  * Application control describes details of behaviour
354  * when widget receives aul bundle data.
355  */
356 namespace AppControlPrefix {
357     const char* const PROCESS_PREFIX = "-__CONTROL_PROCESS__";
358 }
359 struct WidgetAppControl
360 {
361     enum class Disposition {
362         UNDEFINE = 0,
363         WINDOW   = 1,
364         INLINE   = 2
365     };
366
367     DPL::String src;       /* start uri */
368     DPL::String operation; /* service name */
369     DPL::String uri;    /* scheme type*/
370     DPL::String mime;      /* mime type */
371     Disposition disposition;
372     unsigned index;
373
374     bool operator== (const WidgetAppControl& other) const
375     {
376         return src == other.src &&
377                operation == other.operation &&
378                uri == other.uri &&
379                mime == other.mime &&
380                disposition == other.disposition;
381     }
382 };
383
384 typedef std::list<WidgetAppControl> WidgetAppControlList;
385
386 enum class WidgetSecurityModelVersion
387 {
388     WIDGET_SECURITY_MODEL_V1 = 0, // WARP
389     WIDGET_SECURITY_MODEL_V2      // CSP, allow-navigation
390 };
391 } // namespace WrtDB
392 #endif /* WRT_WIDGET_DAO_COMMON_DAO_TYPES_H_ */