2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @author Pawel Misiak (p.misiak@samsung.com)
30 #include <dpl/log/log.h>
31 #include <CommonsJavaScript/Converter.h>
32 #include <CommonsJavaScript/PrivateObject.h>
33 #include <API/Messaging/IMessagingTypes.h>
34 #include <API/Messaging/IMessage.h>
35 #include <API/Messaging/EventUpdateMessage.h>
36 #include "JSMessageBody.h"
42 static JSClassRef m_jsClassRef;
47 * This method initializes object in the JS Engine.
49 static JSClassRef jsInit(JSContextRef context)
52 return JSClassCreate(&m_classInfo);
55 static const JSClassDefinition* getClassInfo()
58 return &(m_classInfo);
61 static JSClassRef getClassRef()
65 m_jsClassRef = JSClassCreate(&m_classInfo);
70 static JSValueRef createJSObject(JSContextRef context,
71 Api::Messaging::EmailAccountInfo& account,
72 Api::Messaging::MessageType msgType,
73 const std::string& msgId = "");
75 static JSValueRef createJSObject(JSContextRef context,
76 Api::Messaging::EventUpdateMessageAnswerReceiver* listener,
77 Api::Messaging::MessageType msgType = Api::Messaging::MESSAGETYPE_COUNT,
78 const std::string& msgId = "");
80 static JSValueRef createJSObject(JSContextRef context,
81 Api::Messaging::MessageType msgType = Api::Messaging::MESSAGETYPE_COUNT,
82 const std::string& msgId = "");
84 static JSValueRef createJSObject(JSContextRef context,
85 const Api::Messaging::IMessagePtr& msg,
86 Api::Messaging::EventUpdateMessageAnswerReceiver* listener);
88 static JSValueRef createJSObject(JSContextRef context,
89 const Api::Messaging::IMessagePtr& msg);
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);
161 * The callback invoked when converting an object to a particular JavaScript type.
163 static JSValueRef convertToType(JSContextRef context,
166 JSValueRef* exception);
167 static JSValueRef getAttachments(JSContextRef context,
169 JSStringRef propertyName,
170 JSValueRef* exception);
171 static JSValueRef getBccAddress(JSContextRef context,
173 JSStringRef propertyName,
174 JSValueRef* exception);
175 static JSValueRef getBody(JSContextRef context,
177 JSStringRef propertyName,
178 JSValueRef* exception);
179 static JSValueRef getCallbackNumber(JSContextRef context,
181 JSStringRef propertyName,
182 JSValueRef* exception);
183 static JSValueRef getCcAddress(JSContextRef context,
185 JSStringRef propertyName,
186 JSValueRef* exception);
187 static JSValueRef getDestinationAddress(JSContextRef context,
189 JSStringRef propertyName,
190 JSValueRef* exception);
191 static JSValueRef getIsRead(JSContextRef context,
193 JSStringRef propertyName,
194 JSValueRef* exception);
195 static JSValueRef getMessageId(JSContextRef context,
197 JSStringRef propertyName,
198 JSValueRef* exception);
199 static JSValueRef getMessagePriority(JSContextRef context,
201 JSStringRef propertyName,
202 JSValueRef* exception);
203 static JSValueRef getMessageType(JSContextRef context,
205 JSStringRef propertyName,
206 JSValueRef* exception);
207 static JSValueRef getSourceAddress(JSContextRef context,
209 JSStringRef propertyName,
210 JSValueRef* exception);
211 static JSValueRef getSubject(JSContextRef context,
213 JSStringRef propertyName,
214 JSValueRef* exception);
215 static JSValueRef getTime(JSContextRef context,
217 JSStringRef propertyName,
218 JSValueRef* exception);
219 static JSValueRef getFolder(JSContextRef context,
221 JSStringRef propertyName,
222 JSValueRef* exception);
223 static JSValueRef getMessageBody(JSContextRef context,
225 JSStringRef propertyName,
226 JSValueRef* exception);
227 static JSValueRef getAccountID(JSContextRef context,
229 JSStringRef propertyName,
230 JSValueRef* exception);
231 static JSValueRef getUID(JSContextRef context,
233 JSStringRef propertyName,
234 JSValueRef* exception);
235 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
236 static bool setAttachments(JSContextRef context,
238 JSStringRef propertyName,
240 JSValueRef* exception);
242 static bool setBccAddress(JSContextRef context,
244 JSStringRef propertyName,
246 JSValueRef* exception);
247 static bool setBody(JSContextRef context,
249 JSStringRef propertyName,
251 JSValueRef* exception);
252 static bool setCcAddress(JSContextRef context,
254 JSStringRef propertyName,
256 JSValueRef* exception);
257 static bool setDestinationAddress(JSContextRef context,
259 JSStringRef propertyName,
261 JSValueRef* exception);
262 static bool setIsRead(JSContextRef context,
264 JSStringRef propertyName,
266 JSValueRef* exception);
267 static bool setMessagePriority(JSContextRef context,
269 JSStringRef propertyName,
271 JSValueRef* exception);
272 static bool setSubject(JSContextRef context,
274 JSStringRef propertyName,
276 JSValueRef* exception);
277 static bool setMessageBody(JSContextRef context,
279 JSStringRef propertyName,
281 JSValueRef* exception);
283 static JSValueRef update(JSContextRef context,
284 JSObjectRef function,
285 JSObjectRef thisObject,
286 size_t argumentCount,
287 const JSValueRef arguments[],
288 JSValueRef* exception);
289 static JSValueRef getConversationId(JSContextRef context,
291 JSStringRef propertyName,
292 JSValueRef* exception);
293 static JSValueRef getInResponseTo(JSContextRef context,
295 JSStringRef propertyName,
296 JSValueRef* exception);
299 static JSValueRef getMessageStatus(JSContextRef context,
301 JSStringRef propertyName,
302 JSValueRef* exception);
305 * This structure describes a statically declared function property.
307 static JSStaticFunction m_function[];
310 * This structure contains properties and callbacks that define a type of object.
312 static JSClassDefinition m_classInfo;
315 * This member variable contains the initialization values for the static properties of this class.
316 * The values are given according to the data structure JSPropertySpec
318 static JSStaticValue m_property[];