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.
19 #include <dpl/log/log.h>
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
24 #include <JSSimpleCoordinates.h>
26 #include <JSTizenExceptionFactory.h>
27 #include <JSTizenException.h>
28 #include <SecurityExceptions.h>
33 #define TIZEN_CONTENT_IMAGE_ATTRIBUTENAME "ImageContent"
34 #define TIZEN_CONTENT_IMAGE_GEOLOCATION "geolocation"
35 #define TIZEN_CONTENT_IMAGE_WIDTH "width"
36 #define TIZEN_CONTENT_IMAGE_HEIGHT "height"
37 #define TIZEN_CONTENT_IMAGE_ORIENTATION "orientation"
39 using namespace DeviceAPI::Tizen;
40 using namespace DeviceAPI::Common;
41 using namespace WrtDeviceApis::Commons;
42 using namespace DeviceAPI::Tizen;
48 JSClassDefinition JSImage::m_classInfo =
51 kJSClassAttributeNone,
52 TIZEN_CONTENT_IMAGE_ATTRIBUTENAME,
53 JSMedia::getClassRef(),
61 NULL, //DeleteProperty,
62 NULL, //GetPropertyNames,
63 NULL, //CallAsFunction,
64 NULL, //CallAsConstructor,
69 JSStaticValue JSImage::m_property[] =
71 // { TIZEN_CONTENT_IMAGE_UID, getPropertyUid, NULL, kJSPropertyAttributeReadOnly},
72 { TIZEN_CONTENT_IMAGE_GEOLOCATION, getPropertyGeoLocation, setPropertyGeolocation, kJSPropertyAttributeNone},
73 { TIZEN_CONTENT_IMAGE_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly},
74 { TIZEN_CONTENT_IMAGE_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly},
75 { TIZEN_CONTENT_IMAGE_ORIENTATION, getPropertyOrientation, setPropertyOrientation, kJSPropertyAttributeNone},
80 JSClassRef JSImage::m_jsClassRef = JSClassCreate(JSImage::getClassInfo());
82 void JSImage::initialize(JSContextRef context, JSObjectRef object)
84 LogDebug( "entered" );
85 ImagePrivObject *priv =
86 static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) );
88 MediacontentImagePtr privateData(new MediacontentImage());
89 priv = new ImagePrivObject(context, privateData);
90 JSObjectSetPrivate(object, static_cast<void*>(priv));
91 LogDebug("new private object is created" );
94 LogDebug("private object already exists");
98 void JSImage::finalize(JSObjectRef object)
100 LogDebug( "entered" );
101 ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) ) ;
106 JSObjectSetPrivate(object, NULL);
110 const JSClassRef JSImage::getClassRef()
112 LogDebug("JSImage::getClassRef()");
115 m_jsClassRef = JSClassCreate(&m_classInfo);
120 const JSClassDefinition* JSImage::getClassInfo()
125 MediacontentImagePtr JSImage::getImageObject(JSObjectRef object)
128 ImagePrivObject *priv = static_cast<ImagePrivObject*>(JSObjectGetPrivate(object));
130 ThrowMsg(NullPointerException, "Private object is null");
132 MediacontentImagePtr result = priv->getObject();
134 ThrowMsg(NullPointerException, "Private object is null");
139 JSValueRef JSImage::getPropertyGeoLocation(
140 JSContextRef context,
142 JSStringRef propertyName,
143 JSValueRef* exception)
149 Converter converter(context);
150 MediacontentImagePtr image = getImageObject(object);
152 LogDebug("lati :" << image->getImageLatitude());
153 LogDebug("longi :" << image->getImageLongitude());
154 DeviceAPI::Tizen::SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(image->getImageLatitude(),image->getImageLongitude()));
155 return JSSimpleCoordinates::createJSObject(context,geoPtr);
160 LogWarning("trying to get incorrect value");
162 return JSValueMakeUndefined(context);
166 JSValueRef JSImage::getPropertyWidth(
167 JSContextRef context,
169 JSStringRef propertyName,
170 JSValueRef* exception)
175 Converter converter(context);
176 MediacontentImagePtr image = getImageObject(object);
177 return converter.toJSValueRef(image->getImageWidth());
181 LogWarning("trying to get incorrect value");
183 return JSValueMakeUndefined(context);
187 JSValueRef JSImage::getPropertyHeight(
188 JSContextRef context,
190 JSStringRef propertyName,
191 JSValueRef* exception)
196 Converter converter(context);
197 MediacontentImagePtr image = getImageObject(object);
198 return converter.toJSValueRef(image->getImageHeight());
202 LogWarning("trying to get incorrect value");
204 return JSValueMakeUndefined(context);
207 JSValueRef JSImage::getPropertyOrientation(
208 JSContextRef context,
210 JSStringRef propertyName,
211 JSValueRef* exception)
216 Converter converter(context);
217 MediacontentImagePtr image = getImageObject(object);
218 return converter.toJSValueRef(image->getImageOrientation());
222 LogWarning("trying to get incorrect value");
224 return JSValueMakeUndefined(context);
227 bool JSImage::setPropertyOrientation(
228 JSContextRef context,
230 JSStringRef propertyName,
232 JSValueRef* exception)
237 Converter converter(context);
238 MediacontentImagePtr objImg = getImageObject(object);
240 string orientation = converter.toString(value);
241 LogDebug("Inserted value : " << orientation);
243 if ((objImg->getImageOrientation()).compare(orientation) !=0 )
245 objImg->setImageOrientation(orientation, true);
252 LogWarning("trying to get incorrect value");
253 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR);
259 bool JSImage::setPropertyGeolocation(
260 JSContextRef context,
262 JSStringRef propertyName,
264 JSValueRef* exception)
270 Converter converter(context);
271 MediacontentImagePtr objImg = getImageObject(object);
273 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation =
274 DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
276 objImg->setImageLatitude(geoLocation->getLatitude());
277 objImg->setImageLongitude(geoLocation->getLongitude());
283 LogWarning("trying to get incorrect value");
284 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);