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>
23 #include <JSWebAPIException.h>
25 //#include <Commons/Exception.h>
26 //#include <JSWebAPIexception.h>
27 //#include <JSTizenExceptionFactory.h>
28 //#include <JSTizenException.h>
30 #include "ApplicationCert.h"
31 #include "JSApplicationCert.h"
35 namespace Application {
37 using namespace WrtDeviceApis;
38 using namespace DeviceAPI::Common;
41 JSClassRef JSApplicationCert::m_classRef = NULL;
43 JSClassDefinition JSApplicationCert::m_classInfo = {
45 kJSClassAttributeNone,
46 TIZEN_INTERFACE_APPLICATION_CERT,
55 NULL, //DeleteProperty,
56 NULL, //GetPropertyNames,
57 NULL, //CallAsFunction,
58 NULL, //CallAsConstructor,
63 JSStaticValue JSApplicationCert::m_property[] = {
64 { TIZEN_APPLICATION_CERT_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
65 { TIZEN_APPLICATION_CERT_VALUE, getProperty, NULL, kJSPropertyAttributeReadOnly },
69 JSClassRef JSApplicationCert::getClassRef() {
71 m_classRef = JSClassCreate(&m_classInfo);
77 void JSApplicationCert::initialize(JSContextRef context, JSObjectRef object)
79 LoggerI(">> initialize");
82 void JSApplicationCert::finalize(JSObjectRef object)
84 LoggerI(">> finalize");
85 JSApplicationCertPriv* priv = static_cast<JSApplicationCertPriv*>(JSObjectGetPrivate(object));
86 JSObjectSetPrivate(object, NULL);
87 LoggerD("Deleting JSApplicationCert object");
91 bool JSApplicationCert::isObjectOfClass(JSContextRef context, JSValueRef value)
93 return JSValueIsObjectOfClass(context, value, getClassRef());
96 ApplicationCertPtr JSApplicationCert::getPrivData(JSObjectRef object)
98 JSApplicationCertPriv *priv = static_cast<JSApplicationCertPriv*>(JSObjectGetPrivate(object));
100 throw TypeMismatchException("Private object is null");
102 ApplicationCertPtr result = priv->getObject();
104 throw TypeMismatchException("Private object is null");
110 JSValueRef JSApplicationCert::getProperty(JSContextRef context,
112 JSStringRef propertyName,
113 JSValueRef* exception)
116 CommonsJavaScript::Converter converter(context);
117 ApplicationCertPtr privateData = getPrivData(object);
119 LoggerE("JSApplicationCert::getProperty = " << propertyName);
121 if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CERT_TYPE)) {
122 return converter.toJSValueRef(privateData->getType());
123 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CERT_VALUE)) {
124 return converter.toJSValueRef(privateData->getValue());
126 } catch (const BasePlatformException &err) {
127 return JSWebAPIException::throwException(context, exception, err);
129 DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
130 return JSWebAPIException::throwException(context, exception, err);
133 return JSValueMakeUndefined(context);