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.
18 #include <SecurityExceptions.h>
21 #include <JSWebAPIError.h>
22 #include <ArgumentValidator.h>
23 #include <GlobalContextManager.h>
24 #include <MultiCallbackUserData.h>
25 #include <PlatformException.h>
27 #include "plugin_config.h"
29 #include "JSPushMessage.h"
31 using namespace WrtDeviceApis::Commons;
32 using namespace DeviceAPI::Common;
37 JSClassDefinition JSPushMessage::m_classInfo = {
39 kJSClassAttributeNone,
43 NULL, //StaticFunctions
44 initialize, //Initialize
49 NULL, //DeleteProperty,
50 NULL, //GetPropertyNames,
51 NULL, //CallAsFunction,
52 NULL, //CallAsConstructor,
58 JSClassRef JSPushMessage::m_jsClassRef = JSClassCreate(JSPushMessage::getClassInfo());
60 const JSClassRef JSPushMessage::getClassRef()
63 m_jsClassRef = JSClassCreate(&m_classInfo);
68 const JSClassDefinition* JSPushMessage::getClassInfo()
73 void JSPushMessage::initialize(JSContextRef context, JSObjectRef object)
75 if (!JSObjectGetPrivate(object)) {
76 PushMessage *priv = new PushMessage();
77 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
83 void JSPushMessage::finalize(JSObjectRef object)
85 PushMessage *priv = static_cast<PushMessage *>(JSObjectGetPrivate(object));
87 JSObjectSetPrivate(object, NULL);
92 PushMessage* JSPushMessage::getPrivateObject(JSContextRef context, JSObjectRef object)
94 PushMessage *priv = static_cast<PushMessage *>(JSObjectGetPrivate(object));
96 throw TypeMismatchException("PushMessage's private object is NULL.");
100 JSValueRef appData = JSUtil::getProperty(context, object, PUSH_MESSAGE_APP_DATA);
101 priv->setAppData(JSUtil::JSValueToString(context, appData));
104 JSValueRef alertMessage = JSUtil::getProperty(context, object, PUSH_MESSAGE_ALERT_MESSAGE);
105 priv->setAlertMessage(JSUtil::JSValueToString(context, alertMessage));
108 JSValueRef date = JSUtil::getProperty(context, object, PUSH_MESSAGE_DATE);
109 priv->setDate(JSUtil::JSValueToTimeT(context, date));
114 void JSPushMessage::setPrivateObject(JSContextRef context, JSObjectRef object, PushMessage *priv)
117 throw TypeMismatchException("PushMessage's private object is NULL.");
120 JSObjectSetPrivate(object, static_cast<void*>(priv));
123 JSUtil::setProperty(context, object, PUSH_MESSAGE_APP_DATA,
124 JSUtil::toJSValueRef(context, priv->getAppData()), kJSPropertyAttributeNone);
127 JSUtil::setProperty(context, object, PUSH_MESSAGE_ALERT_MESSAGE,
128 JSUtil::toJSValueRef(context, priv->getAlertMessage()), kJSPropertyAttributeNone);
131 JSUtil::setProperty(context, object, PUSH_MESSAGE_DATE,
132 JSUtil::makeDateObject(context, priv->getDate()), kJSPropertyAttributeNone);