2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/PrivateObject.h>
23 #include "IMessagingTypes.h"
25 #include "EventUpdateMessage.h"
26 #include "JSMessageBody.h"
33 static JSClassRef m_jsClassRef;
38 * This method initializes object in the JS Engine.
40 static JSClassRef jsInit(JSContextRef context)
43 return JSClassCreate(&m_classInfo);
46 static const JSClassDefinition* getClassInfo()
49 return &(m_classInfo);
52 static JSClassRef getClassRef()
56 m_jsClassRef = JSClassCreate(&m_classInfo);
61 static JSObjectRef constructor(JSContextRef ctx,
62 JSObjectRef constructor,
64 const JSValueRef arguments[],
65 JSValueRef* exception);
67 static JSValueRef createJSObject(JSContextRef context,
68 EmailAccountInfo& account,
70 const std::string& msgId = "");
72 static JSValueRef createJSObject(JSContextRef context,
73 EventUpdateMessageAnswerReceiver* listener,
74 MessageType msgType = MESSAGETYPE_COUNT,
75 const std::string& msgId = "");
77 static JSValueRef createJSObject(JSContextRef context,
78 MessageType msgType = MESSAGETYPE_COUNT,
79 const std::string& msgId = "");
81 static JSValueRef createJSObject(JSContextRef context,
82 const IMessagePtr& msg,
83 EventUpdateMessageAnswerReceiver* listener);
85 static JSValueRef createJSObject(JSContextRef context,
86 const IMessagePtr& msg);
88 static JSValueRef createDummyMessageJSObject(JSContextRef context,
93 * The callback invoked when an object is first created.
95 static void initialize(JSContextRef context,
99 * The callback invoked when an object is finalized.
101 static void finalize(JSObjectRef object);
104 * The callback invoked when determining whether an object has a property.
106 static bool hasProperty(JSContextRef context,
108 JSStringRef propertyName);
111 * The callback invoked when getting a property's value.
113 static JSValueRef getProperty(JSContextRef context,
115 JSStringRef propertyName,
116 JSValueRef* exception);
119 * The callback invoked when setting a property's value.
121 static bool setProperty(JSContextRef context,
123 JSStringRef propertyName,
125 JSValueRef* exception);
128 * The callback invoked when deleting a property.
130 static bool deleteProperty(JSContextRef context,
132 JSStringRef propertyName,
133 JSValueRef* exception);
136 * The callback invoked when collecting the names of an object's properties.
138 static void getPropertyNames(JSContextRef context,
140 JSPropertyNameAccumulatorRef propertyNames);
143 * The callback invoked when an object is called as a function.
145 static JSValueRef callAsFunction(JSContextRef context,
147 JSObjectRef thisObject,
148 size_t argumentCount,
149 const JSValueRef arguments[],
150 JSValueRef* exception);
153 * The callback invoked when an object is used as the target of an 'instanceof' expression.
155 static bool hasInstance(JSContextRef context,
156 JSObjectRef constructor,
157 JSValueRef possibleInstance,
158 JSValueRef* exception);
162 * The callback invoked when converting an object to a particular JavaScript type.
164 static JSValueRef convertToType(JSContextRef context,
167 JSValueRef* exception);
168 static JSValueRef getAttachments(JSContextRef context,
170 JSStringRef propertyName,
171 JSValueRef* exception);
172 static JSValueRef getBccAddress(JSContextRef context,
174 JSStringRef propertyName,
175 JSValueRef* exception);
176 static JSValueRef getBody(JSContextRef context,
178 JSStringRef propertyName,
179 JSValueRef* exception);
180 static JSValueRef getCallbackNumber(JSContextRef context,
182 JSStringRef propertyName,
183 JSValueRef* exception);
184 static JSValueRef getCcAddress(JSContextRef context,
186 JSStringRef propertyName,
187 JSValueRef* exception);
188 static JSValueRef getDestinationAddress(JSContextRef context,
190 JSStringRef propertyName,
191 JSValueRef* exception);
192 static JSValueRef getIsRead(JSContextRef context,
194 JSStringRef propertyName,
195 JSValueRef* exception);
196 static JSValueRef getMessageId(JSContextRef context,
198 JSStringRef propertyName,
199 JSValueRef* exception);
200 static JSValueRef getMessagePriority(JSContextRef context,
202 JSStringRef propertyName,
203 JSValueRef* exception);
204 static JSValueRef getMessageType(JSContextRef context,
206 JSStringRef propertyName,
207 JSValueRef* exception);
208 static JSValueRef getSourceAddress(JSContextRef context,
210 JSStringRef propertyName,
211 JSValueRef* exception);
212 static JSValueRef getSubject(JSContextRef context,
214 JSStringRef propertyName,
215 JSValueRef* exception);
216 static JSValueRef getTime(JSContextRef context,
218 JSStringRef propertyName,
219 JSValueRef* exception);
220 static JSValueRef getFolder(JSContextRef context,
222 JSStringRef propertyName,
223 JSValueRef* exception);
224 static JSValueRef getMessageBody(JSContextRef context,
226 JSStringRef propertyName,
227 JSValueRef* exception);
228 static JSValueRef getAccountID(JSContextRef context,
230 JSStringRef propertyName,
231 JSValueRef* exception);
232 static JSValueRef getUID(JSContextRef context,
234 JSStringRef propertyName,
235 JSValueRef* exception);
236 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
237 static bool setAttachments(JSContextRef context,
239 JSStringRef propertyName,
241 JSValueRef* exception);
243 static bool setAttachments(JSContextRef context,
245 JSStringRef propertyName,
247 JSValueRef* exception);
249 static bool setBccAddress(JSContextRef context,
251 JSStringRef propertyName,
253 JSValueRef* exception);
254 static bool setBody(JSContextRef context,
256 JSStringRef propertyName,
258 JSValueRef* exception);
259 static bool setCcAddress(JSContextRef context,
261 JSStringRef propertyName,
263 JSValueRef* exception);
264 static bool setDestinationAddress(JSContextRef context,
266 JSStringRef propertyName,
268 JSValueRef* exception);
269 static bool setIsRead(JSContextRef context,
271 JSStringRef propertyName,
273 JSValueRef* exception);
274 static bool setMessagePriority(JSContextRef context,
276 JSStringRef propertyName,
278 JSValueRef* exception);
279 static bool setSubject(JSContextRef context,
281 JSStringRef propertyName,
283 JSValueRef* exception);
284 static bool setMessageBody(JSContextRef context,
286 JSStringRef propertyName,
288 JSValueRef* exception);
290 static JSValueRef update(JSContextRef context,
291 JSObjectRef function,
292 JSObjectRef thisObject,
293 size_t argumentCount,
294 const JSValueRef arguments[],
295 JSValueRef* exception);
296 static JSValueRef getConversationId(JSContextRef context,
298 JSStringRef propertyName,
299 JSValueRef* exception);
300 static JSValueRef getInResponseTo(JSContextRef context,
302 JSStringRef propertyName,
303 JSValueRef* exception);
305 static JSValueRef getMessageStatus(JSContextRef context,
307 JSStringRef propertyName,
308 JSValueRef* exception);
310 static JSValueRef hasAttachment(JSContextRef context,
312 JSStringRef propertyName,
313 JSValueRef* exception);
316 * This structure describes a statically declared function property.
318 static JSStaticFunction m_function[];
321 * This structure contains properties and callbacks that define a type of object.
323 static JSClassDefinition m_classInfo;
326 * This member variable contains the initialization values for the static properties of this class.
327 * The values are given according to the data structure JSPropertySpec
329 static JSStaticValue m_property[];
331 // Utility functions. After full refactoring should be moved into lower layer
333 * Functions that provides enum MessageServiceTag support. Converts message
334 * type given as string into MessageType value
336 static MessageType stringToMessageType(std::string type);