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>
34 #define TIZEN_CONTENT_IMAGE_ATTRIBUTENAME "ImageContent"
35 #define TIZEN_CONTENT_IMAGE_GEOLOCATION "geolocation"
36 #define TIZEN_CONTENT_IMAGE_WIDTH "width"
37 #define TIZEN_CONTENT_IMAGE_HEIGHT "height"
38 #define TIZEN_CONTENT_IMAGE_ORIENTATION "orientation"
40 using namespace DeviceAPI::Tizen;
41 using namespace DeviceAPI::Common;
42 using namespace WrtDeviceApis::Commons;
43 using namespace DeviceAPI::Tizen;
49 JSClassDefinition JSImage::m_classInfo =
52 kJSClassAttributeNone,
53 TIZEN_CONTENT_IMAGE_ATTRIBUTENAME,
54 JSMedia::getClassRef(),
62 NULL, //DeleteProperty,
63 NULL, //GetPropertyNames,
64 NULL, //CallAsFunction,
65 NULL, //CallAsConstructor,
70 JSStaticValue JSImage::m_property[] =
72 // { TIZEN_CONTENT_IMAGE_UID, getPropertyUid, NULL, kJSPropertyAttributeReadOnly},
73 // { TIZEN_CONTENT_IMAGE_GEOLOCATION, getPropertyGeoLocation, setPropertyGeolocation, kJSPropertyAttributeNone},
74 { TIZEN_CONTENT_IMAGE_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly},
75 { TIZEN_CONTENT_IMAGE_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly},
76 { TIZEN_CONTENT_IMAGE_ORIENTATION, getPropertyOrientation, setPropertyOrientation, kJSPropertyAttributeNone},
81 JSClassRef JSImage::m_jsClassRef = JSClassCreate(JSImage::getClassInfo());
83 void JSImage::initialize(JSContextRef context, JSObjectRef object)
85 LogDebug( "entered" );
86 ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) );
89 MediacontentImagePtr privateData(new MediacontentImage());
90 priv = new ImagePrivObject(context, privateData);
91 JSObjectSetPrivate(object, static_cast<void*>(priv));
92 LogDebug("new private object is created" );
95 LogDebug("private object already exists");
96 MediacontentImagePtr image = getImageObject(object);
97 DeviceAPI::Tizen::SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(image->getImageLatitude(),image->getImageLongitude()));
98 JSUtil::setProperty(context, object, TIZEN_CONTENT_IMAGE_GEOLOCATION,
99 JSSimpleCoordinates::createJSObject(context,geoPtr),
100 kJSPropertyAttributeNone);
104 void JSImage::finalize(JSObjectRef object)
106 LogDebug( "entered" );
107 ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) ) ;
112 JSObjectSetPrivate(object, NULL);
116 const JSClassRef JSImage::getClassRef()
118 LogDebug("JSImage::getClassRef()");
121 m_jsClassRef = JSClassCreate(&m_classInfo);
126 const JSClassDefinition* JSImage::getClassInfo()
131 MediacontentImagePtr JSImage::getImageObject(JSObjectRef object)
134 ImagePrivObject *priv = static_cast<ImagePrivObject*>(JSObjectGetPrivate(object));
136 ThrowMsg(NullPointerException, "Private object is null");
138 MediacontentImagePtr result = priv->getObject();
140 ThrowMsg(NullPointerException, "Private object is null");
145 JSValueRef JSImage::getPropertyGeoLocation(
146 JSContextRef context,
148 JSStringRef propertyName,
149 JSValueRef* exception)
155 Converter converter(context);
156 MediacontentImagePtr image = getImageObject(object);
158 LogDebug("lati :" << image->getImageLatitude());
159 LogDebug("longi :" << image->getImageLongitude());
160 DeviceAPI::Tizen::SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(image->getImageLatitude(),image->getImageLongitude()));
161 return JSSimpleCoordinates::createJSObject(context,geoPtr);
166 LogWarning("trying to get incorrect value");
168 return JSValueMakeUndefined(context);
172 JSValueRef JSImage::getPropertyWidth(
173 JSContextRef context,
175 JSStringRef propertyName,
176 JSValueRef* exception)
181 Converter converter(context);
182 MediacontentImagePtr image = getImageObject(object);
183 return converter.toJSValueRef(image->getImageWidth());
187 LogWarning("trying to get incorrect value");
189 return JSValueMakeUndefined(context);
193 JSValueRef JSImage::getPropertyHeight(
194 JSContextRef context,
196 JSStringRef propertyName,
197 JSValueRef* exception)
202 Converter converter(context);
203 MediacontentImagePtr image = getImageObject(object);
204 return converter.toJSValueRef(image->getImageHeight());
208 LogWarning("trying to get incorrect value");
210 return JSValueMakeUndefined(context);
213 JSValueRef JSImage::getPropertyOrientation(
214 JSContextRef context,
216 JSStringRef propertyName,
217 JSValueRef* exception)
222 Converter converter(context);
223 MediacontentImagePtr image = getImageObject(object);
224 return converter.toJSValueRef(image->getImageOrientation());
228 LogWarning("trying to get incorrect value");
230 return JSValueMakeUndefined(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 LogDebug("Inserted value : " << orientation);
249 if ((objImg->getImageOrientation()).compare(orientation) !=0 )
251 objImg->setImageOrientation(orientation, true);
258 LogWarning("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 LogWarning("trying to get incorrect value");
290 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);