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 "JSNotificationDetailInfo.h"
31 using namespace WrtDeviceApis::Commons;
32 using namespace DeviceAPI::Common;
35 namespace Notification {
37 JSClassDefinition JSNotificationDetailInfo::m_classInfo = {
39 kJSClassAttributeNone,
40 "NotificationDetailInfo",
43 NULL, //StaticFunctions
44 initialize, //Initialize
49 NULL, //DeleteProperty,
50 NULL, //GetPropertyNames,
51 NULL, //CallAsFunction,
52 NULL, //CallAsConstructor,
58 JSClassRef JSNotificationDetailInfo::m_jsClassRef = JSClassCreate(JSNotificationDetailInfo::getClassInfo());
60 const JSClassRef JSNotificationDetailInfo::getClassRef()
63 m_jsClassRef = JSClassCreate(&m_classInfo);
68 const JSClassDefinition* JSNotificationDetailInfo::getClassInfo()
73 void JSNotificationDetailInfo::initialize(JSContextRef context, JSObjectRef object)
75 if (!JSObjectGetPrivate(object)) {
76 NotificationDetailInfo *priv = new NotificationDetailInfo();
77 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
83 void JSNotificationDetailInfo::finalize(JSObjectRef object)
85 NotificationDetailInfo *priv = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
87 JSObjectSetPrivate(object, NULL);
92 JSObjectRef JSNotificationDetailInfo::constructor(JSContextRef context,
93 JSObjectRef constructor,
95 const JSValueRef arguments[],
96 JSValueRef* exception)
98 ArgumentValidator validator(context, argumentCount, arguments);
100 NotificationDetailInfo *priv = new NotificationDetailInfo();
103 priv->setMainText(validator.toString(0, false, ""));
104 } catch (const BasePlatformException& err) {
105 LogWarning("mainText convertion is failed. %s", err.getMessage().c_str());
109 priv->setSubText(validator.toString(1, true, ""));
110 } catch (const BasePlatformException& err) {
111 LogWarning("subText convertion is failed. %s", err.getMessage().c_str());
114 JSObjectRef obj = JSObjectMake(context, getClassRef(), NULL);
115 setPrivateObject(context, obj, priv);
117 JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
118 JSObjectSetProperty(context, obj, ctorName, constructor,
119 kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
120 JSStringRelease(ctorName);
125 NotificationDetailInfo* JSNotificationDetailInfo::getPrivateObject(JSContextRef context, JSObjectRef object)
127 NotificationDetailInfo *priv = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
129 throw TypeMismatchException("NotificationDetailInfo's private object is NULL.");
133 JSValueRef mainText = JSUtil::getProperty(context, object, NOTIFICATION_DETAIL_INFO_MAIN_TEXT);
134 priv->setMainText(JSUtil::JSValueToString(context, mainText));
137 JSValueRef subText = JSUtil::getProperty(context, object, NOTIFICATION_DETAIL_INFO_SUB_TEXT);
138 priv->setSubText(JSUtil::JSValueToString(context, subText));
143 void JSNotificationDetailInfo::setPrivateObject(JSContextRef context, JSObjectRef object, NotificationDetailInfo *priv)
146 JSObjectSetPrivate(object, static_cast<void*>(priv));
150 JSUtil::setProperty(context, object, NOTIFICATION_DETAIL_INFO_MAIN_TEXT,
151 JSUtil::toJSValueRef(context, priv->getMainText()), kJSPropertyAttributeNone);
154 std::string subText = priv->getSubText();
156 if ( subText.empty())
158 JSUtil::setProperty(context, object, NOTIFICATION_DETAIL_INFO_SUB_TEXT, JSValueMakeNull(context), kJSPropertyAttributeNone);
162 JSUtil::setProperty(context, object, NOTIFICATION_DETAIL_INFO_SUB_TEXT,
163 JSUtil::toJSValueRef(context, priv->getSubText()), kJSPropertyAttributeNone);