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.
17 #include <CommonsJavaScript/Converter.h>
18 #include <CommonsJavaScript/Validator.h>
19 #include <CommonsJavaScript/JSUtils.h>
20 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
21 #include <Tizen/Common/JSTizenExceptionFactory.h>
22 #include <Tizen/Common/JSTizenException.h>
23 #include <Tizen/Common/SecurityExceptions.h>
24 #include "JSGeocoderServiceManager.h"
25 #include "JSGeocoderProvider.h"
26 #include "DefaultGeocoderProvider.h"
27 #include "GeocoderACE.h"
32 #define LOG_TAG "TIZEN_W_GEOCODER"
35 using namespace WrtDeviceApis::CommonsJavaScript;
36 using namespace WrtDeviceApis::Commons;
42 JSContextRef JSGeocoderServiceManager::m_globalContextRef = NULL;
44 JSValueRef JSGeocoderServiceManager::m_defaultObj = NULL;
46 JSClassRef JSGeocoderServiceManager::m_jsClassRef = NULL;
48 JSClassDefinition JSGeocoderServiceManager::m_jsClassInfo = {
49 0, // current (and only) version is 0
50 kJSClassAttributeNone, //attributes
51 "Geocoder", // class name
53 NULL, // static values
54 JSGeocoderServiceManager::m_function, // static functions
55 JSGeocoderServiceManager::initialize, // initialize
56 JSGeocoderServiceManager::finalize,
60 NULL, //deleteProperty
61 NULL, //getPropertyNames
62 NULL, //call as function
63 NULL, //call as constructor
64 JSGeocoderServiceManager::hasInstance,
68 JSStaticFunction JSGeocoderServiceManager::m_function[] = {
69 { "getDefaultProvider",JSGeocoderServiceManager::getDefaultProvider,kJSPropertyAttributeNone },
70 { "getProviders",JSGeocoderServiceManager::getProviders,kJSPropertyAttributeNone },
74 const JSClassRef JSGeocoderServiceManager::getClassRef()
77 m_jsClassRef = JSClassCreate(&m_jsClassInfo);
82 const JSClassDefinition* JSGeocoderServiceManager::getClassInfo()
84 return &m_jsClassInfo;
87 void JSGeocoderServiceManager::initialize(JSContextRef ctx, JSObjectRef object)
89 LOGD("%s - JSGeocoderServiceManager", __func__);
90 if( JSGeocoderServiceManager::m_globalContextRef == NULL )
92 JSGeocoderServiceManager::m_globalContextRef = ctx;
96 void JSGeocoderServiceManager::finalize(JSObjectRef object)
98 LOGD("%s - JSGeocoderServiceManager", __func__);
99 if( JSGeocoderServiceManager::m_defaultObj != NULL )
101 JSValueUnprotect(JSGeocoderServiceManager::m_globalContextRef, JSGeocoderServiceManager::m_defaultObj);
102 JSGeocoderServiceManager::m_defaultObj = NULL;
106 bool JSGeocoderServiceManager::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
108 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
111 JSValueRef JSGeocoderServiceManager::getDefaultProvider(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
113 AceSecurityStatus status = GEOCODER_CHECK_ACCESS(GEOCODER_FUNCTION_CATEGORY_BASIC);
115 if( status != AceSecurityStatus::AccessGranted )
116 return Commons::JSTizenExceptionFactory::postException(context,exception, Commons::JSTizenException::PERMISSION_DENIED_ERROR );
118 if( JSGeocoderServiceManager::m_defaultObj == NULL){
119 GeocoderProvider *geocoder = new DefaultGeocoderProvider();
120 JSGeocoderServiceManager::m_defaultObj = JSObjectMake(context , JSGeocoderProvider::getClassRef() , geocoder);
121 JSValueProtect(context, JSGeocoderServiceManager::m_defaultObj);
123 return JSGeocoderServiceManager::m_defaultObj;
126 JSValueRef JSGeocoderServiceManager::getProviders(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
128 AceSecurityStatus status = GEOCODER_CHECK_ACCESS(GEOCODER_FUNCTION_CATEGORY_BASIC);
130 if( status != AceSecurityStatus::AccessGranted )
131 return Commons::JSTizenExceptionFactory::postException(context,exception, Commons::JSTizenException::PERMISSION_DENIED_ERROR );
133 JSValueRef providers[1];
135 providers[0] = getDefaultProvider(context ,object, thisObject, argumentCount, arguments, exception);
136 array = JSObjectMakeArray( context, 1, providers, NULL);