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/JSUtils.h>
22 #include <CommonsJavaScript/Converter.h>
24 //#include <Commons/Exception.h>
25 #include <JSWebAPIErrorFactory.h>
27 #include "ApplicationCert.h"
28 #include "JSApplicationCert.h"
33 namespace Application {
35 using namespace WrtDeviceApis;
36 using namespace DeviceAPI::Common;
39 JSClassRef JSApplicationCert::m_classRef = NULL;
41 JSClassDefinition JSApplicationCert::m_classInfo = {
43 kJSClassAttributeNone,
44 TIZEN_INTERFACE_APPLICATION_CERT,
53 NULL, //DeleteProperty,
54 NULL, //GetPropertyNames,
55 NULL, //CallAsFunction,
56 NULL, //CallAsConstructor,
61 JSStaticValue JSApplicationCert::m_property[] = {
62 { TIZEN_APPLICATION_CERT_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
63 { TIZEN_APPLICATION_CERT_VALUE, getProperty, NULL, kJSPropertyAttributeReadOnly },
67 JSClassRef DLL_EXPORT JSApplicationCert::getClassRef() {
69 m_classRef = JSClassCreate(&m_classInfo);
75 void JSApplicationCert::initialize(JSContextRef context, JSObjectRef object)
79 void JSApplicationCert::finalize(JSObjectRef object)
81 JSApplicationCertPriv* priv = static_cast<JSApplicationCertPriv*>(JSObjectGetPrivate(object));
82 JSObjectSetPrivate(object, NULL);
86 bool JSApplicationCert::isObjectOfClass(JSContextRef context, JSValueRef value)
88 return JSValueIsObjectOfClass(context, value, getClassRef());
91 ApplicationCertPtr JSApplicationCert::getPrivData(JSObjectRef object)
93 JSApplicationCertPriv *priv = static_cast<JSApplicationCertPriv*>(JSObjectGetPrivate(object));
95 throw TypeMismatchException("Private object is null");
97 ApplicationCertPtr result = priv->getObject();
99 throw TypeMismatchException("Private object is null");
105 JSValueRef JSApplicationCert::getProperty(JSContextRef context,
107 JSStringRef propertyName,
108 JSValueRef* exception)
111 CommonsJavaScript::Converter converter(context);
112 ApplicationCertPtr privateData = getPrivData(object);
114 LoggerD("JSApplicationCert::getProperty = " << propertyName);
116 if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CERT_TYPE)) {
117 return converter.toJSValueRef(privateData->getType());
118 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CERT_VALUE)) {
119 return converter.toJSValueRef(privateData->getValue());
121 } catch (const BasePlatformException &err) {
122 return JSWebAPIErrorFactory::postException(context, exception, err);
124 DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
125 return JSWebAPIErrorFactory::postException(context, exception, err);
128 return JSValueMakeUndefined(context);