#include <CommonsJavaScript/JSDOMExceptionFactory.h>
#include "JSPreferences.h"
#include <Widget/IWidget.h>
-#include "IFrameSupport.h"
#include <LocalStorage/LocalStorageMgr.h>
#include <Commons/WrtAccess/WrtAccess.h>
+#include <js-overlay/js_iframe_support.h>
#define CATCH_EXCEPTION_NO_MODIFABLE \
NULL, //DeleteProperty,
NULL, //GetPropertyNames,
NULL, //CallAsFunction,
- NULL, //CallAsConstructor,
+ callAsConstructor,
NULL, //HasInstance,
NULL, //ConvertToType,
};
JSClassRef JSWidget::m_jsClassRef = JSClassCreate(JSWidget::getClassInfo());
+JSContextRef JSWidget::m_globalContext = NULL;
+
void JSWidget::initialize(JSContextRef context,
JSObjectRef object)
{
- LogDebug("entered");
- LogError("object " << object);
+ LogDebug("entered. Context : " << context);
+ LogDebug("Object: " << object);
JSWidgetPrivateObject* priv =
static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(object));
JSWidgetPrivateObject* priv =
static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(object));
- JSValueUnprotect(priv->getContext(), priv->getObject()->preferencesObject);
+ JSValueUnprotect(priv->getContext(),
+ priv->getObject()->preferencesObject);
delete priv;
- LogDebug("private object is realised");
+ LogDebug("private object is released");
+}
+
+void JSWidget::acquireGlobalContext(java_script_context_t global_context,
+ 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.");
+ } else {
+ LogInfo("Global context already set.");
+ }
}
JSValueRef JSWidget::getAuthor(JSContextRef context,
{
Try {
Converter converter(context);
- return converter.toJSValueRef(getIWidget(object)->getHeight());
+ unsigned int height = getIWidget(object)->getHeight();
+ if (0 == height) {
+ height = 1;
+ }
+ return converter.toJSValueRef(height);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
{
Try {
Converter converter(context);
- return converter.toJSValueRef(getIWidget(object)->getWidth());
+ unsigned int width = getIWidget(object)->getWidth();
+ if (0 == width) {
+ width = 1;
+ }
+ return converter.toJSValueRef(width);
}
CATCH_EXCEPTION_CONVERSION
CATCH_EXCEPTION_NULL_PTR
Converter converter(context);
std::string key = converter.toString(propertyName);
- if(key=="preferences"){
+ if (key == "preferences") {
return true;
}
}
Catch(Commons::PlatformException){
LogError("PlatformException occured");
}
-
return false;
}
{
LogDebug("Object: " << object);
- Try{
+ Try {
Converter converter(context);
std::string key = converter.toString(propertyName);
- if(key=="preferences"){
+ if (key=="preferences") {
Converter converter(context);
JSObjectRef pref = getPreferences(object);
if (!pref)
return false;
}
+JSObjectRef JSWidget::callAsConstructor(JSContextRef context,
+ 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!");
+ return JSObjectMake(context, JSWidget::getClassRef(), NULL);
+ }
+ return JSObjectMake(m_globalContext, JSWidget::getClassRef(), NULL);
+}
+
#undef CATCH_EXCEPTION_NO_MODIFABLE
#undef CATCH_EXCEPTION_CONVERSION
#undef CATCH_EXCEPTION_NULL_PTR