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 <CommonsJavaScript/JSUtils.h>
20 #include <CommonsJavaScript/Validator.h>
21 #include <JSWebAPIErrorFactory.h>
23 #include "ContentListener.h"
24 #include "ContentConverter.h"
27 using namespace DeviceAPI::Common;
28 using namespace WrtDeviceApis::Commons;
29 using namespace WrtDeviceApis::CommonsJavaScript;
35 ContentListener::ContentListener(JSContextRef globalCtx, JSObjectRef object)
37 m_callback = new MultiCallbackUserData(globalCtx);
40 JSValueRef oncontentadded = JSUtil::getProperty(globalCtx , object, "oncontentadded");
41 if(!JSValueIsUndefined(globalCtx,oncontentadded)) {
42 m_callback->setCallback("oncontentadded", JSUtil::JSValueToObject(globalCtx, oncontentadded));
44 JSValueRef oncontentupdated = JSUtil::getProperty(globalCtx , object, "oncontentupdated");
45 if(!JSValueIsUndefined(globalCtx,oncontentupdated)) {
46 m_callback->setCallback("oncontentupdated", JSUtil::JSValueToObject(globalCtx, oncontentupdated));
48 JSValueRef oncontentremoved = JSUtil::getProperty(globalCtx , object, "oncontentremoved");
49 if(!JSValueIsUndefined(globalCtx,oncontentremoved)) {
50 m_callback->setCallback("oncontentremoved", JSUtil::JSValueToObject(globalCtx, oncontentremoved));
55 ContentListener::~ContentListener() {
56 if(m_callback != NULL){
62 void ContentListener::oncontentadded(MediacontentMediaPtr content)
64 JSContextRef context = m_callback->getContext();
66 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
67 JSValueRef result = converter->toJSValueRefMedia(content);
68 m_callback->invokeCallback("oncontentadded", result);
71 void ContentListener::oncontentupdated(MediacontentMediaPtr content)
73 JSContextRef context = m_callback->getContext();
75 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
76 JSValueRef result = converter->toJSValueRefMedia(content);
77 m_callback->invokeCallback("oncontentupdated", result);
81 void ContentListener::oncontentremoved(std::string id)
83 JSContextRef context = m_callback->getContext();
85 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
86 m_callback->invokeCallback("oncontentremoved", converter->toJSValueRef(id));