Update change log and spec for wrt-plugins-tizen_0.4.9
[platform/framework/web/wrt-plugins-tizen.git] / src / Application / JSApplicationCert.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18
19 #include <cassert>
20 #include <memory>
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"
29
30 namespace DeviceAPI {
31 namespace Application { 
32         
33 using namespace WrtDeviceApis;
34 using namespace DeviceAPI::Common;
35
36
37 JSClassRef JSApplicationCert::m_classRef = NULL;
38
39 JSClassDefinition JSApplicationCert::m_classInfo = {
40     0,
41     kJSClassAttributeNone,
42     TIZEN_INTERFACE_APPLICATION_CERT,
43     0,
44     m_property,
45     0,
46     initialize,
47     finalize,
48     NULL,     //HasProperty,
49     getProperty,        //GetProperty,
50     NULL,     //SetProperty,
51     NULL,     //DeleteProperty,
52     NULL,     //GetPropertyNames,
53     NULL,     //CallAsFunction,
54     NULL,     //CallAsConstructor,
55     NULL,
56     NULL,     //ConvertToType
57 };
58
59 JSStaticValue JSApplicationCert::m_property[] = {
60     { TIZEN_APPLICATION_CERT_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
61     { TIZEN_APPLICATION_CERT_VALUE, getProperty, NULL, kJSPropertyAttributeReadOnly },
62     { 0, 0, 0, 0 }
63 };
64
65 JSClassRef JSApplicationCert::getClassRef() {
66         if (!m_classRef) {
67                 m_classRef = JSClassCreate(&m_classInfo);
68         }
69         return m_classRef;
70 }
71
72
73 void JSApplicationCert::initialize(JSContextRef context, JSObjectRef object)
74 {
75         LogInfo(">> initialize");
76 }
77
78 void JSApplicationCert::finalize(JSObjectRef object)
79 {
80     LogInfo(">> finalize");
81     JSApplicationCertPriv* priv = static_cast<JSApplicationCertPriv*>(JSObjectGetPrivate(object));
82     JSObjectSetPrivate(object, NULL);
83     LogDebug("Deleting JSApplicationCert object");
84     delete priv;                
85 }
86
87 bool JSApplicationCert::isObjectOfClass(JSContextRef context, JSValueRef value)
88 {
89         return JSValueIsObjectOfClass(context, value, getClassRef());
90 }
91
92 ApplicationCertPtr JSApplicationCert::getPrivData(JSObjectRef object)
93 {
94         JSApplicationCertPriv *priv = static_cast<JSApplicationCertPriv*>(JSObjectGetPrivate(object));
95         if (!priv) {
96                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
97         }
98         ApplicationCertPtr result = priv->getObject();
99         if (!result) {
100                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
101         }
102         return result;
103 }
104
105
106 JSValueRef JSApplicationCert::getProperty(JSContextRef context,
107         JSObjectRef object,
108         JSStringRef propertyName,
109         JSValueRef* exception)
110 {
111         Try     {
112                 CommonsJavaScript::Converter converter(context);
113                 ApplicationCertPtr privateData = getPrivData(object);
114
115                 LogError("JSApplicationCert::getProperty = " << propertyName);
116         
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());
121                 }
122         } Catch(WrtDeviceApis::Commons::Exception) {
123         LogError("Exception: " << _rethrown_exception.GetMessage());
124                 JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
125     }
126         
127         return JSValueMakeUndefined(context);
128 }
129
130 }
131 }