2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <CommonsJavaScript/Validator.h>
19 #include <CommonsJavaScript/JSUtils.h>
20 #include <CommonsJavaScript/JSCallbackManager.h>
21 #include <CommonsJavaScript/Utils.h>
22 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
23 #include <API/Call/CallFactory.h>
24 #include <API/Call/ICallService.h>
25 #include <API/Call/EventLaunchDialer.h>
26 #include <Tizen/Common/JSTizenExceptionFactory.h>
27 #include <Tizen/Common/JSTizenException.h>
28 #include <Tizen/Common/SecurityExceptions.h>
29 #include <Tizen/Account/JSAccountServices.h>
30 #include "JSCallService.h"
31 #include "ResponseDispatcher.h"
32 #include "Converter.h"
33 #include "plugin_config.h"
37 using namespace WrtDeviceApis;
38 using namespace WrtDeviceApis::Commons;
39 using namespace WrtDeviceApis::CommonsJavaScript;
40 using namespace TizenApis::Api::Call;
41 using namespace TizenApis::Api::Account;
42 using namespace TizenApis::Commons;
47 JSClassRef JSCallService::m_jsClassRef = NULL;
49 JSClassDefinition JSCallService::m_classInfo =
52 kJSClassAttributeNone,
54 JSAccountServices::getClassRef(),
62 NULL, //deleteProperty,
63 NULL, //getPropertyNames,
70 JSStaticValue JSCallService::m_property[] = {
71 { "voicemailNumbers", getProperty, NULL, kJSPropertyAttributeReadOnly },
75 JSStaticFunction JSCallService::m_function[] =
77 { "launchDialer", JSCallService::launchDialer, kJSPropertyAttributeNone },
81 const JSClassRef JSCallService::getClassRef()
84 m_jsClassRef = JSClassCreate(&m_classInfo);
89 const JSClassDefinition* JSCallService::getClassInfo()
94 JSObjectRef JSCallService::createJSObject(JSContextRef context, const AccountServices &serviceInfo)
96 ICallServicePtr callService(CallFactory::getInstance().getCallServiceObject());
97 CallServiceObjectPtr privateData = CallServiceObjectPtr(new CallServiceObject(serviceInfo, callService));
99 JSCallServicePriv *priv = new JSCallServicePriv(context, privateData);
102 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
105 JSObjectRef jsObjRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
106 if (NULL == jsObjRef) {
107 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
112 void JSCallService::initialize(JSContextRef context, JSObjectRef object)
114 LogDebug("JSCallService::initialize ");
117 void JSCallService::finalize(JSObjectRef object)
119 JSCallServicePriv* priv = static_cast<JSCallServicePriv*>(JSObjectGetPrivate(object));
120 JSObjectSetPrivate(object, NULL);
124 JSValueRef JSCallService::getProperty(JSContextRef context,
126 JSStringRef propertyName,
127 JSValueRef* exception)
129 JSCallServicePriv *priv = static_cast<JSCallServicePriv*>(JSObjectGetPrivate(object));
131 return JSValueMakeUndefined(context);
134 JSContextRef globalContext = priv->getContext();
135 CallServiceObjectPtr privateData = priv->getObject();
136 ICallServicePtr callService(privateData->getICallService());
139 Converter convert(context);
140 if(JSStringIsEqualToUTF8CString(propertyName, "voicemailNumbers")) {
141 return convert.toJSValueRef(callService->getVoicemailNumbers(), globalContext);
143 } catch(WrtDeviceApis::Commons::Exception) {
144 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "trying to get incorrect value");
146 return JSValueMakeUndefined(context);
149 bool JSCallService::hasInstance(JSContextRef context, JSObjectRef constructor,
150 JSValueRef possibleInstance, JSValueRef* exception)
152 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
155 JSValueRef JSCallService::launchDialer(JSContextRef context, JSObjectRef object,
156 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
157 JSValueRef* exception)
159 if (argumentCount < 1 || argumentCount > 4) {
160 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");
163 JSCallServicePriv *priv = static_cast<JSCallServicePriv*>(JSObjectGetPrivate(thisObject));
164 JSContextRef gContext = priv->getContext();
166 assert(priv && "Invalid private pointer.");
167 Converter converter(context);
168 Validator check(context, exception);
171 AceSecurityStatus status = CALL_CHECK_ACCESS(
173 CALL_FUNCTION_API_LAUNCHDIALER);
175 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
177 if (!JSValueIsString(context, arguments[0])) {
178 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : remoteparty string");
181 JSCallbackManagerPtr cbm(JSCallbackManager::createObject(gContext));
183 if (argumentCount >= 3) {
184 if (!JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2])) {
185 if (!JSObjectIsFunction(context, converter.toJSObjectRef(arguments[2]))) {
186 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : error callback");
188 cbm->setOnError(arguments[2]);
192 if (argumentCount >= 2) {
193 if (!JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1])) {
194 if (!JSObjectIsFunction(context, converter.toJSObjectRef(arguments[1]))) {
195 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : success callback");
197 cbm->setOnSuccess(arguments[1]);
201 if (argumentCount >= 4) {
202 if (!JSValueIsString(context, arguments[3])) {
203 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : extension string");
207 CallServiceObjectPtr privateData = priv->getObject();
208 ICallServicePtr callService(privateData->getICallService());
210 EventLaunchDialerPtr event(new EventLaunchDialer());
211 event ->setRemoteParty(converter.toString(arguments[0]));
212 if (argumentCount >= 4) {
213 event ->setExtension(converter.toString(arguments[3]));
215 event->setPrivateData(StaticPointerCast<IEventPrivateData> (cbm));
216 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
218 callService->launchDialer(event);
220 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
221 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
222 } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
223 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
224 } catch(const WrtDeviceApis::Commons::Exception& ex) {
225 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
227 return JSValueMakeUndefined(context);