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.
18 #include <CommonsJavaScript/PrivateObject.h>
19 #include <CommonsJavaScript/Converter.h>
20 #include <CommonsJavaScript/JSUtils.h>
21 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
22 #include <JSSimpleCoordinates.h>
24 #include <JSTizenExceptionFactory.h>
25 #include <JSTizenException.h>
26 #include <SecurityExceptions.h>
32 #define TIZEN_CONTENT_IMAGE_ATTRIBUTENAME "ImageContent"
33 #define TIZEN_CONTENT_IMAGE_GEOLOCATION "geolocation"
34 #define TIZEN_CONTENT_IMAGE_WIDTH "width"
35 #define TIZEN_CONTENT_IMAGE_HEIGHT "height"
36 #define TIZEN_CONTENT_IMAGE_ORIENTATION "orientation"
38 using namespace DeviceAPI::Tizen;
39 using namespace DeviceAPI::Common;
40 using namespace WrtDeviceApis::Commons;
41 using namespace DeviceAPI::Tizen;
47 JSClassDefinition JSImage::m_classInfo =
50 kJSClassAttributeNone,
51 TIZEN_CONTENT_IMAGE_ATTRIBUTENAME,
52 JSMedia::getClassRef(),
60 NULL, //DeleteProperty,
61 NULL, //GetPropertyNames,
62 NULL, //CallAsFunction,
63 NULL, //CallAsConstructor,
68 JSStaticValue JSImage::m_property[] =
70 // { TIZEN_CONTENT_IMAGE_UID, getPropertyUid, NULL, kJSPropertyAttributeReadOnly},
71 // { TIZEN_CONTENT_IMAGE_GEOLOCATION, getPropertyGeoLocation, setPropertyGeolocation, kJSPropertyAttributeNone},
72 { TIZEN_CONTENT_IMAGE_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly},
73 { TIZEN_CONTENT_IMAGE_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly},
74 { TIZEN_CONTENT_IMAGE_ORIENTATION, getPropertyOrientation, setPropertyOrientation, kJSPropertyAttributeNone},
79 JSClassRef JSImage::m_jsClassRef = JSClassCreate(JSImage::getClassInfo());
81 void JSImage::initialize(JSContextRef context, JSObjectRef object)
84 ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) );
87 MediacontentImagePtr privateData(new MediacontentImage());
88 priv = new ImagePrivObject(context, privateData);
89 JSObjectSetPrivate(object, static_cast<void*>(priv));
90 LoggerD("new private object is created" );
93 LoggerD("private object already exists");
94 MediacontentImagePtr image = getImageObject(object);
95 DeviceAPI::Tizen::SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(image->getImageLatitude(),image->getImageLongitude()));
96 JSUtil::setProperty(context, object, TIZEN_CONTENT_IMAGE_GEOLOCATION,
97 JSSimpleCoordinates::createJSObject(context,geoPtr),
98 kJSPropertyAttributeNone);
102 void JSImage::finalize(JSObjectRef object)
104 LoggerD( "entered" );
105 ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) ) ;
110 JSObjectSetPrivate(object, NULL);
114 const JSClassRef JSImage::getClassRef()
116 LoggerD("JSImage::getClassRef()");
119 m_jsClassRef = JSClassCreate(&m_classInfo);
124 const JSClassDefinition* JSImage::getClassInfo()
129 MediacontentImagePtr JSImage::getImageObject(JSObjectRef object)
132 ImagePrivObject *priv = static_cast<ImagePrivObject*>(JSObjectGetPrivate(object));
134 ThrowMsg(NullPointerException, "Private object is null");
136 MediacontentImagePtr result = priv->getObject();
138 ThrowMsg(NullPointerException, "Private object is null");
143 JSValueRef JSImage::getPropertyGeoLocation(
144 JSContextRef context,
146 JSStringRef propertyName,
147 JSValueRef* exception)
153 Converter converter(context);
154 MediacontentImagePtr image = getImageObject(object);
156 LoggerD("lati :" << image->getImageLatitude());
157 LoggerD("longi :" << image->getImageLongitude());
158 DeviceAPI::Tizen::SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(image->getImageLatitude(),image->getImageLongitude()));
159 return JSSimpleCoordinates::createJSObject(context,geoPtr);
164 LoggerW("trying to get incorrect value");
166 return JSValueMakeNull(context);
170 JSValueRef JSImage::getPropertyWidth(
171 JSContextRef context,
173 JSStringRef propertyName,
174 JSValueRef* exception)
179 Converter converter(context);
180 MediacontentImagePtr image = getImageObject(object);
181 return converter.toJSValueRef(image->getImageWidth());
185 LoggerW("trying to get incorrect value");
187 return JSValueMakeUndefined(context);
191 JSValueRef JSImage::getPropertyHeight(
192 JSContextRef context,
194 JSStringRef propertyName,
195 JSValueRef* exception)
200 Converter converter(context);
201 MediacontentImagePtr image = getImageObject(object);
202 return converter.toJSValueRef(image->getImageHeight());
206 LoggerW("trying to get incorrect value");
208 return JSValueMakeUndefined(context);
211 JSValueRef JSImage::getPropertyOrientation(
212 JSContextRef context,
214 JSStringRef propertyName,
215 JSValueRef* exception)
220 Converter converter(context);
221 MediacontentImagePtr image = getImageObject(object);
222 if(!(image->getImageOrientation().empty())){
223 return converter.toJSValueRef(image->getImageOrientation());
228 LoggerW("trying to get incorrect value");
230 return JSValueMakeNull(context);
233 bool JSImage::setPropertyOrientation(
234 JSContextRef context,
236 JSStringRef propertyName,
238 JSValueRef* exception)
243 Converter converter(context);
244 MediacontentImagePtr objImg = getImageObject(object);
246 string orientation = converter.toString(value);
247 LoggerD("Inserted value : " << orientation);
249 if ((objImg->getImageOrientation()).compare(orientation) !=0 )
251 objImg->setImageOrientation(orientation, true);
258 LoggerW("trying to get incorrect value");
259 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR);
265 bool JSImage::setPropertyGeolocation(
266 JSContextRef context,
268 JSStringRef propertyName,
270 JSValueRef* exception)
276 Converter converter(context);
277 MediacontentImagePtr objImg = getImageObject(object);
279 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation =
280 DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
282 objImg->setImageLatitude(geoLocation->getLatitude());
283 objImg->setImageLongitude(geoLocation->getLongitude());
289 LoggerW("trying to get incorrect value");
290 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);