#include <Widget/IWidget.h>
#include <LocalStorage/LocalStorageMgr.h>
#include <Commons/WrtAccess/WrtAccess.h>
-#include <js-overlay/js_iframe_support.h>
-
#define CATCH_EXCEPTION_NO_MODIFABLE \
- Catch(Commons::LocalStorageValueNoModifableException) {\
- LogError("The item is read only");\
- return JSDOMExceptionFactory::\
- NoModificationAllowedException.make(context, exception);\
+ Catch(Commons::LocalStorageValueNoModifableException) { \
+ LogError("The item is read only"); \
+ return JSDOMExceptionFactory:: \
+ NoModificationAllowedException.make(context, exception); \
}
#define CATCH_EXCEPTION_CONVERSION \
- Catch(Commons::ConversionException) {\
- LogError("Error on conversion");\
- return JSDOMExceptionFactory::\
- UnknownException.make(context, exception);\
+ Catch(Commons::ConversionException) { \
+ LogError("Error on conversion"); \
+ return JSDOMExceptionFactory:: \
+ UnknownException.make(context, exception); \
}
#define CATCH_EXCEPTION_NULL_PTR \
- Catch(Commons::NullPointerException) {\
- LogError("Error on pointer, null value");\
- return JSDOMExceptionFactory::\
- UnknownException.make(context, exception);\
+ Catch(Commons::NullPointerException) { \
+ LogError("Error on pointer, null value"); \
+ return JSDOMExceptionFactory:: \
+ UnknownException.make(context, exception); \
}
#define CATCH_EXCEPTION_PLATFORM_ERROR \
- Catch(Commons::PlatformException){\
- LogError("PlatformException occured");\
- return JSDOMExceptionFactory::\
- UnknownException.make(context, exception);\
+ Catch(Commons::PlatformException){ \
+ LogError("PlatformException occured"); \
+ return JSDOMExceptionFactory:: \
+ UnknownException.make(context, exception); \
}
#define CATCH_EXCEPTION_SECURITY \
- Catch(Commons::SecurityException){\
- LogError("Security exception occured");\
- return JSDOMExceptionFactory::\
- SecurityException.make(context, exception);\
+ Catch(Commons::SecurityException){ \
+ LogError("Security exception occured"); \
+ return JSDOMExceptionFactory:: \
+ SecurityException.make(context, exception); \
}
#define CATCH_EXCEPTION_OUT_OF_RANGE \
- Catch(Commons::OutOfRangeException) {\
- LogError("OutOfRangeException");\
- return JSDOMExceptionFactory::\
- QuotaExceededException.make(context, exception);\
+ Catch(Commons::OutOfRangeException) { \
+ LogError("OutOfRangeException"); \
+ return JSDOMExceptionFactory:: \
+ QuotaExceededException.make(context, exception); \
}
#define CATCH_EXCEPTION_INVALID_ARG \
- Catch(Commons::InvalidArgumentException) {\
- LogError("Pair for given key doesnt exist");\
- return JSValueMakeNull(context);\
+ Catch(Commons::InvalidArgumentException) { \
+ LogError("Pair for given key doesnt exist"); \
+ return JSValueMakeNull(context); \
}
#define WIDGET_PLUGIN_NAME "Widget"
namespace WrtPlugins {
namespace W3C {
-
using namespace WrtDeviceApis;
using namespace WrtDeviceApis::Commons;
using namespace WrtDeviceApis::CommonsJavaScript;
using namespace WrtDeviceApis::Widget;
-
struct WidgetPrivateObject
{
Widget::Api::IWidgetPtr iwidget;
JSObjectRef preferencesObject;
//TEMP
- int widgetId;
+ //int widgetId // TODO: check is it necessary (g.rynkowski)
JSObjectRef widgetObject;
};
typedef std::shared_ptr<WidgetPrivateObject> WidgetPrivateObjectPtr;
typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT
- <WidgetPrivateObjectPtr>::Type JSWidgetPrivateObject;
+<WidgetPrivateObjectPtr>::Type JSWidgetPrivateObject;
WrtDeviceApis::Widget::Api::IWidgetPtr getIWidget(JSObjectRef arg)
{
return priv->getObject()->iwidget;
}
-
LocalStorage::Api::ILocalStoragePtr getLocalStorage(int widgetId)
{
- static int id = widgetId;
- Assert(id == widgetId && "SPA is not longer supported");
-
- static LocalStorage::Api::ILocalStoragePtr storage(
+ LocalStorage::Api::ILocalStoragePtr storage(
LocalStorage::Api::getLocalStorage(widgetId));
return storage;
JSPreferences::getClassRef(),
priv);
- if(!preferences){
+ if (!preferences) {
LogError("Preferences object is null");
delete priv;
}
JSValueProtect(context, preferences);
return preferences;
-};
-
+}
JSClassDefinition JSWidget::m_classInfo = {
0,
{ 0, 0, 0, 0 }
};
-const JSClassRef JSWidget::getClassRef()
+JSClassRef JSWidget::getClassRef()
{
if (!m_jsClassRef) {
m_jsClassRef = JSClassCreate(&m_classInfo);
JSContextRef JSWidget::m_globalContext = NULL;
void JSWidget::initialize(JSContextRef context,
- JSObjectRef object)
+ JSObjectRef object)
{
LogDebug("entered. Context : " << context);
LogDebug("Object: " << object);
createPreferencesObject(context,
object,
widgetId);
- if(!preferences){
+ if (!preferences) {
LogError("Failed to create preferences object");
}
priv = new JSWidgetPrivateObject(context, widgetPriv);
JSObjectSetPrivate(object, priv);
LogDebug("private object created");
-
}
Catch(Commons::InvalidArgumentException){
LogError("You should register widget id in ON_WIDGET_START");
return;
}
-
+ Catch(DPL::Exception) {
+ LogError("Failed to create private object for JSWidget");
+ return;
+ }
}
}
void JSWidget::finalize(JSObjectRef object)
{
LogDebug("entered");
+ LogDebug("Object: " << object);
JSWidgetPrivateObject* priv =
static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(object));
- JSValueUnprotect(priv->getContext(),
- priv->getObject()->preferencesObject);
+ if (priv) {
+ JSValueUnprotect(priv->getContext(),
+ priv->getObject()->preferencesObject);
- delete priv;
- LogDebug("private object is released");
+ delete priv;
+ LogDebug("private object is released");
+ } else {
+ LogDebug("private object wasn't created");
+ }
}
void JSWidget::acquireGlobalContext(java_script_context_t global_context,
- js_object_instance_t iframe,
- js_object_instance_t object)
+ js_object_instance_t iframe,
+ js_object_instance_t object)
{
- IFrameSupport::RegisterWidget(global_context, iframe, object);
if (!m_globalContext) {
m_globalContext = static_cast<JSContextRef>(global_context);
LogInfo("Global context acquired.");
}
JSValueRef JSWidget::getAuthor(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
+ JSObjectRef object,
+ JSStringRef /*propertyName*/,
+ JSValueRef* exception)
{
LogDebug("entered");
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
- CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_PLATFORM_ERROR
}
JSValueRef JSWidget::getAuthorEmail(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
+ JSObjectRef object,
+ JSStringRef /*propertyName*/,
+ JSValueRef* exception)
{
Try {
Converter converter(context);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
- CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_PLATFORM_ERROR
}
JSValueRef JSWidget::getAuthorHref(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
+ JSObjectRef object,
+ JSStringRef /*propertyName*/,
+ JSValueRef* exception)
{
Try {
Converter converter(context);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
- CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_PLATFORM_ERROR
}
JSValueRef JSWidget::getDescription(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
+ JSObjectRef object,
+ JSStringRef /*propertyName*/,
+ JSValueRef* exception)
{
Try {
Converter converter(context);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
- CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_PLATFORM_ERROR
}
JSValueRef JSWidget::getId(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
+ JSObjectRef object,
+ JSStringRef /*propertyName*/,
+ JSValueRef* exception)
{
Try {
Converter converter(context);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
- CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_PLATFORM_ERROR
}
JSValueRef JSWidget::getName(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
+ JSObjectRef object,
+ JSStringRef /*propertyName*/,
+ JSValueRef* exception)
{
Try {
Converter converter(context);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
- CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_PLATFORM_ERROR
}
JSValueRef JSWidget::getShortName(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
+ JSObjectRef object,
+ JSStringRef /*propertyName*/,
+ JSValueRef* exception)
{
Try {
Converter converter(context);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
- CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_PLATFORM_ERROR
}
JSValueRef JSWidget::getVersion(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
+ JSObjectRef object,
+ JSStringRef /*propertyName*/,
+ JSValueRef* exception)
{
Try {
Converter converter(context);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
- CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_PLATFORM_ERROR
}
JSValueRef JSWidget::getHeight(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
+ JSObjectRef object,
+ JSStringRef /*propertyName*/,
+ JSValueRef* exception)
{
Try {
Converter converter(context);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
- CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_PLATFORM_ERROR
}
JSValueRef JSWidget::getWidth(JSContextRef context,
- JSObjectRef object,
- JSStringRef propertyName,
- JSValueRef* exception)
+ JSObjectRef object,
+ JSStringRef /*propertyName*/,
+ JSValueRef* exception)
{
Try {
Converter converter(context);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
- CATCH_EXCEPTION_PLATFORM_ERROR
+ CATCH_EXCEPTION_PLATFORM_ERROR
}
bool JSWidget::hasProperty(JSContextRef context,
- JSObjectRef object,
+ JSObjectRef /*object*/,
JSStringRef propertyName)
{
LogDebug("enter");
- Try{
+ Try {
Converter converter(context);
std::string key = converter.toString(propertyName);
std::string key = converter.toString(propertyName);
- if (key=="preferences") {
+ if (key == "preferences") {
Converter converter(context);
JSObjectRef pref = getPreferences(object);
- if (!pref)
- {
+ if (!pref) {
LogError("Preferences object is NULL");
return JSValueMakeUndefined(context);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
- CATCH_EXCEPTION_INVALID_ARG
+ CATCH_EXCEPTION_INVALID_ARG
}
bool JSWidget::setProperty(JSContextRef context,
- JSObjectRef object,
+ JSObjectRef /*object*/,
JSStringRef propertyName,
- JSValueRef jvalue,
+ JSValueRef /*jvalue*/,
JSValueRef* exception)
{
LogDebug("enter");
- Try{
+ Try {
Converter converter(context);
std::string key = converter.toString(propertyName);
- if (key == "preferences"){
+ if (key == "preferences") {
LogError("Object is read only");
return true;
}
}
CATCH_EXCEPTION_INVALID_ARG
CATCH_EXCEPTION_CONVERSION
- CATCH_EXCEPTION_NULL_PTR
+ CATCH_EXCEPTION_NULL_PTR
return false;
}
JSObjectRef JSWidget::callAsConstructor(JSContextRef context,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
+ JSObjectRef /*constructor*/,
+ size_t /*argumentCount*/,
+ const JSValueRef /*arguments*/[],
+ JSValueRef* /*exception*/)
{
LogDebug("widget constructor");
if (!m_globalContext) {
LogError("Global context not set. Creating 'widget' object with "
- "local context!");
+ "local context!");
return JSObjectMake(context, JSWidget::getClassRef(), NULL);
}
return JSObjectMake(m_globalContext, JSWidget::getClassRef(), NULL);
#undef CATCH_EXCEPTION_SECURITY
#undef CATCH_EXCEPTION_OUT_OF_RANGE
#undef CATCH_EXCEPTION_INVALID_ARG
-
}
}