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 <dpl/log/log.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <CommonsJavaScript/Converter.h>
24 #include <Commons/Exception.h>
25 #include <JSTizenExceptionFactory.h>
26 #include <JSTizenException.h>
27 #include "ApplicationCert.h"
28 #include "JSApplicationCert.h"
31 namespace Application {
33 using namespace WrtDeviceApis;
34 using namespace DeviceAPI::Common;
37 JSClassRef JSApplicationCert::m_classRef = NULL;
39 JSClassDefinition JSApplicationCert::m_classInfo = {
41 kJSClassAttributeNone,
42 TIZEN_INTERFACE_APPLICATION_CERT,
49 getProperty, //GetProperty,
51 NULL, //DeleteProperty,
52 NULL, //GetPropertyNames,
53 NULL, //CallAsFunction,
54 NULL, //CallAsConstructor,
59 JSStaticValue JSApplicationCert::m_property[] = {
60 { TIZEN_APPLICATION_CERT_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
61 { TIZEN_APPLICATION_CERT_VALUE, getProperty, NULL, kJSPropertyAttributeReadOnly },
65 JSClassRef JSApplicationCert::getClassRef() {
67 m_classRef = JSClassCreate(&m_classInfo);
73 void JSApplicationCert::initialize(JSContextRef context, JSObjectRef object)
75 LogInfo(">> initialize");
78 void JSApplicationCert::finalize(JSObjectRef object)
80 LogInfo(">> finalize");
81 JSApplicationCertPriv* priv = static_cast<JSApplicationCertPriv*>(JSObjectGetPrivate(object));
82 JSObjectSetPrivate(object, NULL);
83 LogDebug("Deleting JSApplicationCert object");
87 bool JSApplicationCert::isObjectOfClass(JSContextRef context, JSValueRef value)
89 return JSValueIsObjectOfClass(context, value, getClassRef());
92 ApplicationCertPtr JSApplicationCert::getPrivData(JSObjectRef object)
94 JSApplicationCertPriv *priv = static_cast<JSApplicationCertPriv*>(JSObjectGetPrivate(object));
96 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
98 ApplicationCertPtr result = priv->getObject();
100 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
106 JSValueRef JSApplicationCert::getProperty(JSContextRef context,
108 JSStringRef propertyName,
109 JSValueRef* exception)
112 CommonsJavaScript::Converter converter(context);
113 ApplicationCertPtr privateData = getPrivData(object);
115 LogError("JSApplicationCert::getProperty = " << propertyName);
117 if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CERT_TYPE)) {
118 return converter.toJSValueRef(privateData->getType());
119 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CERT_VALUE)) {
120 return converter.toJSValueRef(privateData->getValue());
122 } Catch(WrtDeviceApis::Commons::Exception) {
123 LogError("Exception: " << _rethrown_exception.GetMessage());
124 JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
127 return JSValueMakeUndefined(context);