1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * plugin-class.cpp: MoonLight browser plugin.
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
18 #include "plugin-class.h"
19 #include "plugin-accessibility.h"
20 #include "browser-bridge.h"
22 #include "deployment.h"
23 #include "bitmapimage.h"
27 #include "multiscaleimage.h"
28 #include "tilesource.h"
29 #include "deepzoomimagetilesource.h"
32 #define DEBUG_WARN_NOTIMPLEMENTED(x) printf ("not implemented: (%s) " G_STRLOC "\n", x)
35 #define DEBUG_WARN_NOTIMPLEMENTED(x)
39 // debug scriptable object
47 npidentifier_to_downstr (NPIdentifier id
)
49 if (!NPN_IdentifierIsString (id
))
52 NPUTF8
*strname
= NPN_UTF8FromIdentifier (id
);
55 *p
= g_ascii_tolower (*p
);
62 /* for use with bsearch & qsort */
64 compare_mapping (const void *m1
, const void *m2
)
66 MoonNameIdMapping
*map1
= (MoonNameIdMapping
*) m1
;
67 MoonNameIdMapping
*map2
= (MoonNameIdMapping
*) m2
;
68 return strcmp(map1
->name
, map2
->name
);
72 map_name_to_id (NPIdentifier name
, const MoonNameIdMapping mapping
[], int count
)
74 char *strname
= npidentifier_to_downstr (name
);
78 MoonNameIdMapping key
, *result
;
81 result
= (MoonNameIdMapping
*)bsearch(&key
, mapping
, count
,
82 sizeof(MoonNameIdMapping
), compare_mapping
);
85 NPN_MemFree (strname
);
93 map_moon_id_to_event_name (int moon_id
)
95 const char *name
= NULL
;
98 case MoonId_BufferingProgressChanged
: name
= "BufferingProgressChanged"; break;
99 case MoonId_CurrentStateChanged
: name
= "CurrentStateChanged"; break;
100 case MoonId_DownloadProgressChanged
: name
= "DownloadProgressChanged"; break;
101 case MoonId_GotFocus
: name
= "GotFocus"; break;
102 case MoonId_KeyDown
: name
= "KeyDown"; break;
103 case MoonId_KeyUp
: name
= "KeyUp"; break;
104 case MoonId_LostFocus
: name
= "LostFocus"; break;
105 case MoonId_Loaded
: name
= "Loaded"; break;
106 case MoonId_MarkerReached
: name
= "MarkerReached"; break;
107 case MoonId_MediaEnded
: name
= "MediaEnded"; break;
108 case MoonId_MediaFailed
: name
= "MediaFailed"; break;
109 case MoonId_MediaOpened
: name
= "MediaOpened"; break;
110 case MoonId_MouseEnter
: name
= "MouseEnter"; break;
111 case MoonId_MouseLeave
: name
= "MouseLeave"; break;
112 case MoonId_MouseMove
: name
= "MouseMove"; break;
113 case MoonId_MouseLeftButtonDown
: name
= "MouseLeftButtonDown"; break;
114 case MoonId_MouseLeftButtonUp
: name
= "MouseLeftButtonUp"; break;
115 case MoonId_OnResize
: name
= "Resize"; break;
116 case MoonId_OnFullScreenChange
: name
= "FullScreenChange"; break;
117 case MoonId_OnError
: name
= "Error"; break;
118 case MoonId_OnLoad
: name
= "Load"; break;
119 case MoonId_OnSourceDownloadProgressChanged
: name
= "SourceDownloadProgressChanged"; break;
120 case MoonId_OnSourceDownloadComplete
: name
= "SourceDownloadComplete"; break;
128 string_to_npvariant (const char *value
, NPVariant
*result
)
133 retval
= NPN_strdup ((char *)value
);
135 retval
= NPN_strdup ("");
137 STRINGZ_TO_NPVARIANT (retval
, *result
);
141 value_to_variant (NPObject
*npobj
, Value
*v
, NPVariant
*result
, DependencyObject
*parent_obj
= NULL
, DependencyProperty
*parent_property
= NULL
)
147 NULL_TO_NPVARIANT (*result
);
151 switch (v
->GetKind ()) {
153 BOOLEAN_TO_NPVARIANT (v
->AsBool(), *result
);
156 n
= g_unichar_to_utf8 (v
->AsChar (), utf8
);
158 string_to_npvariant (utf8
, result
);
161 INT32_TO_NPVARIANT (v
->AsInt32(), *result
);
164 // XXX not much else we can do here...
165 INT32_TO_NPVARIANT ((gint32
)v
->AsUInt32(), *result
);
168 DOUBLE_TO_NPVARIANT (v
->AsDouble(), *result
);
171 string_to_npvariant (v
->AsString(), result
);
174 MoonlightPoint
*point
= (MoonlightPoint
*) NPN_CreateObject (((MoonlightObject
*) npobj
)->instance
, MoonlightPointClass
);
175 point
->point
= *v
->AsPoint ();
176 OBJECT_TO_NPVARIANT (point
, *result
);
180 MoonlightRect
*rect
= (MoonlightRect
*) NPN_CreateObject (((MoonlightObject
*) npobj
)->instance
, MoonlightRectClass
);
181 rect
->rect
= *v
->AsRect ();
182 OBJECT_TO_NPVARIANT (rect
, *result
);
185 case Type::DURATION
: {
186 MoonlightDuration
*duration
= (MoonlightDuration
*) NPN_CreateObject (((MoonlightObject
*) npobj
)->instance
, MoonlightDurationClass
);
187 duration
->SetParentInfo (parent_obj
, parent_property
);
188 OBJECT_TO_NPVARIANT (duration
, *result
);
191 case Type::TIMESPAN
: {
192 MoonlightTimeSpan
*timespan
= (MoonlightTimeSpan
*) NPN_CreateObject (((MoonlightObject
*) npobj
)->instance
, MoonlightTimeSpanClass
);
193 timespan
->SetParentInfo (parent_obj
, parent_property
);
194 OBJECT_TO_NPVARIANT (timespan
, *result
);
197 case Type::GRIDLENGTH
: {
198 MoonlightGridLength
*gridlength
= (MoonlightGridLength
*) NPN_CreateObject (((MoonlightObject
*) npobj
)->instance
, MoonlightGridLengthClass
);
199 gridlength
->SetParentInfo (parent_obj
, parent_property
);
200 OBJECT_TO_NPVARIANT (gridlength
, *result
);
204 char *uri_string
= v
->AsUri() ? v
->AsUri()->ToString() : NULL
;
205 string_to_npvariant (uri_string
? uri_string
: "", result
);
209 case Type::FONTFAMILY
: {
210 char *family
= v
->AsFontFamily() ? v
->AsFontFamily()->source
: NULL
;
211 string_to_npvariant (family
? family
: "", result
);
214 case Type::FONTWEIGHT
: {
215 const char *weight
= enums_int_to_str ("FontWeight", v
->AsFontWeight() ? v
->AsFontWeight()->weight
: FontWeightsNormal
);
216 string_to_npvariant (weight
, result
);
219 case Type::FONTSTYLE
: {
220 const char *style
= enums_int_to_str ("FontStyle", v
->AsFontStyle() ? v
->AsFontStyle()->style
: FontStylesNormal
);
221 string_to_npvariant (style
, result
);
224 case Type::FONTSTRETCH
: {
225 const char *stretch
= enums_int_to_str ("FontStretch", v
->AsFontStretch() ? v
->AsFontStretch()->stretch
: FontStretchesNormal
);
226 string_to_npvariant (stretch
, result
);
230 Color
*c
= v
->AsColor ();
231 gint32 color
= ((((gint32
)(c
->a
* 255.0)) << 24) | (((gint32
)(c
->r
* 255.0)) << 16) |
232 (((gint32
)(c
->g
* 255.0)) << 8) | ((gint32
)(c
->b
* 255.0)));
233 INT32_TO_NPVARIANT (color
, *result
);
236 case Type::KEYTIME
: {
237 MoonlightKeyTime
*keytime
= (MoonlightKeyTime
*) NPN_CreateObject (((MoonlightObject
*) npobj
)->instance
, MoonlightKeyTimeClass
);
238 keytime
->SetParentInfo (parent_obj
, parent_property
);
239 OBJECT_TO_NPVARIANT (keytime
, *result
);
242 case Type::THICKNESS
: {
243 MoonlightThickness
*thickness
= (MoonlightThickness
*) NPN_CreateObject (((MoonlightObject
*) npobj
)->instance
, MoonlightThicknessClass
);
244 thickness
->SetParentInfo (parent_obj
, parent_property
);
245 OBJECT_TO_NPVARIANT (thickness
, *result
);
248 case Type::CORNERRADIUS
: {
249 MoonlightCornerRadius
*corner_radius
= (MoonlightCornerRadius
*) NPN_CreateObject (((MoonlightObject
*) npobj
)->instance
, MoonlightCornerRadiusClass
);
250 corner_radius
->SetParentInfo (parent_obj
, parent_property
);
251 OBJECT_TO_NPVARIANT (corner_radius
, *result
);
255 OBJECT_TO_NPVARIANT ((NPObject
*) v
->AsNPObj (), *result
);
259 /* more builtins.. */
260 if (v
->Is (Type::DEPENDENCY_OBJECT
)) {
261 MoonlightEventObjectObject
*depobj
=
262 EventObjectCreateWrapper (((MoonlightObject
*) npobj
)->instance
, v
->AsDependencyObject ());
263 OBJECT_TO_NPVARIANT (depobj
, *result
);
265 printf ("value_to_variant, can't create a variant of a %i = %s\n", v
->GetKind (), Type::Find (v
->GetKind ())->GetName ());
266 NULL_TO_NPVARIANT (*result
);
273 variant_to_value (const NPVariant
*v
, Value
**result
)
276 case NPVariantType_Bool
:
277 *result
= new Value (NPVARIANT_TO_BOOLEAN (*v
));
279 case NPVariantType_Int32
:
280 *result
= new Value ((int32_t) NPVARIANT_TO_INT32 (*v
));
282 case NPVariantType_Double
:
283 *result
= new Value (NPVARIANT_TO_DOUBLE (*v
));
285 case NPVariantType_String
: {
286 char *value
= STRDUP_FROM_VARIANT (*v
);
287 *result
= new Value (value
);
291 case NPVariantType_Void
:
292 DEBUG_WARN_NOTIMPLEMENTED ("void variant type");
295 case NPVariantType_Null
:
296 DEBUG_WARN_NOTIMPLEMENTED ("null variant type");
297 *result
= new Value (Type::DEPENDENCY_OBJECT
);
299 case NPVariantType_Object
:
300 *result
= new Value (Type::NPOBJ
, NPVARIANT_TO_OBJECT (*v
));
303 d (printf ("Got invalid value from javascript.\n"));
309 enum DependencyObjectClassNames
{
312 DEPENDENCY_OBJECT_CLASS
,
320 STYLUS_POINT_COLLECTION_CLASS
,
321 STROKE_COLLECTION_CLASS
,
327 ROUTED_EVENT_ARGS_CLASS
,
328 ERROR_EVENT_ARGS_CLASS
,
329 KEY_EVENT_ARGS_CLASS
,
330 MARKER_REACHED_EVENT_ARGS_CLASS
,
331 MOUSE_EVENT_ARGS_CLASS
,
332 DOWNLOAD_PROGRESS_EVENT_ARGS_CLASS
,
333 MULTI_SCALE_IMAGE_CLASS
,
335 DEPENDENCY_OBJECT_CLASS_NAMES_LAST
338 NPClass
*dependency_object_classes
[DEPENDENCY_OBJECT_CLASS_NAMES_LAST
];
341 npobject_is_dependency_object (NPObject
*obj
)
343 for (int i
= 0; i
< DEPENDENCY_OBJECT_CLASS_NAMES_LAST
; i
++) {
344 if (dependency_object_classes
[i
] == obj
->_class
)
351 npvariant_is_dependency_object (NPVariant var
)
353 if (!NPVARIANT_IS_OBJECT (var
))
356 return npobject_is_dependency_object (NPVARIANT_TO_OBJECT (var
));
360 npvariant_is_object_class (NPVariant var
, int type
)
364 if (type
< 0 || type
>= DEPENDENCY_OBJECT_CLASS_NAMES_LAST
)
367 if (!NPVARIANT_IS_OBJECT (var
))
370 obj
= NPVARIANT_TO_OBJECT (var
);
372 return obj
->_class
== dependency_object_classes
[type
];
375 #define npvariant_is_downloader(v) npvariant_is_object_class (v, DOWNLOADER_CLASS)
378 npvariant_is_moonlight_object (NPVariant var
)
380 NPClass
*moonlight_types
[] = {
381 MoonlightContentClass
,
382 MoonlightDurationClass
,
383 MoonlightObjectClass
,
385 MoonlightScriptableObjectClass
,
386 MoonlightScriptControlClass
,
387 MoonlightSettingsClass
,
388 MoonlightTimeSpanClass
393 if (!NPVARIANT_IS_OBJECT (var
))
396 obj
= NPVARIANT_TO_OBJECT (var
);
397 if (npobject_is_dependency_object (obj
))
400 for (i
= 0; i
< G_N_ELEMENTS (moonlight_types
); i
++) {
401 if (obj
->_class
== moonlight_types
[i
])
408 EventListenerProxy::EventListenerProxy (NPP instance
, const char *event_name
, const char *cb_name
)
409 : EventObject (Type::EVENTLISTENERPROXY
)
411 this->instance
= instance
;
412 this->event_name
= g_strdup (event_name
);
414 this->target_object
= NULL
;
416 this->one_shot
= false;
417 this->is_func
= false;
418 if (!strncmp (cb_name
, "javascript:", strlen ("javascript:")))
419 cb_name
+= strlen ("javascript:");
420 this->callback
= g_strdup (cb_name
);
423 EventListenerProxy::EventListenerProxy (NPP instance
, const char *event_name
, const NPVariant
*cb
)
424 : EventObject (Type::EVENTLISTENERPROXY
)
426 this->instance
= instance
;
427 this->event_name
= g_strdup (event_name
);
429 this->target_object
= NULL
;
431 this->one_shot
= false;
433 if (NPVARIANT_IS_OBJECT (*cb
)) {
434 this->is_func
= true;
435 this->callback
= NPVARIANT_TO_OBJECT (*cb
);
436 NPN_RetainObject ((NPObject
*) this->callback
);
438 this->is_func
= false;
439 this->callback
= STRDUP_FROM_VARIANT (*cb
);
443 EventListenerProxy::~EventListenerProxy ()
446 // XXX we *want* to be able to do this, we really do, but we have no
447 // good means to invalidate EventListenerProxy, and thereby set the
450 // instead we do it in ::RemoveHandler, which is only invoked via JS's removeEventListener
452 // if (callback != NULL)
453 // NPN_ReleaseObject ((NPObject *) callback);
463 EventListenerProxy::GetCallbackAsString ()
468 return (const char *)callback
;
472 EventListenerProxy::SetOwner (MoonlightObject
*owner
)
478 EventListenerProxy::AddHandler (EventObject
*obj
)
482 event_id
= obj
->GetType()->LookupEvent (event_name
);
484 if (event_id
== -1) {
485 d(printf ("object of type `%s' does not provide an event named `%s'\n",
486 obj
->GetTypeName(), event_name
));
490 token
= obj
->AddHandler (event_id
, proxy_listener_to_javascript
, this, on_handler_removed
);
495 EventListenerProxy::AddXamlHandler (EventObject
*obj
)
499 event_id
= obj
->GetType()->LookupEvent (event_name
);
501 if (event_id
== -1) {
502 d(printf ("object of type `%s' does not provide an event named `%s'\n",
503 obj
->GetTypeName(), event_name
));
507 token
= obj
->AddXamlHandler (event_id
, proxy_listener_to_javascript
, this, on_handler_removed
);
513 EventListenerProxy::RemoveHandler ()
515 if (target_object
&& event_id
!= -1) {
516 target_object
->RemoveHandler (event_id
, token
);
517 if (is_func
&& callback
) {
518 NPN_ReleaseObject ((NPObject
*) callback
);
523 on_handler_removed (this);
528 EventListenerProxy::on_handler_removed (gpointer closure
)
530 // by the time we get here, the target_object has disclaimed
531 // all knowledge of this proxy.
533 EventListenerProxy
*proxy
= (EventListenerProxy
*) closure
;
536 proxy
->owner
->ClearEventProxy (proxy
);
539 // we don't have an owner, so there's nothing special
540 // for us to do here.
543 proxy
->target_object
= NULL
;
544 proxy
->event_id
= -1;
545 proxy
->unref_delayed();
549 EventListenerProxy::proxy_listener_to_javascript (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
)
551 EventListenerProxy
*proxy
= (EventListenerProxy
*) closure
;
552 EventObject
*js_sender
= sender
;
556 PluginInstance
*plugin
= (PluginInstance
*)proxy
->instance
->pdata
;
557 Deployment
*previous_deployment
;
559 if (plugin
== NULL
) {
560 // Firefox can invalidate our NPObjects after the plugin itself
561 // has been destroyed. During this invalidation our NPObjects call
562 // into the moonlight runtime, which then emits events.
563 d(printf ("Moonlight: The plugin has been deleted, but we're still emitting events?\n"));
567 // do not let cross-domain application re-register the events (e.g. via scripting)
568 if (plugin
->IsCrossDomainApplication ()) {
569 // g_warning ("xdomain restriction on javascript event: %s", proxy->GetCallbackAsString ());
573 previous_deployment
= Deployment::GetCurrent ();
574 Deployment::SetCurrent (plugin
->GetDeployment ());
576 if (js_sender
->GetObjectType () == Type::SURFACE
) {
577 // This is somewhat hackish, but is required for
578 // the FullScreenChanged event (js expects the
579 // sender to be the toplevel canvas, not the surface,
581 js_sender
= ((Surface
*) js_sender
)->GetToplevel ();
584 MoonlightEventObjectObject
*depobj
= NULL
;
586 depobj
= EventObjectCreateWrapper (proxy
->instance
, js_sender
);
587 plugin
->AddCleanupPointer (&depobj
);
588 OBJECT_TO_NPVARIANT (depobj
, args
[0]);
590 NULL_TO_NPVARIANT (args
[0]);
593 //printf ("proxying event %s to javascript, sender = %p (%s)\n", proxy->event_name, sender, sender->GetTypeName ());
594 MoonlightEventObjectObject
*depargs
= NULL
;
596 depargs
= EventObjectCreateWrapper (proxy
->instance
, calldata
);
597 plugin
->AddCleanupPointer (&depargs
);
598 OBJECT_TO_NPVARIANT (depargs
, args
[1]);
602 if (proxy
->is_func
&& proxy
->callback
) {
603 /* the event listener was added with a JS function object */
604 if (NPN_InvokeDefault (proxy
->instance
, (NPObject
*) proxy
->callback
, args
, argcount
, &result
))
605 NPN_ReleaseVariantValue (&result
);
607 /* the event listener was added with a JS string (the function name) */
608 NPObject
*object
= NULL
;
610 if (NPN_GetValue (proxy
->instance
, NPNVWindowNPObject
, &object
) == NPERR_NO_ERROR
) {
611 if (NPN_Invoke (proxy
->instance
, object
, NPID ((char *) proxy
->callback
), args
, argcount
, &result
))
612 NPN_ReleaseVariantValue (&result
);
617 plugin
->RemoveCleanupPointer (&depobj
);
618 NPN_ReleaseObject (depobj
);
621 plugin
->RemoveCleanupPointer (&depargs
);
622 NPN_ReleaseObject (depargs
);
625 proxy
->RemoveHandler();
627 Deployment::SetCurrent (previous_deployment
);
631 event_object_add_xaml_listener (EventObject
*obj
, PluginInstance
*plugin
, const char *event_name
, const char *cb_name
)
633 EventListenerProxy
*proxy
= new EventListenerProxy (plugin
->GetInstance (), event_name
, cb_name
);
634 proxy
->AddXamlHandler (obj
);
637 class NamedProxyPredicate
{
639 NamedProxyPredicate (char *name
) { this->name
= g_strdup (name
); }
640 ~NamedProxyPredicate () { g_free (name
); }
642 static bool matches (EventHandler cb_handler
, gpointer cb_data
, gpointer data
)
644 if (cb_handler
!= EventListenerProxy::proxy_listener_to_javascript
)
648 EventListenerProxy
*proxy
= (EventListenerProxy
*)cb_data
;
649 NamedProxyPredicate
*pred
= (NamedProxyPredicate
*)data
;
651 return !strcasecmp (proxy
->GetCallbackAsString(), pred
->name
);
660 event_args_allocate (NPP instance
, NPClass
*klass
)
662 return new MoonlightEventArgs (instance
);
665 MoonlightEventArgsType::MoonlightEventArgsType ()
667 allocate
= event_args_allocate
;
670 MoonlightEventArgsType
*MoonlightEventArgsClass
;
672 /*** RoutedEventArgs ***/
674 routedeventargs_allocate (NPP instance
, NPClass
*klass
)
676 return new MoonlightRoutedEventArgs (instance
);
679 static const MoonNameIdMapping
680 routedeventargs_mapping
[] = {
681 { "source", MoonId_Source
},
685 MoonlightRoutedEventArgs::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
687 RoutedEventArgs
*args
= GetRoutedEventArgs ();
690 case MoonId_Source
: {
691 DependencyObject
*source
= args
->GetSource ();
693 MoonlightEventObjectObject
*source_obj
= EventObjectCreateWrapper (instance
, source
);
694 OBJECT_TO_NPVARIANT (source_obj
, *result
);
697 NULL_TO_NPVARIANT (*result
);
704 return MoonlightEventArgs::GetProperty (id
, name
, result
);
708 MoonlightRoutedEventArgsType::MoonlightRoutedEventArgsType ()
710 allocate
= routedeventargs_allocate
;
712 AddMapping (routedeventargs_mapping
, G_N_ELEMENTS (routedeventargs_mapping
));
715 MoonlightRoutedEventArgsType
*MoonlightRoutedEventArgsClass
;
718 /*** ErrorEventArgs ***/
720 erroreventargs_allocate (NPP instance
, NPClass
*klass
)
722 return new MoonlightErrorEventArgs (instance
);
725 static const MoonNameIdMapping
726 erroreventargs_mapping
[] = {
727 { "charposition", MoonId_CharPosition
},
728 { "errorcode", MoonId_ErrorCode
},
729 { "errormessage", MoonId_ErrorMessage
},
730 { "errortype", MoonId_ErrorType
},
731 { "linenumber", MoonId_LineNumber
},
732 { "methodname", MoonId_MethodName
},
733 { "xamlfile", MoonId_XamlFile
},
737 MoonlightErrorEventArgs::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
739 ErrorEventArgs
*args
= GetErrorEventArgs ();
742 case MoonId_ErrorCode
:
743 INT32_TO_NPVARIANT (args
->GetErrorCode(), *result
);
746 case MoonId_ErrorType
:
747 switch (args
->GetErrorType()) {
748 case NoError
: string_to_npvariant ("NoError", result
); break;
749 case UnknownError
: string_to_npvariant ("UnknownError", result
); break;
750 case InitializeError
: string_to_npvariant ("InitializeError", result
); break;
751 case ParserError
: string_to_npvariant ("ParserError", result
); break;
752 case ObjectModelError
: string_to_npvariant ("ObjectModelError", result
); break;
753 case RuntimeError
: string_to_npvariant ("RuntimeError", result
); break;
754 case DownloadError
: string_to_npvariant ("DownloadError", result
); break;
755 case MediaError
: string_to_npvariant ("MediaError", result
); break;
756 case ImageError
: string_to_npvariant ("ImageError", result
); break;
759 case MoonId_ErrorMessage
:
760 string_to_npvariant (args
->GetErrorMessage(), result
);
762 case MoonId_LineNumber
:
763 if (args
->GetErrorType() == ParserError
) {
764 INT32_TO_NPVARIANT (((ParserErrorEventArgs
*)args
)->line_number
, *result
);
766 DEBUG_WARN_NOTIMPLEMENTED ("ErrorEventArgs.lineNumber");
767 INT32_TO_NPVARIANT (0, *result
);
770 case MoonId_CharPosition
:
771 if (args
->GetErrorType() == ParserError
) {
772 INT32_TO_NPVARIANT (((ParserErrorEventArgs
*)args
)->char_position
, *result
);
774 DEBUG_WARN_NOTIMPLEMENTED ("ErrorEventArgs.charPosition");
775 INT32_TO_NPVARIANT (0, *result
);
778 case MoonId_MethodName
:
779 DEBUG_WARN_NOTIMPLEMENTED ("ErrorEventArgs.methodName");
780 NULL_TO_NPVARIANT (*result
);
782 case MoonId_XamlFile
:
783 if (args
->GetErrorType() == ParserError
) {
784 string_to_npvariant (((ParserErrorEventArgs
*)args
)->xaml_file
, result
);
786 DEBUG_WARN_NOTIMPLEMENTED ("ErrorEventArgs.xamlFile");
787 NULL_TO_NPVARIANT (*result
);
791 return MoonlightEventArgs::GetProperty (id
, name
, result
);
795 MoonlightErrorEventArgsType::MoonlightErrorEventArgsType ()
797 allocate
= erroreventargs_allocate
;
799 AddMapping (erroreventargs_mapping
, G_N_ELEMENTS (erroreventargs_mapping
));
802 MoonlightErrorEventArgsType
*MoonlightErrorEventArgsClass
;
806 point_allocate (NPP instance
, NPClass
*klass
)
808 return new MoonlightPoint (instance
);
811 static const MoonNameIdMapping
819 MoonlightPoint::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
823 DOUBLE_TO_NPVARIANT (point
.x
, *result
);
827 DOUBLE_TO_NPVARIANT (point
.y
, *result
);
831 return MoonlightObject::GetProperty (id
, name
, result
);
836 MoonlightPoint::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
840 point
.x
= NPVARIANT_TO_DOUBLE (*value
);
843 point
.y
= NPVARIANT_TO_DOUBLE (*value
);
846 return MoonlightObject::SetProperty (id
, name
, value
);
850 MoonlightPointType::MoonlightPointType ()
852 allocate
= point_allocate
;
854 AddMapping (point_mapping
, G_N_ELEMENTS (point_mapping
));
857 MoonlightPointType
*MoonlightPointClass
;
861 rect_allocate (NPP instance
, NPClass
*klass
)
863 return new MoonlightRect (instance
);
866 static const MoonNameIdMapping
868 { "height", MoonId_Height
},
869 { "width", MoonId_Width
},
875 MoonlightRect::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
879 DOUBLE_TO_NPVARIANT (rect
.x
, *result
);
883 DOUBLE_TO_NPVARIANT (rect
.y
, *result
);
887 DOUBLE_TO_NPVARIANT (rect
.width
, *result
);
891 DOUBLE_TO_NPVARIANT (rect
.height
, *result
);
895 return MoonlightObject::GetProperty (id
, name
, result
);
900 MoonlightRect::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
904 rect
.x
= NPVARIANT_TO_DOUBLE (*value
);
908 rect
.y
= NPVARIANT_TO_DOUBLE (*value
);
912 rect
.width
= NPVARIANT_TO_DOUBLE (*value
);
916 rect
.height
= NPVARIANT_TO_DOUBLE (*value
);
920 return MoonlightObject::SetProperty (id
, name
, value
);;
925 MoonlightRectType::MoonlightRectType ()
927 allocate
= rect_allocate
;
929 AddMapping (rect_mapping
, G_N_ELEMENTS (rect_mapping
));
932 MoonlightRectType
*MoonlightRectClass
;
937 duration_allocate (NPP instance
, NPClass
*klass
)
939 return new MoonlightDuration (instance
);
942 static const MoonNameIdMapping
943 duration_mapping
[] = {
944 { "name", MoonId_Name
},
945 { "seconds", MoonId_Seconds
}
949 MoonlightDuration::SetParentInfo (DependencyObject
*parent_obj
, DependencyProperty
*parent_property
)
951 this->parent_obj
= parent_obj
;
952 this->parent_property
= parent_property
;
957 MoonlightDuration::GetValue()
959 Value
*v
= parent_obj
->GetValue (parent_property
);
960 return v
? v
->AsDuration()->ToSecondsFloat () : 0.0;
964 MoonlightDuration::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
968 string_to_npvariant ("", result
);
972 DOUBLE_TO_NPVARIANT (GetValue(), *result
);
976 return MoonlightObject::GetProperty (id
, name
, result
);
981 MoonlightDuration::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
988 parent_obj
->SetValue (parent_property
, Value(Duration::FromSecondsFloat (NPVARIANT_TO_DOUBLE (*value
))));
992 return MoonlightObject::SetProperty (id
, name
, value
);
996 MoonlightDuration::~MoonlightDuration ()
1002 MoonlightDurationType::MoonlightDurationType ()
1004 allocate
= duration_allocate
;
1006 AddMapping (duration_mapping
, G_N_ELEMENTS (duration_mapping
));
1009 MoonlightDurationType
*MoonlightDurationClass
;
1014 timespan_allocate (NPP instance
, NPClass
*klass
)
1016 return new MoonlightTimeSpan (instance
);
1019 static const MoonNameIdMapping
1020 timespan_mapping
[] = {
1021 { "name", MoonId_Name
},
1022 { "seconds", MoonId_Seconds
}
1026 MoonlightTimeSpan::SetParentInfo (DependencyObject
*parent_obj
, DependencyProperty
*parent_property
)
1028 this->parent_obj
= parent_obj
;
1029 this->parent_property
= parent_property
;
1034 MoonlightTimeSpan::GetValue()
1036 Value
*v
= parent_obj
->GetValue (parent_property
);
1037 return v
? v
->AsTimeSpan() : (TimeSpan
)0;
1041 MoonlightTimeSpan::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
1045 string_to_npvariant ("", result
);
1047 case MoonId_Seconds
:
1048 DOUBLE_TO_NPVARIANT (TimeSpan_ToSecondsFloat (GetValue ()), *result
);
1051 return MoonlightObject::GetProperty (id
, name
, result
);
1056 MoonlightTimeSpan::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
1062 case MoonId_Seconds
:
1063 if (NPVARIANT_IS_INT32 (*value
)) {
1064 parent_obj
->SetValue (parent_property
, Value(TimeSpan_FromSecondsFloat (NPVARIANT_TO_INT32 (*value
)), Type::TIMESPAN
));
1065 } else if (NPVARIANT_IS_DOUBLE (*value
)) {
1066 parent_obj
->SetValue (parent_property
, Value(TimeSpan_FromSecondsFloat (NPVARIANT_TO_DOUBLE (*value
)), Type::TIMESPAN
));
1073 return MoonlightObject::SetProperty (id
, name
, value
);
1077 MoonlightTimeSpan::~MoonlightTimeSpan ()
1080 parent_obj
->unref ();
1083 MoonlightTimeSpanType::MoonlightTimeSpanType ()
1085 allocate
= timespan_allocate
;
1087 AddMapping (timespan_mapping
, G_N_ELEMENTS (timespan_mapping
));
1090 MoonlightTimeSpanType
*MoonlightTimeSpanClass
;
1094 keytime_allocate (NPP instance
, NPClass
*klass
)
1096 return new MoonlightKeyTime (instance
);
1099 static const MoonNameIdMapping
1100 keytime_mapping
[] = {
1101 { "name", MoonId_Name
},
1102 { "seconds", MoonId_Seconds
}
1106 MoonlightKeyTime::SetParentInfo (DependencyObject
*parent_obj
, DependencyProperty
*parent_property
)
1108 this->parent_obj
= parent_obj
;
1109 this->parent_property
= parent_property
;
1114 MoonlightKeyTime::GetValue()
1116 Value
*v
= parent_obj
->GetValue (parent_property
);
1117 return (v
? v
->AsKeyTime() : NULL
);
1121 MoonlightKeyTime::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
1125 string_to_npvariant ("", result
);
1127 case MoonId_Seconds
:
1128 DOUBLE_TO_NPVARIANT (TimeSpan_ToSecondsFloat (GetValue ()->GetTimeSpan ()), *result
);
1131 return MoonlightObject::GetProperty (id
, name
, result
);
1136 MoonlightKeyTime::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
1142 case MoonId_Seconds
:
1143 if (NPVARIANT_IS_INT32 (*value
))
1144 parent_obj
->SetValue (parent_property
, Value(KeyTime::FromTimeSpan (TimeSpan_FromSecondsFloat (NPVARIANT_TO_INT32 (*value
)))));
1145 else if (NPVARIANT_IS_DOUBLE (*value
))
1146 parent_obj
->SetValue (parent_property
, Value(KeyTime::FromTimeSpan (TimeSpan_FromSecondsFloat (NPVARIANT_TO_DOUBLE (*value
)))));
1150 return MoonlightObject::SetProperty (id
, name
, value
);
1154 MoonlightKeyTime::~MoonlightKeyTime ()
1157 parent_obj
->unref ();
1160 MoonlightKeyTimeType::MoonlightKeyTimeType ()
1162 allocate
= keytime_allocate
;
1164 AddMapping (keytime_mapping
, G_N_ELEMENTS (keytime_mapping
));
1167 MoonlightKeyTimeType
*MoonlightKeyTimeClass
;
1172 thickness_allocate (NPP instance
, NPClass
*klass
)
1174 return new MoonlightThickness (instance
);
1177 static const MoonNameIdMapping
1178 thickness_mapping
[] = {
1179 { "bottom", MoonId_Bottom
},
1180 { "left", MoonId_Left
},
1181 { "right", MoonId_Right
},
1182 { "top", MoonId_Top
}
1186 MoonlightThickness::SetParentInfo (DependencyObject
*parent_obj
, DependencyProperty
*parent_property
)
1188 this->parent_obj
= parent_obj
;
1189 this->parent_property
= parent_property
;
1194 MoonlightThickness::GetValue()
1196 Value
*v
= parent_obj
->GetValue (parent_property
);
1197 return (v
? v
->AsThickness() : NULL
);
1201 MoonlightThickness::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
1205 string_to_npvariant ("", result
);
1208 DOUBLE_TO_NPVARIANT (GetValue ()->left
, *result
);
1211 DOUBLE_TO_NPVARIANT (GetValue ()->top
, *result
);
1214 DOUBLE_TO_NPVARIANT (GetValue ()->right
, *result
);
1217 DOUBLE_TO_NPVARIANT (GetValue ()->bottom
, *result
);
1220 return MoonlightObject::GetProperty (id
, name
, result
);
1225 MoonlightThickness::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
1238 return MoonlightObject::SetProperty (id
, name
, value
);
1242 MoonlightThickness::~MoonlightThickness ()
1245 parent_obj
->unref ();
1248 MoonlightThicknessType::MoonlightThicknessType ()
1250 allocate
= thickness_allocate
;
1252 AddMapping (thickness_mapping
, G_N_ELEMENTS (thickness_mapping
));
1255 MoonlightThicknessType
*MoonlightThicknessClass
;
1257 /*** CornerRadius ***/
1259 CornerRadius_allocate (NPP instance
, NPClass
*klass
)
1261 return new MoonlightCornerRadius (instance
);
1264 static const MoonNameIdMapping
1265 CornerRadius_mapping
[] = {
1266 { "bottomright", MoonId_BottomRight
},
1267 { "bottomleft", MoonId_BottomLeft
},
1268 { "topright", MoonId_TopRight
},
1269 { "topleft", MoonId_TopLeft
}
1273 MoonlightCornerRadius::SetParentInfo (DependencyObject
*parent_obj
, DependencyProperty
*parent_property
)
1275 this->parent_obj
= parent_obj
;
1276 this->parent_property
= parent_property
;
1281 MoonlightCornerRadius::GetValue()
1283 Value
*v
= parent_obj
->GetValue (parent_property
);
1284 return (v
? v
->AsCornerRadius() : NULL
);
1288 MoonlightCornerRadius::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
1292 string_to_npvariant ("", result
);
1294 case MoonId_TopLeft
:
1295 DOUBLE_TO_NPVARIANT (GetValue ()->topLeft
, *result
);
1297 case MoonId_TopRight
:
1298 DOUBLE_TO_NPVARIANT (GetValue ()->topRight
, *result
);
1300 case MoonId_BottomLeft
:
1301 DOUBLE_TO_NPVARIANT (GetValue ()->bottomLeft
, *result
);
1303 case MoonId_BottomRight
:
1304 DOUBLE_TO_NPVARIANT (GetValue ()->bottomRight
, *result
);
1307 return MoonlightObject::GetProperty (id
, name
, result
);
1312 MoonlightCornerRadius::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
1318 case MoonId_TopLeft
:
1319 case MoonId_TopRight
:
1320 case MoonId_BottomLeft
:
1321 case MoonId_BottomRight
:
1325 return MoonlightObject::SetProperty (id
, name
, value
);
1329 MoonlightCornerRadius::~MoonlightCornerRadius ()
1332 parent_obj
->unref ();
1335 MoonlightCornerRadiusType::MoonlightCornerRadiusType ()
1337 allocate
= CornerRadius_allocate
;
1339 AddMapping (CornerRadius_mapping
, G_N_ELEMENTS (CornerRadius_mapping
));
1342 MoonlightCornerRadiusType
*MoonlightCornerRadiusClass
;
1344 /*** GridLength ***/
1346 gridlength_allocate (NPP instance
, NPClass
*klass
)
1348 return new MoonlightGridLength (instance
);
1351 static const MoonNameIdMapping
1352 gridlength_mapping
[] = {
1353 { "gridunittype", MoonId_GridUnitType
},
1354 { "value", MoonId_Value
},
1358 MoonlightGridLength::SetParentInfo (DependencyObject
*parent_obj
, DependencyProperty
*parent_property
)
1360 this->parent_obj
= parent_obj
;
1361 this->parent_property
= parent_property
;
1366 MoonlightGridLength::GetValue()
1368 Value
*v
= parent_obj
->GetValue (parent_property
);
1369 return (v
? v
->AsGridLength() : NULL
);
1373 MoonlightGridLength::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
1377 string_to_npvariant ("", result
);
1380 DOUBLE_TO_NPVARIANT (GetValue ()->val
, *result
);
1382 case MoonId_GridUnitType
:
1383 string_to_npvariant (enums_int_to_str ("GridUnitType", GetValue()->type
), result
);
1386 return MoonlightObject::GetProperty (id
, name
, result
);
1391 MoonlightGridLength::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
1393 GridLength
*current_gridlength
= GetValue();
1394 GridLength gridlength
;
1396 if (current_gridlength
)
1397 gridlength
= *current_gridlength
;
1404 gridlength
.val
= NPVARIANT_TO_DOUBLE (*value
);
1405 parent_obj
->SetValue (parent_property
, Value(gridlength
.val
));
1407 case MoonId_GridUnitType
: {
1408 int unit_type
= enums_str_to_int ("GridUnitType", NPVARIANT_TO_STRING (*value
).utf8characters
);
1409 if (unit_type
== -1)
1410 return false; // FIXME: throw an exception?
1412 gridlength
.type
= (GridUnitType
)unit_type
;
1414 parent_obj
->SetValue (parent_property
, Value(gridlength
));
1419 return MoonlightObject::SetProperty (id
, name
, value
);
1423 MoonlightGridLength::~MoonlightGridLength ()
1426 parent_obj
->unref ();
1429 MoonlightGridLengthType::MoonlightGridLengthType ()
1431 allocate
= gridlength_allocate
;
1433 AddMapping (gridlength_mapping
, G_N_ELEMENTS (gridlength_mapping
));
1436 MoonlightGridLengthType
*MoonlightGridLengthClass
;
1438 /*** MoonlightDownloadProgressEventArgsClass **************************************************************/
1441 download_progress_event_allocate (NPP instance
, NPClass
*klass
)
1443 return new MoonlightDownloadProgressEventArgs (instance
);
1446 static const MoonNameIdMapping
1447 download_progress_event_mapping
[] = {
1448 { "progress", MoonId_Progress
},
1452 MoonlightDownloadProgressEventArgs::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
1454 DownloadProgressEventArgs
*event_args
= GetDownloadProgressEventArgs ();
1457 case MoonId_Progress
:
1458 DOUBLE_TO_NPVARIANT (event_args
->GetProgress (), *result
);
1461 return MoonlightEventArgs::GetProperty (id
, name
, result
);
1467 MoonlightDownloadProgressEventArgsType::MoonlightDownloadProgressEventArgsType ()
1469 allocate
= download_progress_event_allocate
;
1471 AddMapping (download_progress_event_mapping
, G_N_ELEMENTS (download_progress_event_mapping
));
1474 MoonlightDownloadProgressEventArgsType
*MoonlightDownloadProgressEventArgsClass
;
1477 /*** MoonlightMouseEventArgsClass **************************************************************/
1480 mouse_event_allocate (NPP instance
, NPClass
*klass
)
1482 return new MoonlightMouseEventArgsObject (instance
);
1485 static const MoonNameIdMapping
1486 mouse_event_mapping
[] = {
1487 { "ctrl", MoonId_Ctrl
},
1488 { "handled", MoonId_Handled
},
1489 { "getposition", MoonId_GetPosition
},
1490 { "getstylusinfo", MoonId_GetStylusInfo
},
1491 { "getstyluspoints", MoonId_GetStylusPoints
},
1492 { "shift", MoonId_Shift
},
1496 MoonlightMouseEventArgsObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
1498 MouseEventArgs
*event_args
= GetMouseEventArgs ();
1499 int state
= event_args
->GetState ();
1503 BOOLEAN_TO_NPVARIANT ((state
& GDK_SHIFT_MASK
) != 0, *result
);
1507 BOOLEAN_TO_NPVARIANT ((state
& GDK_CONTROL_MASK
) != 0, *result
);
1510 case MoonId_Handled
:
1511 BOOLEAN_TO_NPVARIANT (event_args
->GetHandled(), *result
);
1515 return MoonlightRoutedEventArgs::GetProperty (id
, name
, result
);
1520 MoonlightMouseEventArgsObject::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
1522 MouseEventArgs
*event_args
= GetMouseEventArgs ();
1525 case MoonId_Handled
:
1526 if (NPVARIANT_IS_BOOLEAN (*value
))
1527 event_args
->SetHandled (NPVARIANT_TO_BOOLEAN (*value
));
1530 return MoonlightRoutedEventArgs::SetProperty (id
, name
, value
);
1535 MoonlightMouseEventArgsObject::Invoke (int id
, NPIdentifier name
,
1536 const NPVariant
*args
, guint32 argCount
,
1539 MouseEventArgs
*event_args
= GetMouseEventArgs ();
1542 case MoonId_GetPosition
: {
1543 if (!check_arg_list ("(no)", argCount
, args
) && (!NPVARIANT_IS_NULL(args
[0]) || !npvariant_is_dependency_object (args
[0])))
1549 // The argument is an element
1550 // to calculate the position with respect to (or null
1551 // for screen space)
1553 UIElement
*el
= NULL
;
1555 if (npvariant_is_dependency_object (args
[0])) {
1556 DependencyObject
*dob
= DEPENDENCY_OBJECT_FROM_VARIANT (args
[0]);
1557 if (dob
->Is (Type::UIELEMENT
))
1558 el
= (UIElement
*)dob
;
1561 event_args
->GetPosition (el
, &x
, &y
);
1563 MoonlightPoint
*point
= (MoonlightPoint
*)NPN_CreateObject (instance
, MoonlightPointClass
);
1564 point
->point
= Point (x
, y
);
1566 OBJECT_TO_NPVARIANT (point
, *result
);
1570 case MoonId_GetStylusInfo
: {
1572 THROW_JS_EXCEPTION ("getStylusInfo");
1574 StylusInfo
*info
= event_args
->GetStylusInfo ();
1575 MoonlightEventObjectObject
*info_obj
= EventObjectCreateWrapper (instance
, info
);
1577 OBJECT_TO_NPVARIANT (info_obj
, *result
);
1581 case MoonId_GetStylusPoints
: {
1582 if (!check_arg_list ("o", argCount
, args
))
1583 THROW_JS_EXCEPTION ("getStylusPoints");
1585 if (npvariant_is_dependency_object (args
[0])) {
1586 DependencyObject
*dob
= DEPENDENCY_OBJECT_FROM_VARIANT (args
[0]);
1587 if (!dob
->Is (Type::INKPRESENTER
))
1588 THROW_JS_EXCEPTION ("getStylusPoints");
1590 StylusPointCollection
*points
= event_args
->GetStylusPoints ((UIElement
*)dob
);
1591 MoonlightEventObjectObject
*col_obj
= EventObjectCreateWrapper (instance
, points
);
1593 OBJECT_TO_NPVARIANT (col_obj
, *result
);
1599 return MoonlightRoutedEventArgs::Invoke (id
, name
, args
, argCount
, result
);
1604 MoonlightMouseEventArgsType::MoonlightMouseEventArgsType ()
1606 allocate
= mouse_event_allocate
;
1608 AddMapping (mouse_event_mapping
, G_N_ELEMENTS (mouse_event_mapping
));
1611 MoonlightMouseEventArgsType
*MoonlightMouseEventArgsClass
;
1614 /*** MoonlightMarkerReachedEventArgsClass **************************************************************/
1617 marker_reached_event_allocate (NPP instance
, NPClass
*klass
)
1619 return new MoonlightMarkerReachedEventArgsObject (instance
);
1622 static const MoonNameIdMapping
1623 marker_reached_event_mapping
[] = {
1624 { "marker", MoonId_Marker
}
1628 MoonlightMarkerReachedEventArgsObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
1630 MarkerReachedEventArgs
*args
= GetMarkerReachedEventArgs ();
1631 TimelineMarker
*marker
= args
? args
->GetMarker () : NULL
;
1634 case MoonId_Marker
: {
1635 MoonlightEventObjectObject
*meoo
= EventObjectCreateWrapper (instance
, marker
);
1636 OBJECT_TO_NPVARIANT (meoo
, *result
);
1640 return MoonlightEventArgs::GetProperty (id
, name
, result
);;
1644 MoonlightMarkerReachedEventArgsType::MoonlightMarkerReachedEventArgsType ()
1646 allocate
= marker_reached_event_allocate
;
1648 AddMapping (marker_reached_event_mapping
, G_N_ELEMENTS (marker_reached_event_mapping
));
1651 MoonlightMarkerReachedEventArgsType
*MoonlightMarkerReachedEventArgsClass
;
1653 /*** MoonlightKeyEventArgsClass **************************************************************/
1656 keyboard_event_allocate (NPP instance
, NPClass
*klass
)
1658 return new MoonlightKeyEventArgsObject (instance
);
1661 static const MoonNameIdMapping
1662 keyboard_event_mapping
[] = {
1663 { "ctrl", MoonId_Ctrl
},
1664 { "handled", MoonId_Handled
},
1665 { "key", MoonId_Key
},
1666 { "platformkeycode", MoonId_PlatformKeyCode
},
1667 { "shift", MoonId_Shift
},
1672 MoonlightKeyEventArgsObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
1674 KeyEventArgs
*args
= GetKeyEventArgs ();
1678 BOOLEAN_TO_NPVARIANT ((args
->GetModifiers () & GDK_SHIFT_MASK
) != 0, *result
);
1682 BOOLEAN_TO_NPVARIANT ((args
->GetModifiers () & GDK_CONTROL_MASK
) != 0, *result
);
1685 case MoonId_Handled
:
1686 BOOLEAN_TO_NPVARIANT (args
->GetHandled(), *result
);
1690 INT32_TO_NPVARIANT (args
->GetKey (), *result
);
1693 case MoonId_PlatformKeyCode
:
1694 INT32_TO_NPVARIANT (args
->GetPlatformKeyCode (), *result
);
1698 return MoonlightEventArgs::GetProperty (id
, name
, result
);
1702 MoonlightKeyEventArgsType::MoonlightKeyEventArgsType ()
1704 allocate
= keyboard_event_allocate
;
1706 AddMapping (keyboard_event_mapping
, G_N_ELEMENTS (keyboard_event_mapping
));
1709 MoonlightKeyEventArgsType
*MoonlightKeyEventArgsClass
;
1711 /*** our object base class */
1713 _allocate (NPP instance
, NPClass
*klass
)
1715 PluginInstance
*plugin
= (PluginInstance
*)instance
->pdata
;
1718 Deployment::SetCurrent (plugin
->GetDeployment ());
1720 return new MoonlightObject (instance
);
1724 _set_deployment (NPObject
*npobj
)
1726 MoonlightObject
*obj
= (MoonlightObject
*) npobj
;
1727 PluginInstance
*instance
= (PluginInstance
*)obj
->instance
->pdata
;
1730 Deployment::SetCurrent (instance
->GetDeployment ());
1734 _deallocate (NPObject
*npobj
)
1736 _set_deployment (npobj
);
1737 MoonlightObject
*obj
= (MoonlightObject
*) npobj
;
1743 detach_xaml_proxy (gpointer key
, gpointer value
, gpointer closure
)
1745 EventListenerProxy
*proxy
= (EventListenerProxy
*)value
;
1746 proxy
->SetOwner (NULL
);
1750 moonlight_object_to_npobject (MoonlightObject
*obj
)
1752 return (NPObject
*) obj
;
1756 npobject_to_moonlight_object (NPObject
*obj
)
1758 return (MoonlightObject
*) obj
;
1761 MoonlightObject::~MoonlightObject ()
1763 if (event_listener_proxies
) {
1764 g_hash_table_foreach (event_listener_proxies
, detach_xaml_proxy
, NULL
);
1765 g_hash_table_destroy (event_listener_proxies
);
1766 event_listener_proxies
= NULL
;
1771 MoonlightObject::destroy_proxy (gpointer data
)
1773 EventListenerProxy
*proxy
= (EventListenerProxy
*)data
;
1774 proxy
->RemoveHandler ();
1778 MoonlightObject::HasProperty (NPIdentifier name
)
1780 return IS_PROPERTY (LookupName (name
));
1784 MoonlightObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
1786 NULL_TO_NPVARIANT (*result
);
1787 THROW_JS_EXCEPTION ("AG_E_RUNTIME_GETVALUE");
1792 MoonlightObject::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
1794 THROW_JS_EXCEPTION ("AG_E_RUNTIME_SETVALUE");
1799 MoonlightObject::HasMethod (NPIdentifier name
)
1801 return IS_METHOD (LookupName (name
));
1805 MoonlightObject::Invoke (int id
, NPIdentifier name
, const NPVariant
*args
, guint32 argCount
, NPVariant
*result
)
1808 case MoonId_ToString
:
1812 if (moonlight_type
!= Type::INVALID
) {
1813 string_to_npvariant (Type::Find (moonlight_type
)->GetName (), result
);
1816 //string_to_npvariant ("", result);
1817 NULL_TO_NPVARIANT (*result
);
1827 EventListenerProxy
*
1828 MoonlightObject::LookupEventProxy (int event_id
)
1830 return (EventListenerProxy
*)g_hash_table_lookup (event_listener_proxies
, GINT_TO_POINTER (event_id
));
1834 MoonlightObject::SetEventProxy (EventListenerProxy
*proxy
)
1836 g_hash_table_insert (event_listener_proxies
, GINT_TO_POINTER (proxy
->GetEventId()), proxy
);
1840 MoonlightObject::ClearEventProxy (EventListenerProxy
*proxy
)
1842 proxy
->SetOwner (NULL
);
1845 EventListenerProxy
*p
= LookupEventProxy (proxy
->GetEventId());
1849 g_hash_table_remove (event_listener_proxies
, GINT_TO_POINTER (proxy
->GetEventId()));
1854 _invalidate (NPObject
*npobj
)
1856 _set_deployment (npobj
);
1857 MoonlightObject
*obj
= (MoonlightObject
*) npobj
;
1863 _has_method (NPObject
*npobj
, NPIdentifier name
)
1865 _set_deployment (npobj
);
1866 MoonlightObject
*obj
= (MoonlightObject
*) npobj
;
1867 return obj
->HasMethod (name
);
1871 _has_property (NPObject
*npobj
, NPIdentifier name
)
1873 _set_deployment (npobj
);
1874 MoonlightObject
*obj
= (MoonlightObject
*) npobj
;
1875 return obj
->HasProperty (name
);
1879 _get_property (NPObject
*npobj
, NPIdentifier name
, NPVariant
*result
)
1881 _set_deployment (npobj
);
1883 NPUTF8
*strname
= NPN_UTF8FromIdentifier (name
);
1884 printf ("getting object property %s\n", strname
);
1885 NPN_MemFree (strname
);
1888 MoonlightObject
*obj
= (MoonlightObject
*) npobj
;
1889 int id
= obj
->LookupName (name
);
1890 bool ret
= obj
->GetProperty (id
, name
, result
);
1892 printf ("==>done ==> %p\n", NPVARIANT_TO_OBJECT (*result
));
1898 _set_property (NPObject
*npobj
, NPIdentifier name
, const NPVariant
*value
)
1900 _set_deployment (npobj
);
1901 MoonlightObject
*obj
= (MoonlightObject
*) npobj
;
1902 int id
= obj
->LookupName (name
);
1903 return obj
->SetProperty (id
, name
, value
);
1907 _remove_property (NPObject
*npobj
, NPIdentifier name
)
1909 _set_deployment (npobj
);
1910 g_warning ("moonlight_object_remove_property reached");
1915 _enumerate (NPObject
*npobj
, NPIdentifier
**value
, guint32
*count
)
1917 _set_deployment (npobj
);
1918 return ((MoonlightObjectType
*)npobj
->_class
)->Enumerate (value
, count
);
1922 _invoke (NPObject
*npobj
, NPIdentifier name
,
1923 const NPVariant
*args
, guint32 argCount
,
1926 _set_deployment (npobj
);
1927 MoonlightObject
*obj
= (MoonlightObject
*) npobj
;
1928 int id
= obj
->LookupName (name
);
1929 return obj
->Invoke (id
, name
, args
, argCount
, result
);
1933 _invoke_default (NPObject
*npobj
,
1934 const NPVariant
*args
, guint32 argCount
,
1937 _set_deployment (npobj
);
1938 g_warning ("moonlight_object_invoke_default reached");
1942 static const MoonNameIdMapping
1943 object_mapping
[] = {
1944 { "tostring", MoonId_ToString
},
1947 MoonlightObjectType::MoonlightObjectType ()
1949 structVersion
= 0; /* strictly not needed, but it prevents head-scratching due to uninitialized fields in gdb */
1950 allocate
= _allocate
;
1952 deallocate
= _deallocate
;
1953 invalidate
= _invalidate
;
1954 hasMethod
= _has_method
;
1956 invokeDefault
= _invoke_default
;
1957 hasProperty
= _has_property
;
1958 getProperty
= _get_property
;
1959 setProperty
= _set_property
;
1960 removeProperty
= _remove_property
;
1961 enumerate
= _enumerate
;
1966 AddMapping (object_mapping
, G_N_ELEMENTS (object_mapping
));
1973 MoonlightObjectType::Enumerate (NPIdentifier
**value
, guint32
*count
)
1975 if (mapping_count
== 0) {
1981 // caller frees this
1982 NPIdentifier
*ids
= (NPIdentifier
*)NPN_MemAlloc (sizeof (NPIdentifier
) * mapping_count
);
1984 for (int i
= 0; i
< mapping_count
; i
++)
1985 ids
[i
] = NPN_GetStringIdentifier (mapping
[i
].name
);
1987 *count
= mapping_count
;
1994 MoonlightObjectType::AddMapping (const MoonNameIdMapping
*mapping
, int count
)
1996 if (this->mapping
) {
1997 MoonNameIdMapping
*new_mapping
= (MoonNameIdMapping
*) g_new (MoonNameIdMapping
, count
+ mapping_count
);
1999 memmove (new_mapping
, this->mapping
, mapping_count
* sizeof (MoonNameIdMapping
));
2000 memmove ((char *) new_mapping
+ (mapping_count
* sizeof (MoonNameIdMapping
)), mapping
, count
* sizeof (MoonNameIdMapping
));
2001 g_free (this->mapping
);
2002 this->mapping
= new_mapping
;
2003 mapping_count
+= count
;
2005 this->mapping
= (MoonNameIdMapping
*) g_new (MoonNameIdMapping
, count
);
2007 memmove (this->mapping
, mapping
, count
* sizeof (MoonNameIdMapping
));
2008 mapping_count
= count
;
2011 qsort (this->mapping
, mapping_count
, sizeof (MoonNameIdMapping
), compare_mapping
);
2015 MoonlightObjectType::LookupName (NPIdentifier name
)
2017 if (last_lookup
== name
)
2020 int id
= map_name_to_id (name
, mapping
, mapping_count
);
2023 /* only cache hits */
2031 MoonlightObjectType
*MoonlightObjectClass
;
2033 /*** MoonlightScriptControlClass **********************************************************/
2035 moonlight_scriptable_control_allocate (NPP instance
, NPClass
*klass
)
2037 return new MoonlightScriptControlObject (instance
);
2040 static const MoonNameIdMapping
2041 scriptable_control_mapping
[] = {
2042 { "content", MoonId_Content
},
2043 { "isloaded", MoonId_IsLoaded
},
2044 { "createobject", MoonId_CreateObject
},
2045 { "initparams", MoonId_InitParams
},
2046 { "id", MoonId_Id
},
2047 { "isversionsupported", MoonId_IsVersionSupported
},
2048 { "onerror", MoonId_OnError
},
2049 { "onload", MoonId_OnLoad
},
2050 { "settings", MoonId_Settings
},
2051 { "source", MoonId_Source
},
2052 { "onsourcedownloadprogresschanged", MoonId_OnSourceDownloadProgressChanged
},
2053 { "onsourcedownloadcomplete", MoonId_OnSourceDownloadComplete
},
2056 MoonlightScriptControlObject::~MoonlightScriptControlObject ()
2059 NPN_ReleaseObject (settings
);
2064 NPN_ReleaseObject (content
);
2070 MoonlightScriptControlObject::Invalidate ()
2072 MoonlightObject::Invalidate ();
2079 MoonlightScriptControlObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
2081 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
2084 case MoonId_Settings
:
2085 NPN_RetainObject (settings
);
2086 OBJECT_TO_NPVARIANT (settings
, *result
);
2088 case MoonId_Content
:
2089 NPN_RetainObject (content
);
2090 OBJECT_TO_NPVARIANT (content
, *result
);
2092 case MoonId_InitParams
:
2093 string_to_npvariant (plugin
->GetInitParams (), result
);
2095 case MoonId_IsLoaded
:
2096 BOOLEAN_TO_NPVARIANT (plugin
->IsLoaded(), *result
);
2098 case MoonId_OnError
:
2100 case MoonId_OnSourceDownloadProgressChanged
:
2101 case MoonId_OnSourceDownloadComplete
: {
2102 const char *event_name
= map_moon_id_to_event_name (id
);
2103 EventObject
*obj
= plugin
->GetSurface ();
2106 int event_id
= obj
->GetType()->LookupEvent (event_name
);
2107 EventListenerProxy
*proxy
= LookupEventProxy (event_id
);
2108 string_to_npvariant (proxy
== NULL
? "" : proxy
->GetCallbackAsString (), result
);
2110 string_to_npvariant ("", result
);
2115 string_to_npvariant (plugin
->GetSource (), result
);
2119 char *id
= plugin
->GetId ();
2121 string_to_npvariant (id
, result
);
2123 NULL_TO_NPVARIANT (*result
);
2129 return MoonlightObject::GetProperty (id
, name
, result
);
2134 MoonlightScriptControlObject::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
2136 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
2139 case MoonId_Source
: {
2140 char *source
= STRDUP_FROM_VARIANT (*value
);
2141 plugin
->SetSource (source
);
2145 case MoonId_OnError
:
2147 case MoonId_OnSourceDownloadProgressChanged
:
2148 case MoonId_OnSourceDownloadComplete
: {
2149 const char *event_name
= map_moon_id_to_event_name (id
);
2150 EventObject
*obj
= plugin
->GetSurface ();
2153 int event_id
= obj
->GetType()->LookupEvent (event_name
);
2155 if (event_id
!= -1) {
2156 EventListenerProxy
*proxy
= LookupEventProxy (event_id
);
2158 proxy
->RemoveHandler ();
2160 if (!NPVARIANT_IS_NULL (*value
)) {
2161 EventListenerProxy
*proxy
= new EventListenerProxy (instance
,
2164 proxy
->SetOwner (this);
2165 proxy
->AddHandler (plugin
->GetSurface());
2166 // we only emit that event once, when
2167 // the plugin is initialized, so don't
2168 // leave it in the event list
2170 if (id
== MoonId_OnLoad
)
2171 proxy
->SetOneShot ();
2172 SetEventProxy (proxy
);
2180 case MoonId_InitParams
: {
2181 char *init_params
= STRDUP_FROM_VARIANT (*value
);
2182 plugin
->SetInitParams (init_params
);
2183 g_free (init_params
);
2187 return MoonlightObject::SetProperty (id
, name
, value
);
2192 MoonlightScriptControlObject::Invoke (int id
, NPIdentifier name
,
2193 const NPVariant
*args
, guint32 argCount
,
2197 case MoonId_CreateObject
: {
2198 if (!check_arg_list ("s", argCount
, args
)) {
2199 NULL_TO_NPVARIANT (*result
);
2203 NPObject
*obj
= NULL
;
2204 char *object_type
= STRDUP_FROM_VARIANT (args
[0]);
2205 if (!g_ascii_strcasecmp ("downloader", object_type
)) {
2206 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
2207 Downloader
*dl
= PluginInstance::CreateDownloader (plugin
);
2209 obj
= EventObjectCreateWrapper (instance
, dl
);
2212 OBJECT_TO_NPVARIANT (obj
, *result
);
2213 g_free (object_type
);
2216 NULL_TO_NPVARIANT (*result
);
2217 g_free (object_type
);
2219 THROW_JS_EXCEPTION ("createObject");
2224 case MoonId_IsVersionSupported
: {
2225 if (!check_arg_list ("s", argCount
, args
))
2228 gchar
*version_list
= STRDUP_FROM_VARIANT (args
[0]);
2229 bool supported
= Surface::IsVersionSupported (version_list
);
2230 g_free (version_list
);
2232 BOOLEAN_TO_NPVARIANT (supported
, *result
);
2238 return MoonlightObject::Invoke (id
, name
, args
, argCount
, result
);
2242 MoonlightScriptControlType::MoonlightScriptControlType ()
2244 allocate
= moonlight_scriptable_control_allocate
;
2246 AddMapping (scriptable_control_mapping
, G_N_ELEMENTS (scriptable_control_mapping
));
2249 MoonlightScriptControlType
*MoonlightScriptControlClass
;
2251 /*** MoonlightSettingsClass ***********************************************************/
2254 moonlight_settings_allocate (NPP instance
, NPClass
*klass
)
2256 return new MoonlightSettingsObject (instance
);
2259 static const MoonNameIdMapping
2260 moonlight_settings_mapping
[] = {
2261 { "background", MoonId_Background
},
2262 { "enableframeratecounter", MoonId_EnableFramerateCounter
},
2263 { "enablehtmlaccess", MoonId_EnableHtmlAccess
},
2264 { "enableredrawregions", MoonId_EnableRedrawRegions
},
2265 { "maxframerate", MoonId_MaxFrameRate
},
2266 { "version", MoonId_Version
},
2267 { "windowless", MoonId_Windowless
}
2271 MoonlightSettingsObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
2273 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
2276 case MoonId_Background
:
2277 string_to_npvariant (plugin
->GetBackground (), result
);
2280 case MoonId_EnableFramerateCounter
:
2281 BOOLEAN_TO_NPVARIANT (plugin
->GetEnableFramerateCounter (), *result
);
2284 case MoonId_EnableRedrawRegions
:
2285 BOOLEAN_TO_NPVARIANT (plugin
->GetEnableRedrawRegions (), *result
);
2288 case MoonId_EnableHtmlAccess
:
2289 BOOLEAN_TO_NPVARIANT (plugin
->GetEnableHtmlAccess (), *result
);
2292 case MoonId_MaxFrameRate
:
2293 INT32_TO_NPVARIANT (plugin
->GetMaxFrameRate (), *result
);
2296 case MoonId_Version
:
2297 string_to_npvariant (PLUGIN_VERSION
, result
);
2300 case MoonId_Windowless
:
2301 BOOLEAN_TO_NPVARIANT (plugin
->GetWindowless (), *result
);
2305 return MoonlightObject::GetProperty (id
, name
, result
);
2310 MoonlightSettingsObject::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
2312 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
2316 case MoonId_Background
: {
2317 char *color
= STRDUP_FROM_VARIANT (*value
);
2318 if (!plugin
->SetBackground (color
)) {
2320 THROW_JS_EXCEPTION ("AG_E_RUNTIME_SETVALUE");
2326 // Cant be set after initialization so return true
2327 case MoonId_EnableFramerateCounter
:
2328 plugin
->SetEnableFramerateCounter (NPVARIANT_TO_BOOLEAN (*value
));
2331 case MoonId_EnableRedrawRegions
:
2332 plugin
->SetEnableRedrawRegions (NPVARIANT_TO_BOOLEAN (*value
));
2335 // Cant be set after initialization so return true
2336 case MoonId_EnableHtmlAccess
:
2339 // not implemented yet.
2340 case MoonId_MaxFrameRate
:
2341 plugin
->SetMaxFrameRate (NPVARIANT_TO_INT32 (*value
));
2344 // Cant be set after initialization so return true
2345 case MoonId_Windowless
:
2348 return MoonlightObject::SetProperty (id
, name
, value
);
2353 MoonlightSettingsObject::Invoke (int id
, NPIdentifier name
,
2354 const NPVariant
*args
, guint32 argCount
, NPVariant
*result
)
2357 case MoonId_ToString
:
2361 string_to_npvariant ("Settings", result
);
2364 return MoonlightObject::Invoke (id
, name
, args
, argCount
, result
);
2368 MoonlightSettingsType::MoonlightSettingsType ()
2370 allocate
= moonlight_settings_allocate
;
2371 AddMapping (moonlight_settings_mapping
, G_N_ELEMENTS (moonlight_settings_mapping
));
2374 MoonlightSettingsType
*MoonlightSettingsClass
;
2377 /*** MoonlightContentClass ************************************************************/
2379 moonlight_content_allocate (NPP instance
, NPClass
*klass
)
2381 return new MoonlightContentObject (instance
);
2384 MoonlightContentObject::~MoonlightContentObject ()
2386 // FIXME: need to free registered scriptable objects
2387 if (registered_scriptable_objects
) {
2388 g_hash_table_destroy (registered_scriptable_objects
);
2389 registered_scriptable_objects
= NULL
;
2392 accessibility
->unref();
2395 static const MoonNameIdMapping
2396 moonlight_content_mapping
[] = {
2397 { "accessibility", MoonId_Accessibility
},
2398 { "actualheight", MoonId_ActualHeight
},
2399 { "actualwidth", MoonId_ActualWidth
},
2400 { "createfromxaml", MoonId_CreateFromXaml
},
2401 { "createfromxamldownloader", MoonId_CreateFromXamlDownloader
},
2402 { "createobject", MoonId_CreateObject
},
2403 { "findname", MoonId_FindName
},
2404 { "fullscreen", MoonId_FullScreen
},
2405 { "onfullscreenchange", MoonId_OnFullScreenChange
},
2406 { "onresize", MoonId_OnResize
},
2407 { "root", MoonId_Root
},
2411 MoonlightContentObject::HasProperty (NPIdentifier name
)
2414 NPUTF8
*strname
= NPN_UTF8FromIdentifier (name
);
2415 printf ("content has property %s\n", strname
);
2416 NPN_MemFree (strname
);
2419 if (MoonlightObject::HasProperty (name
))
2422 bool ret
= g_hash_table_lookup (registered_scriptable_objects
, name
) != NULL
;
2427 MoonlightContentObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
2429 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
2432 case MoonId_Accessibility
: {
2434 accessibility
= new Accessibility ();
2435 MoonlightEventObjectObject
*acc
= EventObjectCreateWrapper (instance
, accessibility
);
2437 OBJECT_TO_NPVARIANT (acc
, *result
);
2440 case MoonId_ActualHeight
:
2441 INT32_TO_NPVARIANT (plugin
->GetActualHeight (), *result
);
2443 case MoonId_ActualWidth
:
2444 INT32_TO_NPVARIANT (plugin
->GetActualWidth (), *result
);
2446 case MoonId_FullScreen
:
2447 if (!plugin
->GetSurface ()) {
2448 BOOLEAN_TO_NPVARIANT (false, *result
);
2450 BOOLEAN_TO_NPVARIANT (plugin
->GetSurface()->GetFullScreen (), *result
);
2453 case MoonId_OnResize
:
2454 case MoonId_OnFullScreenChange
: {
2455 Surface
*surface
= plugin
->GetSurface ();
2456 const char *event_name
;
2459 if (surface
== NULL
) {
2460 string_to_npvariant ("", result
);
2462 event_name
= map_moon_id_to_event_name (id
);
2463 event_id
= surface
->GetType()->LookupEvent (event_name
);
2464 EventListenerProxy
*proxy
= LookupEventProxy (event_id
);
2465 string_to_npvariant (proxy
== NULL
? "" : proxy
->GetCallbackAsString (), result
);
2470 Surface
*surface
= plugin
->GetSurface ();
2471 DependencyObject
*top
;
2473 if (surface
== NULL
) {
2474 NULL_TO_NPVARIANT (*result
);
2475 } else if ((top
= surface
->GetToplevel ()) == NULL
) {
2476 NULL_TO_NPVARIANT (*result
);
2478 MoonlightEventObjectObject
*topobj
= EventObjectCreateWrapper (instance
, top
);
2480 OBJECT_TO_NPVARIANT (topobj
, *result
);
2485 MoonlightScriptableObjectObject
*obj
;
2488 if (!(val
= g_hash_table_lookup (registered_scriptable_objects
, name
)))
2491 obj
= (MoonlightScriptableObjectObject
*) val
;
2493 NPN_RetainObject (obj
);
2494 OBJECT_TO_NPVARIANT (obj
, *result
);
2498 return MoonlightObject::GetProperty (id
, name
, result
);
2503 MoonlightContentObject::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
2505 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
2506 Surface
*surface
= NULL
;
2509 case MoonId_Accessibility
:
2510 THROW_JS_EXCEPTION ("AG_E_RUNTIME_SETVALUE");
2512 case MoonId_FullScreen
:
2513 surface
= plugin
->GetSurface ();
2514 if (surface
!= NULL
)
2515 surface
->SetFullScreen (NPVARIANT_TO_BOOLEAN (*value
));
2517 case MoonId_OnFullScreenChange
:
2518 case MoonId_OnResize
: {
2519 const char *event_name
= map_moon_id_to_event_name (id
);
2522 surface
= plugin
->GetSurface ();
2523 if (surface
== NULL
)
2526 event_id
= surface
->GetType()->LookupEvent (event_name
);
2528 if (event_id
!= -1) {
2529 EventListenerProxy
*proxy
= LookupEventProxy (event_id
);
2531 proxy
->RemoveHandler();
2533 if (!NPVARIANT_IS_NULL (*value
)) {
2534 EventListenerProxy
*proxy
= new EventListenerProxy (instance
,
2537 proxy
->SetOwner (this);
2538 proxy
->AddHandler (plugin
->GetSurface());
2539 SetEventProxy (proxy
);
2546 return MoonlightObject::SetProperty (id
, name
, value
);
2551 MoonlightContentObject::Invoke (int id
, NPIdentifier name
,
2552 const NPVariant
*args
, guint32 argCount
, NPVariant
*result
)
2554 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
2557 case MoonId_FindName
: {
2558 if (!check_arg_list ("s", argCount
, args
))
2559 THROW_JS_EXCEPTION ("AG_E_RUNTIME_FINDNAME");
2561 if (plugin
->IsCrossDomainApplication ())
2562 THROW_JS_EXCEPTION ("XDomain Restriction");
2564 if (!plugin
->GetSurface() || !plugin
->GetSurface()->GetToplevel ())
2567 char *name
= STRDUP_FROM_VARIANT (args
[0]);
2568 DependencyObject
*element
= plugin
->GetSurface()->GetToplevel ()->FindName (name
);
2572 NULL_TO_NPVARIANT (*result
);
2576 OBJECT_TO_NPVARIANT (EventObjectCreateWrapper (instance
, element
), *result
);
2580 case MoonId_CreateObject
:
2581 // not implemented yet
2582 DEBUG_WARN_NOTIMPLEMENTED ("content.createObject");
2585 case MoonId_CreateFromXaml
: {
2586 if (!check_arg_list ("s[b]", argCount
, args
))
2587 THROW_JS_EXCEPTION ("createFromXaml argException");
2589 bool create_namescope
= argCount
>= 2 ? NPVARIANT_TO_BOOLEAN (args
[1]) : false;
2590 char *xaml
= STRDUP_FROM_VARIANT (args
[0]);
2593 THROW_JS_EXCEPTION ("createFromXaml argNullException");
2595 Type::Kind element_type
;
2597 DependencyObject
*dep
= NULL
;
2598 XamlLoader
*loader
= PluginXamlLoader::FromStr (NULL
/*FIXME*/, xaml
, plugin
, plugin
->GetSurface());
2602 Value
*val
= loader
->CreateFromStringWithError (xaml
, create_namescope
, &element_type
, XamlLoader::IMPORT_DEFAULT_XMLNS
, &error
);
2603 if (val
&& val
->Is (Type::DEPENDENCY_OBJECT
))
2604 dep
= val
->AsDependencyObject ();
2610 char *msg
= g_strdup_printf ("createFromXaml error: %s", error
.message
);
2611 THROW_JS_EXCEPTION (msg
);
2615 MoonlightEventObjectObject
*depobj
= EventObjectCreateWrapper (instance
, dep
);
2618 OBJECT_TO_NPVARIANT (depobj
, *result
);
2622 case MoonId_CreateFromXamlDownloader
: {
2623 if (!check_arg_list ("os", argCount
, args
))
2624 THROW_JS_EXCEPTION ("createFromXamlDownloader");
2626 Downloader
*down
= (Downloader
*)((MoonlightDependencyObjectObject
*) NPVARIANT_TO_OBJECT (args
[0]))->GetDependencyObject ();
2627 DependencyObject
*dep
= NULL
;
2628 Type::Kind element_type
;
2630 char *path
= STRDUP_FROM_VARIANT (args
[1]);
2631 char *fname
= down
->GetDownloadedFilename (path
);
2634 if (fname
!= NULL
) {
2635 XamlLoader
*loader
= PluginXamlLoader::FromFilename (NULL
/*FIXME*/, fname
, plugin
, plugin
->GetSurface());
2636 dep
= loader
->CreateDependencyObjectFromFile (fname
, false, &element_type
);
2643 THROW_JS_EXCEPTION ("createFromXamlDownloader");
2645 OBJECT_TO_NPVARIANT (EventObjectCreateWrapper (instance
, dep
), *result
);
2650 case MoonId_ToString
: {
2654 string_to_npvariant ("Content", result
);
2659 return MoonlightObject::Invoke (id
, name
, args
, argCount
, result
);
2663 MoonlightContentType::MoonlightContentType ()
2665 allocate
= moonlight_content_allocate
;
2667 AddMapping (moonlight_content_mapping
, G_N_ELEMENTS (moonlight_content_mapping
));
2670 MoonlightContentType
*MoonlightContentClass
;
2674 /*** MoonlightDependencyObjectClass ***************************************************/
2676 static const MoonNameIdMapping
2677 moonlight_dependency_object_mapping
[] = {
2678 { "addeventlistener", MoonId_AddEventListener
},
2679 #if DEBUG_JAVASCRIPT
2680 { "dumpnamescope", MoonId_DumpNameScope
},
2682 { "equals", MoonId_Equals
},
2683 { "findname", MoonId_FindName
},
2684 { "gethost", MoonId_GetHost
},
2685 { "getparent", MoonId_GetParent
},
2686 { "getvalue", MoonId_GetValue
},
2687 { "gotfocus", MoonId_GotFocus
},
2688 { "keydown", MoonId_KeyDown
},
2689 { "keyup", MoonId_KeyUp
},
2690 { "loaded", MoonId_Loaded
},
2691 { "lostfocus", MoonId_LostFocus
},
2692 { "mouseenter", MoonId_MouseEnter
},
2693 { "mouseleave", MoonId_MouseLeave
},
2694 { "mouseleftbuttondown", MoonId_MouseLeftButtonDown
},
2695 { "mouseleftbuttonup", MoonId_MouseLeftButtonUp
},
2696 { "mousemove", MoonId_MouseMove
},
2697 #if DEBUG_JAVASCRIPT
2698 { "printf", MoonId_Printf
},
2700 { "removeeventlistener", MoonId_RemoveEventListener
},
2701 { "setvalue", MoonId_SetValue
},
2705 moonlight_dependency_object_allocate (NPP instance
, NPClass
*klass
)
2707 return new MoonlightDependencyObjectObject (instance
);
2710 static DependencyProperty
*
2711 _get_dependency_property (DependencyObject
*obj
, char *attrname
)
2713 // don't need to downcase here since dependency property lookup is already case insensitive
2714 DependencyProperty
*p
= obj
->GetDependencyProperty (attrname
);
2719 char *period
= strchr (attrname
, '.');
2721 char *type_name
= g_strndup (attrname
, period
-attrname
);
2722 attrname
= period
+ 1;
2724 Type
*type
= Type::Find (type_name
);
2727 p
= DependencyProperty::GetDependencyProperty (type
->GetKind (), attrname
);
2736 _set_dependency_property_value (DependencyObject
*dob
, DependencyProperty
*prop
, const NPVariant
*value
, MoonError
*error
)
2738 if (npvariant_is_moonlight_object (*value
)) {
2739 MoonlightObject
*obj
= (MoonlightObject
*) NPVARIANT_TO_OBJECT (*value
);
2740 MoonlightDuration
*duration
;
2741 MoonlightTimeSpan
*ts
;
2742 MoonlightPoint
*point
;
2743 MoonlightRect
*rect
;
2745 if (Type::IsSubclassOf (obj
->moonlight_type
, Type::DEPENDENCY_OBJECT
) && obj
->moonlight_type
!= Type::INVALID
) {
2746 MoonlightDependencyObjectObject
*depobj
= (MoonlightDependencyObjectObject
*) NPVARIANT_TO_OBJECT (*value
);
2747 dob
->SetValueWithError (prop
, Value (depobj
->GetDependencyObject ()), error
);
2749 return error
->number
== 0;
2752 switch (obj
->moonlight_type
) {
2753 case Type::TIMESPAN
:
2754 ts
= (MoonlightTimeSpan
*) obj
;
2755 dob
->SetValue (prop
, Value (ts
->GetValue (), Type::TIMESPAN
));
2757 case Type::DURATION
:
2758 duration
= (MoonlightDuration
*) obj
;
2759 dob
->SetValue (prop
, Value (duration
->GetValue ()));
2762 rect
= (MoonlightRect
*) obj
;
2763 dob
->SetValue (prop
, Value (rect
->rect
));
2766 point
= (MoonlightPoint
*) obj
;
2767 dob
->SetValue (prop
, Value (point
->point
));
2770 d(printf ("unhandled object type %d - %s in do.set_property\n",
2771 obj
->moonlight_type
, Type::Find (obj
->moonlight_type
)->GetName ()));
2772 w(printf ("unhandled object type in do.set_property\n"));
2776 char *strval
= NULL
;
2780 if (NPVARIANT_IS_BOOLEAN (*value
)) {
2781 if (NPVARIANT_TO_BOOLEAN (*value
))
2782 strcpy (strbuf
, "true");
2784 strcpy (strbuf
, "false");
2787 } else if (NPVARIANT_IS_INT32 (*value
)) {
2788 g_snprintf (strbuf
, sizeof (strbuf
), "%d", NPVARIANT_TO_INT32 (*value
));
2791 } else if (NPVARIANT_IS_DOUBLE (*value
)) {
2792 g_ascii_dtostr (strbuf
, sizeof (strbuf
), NPVARIANT_TO_DOUBLE (*value
));
2795 } else if (NPVARIANT_IS_STRING (*value
)) {
2796 strval
= STRDUP_FROM_VARIANT (*value
);
2797 } else if (NPVARIANT_IS_NULL (*value
)) {
2798 if (Type::IsSubclassOf (prop
->GetPropertyType(), Type::DEPENDENCY_OBJECT
)) {
2799 DependencyObject
*val
= NULL
;
2801 dob
->SetValueWithError (prop
, Value (val
), error
);
2802 } else if (prop
->GetPropertyType() == Type::STRING
) {
2805 dob
->SetValueWithError (prop
, Value (val
), error
);
2807 dob
->SetValueWithError (prop
, NULL
, error
);
2809 return error
->number
== 0;
2810 } else if (NPVARIANT_IS_VOID (*value
)) {
2811 d(printf ("unhandled variant type VOID in do.set_property for (%s::%s)\n",
2812 dob
->GetTypeName (), prop
->GetName()));
2815 d(printf ("unhandled variant type in do.set_property for (%s::%s)\n",
2816 dob
->GetTypeName (), prop
->GetName()));
2820 rv
= xaml_set_property_from_str (dob
, prop
, strval
, error
);
2822 if (strval
!= strbuf
)
2833 MoonlightDependencyObjectObject::HasProperty (NPIdentifier name
)
2835 if (MoonlightObject::HasProperty (name
))
2838 DependencyObject
*dob
= GetDependencyObject ();
2840 // don't need to downcase here since dependency property lookup is already case insensitive
2841 NPUTF8
*strname
= NPN_UTF8FromIdentifier (name
);
2845 DependencyProperty
*p
= _get_dependency_property (dob
, strname
);
2846 NPN_MemFree (strname
);
2852 MoonlightDependencyObjectObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
2854 // don't need to downcase here since dependency property lookup is already case insensitive
2855 NPUTF8
*strname
= NPN_UTF8FromIdentifier (name
);
2856 DependencyObject
*dob
= GetDependencyObject ();
2857 DependencyProperty
*prop
;
2858 const char *event_name
;
2864 prop
= _get_dependency_property (dob
, strname
);
2865 NPN_MemFree (strname
);
2869 // some default values are different between SL1 and SL2 (even if the SL1 apps runs under SL2)
2870 if (prop
->GetId () == UIElement::RenderTransformProperty
) {
2871 // e.g. the default RenderTransform is NULL for Javascript, unless it was setted by application code
2872 value
= dob
->ReadLocalValue (prop
);
2873 } else if ((prop
->GetId () == FrameworkElement::HeightProperty
) || (prop
->GetId () == FrameworkElement::WidthProperty
)) {
2874 // e.g. the Width and Height are NaN in SL2 and 0 in Javascript (unless set to NaN in managed code)
2875 value
= dob
->ReadLocalValue (prop
);
2877 DOUBLE_TO_NPVARIANT (0.0, *result
);
2880 } else if (prop
->GetId () == MediaElement::CurrentStateProperty
) {
2881 // Javascript applications use strings, while managed use an enum
2882 int enum_value
= dob
->GetValue (prop
)->AsInt32 ();
2883 const char *name
= enums_int_to_str ("MediaState", enum_value
);
2884 string_to_npvariant (name
, result
);
2887 value
= dob
->GetValue (prop
);
2891 // strings aren't null, they seem to just be empty strings
2892 if (prop
->GetPropertyType() == Type::STRING
) {
2893 string_to_npvariant ("", result
);
2897 NULL_TO_NPVARIANT (*result
);
2901 if (value
->GetKind () == Type::INT32
) {
2902 const char *s
= enums_int_to_str (prop
->GetName(), value
->AsInt32 ());
2904 string_to_npvariant (s
, result
);
2906 value_to_variant (this, value
, result
, dob
, prop
);
2908 value_to_variant (this, value
, result
, dob
, prop
);
2913 // it wasn't a dependency property. let's see if it's an
2914 // event, and hook it up if it is valid on this object.
2915 if (!(event_name
= map_moon_id_to_event_name (id
)))
2916 return MoonlightObject::GetProperty (id
, name
, result
);
2918 if ((event_id
= dob
->GetType()->LookupEvent (event_name
)) == -1) {
2920 EventListenerProxy
*proxy
= LookupEventProxy (event_id
);
2921 string_to_npvariant (proxy
== NULL
? "" : proxy
->GetCallbackAsString (), result
);
2924 // on silverlight, these seem to always return ""
2925 // regardless of how we attempt to set them.
2926 string_to_npvariant ("", result
);
2931 return MoonlightObject::GetProperty (id
, name
, result
);
2935 MoonlightDependencyObjectObject::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
2937 // don't need to downcase here since dependency property lookup is already case insensitive
2938 NPUTF8
*strname
= NPN_UTF8FromIdentifier (name
);
2939 DependencyObject
*dob
= GetDependencyObject ();
2940 DependencyProperty
*prop
;
2945 prop
= _get_dependency_property (dob
, strname
);
2946 NPN_MemFree (strname
);
2950 if (_set_dependency_property_value (dob
, prop
, value
, &error
)) {
2953 THROW_JS_EXCEPTION ("AG_E_RUNTIME_SETVALUE");
2957 return MoonlightObject::SetProperty (id
, name
, value
);
2961 MoonlightDependencyObjectObject::Invoke (int id
, NPIdentifier name
,
2962 const NPVariant
*args
, guint32 argCount
,
2965 DependencyObject
*dob
= GetDependencyObject ();
2968 #if DEBUG_JAVASCRIPT
2969 // Some debug code...
2970 // with this it is possible to do obj.printf ("msg") from js
2971 case MoonId_Printf
: {
2972 char *message
= STRDUP_FROM_VARIANT (args
[0]);
2973 fprintf (stderr
, "JS message: %s\n", message
);
2975 VOID_TO_NPVARIANT (*result
);
2978 case MoonId_DumpNameScope
: {
2979 fprintf (stderr
, "dumping namescope for object %p (%s)\n", dob
, dob
->GetTypeName());
2980 DependencyObject
*ns_dob
= dob
;
2982 while (!(ns
= NameScope::GetNameScope(ns_dob
)))
2983 ns_dob
= ns_dob
->GetParent();
2985 fprintf (stderr
, " no namescope in logical hierarchy!\n");
2988 fprintf (stderr
, "namescope is actually on object %p (%s)\n", ns_dob
, ns_dob
->GetTypeName());
2994 case MoonId_Equals
: {
2995 if (!check_arg_list ("o", argCount
, args
))
2996 THROW_JS_EXCEPTION ("equals");
2998 NPObject
*o
= NPVARIANT_TO_OBJECT (args
[0]);
2999 if (npobject_is_dependency_object (o
)) {
3000 MoonlightDependencyObjectObject
*obj
= (MoonlightDependencyObjectObject
*) o
;
3002 BOOLEAN_TO_NPVARIANT (obj
->GetDependencyObject() == dob
, *result
);
3004 BOOLEAN_TO_NPVARIANT (false, *result
);
3010 case MoonId_SetValue
: {
3011 /* obj.setValue (prop, val) is another way of writing obj[prop] = val (or obj.prop = val) */
3012 if (!check_arg_list ("s*", argCount
, args
))
3013 THROW_JS_EXCEPTION ("setValue");
3015 char *value
= STRDUP_FROM_VARIANT (args
[0]);
3016 _class
->setProperty (this, NPID (value
), &args
[1]);
3019 VOID_TO_NPVARIANT (*result
);
3023 case MoonId_GetValue
: {
3024 if (!check_arg_list ("s", argCount
, args
))
3025 THROW_JS_EXCEPTION ("getValue");
3027 char *value
= STRDUP_FROM_VARIANT (args
[0]);
3028 _class
->getProperty (this, NPID (value
), result
);
3034 case MoonId_FindName
: {
3035 if (!check_arg_list ("s", argCount
, args
))
3036 THROW_JS_EXCEPTION ("AG_E_RUNTIME_FINDNAME");
3038 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
3039 if (plugin
->IsCrossDomainApplication ())
3040 THROW_JS_EXCEPTION ("XDomain Restriction");
3042 char *name
= STRDUP_FROM_VARIANT (args
[0]);
3044 DependencyObject
*element
= dob
->FindName (name
);
3046 if (dob
!= plugin
->GetSurface()->GetToplevel()) {
3047 // fall back to looking the object up on the toplevel element
3048 element
= plugin
->GetSurface()->GetToplevel ()->FindName (name
);
3053 NULL_TO_NPVARIANT (*result
);
3059 OBJECT_TO_NPVARIANT (EventObjectCreateWrapper (instance
, element
), *result
);
3063 case MoonId_GetHost
: {
3064 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
3067 THROW_JS_EXCEPTION ("AG_E_RUNTIME_GETHOST");
3069 OBJECT_TO_NPVARIANT (plugin
->GetHost (), *result
);
3074 case MoonId_GetParent
: {
3075 if (argCount
!= 0 || !dob
->GetType ()->IsSubclassOf (Type::FRAMEWORKELEMENT
))
3076 THROW_JS_EXCEPTION ("AG_E_RUNTIME_GETPARENT");
3078 DependencyObject
*parent
= ((FrameworkElement
*)dob
)->GetLogicalParent ();
3080 OBJECT_TO_NPVARIANT (EventObjectCreateWrapper (instance
, parent
), *result
);
3082 NULL_TO_NPVARIANT (*result
);
3087 case MoonId_AddEventListener
: {
3088 /* FIXME: how do we check if args[1] is a function? */
3089 if (!check_arg_list ("s(so)", argCount
, args
))
3090 THROW_JS_EXCEPTION ("addEventListener");
3092 char *name
= STRDUP_FROM_VARIANT (args
[0]);
3093 name
[0] = toupper(name
[0]);
3095 EventListenerProxy
*proxy
= new EventListenerProxy (instance
, name
, &args
[1]);
3096 int token
= proxy
->AddHandler (dob
);
3100 THROW_JS_EXCEPTION ("AG_E_RUNTIME_ADDEVENT");
3102 INT32_TO_NPVARIANT (token
, *result
);
3105 case MoonId_RemoveEventListener
: {
3106 if (!check_arg_list ("s(is)", argCount
, args
))
3107 THROW_JS_EXCEPTION ("removeEventListener");
3109 char *event
= STRDUP_FROM_VARIANT (args
[0]);
3110 int id
= dob
->GetType()->LookupEvent (event
);
3114 THROW_JS_EXCEPTION ("AG_E_RUNTIME_DELEVENT");
3115 } else if (NPVARIANT_IS_INT32 (args
[1])) {
3116 dob
->RemoveHandler (id
, NPVARIANT_TO_INT32 (args
[1]));
3117 } else if (NPVARIANT_IS_STRING (args
[1])) {
3118 char *value
= STRDUP_FROM_VARIANT (args
[1]);
3119 NamedProxyPredicate
predicate (value
);
3122 dob
->RemoveMatchingHandlers (id
, NamedProxyPredicate::matches
, &predicate
);
3128 // FIXME: these next two methods should live in a UIElement
3129 // wrapper class, not in the DependencyObject wrapper.
3131 case MoonId_CaptureMouse:
3132 BOOLEAN_TO_NPVARIANT (((UIElement*)dob)->CaptureMouse (), *result);
3134 case MoonId_ReleaseMouseCapture:
3135 ((UIElement*)dob)->ReleaseMouseCapture ();
3137 VOID_TO_NPVARIANT (*result);
3141 return MoonlightObject::Invoke (id
, name
, args
, argCount
, result
);
3146 MoonlightDependencyObjectType::MoonlightDependencyObjectType ()
3148 allocate
= moonlight_dependency_object_allocate
;
3150 AddMapping (moonlight_dependency_object_mapping
, G_N_ELEMENTS (moonlight_dependency_object_mapping
));
3155 /*** MoonlightEventObjectClass ***************************************************/
3158 moonlight_event_object_allocate (NPP instance
, NPClass
*klass
)
3160 return new MoonlightEventObjectObject (instance
);
3163 MoonlightEventObjectObject::~MoonlightEventObjectObject ()
3166 PluginInstance
*plugin
;
3167 if ((plugin
= (PluginInstance
*) instance
->pdata
))
3168 plugin
->RemoveWrappedObject (eo
);
3170 moonlight_type
= Type::INVALID
;
3177 MoonlightEventObjectType::MoonlightEventObjectType ()
3179 allocate
= moonlight_event_object_allocate
;
3182 MoonlightEventObjectType
*MoonlightEventObjectClass
;
3184 MoonlightEventObjectObject
*
3185 EventObjectCreateWrapper (NPP instance
, EventObject
*obj
)
3187 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
3188 MoonlightEventObjectObject
*depobj
;
3194 depobj
= (MoonlightEventObjectObject
*) plugin
->LookupWrappedObject (obj
);
3197 NPN_RetainObject (depobj
);
3201 /* for EventObject subclasses which have special plugin classes, check here */
3202 Type::Kind kind
= obj
->GetObjectType ();
3204 case Type::STORYBOARD
:
3205 np_class
= dependency_object_classes
[STORYBOARD_CLASS
];
3207 case Type::MEDIAELEMENT
:
3208 np_class
= dependency_object_classes
[MEDIA_ELEMENT_CLASS
];
3210 case Type::DOWNLOADER
:
3211 np_class
= dependency_object_classes
[DOWNLOADER_CLASS
];
3214 np_class
= dependency_object_classes
[IMAGE_CLASS
];
3216 case Type::IMAGEBRUSH
:
3217 np_class
= dependency_object_classes
[IMAGE_BRUSH_CLASS
];
3219 case Type::TEXTBLOCK
:
3220 np_class
= dependency_object_classes
[TEXT_BLOCK_CLASS
];
3223 np_class
= dependency_object_classes
[TEXT_BOX_CLASS
];
3225 case Type::PASSWORDBOX
:
3226 np_class
= dependency_object_classes
[PASSWORD_BOX_CLASS
];
3228 case Type::MULTISCALEIMAGE
:
3229 np_class
= dependency_object_classes
[MULTI_SCALE_IMAGE_CLASS
];
3231 case Type::EVENTOBJECT
:
3233 np_class
= MoonlightEventObjectClass
;
3235 case Type::STYLUSINFO
:
3236 np_class
= dependency_object_classes
[STYLUS_INFO_CLASS
];
3238 case Type::STYLUSPOINT_COLLECTION
:
3239 np_class
= dependency_object_classes
[STYLUS_POINT_COLLECTION_CLASS
];
3241 case Type::STROKE_COLLECTION
:
3242 np_class
= dependency_object_classes
[STROKE_COLLECTION_CLASS
];
3245 np_class
= dependency_object_classes
[STROKE_CLASS
];
3247 case Type::ROUTEDEVENTARGS
:
3248 np_class
= dependency_object_classes
[ROUTED_EVENT_ARGS_CLASS
];
3250 case Type::MOUSEEVENTARGS
:
3251 case Type::MOUSEBUTTONEVENTARGS
:
3252 case Type::MOUSEWHEELEVENTARGS
:
3253 np_class
= dependency_object_classes
[MOUSE_EVENT_ARGS_CLASS
];
3255 case Type::DOWNLOADPROGRESSEVENTARGS
:
3256 np_class
= dependency_object_classes
[DOWNLOAD_PROGRESS_EVENT_ARGS_CLASS
];
3258 case Type::KEYEVENTARGS
:
3259 np_class
= dependency_object_classes
[KEY_EVENT_ARGS_CLASS
];
3261 case Type::MARKERREACHEDEVENTARGS
:
3262 np_class
= dependency_object_classes
[MARKER_REACHED_EVENT_ARGS_CLASS
];
3264 case Type::ERROREVENTARGS
:
3265 case Type::PARSERERROREVENTARGS
:
3266 case Type::IMAGEERROREVENTARGS
:
3267 np_class
= dependency_object_classes
[ERROR_EVENT_ARGS_CLASS
];
3269 case Type::UIELEMENT
:
3270 np_class
= dependency_object_classes
[UI_ELEMENT_CLASS
];
3273 if (Type::Find (kind
)->IsSubclassOf (Type::CONTROL
))
3274 np_class
= dependency_object_classes
[CONTROL_CLASS
];
3275 else if (Type::Find (kind
)->IsSubclassOf (Type::UIELEMENT
))
3276 np_class
= dependency_object_classes
[UI_ELEMENT_CLASS
];
3277 else if (Type::Find (kind
)->IsSubclassOf (Type::COLLECTION
))
3278 np_class
= dependency_object_classes
[COLLECTION_CLASS
];
3279 else if (Type::Find (kind
)->IsSubclassOf (Type::EVENTARGS
))
3280 np_class
= dependency_object_classes
[EVENT_ARGS_CLASS
];
3282 np_class
= dependency_object_classes
[DEPENDENCY_OBJECT_CLASS
];
3285 depobj
= (MoonlightEventObjectObject
*) NPN_CreateObject (instance
, np_class
);
3286 depobj
->moonlight_type
= obj
->GetObjectType ();
3290 plugin
->AddWrappedObject (obj
, depobj
);
3297 /*** MoonlightCollectionClass ***************************************************/
3300 moonlight_collection_allocate (NPP instance
, NPClass
*klass
)
3302 return new MoonlightCollectionObject (instance
);
3305 static const MoonNameIdMapping
3306 moonlight_collection_mapping
[] = {
3307 { "add", MoonId_Add
},
3308 { "clear", MoonId_Clear
},
3309 { "count", MoonId_Count
},
3310 { "getitem", MoonId_GetItem
},
3311 { "getitembyname", MoonId_GetItemByName
},
3312 { "insert", MoonId_Insert
},
3313 { "remove", MoonId_Remove
},
3314 { "removeat", MoonId_RemoveAt
},
3318 MoonlightCollectionObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
3320 Collection
*col
= (Collection
*) GetDependencyObject ();
3324 INT32_TO_NPVARIANT (col
->GetCount (), *result
);
3327 return MoonlightDependencyObjectObject::GetProperty (id
, name
, result
);
3332 MoonlightCollectionObject::Invoke (int id
, NPIdentifier name
,
3333 const NPVariant
*args
, guint32 argCount
,
3336 Collection
*col
= (Collection
*) GetDependencyObject ();
3340 if (!check_arg_list ("o", argCount
, args
) ||
3341 !npvariant_is_dependency_object (args
[0]))
3342 THROW_JS_EXCEPTION ("add");
3344 MoonlightDependencyObjectObject
*el
= (MoonlightDependencyObjectObject
*) NPVARIANT_TO_OBJECT (args
[0]);
3345 int n
= col
->Add (Value (el
->GetDependencyObject ()));
3348 THROW_JS_EXCEPTION ("add");
3350 INT32_TO_NPVARIANT (n
, *result
);
3354 case MoonId_Remove
: {
3355 if (col
->GetObjectType () == Type::RESOURCE_DICTIONARY
) {
3356 if (check_arg_list ("s", argCount
, args
)) {
3357 bool res
= ((ResourceDictionary
*)col
)->Remove (NPVARIANT_TO_STRING (args
[0]).utf8characters
);
3358 BOOLEAN_TO_NPVARIANT (res
, *result
);
3363 if (!check_arg_list ("o", argCount
, args
) ||
3364 !npvariant_is_dependency_object (args
[0]))
3365 THROW_JS_EXCEPTION ("remove");
3367 MoonlightDependencyObjectObject
*el
= (MoonlightDependencyObjectObject
*) NPVARIANT_TO_OBJECT (args
[0]);
3368 bool res
= col
->Remove (Value (el
->GetDependencyObject ()));
3370 BOOLEAN_TO_NPVARIANT (res
, *result
);
3374 case MoonId_RemoveAt
: {
3375 if (!check_arg_list ("i", argCount
, args
))
3376 THROW_JS_EXCEPTION ("removeAt");
3378 int index
= NPVARIANT_TO_INT32 (args
[0]);
3380 if (index
< 0 || index
>= col
->GetCount ())
3381 THROW_JS_EXCEPTION ("removeAt");
3383 DependencyObject
*obj
= col
->GetValueAt (index
)->AsDependencyObject ();
3384 OBJECT_TO_NPVARIANT (EventObjectCreateWrapper (instance
, obj
), *result
);
3386 col
->RemoveAt (index
);
3390 case MoonId_Insert
: {
3391 if (!check_arg_list ("i[o]", argCount
, args
)) {
3392 g_warning ("insert 1");
3393 THROW_JS_EXCEPTION ("insert");
3397 VOID_TO_NPVARIANT (*result
);
3401 if (!npvariant_is_dependency_object (args
[1])) {
3402 g_warning ("insert 2");
3403 THROW_JS_EXCEPTION ("insert");
3406 MoonlightDependencyObjectObject
*el
= (MoonlightDependencyObjectObject
*) NPVARIANT_TO_OBJECT (args
[1]);
3407 int index
= NPVARIANT_TO_INT32 (args
[0]);
3409 Value
val (el
->GetDependencyObject ());
3411 if (!col
->InsertWithError (index
, &val
, &err
)) {
3412 g_warning ("insert 2: %s", err
.message
);
3413 THROW_JS_EXCEPTION ("insert");
3416 VOID_TO_NPVARIANT (*result
);
3420 case MoonId_Clear
: {
3422 THROW_JS_EXCEPTION ("clear");
3426 VOID_TO_NPVARIANT (*result
);
3430 case MoonId_GetItem
: {
3431 if (col
->GetObjectType () == Type::RESOURCE_DICTIONARY
) {
3432 if (check_arg_list ("s", argCount
, args
)) {
3433 // handle the string case here, we
3434 // handle the int case in the common
3438 Value
*v
= ((ResourceDictionary
*)col
)->Get (NPVARIANT_TO_STRING (args
[0]).utf8characters
, &unused
);
3439 value_to_variant (this, v
, result
);
3444 if (!check_arg_list ("i", argCount
, args
))
3445 THROW_JS_EXCEPTION ("getItem");
3447 int index
= NPVARIANT_TO_INT32 (args
[0]);
3450 THROW_JS_EXCEPTION ("getItem");
3452 if (index
>= col
->GetCount ()) {
3453 NULL_TO_NPVARIANT (*result
);
3457 DependencyObject
*obj
= col
->GetValueAt (index
)->AsDependencyObject ();
3458 OBJECT_TO_NPVARIANT (EventObjectCreateWrapper (instance
, obj
), *result
);
3462 case MoonId_GetItemByName
: {
3463 if (col
->GetObjectType () != Type::MEDIAATTRIBUTE_COLLECTION
||
3464 !check_arg_list ("s", argCount
, args
))
3465 THROW_JS_EXCEPTION ("getItemByName");
3467 char *name
= STRDUP_FROM_VARIANT (args
[0]);
3468 DependencyObject
*obj
= ((MediaAttributeCollection
*) col
)->GetItemByName (name
);
3471 OBJECT_TO_NPVARIANT (EventObjectCreateWrapper (instance
, obj
), *result
);
3476 return MoonlightDependencyObjectObject::Invoke (id
, name
, args
, argCount
, result
);
3481 MoonlightCollectionType::MoonlightCollectionType ()
3483 AddMapping (moonlight_collection_mapping
, G_N_ELEMENTS (moonlight_collection_mapping
));
3485 allocate
= moonlight_collection_allocate
;
3489 /*** MoonlightStoryboardClass ***************************************************/
3492 moonlight_storyboard_allocate (NPP instance
, NPClass
*klass
)
3494 return new MoonlightStoryboardObject (instance
);
3497 static const MoonNameIdMapping
3498 moonlight_storyboard_mapping
[] = {
3499 { "begin", MoonId_Begin
},
3500 { "completed", MoonId_Completed
},
3501 { "pause", MoonId_Pause
},
3502 { "resume", MoonId_Resume
},
3503 { "seek", MoonId_Seek
},
3504 { "stop", MoonId_Stop
}
3508 MoonlightStoryboardObject::Invoke (int id
, NPIdentifier name
,
3509 const NPVariant
*args
, guint32 argCount
,
3512 // FIXME: all the WithError calls should be using a MoonError,
3513 // which we convert to a JS exception and throw if there's a
3515 Storyboard
*sb
= (Storyboard
*)GetDependencyObject ();
3519 if (argCount
!= 0 || !sb
->BeginWithError (NULL
))
3520 THROW_JS_EXCEPTION ("begin");
3522 VOID_TO_NPVARIANT (*result
);
3527 THROW_JS_EXCEPTION ("pause");
3529 sb
->PauseWithError (NULL
);
3531 VOID_TO_NPVARIANT (*result
);
3536 THROW_JS_EXCEPTION ("resume");
3538 sb
->ResumeWithError (NULL
);
3540 VOID_TO_NPVARIANT (*result
);
3544 if (!check_arg_list ("(is)", argCount
, args
))
3545 THROW_JS_EXCEPTION ("seek");
3550 if (NPVARIANT_IS_INT32 (args
[0])) {
3551 ts
= (TimeSpan
) NPVARIANT_TO_INT32 (args
[0]);
3552 } else if (NPVARIANT_IS_STRING (args
[0])) {
3553 char *span
= STRDUP_FROM_VARIANT (args
[0]);
3554 ok
= time_span_from_str (span
, &ts
);
3558 THROW_JS_EXCEPTION ("seek");
3561 sb
->SeekWithError (ts
, NULL
);
3563 VOID_TO_NPVARIANT (*result
);
3569 THROW_JS_EXCEPTION ("stop");
3571 sb
->StopWithError (NULL
);
3573 VOID_TO_NPVARIANT (*result
);
3577 return MoonlightDependencyObjectObject::Invoke (id
, name
, args
, argCount
, result
);
3581 MoonlightStoryboardType::MoonlightStoryboardType ()
3583 AddMapping (moonlight_storyboard_mapping
, G_N_ELEMENTS (moonlight_storyboard_mapping
));
3585 allocate
= moonlight_storyboard_allocate
;
3589 /*** MoonlightMediaElementClass ***************************************************/
3592 moonlight_media_element_allocate (NPP instance
, NPClass
*)
3594 return new MoonlightMediaElementObject (instance
);
3597 static const MoonNameIdMapping
3598 moonlight_media_element_mapping
[] = {
3599 { "bufferingprogresschanged", MoonId_BufferingProgressChanged
},
3600 { "currentstatechanged", MoonId_CurrentStateChanged
},
3601 { "downloadprogresschanged", MoonId_DownloadProgressChanged
},
3602 { "markerreached", MoonId_MarkerReached
},
3603 { "mediaended", MoonId_MediaEnded
},
3604 { "mediafailed", MoonId_MediaFailed
},
3605 { "mediaopened", MoonId_MediaOpened
},
3606 { "pause", MoonId_Pause
},
3607 { "play", MoonId_Play
},
3608 { "setsource", MoonId_SetSource
},
3609 { "stop", MoonId_Stop
},
3613 MoonlightMediaElementObject::Invoke (int id
, NPIdentifier name
,
3614 const NPVariant
*args
, guint32 argCount
,
3617 MediaElement
*media
= (MediaElement
*)GetDependencyObject ();
3622 THROW_JS_EXCEPTION ("play");
3626 VOID_TO_NPVARIANT (*result
);
3632 THROW_JS_EXCEPTION ("pause");
3636 VOID_TO_NPVARIANT (*result
);
3642 THROW_JS_EXCEPTION ("stop");
3646 VOID_TO_NPVARIANT (*result
);
3650 case MoonId_SetSource
: {
3651 if (!check_arg_list ("os", argCount
, args
) ||
3652 !npvariant_is_downloader (args
[0]))
3653 THROW_JS_EXCEPTION ("AG_E_RUNTIME_METHOD");
3655 DependencyObject
*downloader
= ((MoonlightDependencyObjectObject
*) NPVARIANT_TO_OBJECT (args
[0]))->GetDependencyObject ();
3657 char *part
= STRDUP_FROM_VARIANT (args
[1]);
3658 media
->SetSource ((Downloader
*) downloader
, part
);
3661 VOID_TO_NPVARIANT (*result
);
3667 return MoonlightUIElementObject::Invoke (id
, name
, args
, argCount
, result
);
3671 MoonlightMediaElementType::MoonlightMediaElementType ()
3673 AddMapping (moonlight_media_element_mapping
, G_N_ELEMENTS (moonlight_media_element_mapping
));
3675 allocate
= moonlight_media_element_allocate
;
3678 /*** MoonlightMultiScaleImageClass *********/
3680 moonlight_multiscaleimage_allocate (NPP instance
, NPClass
*klass
)
3682 return new MoonlightMultiScaleImageObject (instance
);
3685 static const MoonNameIdMapping moonlight_multiscaleimage_mapping
[] = {
3686 {"getithsubimage", MoonId_MultiScaleImage_GetIthSubImage
},
3687 {"getsubimagecount", MoonId_MultiScaleImage_GetSubImageCount
},
3688 {"logicaltoelementx", MoonId_MultiScaleImage_LogicalToElementX
},
3689 {"logicaltoelementy", MoonId_MultiScaleImage_LogicalToElementY
},
3690 {"source", MoonId_MultiScaleImage_Source
},
3691 {"zoomaboutlogicalpoint", MoonId_MultiScaleImage_ZoomAboutLogicalPoint
}
3695 MoonlightMultiScaleImageObject::Invoke (int id
, NPIdentifier name
,
3696 const NPVariant
*args
, guint32 argCount
,
3699 MultiScaleImage
*dob
= (MultiScaleImage
*)GetDependencyObject ();
3703 case MoonId_MultiScaleImage_GetIthSubImage
: {
3704 if (!check_arg_list ("i", argCount
, args
))
3705 THROW_JS_EXCEPTION ("GetIthSubImage");
3706 int arg0
= NPVARIANT_TO_INT32 (args
[0]);
3707 MultiScaleSubImage
* ret
= dob
->GetIthSubImage(arg0
);
3709 OBJECT_TO_NPVARIANT (EventObjectCreateWrapper (instance
, ret
), *result
);
3711 NULL_TO_NPVARIANT (*result
);
3716 case MoonId_MultiScaleImage_GetSubImageCount
: {
3717 int ret
= dob
->GetSubImageCount();
3718 INT32_TO_NPVARIANT (ret
, *result
);
3723 case MoonId_MultiScaleImage_LogicalToElementX
: {
3724 if (!check_arg_list ("ii", argCount
, args
))
3725 THROW_JS_EXCEPTION ("LogicalToElementX");
3726 int arg0
= NPVARIANT_TO_INT32 (args
[0]);
3727 int arg1
= NPVARIANT_TO_INT32 (args
[1]);
3728 int ret
= dob
->LogicalToElementX(arg0
,arg1
);
3729 INT32_TO_NPVARIANT (ret
, *result
);
3734 case MoonId_MultiScaleImage_LogicalToElementY
: {
3735 if (!check_arg_list ("ii", argCount
, args
))
3736 THROW_JS_EXCEPTION ("LogicalToElementY");
3737 int arg0
= NPVARIANT_TO_INT32 (args
[0]);
3738 int arg1
= NPVARIANT_TO_INT32 (args
[1]);
3739 int ret
= dob
->LogicalToElementY(arg0
,arg1
);
3740 INT32_TO_NPVARIANT (ret
, *result
);
3745 case MoonId_MultiScaleImage_ZoomAboutLogicalPoint
: {
3746 if (!check_arg_list ("ddd", argCount
, args
))
3747 THROW_JS_EXCEPTION ("ZoomAboutLogicalPoint");
3748 double arg0
= NPVARIANT_TO_DOUBLE (args
[0]);
3749 double arg1
= NPVARIANT_TO_DOUBLE (args
[1]);
3750 double arg2
= NPVARIANT_TO_DOUBLE (args
[2]);
3751 dob
->ZoomAboutLogicalPoint(arg0
,arg1
,arg2
);
3752 VOID_TO_NPVARIANT (*result
);
3758 return MoonlightDependencyObjectObject::Invoke (id
, name
, args
, argCount
, result
);
3762 MoonlightMultiScaleImageObject::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
3764 MultiScaleImage
*msi
= (MultiScaleImage
*) GetDependencyObject ();
3766 case MoonId_MultiScaleImage_Source
: {
3767 MultiScaleTileSource
*ts
= (MultiScaleTileSource
*) msi
->GetSource ();
3768 if (ts
&& ts
->Is (Type::DEEPZOOMIMAGETILESOURCE
)) {
3769 Uri
*uri
= new Uri ();
3771 uri
->Parse (NPVARIANT_TO_STRING (*value
).utf8characters
);
3772 ((DeepZoomImageTileSource
*)ts
)->SetUriSource (uri
);
3778 return MoonlightDependencyObjectObject::SetProperty (id
, name
, value
);;
3782 MoonlightMultiScaleImageType::MoonlightMultiScaleImageType ()
3784 AddMapping (moonlight_multiscaleimage_mapping
, G_N_ELEMENTS (moonlight_multiscaleimage_mapping
));
3786 allocate
= moonlight_multiscaleimage_allocate
;
3789 /*** MoonlightImageClass ***************************************************/
3792 moonlight_image_allocate (NPP instance
, NPClass
*klass
)
3794 return new MoonlightImageObject (instance
);
3797 static const MoonNameIdMapping
3798 moonlight_image_mapping
[] = {
3799 { "downloadprogresschanged", MoonId_DownloadProgressChanged
},
3800 { "imagefailed", MoonId_ImageFailed
},
3801 { "source", MoonId_Source
},
3802 { "setsource", MoonId_SetSource
}
3806 MoonlightImageObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
3808 Image
*img
= (Image
*) GetDependencyObject ();
3811 case MoonId_Source
: {
3812 ImageSource
*source
= (ImageSource
*) img
->GetSource ();
3813 if (source
&& source
->Is (Type::BITMAPIMAGE
)) {
3814 char *uri
= ((BitmapImage
*)source
)->GetUriSource()->ToString();
3815 STRINGN_TO_NPVARIANT (uri
, strlen (uri
), *result
);
3817 NULL_TO_NPVARIANT (*result
);
3824 return MoonlightUIElementObject::GetProperty (id
, name
, result
);
3829 MoonlightImageObject::Invoke (int id
, NPIdentifier name
,
3830 const NPVariant
*args
, guint32 argCount
,
3833 Image
*img
= (Image
*) GetDependencyObject ();
3834 DependencyObject
*downloader
;
3838 case MoonId_SetSource
:
3839 if (!check_arg_list ("os", argCount
, args
) ||
3840 !npvariant_is_downloader (args
[0]))
3841 THROW_JS_EXCEPTION ("AG_E_RUNTIME_METHOD");
3843 downloader
= ((MoonlightDependencyObjectObject
*) NPVARIANT_TO_OBJECT (args
[0]))->GetDependencyObject ();
3845 part
= STRDUP_FROM_VARIANT (args
[1]);
3846 img
->SetSource ((Downloader
*) downloader
, part
);
3849 VOID_TO_NPVARIANT (*result
);
3853 return MoonlightUIElementObject::Invoke (id
, name
, args
, argCount
, result
);
3857 MoonlightImageType::MoonlightImageType ()
3859 AddMapping (moonlight_image_mapping
, G_N_ELEMENTS (moonlight_image_mapping
));
3861 allocate
= moonlight_image_allocate
;
3865 /*** MoonlightImageBrushClass ***************************************************/
3868 moonlight_image_brush_allocate (NPP instance
, NPClass
*klass
)
3870 return new MoonlightImageBrushObject (instance
);
3874 static const MoonNameIdMapping
3875 moonlight_image_brush_mapping
[] = {
3876 { "downloadprogresschanged", MoonId_DownloadProgressChanged
},
3877 { "imagesource", MoonId_Source
},
3878 { "setsource", MoonId_SetSource
}
3882 MoonlightImageBrushObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
3884 ImageBrush
*brush
= (ImageBrush
*) GetDependencyObject ();
3887 case MoonId_Source
: {
3888 ImageSource
*source
= (ImageSource
*) brush
->GetImageSource ();
3889 if (source
&& source
->Is (Type::BITMAPIMAGE
)) {
3890 char *uri
= ((BitmapImage
*)source
)->GetUriSource()->ToString();
3891 STRINGN_TO_NPVARIANT (uri
, strlen (uri
), *result
);
3893 NULL_TO_NPVARIANT (*result
);
3900 return MoonlightDependencyObjectObject::GetProperty (id
, name
, result
);
3905 MoonlightImageBrushObject::Invoke (int id
, NPIdentifier name
,
3906 const NPVariant
*args
, guint32 argCount
,
3909 ImageBrush
*img
= (ImageBrush
*) GetDependencyObject ();
3910 DependencyObject
*downloader
;
3913 case MoonId_SetSource
: {
3914 if (!check_arg_list ("os", argCount
, args
) ||
3915 !npvariant_is_downloader (args
[0]))
3916 THROW_JS_EXCEPTION ("setSource");
3918 downloader
= ((MoonlightDependencyObjectObject
*) NPVARIANT_TO_OBJECT (args
[0]))->GetDependencyObject ();
3920 char *part
= STRDUP_FROM_VARIANT (args
[1]);
3921 img
->SetSource ((Downloader
*) downloader
, part
);
3924 VOID_TO_NPVARIANT (*result
);
3930 return MoonlightDependencyObjectObject::Invoke (id
, name
, args
, argCount
, result
);
3934 MoonlightImageBrushType::MoonlightImageBrushType ()
3936 AddMapping (moonlight_image_brush_mapping
, G_N_ELEMENTS (moonlight_image_brush_mapping
));
3938 allocate
= moonlight_image_brush_allocate
;
3942 /*** MoonlightControlClass ***************************************************/
3945 moonlight_control_allocate (NPP instance
, NPClass
*klass
)
3947 return new MoonlightControlObject (instance
);
3951 static const MoonNameIdMapping moonlight_control_mapping
[] = {
3952 { "focus", MoonId_Focus
}
3957 MoonlightControlObject::Invoke (int id
, NPIdentifier name
,
3958 const NPVariant
*args
, guint32 argCount
,
3961 Control
*control
= (Control
*) GetDependencyObject ();
3966 THROW_JS_EXCEPTION ("focus");
3968 BOOLEAN_TO_NPVARIANT (control
->Focus (), *result
);
3972 return MoonlightUIElementObject::Invoke (id
, name
, args
, argCount
, result
);
3976 MoonlightControlType::MoonlightControlType ()
3978 AddMapping (moonlight_control_mapping
, G_N_ELEMENTS (moonlight_control_mapping
));
3980 allocate
= moonlight_control_allocate
;
3984 /*** MoonlightTextBoxClass ***************************************************/
3987 moonlight_text_box_allocate (NPP instance
, NPClass
*klass
)
3989 return new MoonlightTextBoxObject (instance
);
3993 static const MoonNameIdMapping moonlight_text_box_mapping
[] = {
3994 { "select", MoonId_Select
},
3995 { "selectall", MoonId_SelectAll
}
4000 MoonlightTextBoxObject::Invoke (int id
, NPIdentifier name
,
4001 const NPVariant
*args
, guint32 argCount
,
4004 TextBox
*textbox
= (TextBox
*) GetDependencyObject ();
4009 if (!check_arg_list ("ii", argCount
, args
))
4010 THROW_JS_EXCEPTION ("select");
4012 if (!textbox
->SelectWithError (NPVARIANT_TO_INT32 (args
[0]),
4013 NPVARIANT_TO_INT32 (args
[1]),
4015 THROW_JS_EXCEPTION (err
.message
);
4018 VOID_TO_NPVARIANT (*result
);
4021 case MoonId_SelectAll
:
4023 THROW_JS_EXCEPTION ("selectAll");
4025 textbox
->SelectAll ();
4027 VOID_TO_NPVARIANT (*result
);
4031 return MoonlightControlObject::Invoke (id
, name
, args
, argCount
, result
);
4035 MoonlightTextBoxType::MoonlightTextBoxType ()
4037 AddMapping (moonlight_text_box_mapping
, G_N_ELEMENTS (moonlight_text_box_mapping
));
4039 allocate
= moonlight_text_box_allocate
;
4042 /*** MoonlightPasswordBoxClass ***************************************************/
4045 moonlight_password_box_allocate (NPP instance
, NPClass
*klass
)
4047 return new MoonlightPasswordBoxObject (instance
);
4051 static const MoonNameIdMapping moonlight_password_box_mapping
[] = {
4052 { "select", MoonId_Select
},
4053 { "selectall", MoonId_SelectAll
}
4058 MoonlightPasswordBoxObject::Invoke (int id
, NPIdentifier name
,
4059 const NPVariant
*args
, guint32 argCount
,
4062 PasswordBox
*passwordbox
= (PasswordBox
*) GetDependencyObject ();
4067 if (!check_arg_list ("ii", argCount
, args
))
4068 THROW_JS_EXCEPTION ("select");
4070 if (!passwordbox
->SelectWithError (NPVARIANT_TO_INT32 (args
[0]),
4071 NPVARIANT_TO_INT32 (args
[1]),
4073 THROW_JS_EXCEPTION (err
.message
);
4076 VOID_TO_NPVARIANT (*result
);
4079 case MoonId_SelectAll
:
4081 THROW_JS_EXCEPTION ("selectAll");
4083 passwordbox
->SelectAll ();
4085 VOID_TO_NPVARIANT (*result
);
4089 return MoonlightControlObject::Invoke (id
, name
, args
, argCount
, result
);
4093 MoonlightPasswordBoxType::MoonlightPasswordBoxType ()
4095 AddMapping (moonlight_password_box_mapping
, G_N_ELEMENTS (moonlight_password_box_mapping
));
4097 allocate
= moonlight_password_box_allocate
;
4101 /*** MoonlightTextBlockClass ***************************************************/
4104 moonlight_text_block_allocate (NPP instance
, NPClass
*klass
)
4106 return new MoonlightTextBlockObject (instance
);
4110 static const MoonNameIdMapping moonlight_text_block_mapping
[] = {
4111 { "setfontsource", MoonId_SetFontSource
}
4116 MoonlightTextBlockObject::Invoke (int id
, NPIdentifier name
,
4117 const NPVariant
*args
, guint32 argCount
,
4120 TextBlock
*tb
= (TextBlock
*) GetDependencyObject ();
4121 DependencyObject
*downloader
= NULL
;
4124 case MoonId_SetFontSource
:
4125 if (!check_arg_list ("(no)", argCount
, args
) && (!NPVARIANT_IS_NULL(args
[0]) || !npvariant_is_downloader (args
[0])))
4126 THROW_JS_EXCEPTION ("setFontSource");
4128 if (NPVARIANT_IS_OBJECT (args
[0]))
4129 downloader
= ((MoonlightDependencyObjectObject
*) NPVARIANT_TO_OBJECT (args
[0]))->GetDependencyObject ();
4131 tb
->SetFontSource ((Downloader
*) downloader
);
4133 VOID_TO_NPVARIANT (*result
);
4137 return MoonlightUIElementObject::Invoke (id
, name
, args
, argCount
, result
);
4141 MoonlightTextBlockType::MoonlightTextBlockType ()
4143 AddMapping (moonlight_text_block_mapping
, G_N_ELEMENTS (moonlight_text_block_mapping
));
4145 allocate
= moonlight_text_block_allocate
;
4149 /*** MoonlightStylusInfoClass ***************************************************/
4152 moonlight_stylus_info_allocate (NPP instance
, NPClass
*klass
)
4154 return new MoonlightStylusInfoObject (instance
);
4157 static const MoonNameIdMapping
4158 moonlight_stylus_info_mapping
[] = {
4159 { "devicetype", MoonId_DeviceType
},
4160 { "isinverted", MoonId_IsInverted
},
4164 MoonlightStylusInfoObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
4166 StylusInfo
*info
= (StylusInfo
*) GetDependencyObject ();
4169 case MoonId_DeviceType
: {
4170 switch (info
->GetDeviceType ()) {
4171 case TabletDeviceTypeMouse
:
4172 string_to_npvariant ("Mouse", result
);
4174 case TabletDeviceTypeStylus
:
4175 string_to_npvariant ("Stylus", result
);
4177 case TabletDeviceTypeTouch
:
4178 string_to_npvariant ("Touch", result
);
4181 THROW_JS_EXCEPTION ("deviceType");
4185 case MoonId_IsInverted
: {
4186 BOOLEAN_TO_NPVARIANT (info
->GetIsInverted (), *result
);
4191 return MoonlightDependencyObjectObject::GetProperty (id
, name
, result
);
4195 MoonlightStylusInfoType::MoonlightStylusInfoType ()
4197 AddMapping (moonlight_stylus_info_mapping
, G_N_ELEMENTS (moonlight_stylus_info_mapping
));
4199 allocate
= moonlight_stylus_info_allocate
;
4203 /*** MoonlightStylusPointCollectionClass ****************************************/
4206 moonlight_stylus_point_collection_allocate (NPP instance
, NPClass
*klass
)
4208 return new MoonlightStylusPointCollectionObject (instance
);
4211 static const MoonNameIdMapping
4212 moonlight_stylus_point_collection_mapping
[] = {
4213 { "addstyluspoints", MoonId_AddStylusPoints
},
4217 MoonlightStylusPointCollectionObject::Invoke (int id
, NPIdentifier name
, const NPVariant
*args
, guint32 argCount
, NPVariant
*result
)
4219 StylusPointCollection
*col
= (StylusPointCollection
*) GetDependencyObject ();
4222 case MoonId_AddStylusPoints
: {
4223 if (!col
|| !check_arg_list ("o", argCount
, args
))
4226 MoonlightStylusPointCollectionObject
*spco
= (MoonlightStylusPointCollectionObject
*) NPVARIANT_TO_OBJECT(args
[0]);
4227 double ret
= col
->AddStylusPoints ((StylusPointCollection
*) spco
->GetDependencyObject ());
4228 DOUBLE_TO_NPVARIANT (ret
, *result
);
4232 return MoonlightCollectionObject::Invoke (id
, name
, args
, argCount
, result
);
4236 MoonlightStylusPointCollectionType::MoonlightStylusPointCollectionType ()
4238 AddMapping (moonlight_stylus_point_collection_mapping
, G_N_ELEMENTS (moonlight_stylus_point_collection_mapping
));
4240 allocate
= moonlight_stylus_point_collection_allocate
;
4244 /*** MoonlightStrokeCollectionClass ****************************************/
4247 moonlight_stroke_collection_allocate (NPP instance
, NPClass
*klass
)
4249 return new MoonlightStrokeCollectionObject (instance
);
4252 static const MoonNameIdMapping
4253 moonlight_stroke_collection_mapping
[] = {
4254 { "getbounds", MoonId_GetBounds
},
4255 { "hittest", MoonId_HitTest
}
4259 MoonlightStrokeCollectionObject::Invoke (int id
, NPIdentifier name
,
4260 const NPVariant
*args
, guint32 argCount
, NPVariant
*result
)
4262 StrokeCollection
*col
= (StrokeCollection
*) GetDependencyObject ();
4265 case MoonId_GetBounds
: {
4266 Rect r
= col
->GetBounds ();
4268 value_to_variant (this, &v
, result
);
4272 case MoonId_HitTest
: {
4273 if (!check_arg_list ("o", argCount
, args
) ||
4274 !npvariant_is_dependency_object (args
[0]))
4275 THROW_JS_EXCEPTION ("hitTest");
4277 DependencyObject
*dob
= DEPENDENCY_OBJECT_FROM_VARIANT (args
[0]);
4278 if (!dob
->Is (Type::STYLUSPOINT_COLLECTION
))
4279 THROW_JS_EXCEPTION ("hitTest");
4281 StrokeCollection
*hit_col
= col
->HitTest ((StylusPointCollection
*)dob
);
4283 OBJECT_TO_NPVARIANT (EventObjectCreateWrapper (instance
, hit_col
), *result
);
4289 return MoonlightCollectionObject::Invoke (id
, name
, args
, argCount
, result
);
4293 MoonlightStrokeCollectionType::MoonlightStrokeCollectionType ()
4295 AddMapping (moonlight_stroke_collection_mapping
, G_N_ELEMENTS (moonlight_stroke_collection_mapping
));
4297 allocate
= moonlight_stroke_collection_allocate
;
4301 /*** MoonlightStrokeClass ****************************************/
4304 moonlight_stroke_allocate (NPP instance
, NPClass
*klass
)
4306 return new MoonlightStrokeObject (instance
);
4309 static const MoonNameIdMapping
4310 moonlight_stroke_mapping
[] = {
4311 { "getbounds", MoonId_GetBounds
},
4312 { "hittest", MoonId_HitTest
}
4316 MoonlightStrokeObject::Invoke (int id
, NPIdentifier name
,
4317 const NPVariant
*args
, guint32 argCount
, NPVariant
*result
)
4319 Stroke
*stroke
= (Stroke
*) GetDependencyObject ();
4322 case MoonId_GetBounds
: {
4323 Rect r
= stroke
->GetBounds ();
4325 value_to_variant (this, &v
, result
);
4329 case MoonId_HitTest
: {
4330 if (!check_arg_list ("o", argCount
, args
) ||
4331 !npvariant_is_dependency_object (args
[0]))
4332 THROW_JS_EXCEPTION ("hitTest");
4334 DependencyObject
*dob
= DEPENDENCY_OBJECT_FROM_VARIANT (args
[0]);
4335 if (!dob
->Is (Type::STYLUSPOINT_COLLECTION
))
4336 THROW_JS_EXCEPTION ("hitTest");
4338 BOOLEAN_TO_NPVARIANT (stroke
->HitTest ((StylusPointCollection
*)dob
), *result
);
4343 return MoonlightDependencyObjectObject::Invoke (id
, name
, args
, argCount
, result
);
4347 MoonlightStrokeType::MoonlightStrokeType ()
4349 AddMapping (moonlight_stroke_mapping
, G_N_ELEMENTS (moonlight_stroke_mapping
));
4351 allocate
= moonlight_stroke_allocate
;
4355 /*** MoonlightDownloaderClass ***************************************************/
4358 moonlight_downloader_allocate (NPP instance
, NPClass
*klass
)
4360 return new MoonlightDownloaderObject (instance
);
4364 static const MoonNameIdMapping
4365 moonlight_downloader_mapping
[] = {
4366 { "abort", MoonId_Abort
},
4367 { "completed", MoonId_Completed
},
4368 { "downloadprogresschanged", MoonId_DownloadProgressChanged
},
4369 { "getresponsetext", MoonId_GetResponseText
},
4370 { "open", MoonId_Open
},
4371 { "responsetext", MoonId_ResponseText
},
4372 { "send", MoonId_Send
}
4376 MoonlightDownloaderObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
4378 Downloader
*downloader
= (Downloader
*) GetDependencyObject ();
4383 case MoonId_ResponseText
:
4384 if ((text
= downloader
->GetResponseText (NULL
, &size
))) {
4385 char *s
= (char *) NPN_MemAlloc (size
+ 1);
4386 memcpy (s
, text
, size
+ 1);
4389 STRINGN_TO_NPVARIANT (s
, (guint32
) size
, *result
);
4391 string_to_npvariant ("", result
);
4396 return MoonlightDependencyObjectObject::GetProperty (id
, name
, result
);
4401 MoonlightDownloaderObject::Invoke (int id
, NPIdentifier name
,
4402 const NPVariant
*args
, guint32 argCount
,
4405 Downloader
*downloader
= (Downloader
*) GetDependencyObject ();
4406 char *part
, *verb
, *uri
, *text
;
4412 THROW_JS_EXCEPTION ("abort");
4414 downloader
->Abort ();
4416 VOID_TO_NPVARIANT (*result
);
4420 if (!check_arg_list ("s(ns)", argCount
, args
))
4421 THROW_JS_EXCEPTION ("open");
4423 verb
= STRDUP_FROM_VARIANT (args
[0]);
4425 if (NPVARIANT_IS_STRING (args
[1]))
4426 uri
= STRDUP_FROM_VARIANT (args
[1]);
4430 downloader
->Open (verb
, uri
, DownloaderPolicy
);
4434 VOID_TO_NPVARIANT (*result
);
4438 if (argCount
!= 0 || downloader
->GetSurface () == NULL
)
4439 THROW_JS_EXCEPTION ("send");
4441 downloader
->Send ();
4443 VOID_TO_NPVARIANT (*result
);
4446 case MoonId_GetResponseText
:
4447 if (!check_arg_list ("s", argCount
, args
))
4448 THROW_JS_EXCEPTION ("getResponseText");
4450 part
= STRDUP_FROM_VARIANT (args
[0]);
4451 if ((text
= downloader
->GetResponseText (part
, &size
))) {
4452 char *s
= (char *) NPN_MemAlloc (size
+ 1);
4453 memcpy (s
, text
, size
+ 1);
4456 STRINGN_TO_NPVARIANT (s
, (guint32
) size
, *result
);
4458 string_to_npvariant ("", result
);
4464 return MoonlightDependencyObjectObject::Invoke (id
, name
, args
, argCount
, result
);
4468 MoonlightDownloaderType::MoonlightDownloaderType ()
4470 AddMapping (moonlight_downloader_mapping
, G_N_ELEMENTS (moonlight_downloader_mapping
));
4472 allocate
= moonlight_downloader_allocate
;
4475 /*** MoonlightScriptableObjectClass ***************************************************/
4477 struct ScriptableProperty
{
4478 gpointer property_handle
;
4484 struct ScriptableEvent
{
4485 gpointer event_handle
;
4488 struct ScriptableMethod
{
4489 gpointer method_handle
;
4490 int method_return_type
;
4491 int *method_parameter_types
;
4492 int parameter_count
;
4497 moonlight_scriptable_object_allocate (NPP instance
, NPClass
*klass
)
4499 return new MoonlightScriptableObjectObject (instance
);
4502 MoonlightScriptableObjectObject::~MoonlightScriptableObjectObject ()
4504 if (managed_scriptable
) {
4505 // FIXME: unref the scriptable object however we need to.
4506 managed_scriptable
= NULL
;
4509 // FIXME: free the properties, events, and methods hashes.
4510 g_hash_table_destroy (properties
);
4511 g_hash_table_destroy (methods
);
4512 g_hash_table_destroy (events
);
4516 MoonlightScriptableObjectObject::HasProperty (NPIdentifier name
)
4521 NPUTF8
*strname
= NPN_UTF8FromIdentifier (name
);
4522 printf ("scriptable has property %x = %s\n", name
, strname
);
4525 result
= (g_hash_table_lookup (properties
, name
) != NULL
4526 || g_hash_table_lookup (events
, name
)) || MoonlightObject::HasProperty (name
);
4529 printf ("scriptable has property %x = %s: result: %i\n", name
, strname
, result
);
4530 NPN_MemFree (strname
);
4538 MoonlightScriptableObjectObject::GetProperty (int id
, NPIdentifier name
, NPVariant
*result
)
4542 NPUTF8
*strname
= NPN_UTF8FromIdentifier (name
);
4544 printf ("getting scriptable object property %x = %s\n", name
, strname
);
4547 ScriptableProperty
*prop
= (ScriptableProperty
*)g_hash_table_lookup (properties
, name
);
4549 res
= MoonlightObject::GetProperty (id
, name
, result
);
4553 getprop (managed_scriptable
, strname
, &v
);
4555 value_to_variant (this, &v
, result
);
4560 printf ("getting scriptable object property %x = %s result: %i\n", name
, strname
, result
);
4562 NPN_MemFree (strname
);
4568 MoonlightScriptableObjectObject::SetProperty (int id
, NPIdentifier name
, const NPVariant
*value
)
4570 ScriptableProperty
*prop
;
4571 ScriptableEvent
*event
;
4574 // first we try the property hash
4575 if ((prop
= (ScriptableProperty
*) g_hash_table_lookup (properties
, name
))) {
4577 NPUTF8
*strname
= NPN_UTF8FromIdentifier (name
);
4579 ds(printf ("setting scriptable object property %s\n", strname
));
4581 variant_to_value (value
, &v
);
4582 setprop (managed_scriptable
, strname
, v
);
4584 NPN_MemFree (strname
);
4589 // if that fails, look for the event of that name
4590 if ((event
= (ScriptableEvent
*) g_hash_table_lookup (events
, name
))) {
4592 NPUTF8
*strname
= NPN_UTF8FromIdentifier (name
);
4593 printf ("adding scriptable object event %s\n", strname
);
4594 NPN_MemFree (strname
);
4597 if (NPVARIANT_IS_OBJECT (*value
)) {
4598 NPObject
*cb_obj
= NPVARIANT_TO_OBJECT (*value
);
4600 NPN_RetainObject (cb_obj
);
4602 addevent (managed_scriptable
, event
->event_handle
, this, cb_obj
);
4604 DEBUG_WARN_NOTIMPLEMENTED ("scriptableobject.register_event (non-object)");
4610 return MoonlightObject::SetProperty (id
, name
, value
);
4615 dump_ptr_npid_hash (gpointer key
, gpointer value
, gpointer user_data
)
4617 NPUTF8
*strname
= NPN_UTF8FromIdentifier ((NPIdentifier
) key
);
4618 printf (" %i (%s) => %p\n", (int) key
, strname
, value
);
4619 NPN_MemFree (strname
);
4624 MoonlightScriptableObjectObject::HasMethod (NPIdentifier name
)
4629 NPUTF8
*strname
= NPN_UTF8FromIdentifier (name
);
4630 printf ("MoonlightScriptableObjectObject::HasMethod (%x = %s) this: %p hash table: %p\n", name
, strname
, this, methods
);
4633 result
= g_hash_table_lookup (methods
, name
) != NULL
;
4638 printf ("MoonlightScriptableObjectObject::HasMethod (%x = %s) failed, this: %p\n", name
, strname
, this);
4639 g_hash_table_foreach (methods
, dump_ptr_npid_hash
, NULL
);
4641 printf ("MoonlightScriptableObjectObject::HasMethod (%x = %s) this: %p result: %i\n", name
, strname
, this, result
);
4643 NPN_MemFree (strname
);
4650 MoonlightScriptableObjectObject::Invoke (int id
, NPIdentifier name
,
4651 const NPVariant
*args
, guint32 argCount
,
4654 PluginInstance
*plugin
= (PluginInstance
*) instance
->pdata
;
4655 if (plugin
->IsCrossDomainApplication ()) {
4656 if (Deployment::GetCurrent ()->GetExternalCallersFromCrossDomain () == CrossDomainAccessNoAccess
)
4657 THROW_JS_EXCEPTION ("XDomain Restriction");
4660 ScriptableMethod
*method
= (ScriptableMethod
*)g_hash_table_lookup (methods
, name
);
4661 Value rv
, **vargs
= NULL
;
4665 return MoonlightObject::Invoke (id
, name
, args
, argCount
, result
);
4667 NPUTF8
*strname
= NPN_UTF8FromIdentifier (name
);
4669 printf ("invoking scriptable object method %s\n", strname
);
4673 vargs
= new Value
*[argCount
];
4674 for (i
= 0; i
< argCount
; i
++)
4675 variant_to_value (&args
[i
], &vargs
[i
]);
4678 invoke (managed_scriptable
, method
->method_handle
, strname
, vargs
, argCount
, &rv
);
4681 for (i
= 0; i
< argCount
; i
++)
4687 ds(printf ("result of invoking %s was %p\n", strname
, rv
.ToString()));
4689 /* Note: this 1 is "void" */
4690 if (method
->method_return_type
!= 0)
4691 value_to_variant (this, &rv
, result
);
4693 VOID_TO_NPVARIANT (*result
);
4695 NPN_MemFree (strname
);
4700 MoonlightScriptableObjectType::MoonlightScriptableObjectType ()
4702 allocate
= moonlight_scriptable_object_allocate
;
4705 MoonlightScriptableObjectType
*MoonlightScriptableObjectClass
;
4707 MoonlightScriptableObjectObject
*
4708 moonlight_scriptable_object_wrapper_create_root (PluginInstance
*plugin
, gpointer scriptable
,
4709 InvokeDelegate invoke_func
,
4710 SetPropertyDelegate setprop_func
,
4711 GetPropertyDelegate getprop_func
,
4712 EventHandlerDelegate addevent_func
,
4713 EventHandlerDelegate removeevent_func
)
4716 MoonlightScriptControlObject
*root_object
= plugin
->GetRootObject ();
4717 return moonlight_scriptable_object_wrapper_create (root_object
, scriptable
,
4725 MoonlightScriptableObjectObject
*
4726 moonlight_scriptable_object_wrapper_create (NPObject
*parent
, gpointer scriptable
,
4727 InvokeDelegate invoke_func
,
4728 SetPropertyDelegate setprop_func
,
4729 GetPropertyDelegate getprop_func
,
4730 EventHandlerDelegate addevent_func
,
4731 EventHandlerDelegate removeevent_func
)
4733 MoonlightScriptableObjectObject
*obj
= (MoonlightScriptableObjectObject
*)
4734 NPN_CreateObject (((MoonlightObject
*) parent
)->instance
,
4735 MoonlightScriptableObjectClass
);
4737 obj
->managed_scriptable
= scriptable
;
4738 obj
->invoke
= invoke_func
;
4739 obj
->setprop
= setprop_func
;
4740 obj
->getprop
= getprop_func
;
4741 obj
->addevent
= addevent_func
;
4742 obj
->removeevent
= removeevent_func
;
4744 ds(printf ("creating scriptable object wrapper => %p\n", obj
));
4751 moonlight_scriptable_object_add_property (PluginInstance
*plugin
,
4752 MoonlightScriptableObjectObject
*obj
,
4753 gpointer property_handle
,
4754 char *property_name
,
4759 ds(printf ("adding property named %s to scriptable object %p\n", property_name
, obj
));
4761 ScriptableProperty
*prop
= new ScriptableProperty ();
4762 prop
->property_handle
= property_handle
;
4763 prop
->property_type
= property_type
;
4764 prop
->can_read
= can_read
;
4765 prop
->can_write
= can_write
;
4767 g_hash_table_insert (obj
->properties
, NPID(property_name
), prop
);
4771 moonlight_scriptable_object_add_event (PluginInstance
*plugin
,
4772 MoonlightScriptableObjectObject
*obj
,
4773 gpointer event_handle
,
4776 ds(printf ("adding event named %s to scriptable object %p\n", event_name
, obj
));
4778 ScriptableEvent
*event
= new ScriptableEvent ();
4779 event
->event_handle
= event_handle
;
4781 g_hash_table_insert (obj
->events
, NPID(event_name
), event
);
4785 moonlight_scriptable_object_add_method (PluginInstance
*plugin
,
4786 MoonlightScriptableObjectObject
*obj
,
4787 gpointer method_handle
,
4789 int method_return_type
,
4790 int *method_parameter_types
,
4791 int parameter_count
)
4794 NPIdentifier id
= NPID (method_name
);
4796 ds(printf ("adding method named %s (npid: %i) (return type = %d) to scriptable object %p\n", method_name
, id
, method_return_type
, obj
));
4798 ScriptableMethod
*method
= new ScriptableMethod ();
4799 method
->method_handle
= method_handle
;
4800 method
->method_return_type
= method_return_type
;
4801 method
->method_parameter_types
= new int[parameter_count
];
4802 memcpy (method
->method_parameter_types
, method_parameter_types
, sizeof (int) * parameter_count
);
4803 method
->parameter_count
= parameter_count
;
4805 g_hash_table_insert (obj
->methods
, id
, method
);
4809 moonlight_scriptable_object_register (PluginInstance
*plugin
,
4811 MoonlightScriptableObjectObject
*obj
)
4813 MoonlightContentObject
*content
= (MoonlightContentObject
*) plugin
->GetRootObject ()->content
;
4815 ds(printf ("registering scriptable object '%s' => %p\n", name
, obj
));
4817 g_hash_table_insert (content
->registered_scriptable_objects
, NPID (name
), obj
);
4819 ds(printf (" => done\n"));
4823 moonlight_scriptable_object_emit_event (PluginInstance
*plugin
,
4824 MoonlightScriptableObjectObject
*sobj
,
4825 MoonlightScriptableObjectObject
*event_args
,
4831 OBJECT_TO_NPVARIANT (sobj
, args
[0]);
4832 OBJECT_TO_NPVARIANT (event_args
, args
[1]);
4834 if (NPN_InvokeDefault (plugin
->GetInstance (), cb_obj
, args
, 2, &result
))
4835 NPN_ReleaseVariantValue (&result
);
4839 /****************************** HtmlObject *************************/
4842 // Debug method to reflect over a NPObject and dump it to stdout.
4844 enumerate_html_object (NPP npp
, NPObject
*npobj
, int recurse
, int initial_recurse
)
4847 NPIdentifier
*identifiers
= NULL
;
4848 guint32 id_count
= 0;
4853 char *tab
= (char *) g_malloc (sizeof (char *) * (initial_recurse
+ 1) * 4);
4854 char *tab2
= (char *) g_malloc (sizeof (char *) * (initial_recurse
+ 1) * 4);
4856 memset (tab
, 0, (initial_recurse
+ 1) * 4);
4857 memset (tab
, ' ', (initial_recurse
- recurse
) * 4);
4859 memset (tab2
, 0, (initial_recurse
+ 1) * 4);
4860 memset (tab2
, ' ', (initial_recurse
- recurse
+ 1) * 4);
4862 if (NPN_Enumerate (npp
, npobj
, &identifiers
, &id_count
)) {
4863 //printf ("%senumerate_html_object (%p, %p, %i, %i): Enumerating %i identifiers.\n", tab, npp, npobj, recurse, initial_recurse, id_count);
4864 for (guint32 i
= 0; i
< id_count
; i
++) {
4865 if (NPN_IdentifierIsString (identifiers
[i
])) {
4866 printf ("%s'%s': ", tab2
, NPN_UTF8FromIdentifier (identifiers
[i
]));
4868 printf ("%s%i: ", tab2
, NPN_IntFromIdentifier (identifiers
[i
]));
4871 NPN_GetProperty (npp
, npobj
, identifiers
[i
], &npresult
);
4873 if (NPVARIANT_IS_VOID (npresult
)) {
4875 } else if (NPVARIANT_IS_NULL (npresult
)) {
4877 } else if (NPVARIANT_IS_STRING (npresult
)) {
4878 printf ("String: %s\n", NPVARIANT_TO_STRING (npresult
).utf8characters
);
4879 } else if (NPVARIANT_IS_BOOLEAN (npresult
)) {
4880 printf ("Boolean: %i\n", NPVARIANT_TO_BOOLEAN (npresult
));
4881 } else if (NPVARIANT_IS_INT32 (npresult
)) {
4882 printf ("Int32: %i\n", NPVARIANT_TO_INT32 (npresult
));
4883 } else if (NPVARIANT_IS_DOUBLE (npresult
)) {
4884 printf ("Double: %f\n", NPVARIANT_TO_DOUBLE (npresult
));
4885 } else if (NPVARIANT_IS_OBJECT (npresult
)) {
4886 printf ("Object.\n");
4889 enumerate_html_object (npp
, NPVARIANT_TO_OBJECT (npresult
), recurse
- 1, initial_recurse
);
4892 printf ("Invalid value.\n");
4903 html_object_has_property (PluginInstance
*plugin
, NPObject
*npobj
, char *name
)
4905 NPP npp
= plugin
->GetInstance ();
4906 NPObject
*window
= NULL
;
4907 NPIdentifier identifier
= NPN_GetStringIdentifier (name
);
4908 if (npobj
== NULL
) {
4909 NPN_GetValue (npp
, NPNVWindowNPObject
, &window
);
4913 return NPN_HasProperty (npp
, npobj
, identifier
);
4917 html_object_get_property (PluginInstance
*plugin
, NPObject
*npobj
, char *name
, Value
*result
)
4920 NPObject
*window
= NULL
;
4921 NPP npp
= plugin
->GetInstance ();
4922 NPIdentifier identifier
= NPN_GetStringIdentifier (name
);
4924 if (npobj
== NULL
) {
4925 NPN_GetValue (npp
, NPNVWindowNPObject
, &window
);
4929 bool ret
= NPN_GetProperty (npp
, npobj
, identifier
, &npresult
);
4933 if (!NPVARIANT_IS_VOID (npresult
) && !NPVARIANT_IS_NULL (npresult
)) {
4934 variant_to_value (&npresult
, &res
);
4937 *result
= Value (Type::INVALID
);
4940 // can't throw exceptions here for now, they
4941 // get stuck in firefox and subsequent eval calls
4943 // THROW_JS_EXCEPTION2 (npobj, name);
4944 *result
= Value (Type::INVALID
);
4949 html_object_set_property (PluginInstance
*plugin
, NPObject
*npobj
, char *name
, Value
*value
)
4952 NPObject
*window
= NULL
;
4953 NPP npp
= plugin
->GetInstance ();
4954 NPIdentifier identifier
= NPN_GetStringIdentifier (name
);
4956 if (npobj
== NULL
) {
4957 NPN_GetValue (npp
, NPNVWindowNPObject
, &window
);
4961 value_to_variant (npobj
, value
, &npvalue
);
4963 bool ret
= NPN_SetProperty (npp
, npobj
, identifier
, &npvalue
);
4965 d (printf ("Error setting property %s.\n", name
));
4969 html_object_invoke (PluginInstance
*plugin
, NPObject
*npobj
, char *name
,
4970 Value
*args
, guint32 arg_count
, Value
*result
)
4973 NPVariant
*npargs
= NULL
;
4974 NPObject
*window
= NULL
;
4975 NPP npp
= plugin
->GetInstance ();
4976 NPIdentifier identifier
= NPN_GetStringIdentifier (name
);
4978 if (npobj
== NULL
) {
4979 NPN_GetValue (npp
, NPNVWindowNPObject
, &window
);
4984 npargs
= new NPVariant
[arg_count
];
4985 for (guint32 i
= 0; i
< arg_count
; i
++)
4986 value_to_variant (npobj
, &args
[i
], &npargs
[i
]);
4989 bool ret
= NPN_Invoke (npp
, npobj
, identifier
, npargs
, arg_count
, &npresult
);
4992 for (guint32 i
= 0; i
< arg_count
; i
++)
4993 NPN_ReleaseVariantValue (&npargs
[i
]);
5000 if (!NPVARIANT_IS_VOID (npresult
) && !NPVARIANT_IS_NULL (npresult
)) {
5001 variant_to_value (&npresult
, &res
);
5004 *result
= Value (Type::INVALID
);
5007 // can't throw exceptions here for now, they
5008 // get stuck in firefox and subsequent eval calls
5010 // THROW_JS_EXCEPTION2 (npobj, name);
5011 *result
= Value (Type::INVALID
);
5017 html_object_invoke_self (PluginInstance
*plugin
, NPObject
*npobj
,
5018 Value
*args
, guint32 arg_count
, Value
*result
)
5021 NPVariant
*npargs
= NULL
;
5022 NPObject
*window
= NULL
;
5023 NPP npp
= plugin
->GetInstance ();
5025 if (npobj
== NULL
) {
5026 NPN_GetValue (npp
, NPNVWindowNPObject
, &window
);
5031 npargs
= new NPVariant
[arg_count
];
5032 for (guint32 i
= 0; i
< arg_count
; i
++)
5033 value_to_variant (npobj
, &args
[i
], &npargs
[i
]);
5036 bool ret
= NPN_InvokeDefault (npp
, npobj
, npargs
, arg_count
, &npresult
);
5039 for (guint32 i
= 0; i
< arg_count
; i
++)
5040 NPN_ReleaseVariantValue (&npargs
[i
]);
5047 if (!NPVARIANT_IS_VOID (npresult
) && !NPVARIANT_IS_NULL (npresult
)) {
5048 variant_to_value (&npresult
, &res
);
5051 *result
= Value (Type::INVALID
);
5054 THROW_JS_EXCEPTION2 (npobj
, "");
5055 *result
= Value (Type::INVALID
);
5061 html_get_element_text (PluginInstance
*plugin
, const char *element_id
)
5063 if (!plugin
->GetBridge())
5065 return plugin
->GetBridge()->HtmlElementGetText(plugin
->GetInstance(), element_id
);
5069 html_object_attach_event (PluginInstance
*plugin
, NPObject
*npobj
, char *name
, callback_dom_event
*cb
, gpointer context
)
5071 if (!plugin
->GetBridge())
5073 return plugin
->GetBridge()->HtmlObjectAttachEvent (plugin
->GetInstance(), npobj
, name
, cb
, context
);
5077 html_object_detach_event (PluginInstance
*plugin
, const char *name
, gpointer listener_ptr
)
5079 if (!plugin
->GetBridge())
5081 plugin
->GetBridge()->HtmlObjectDetachEvent (plugin
->GetInstance(), name
, listener_ptr
);
5084 struct release_data
{
5085 PluginInstance
*plugin
;
5090 html_object_release_callback (gpointer user_data
)
5092 release_data
*d
= (release_data
*) user_data
;
5093 html_object_release (d
->plugin
, d
->npobj
);
5094 d
->plugin
->unref ();
5100 html_object_release (PluginInstance
*plugin
, NPObject
*npobj
)
5105 if (!Surface::InMainThread ()) {
5106 release_data
*d
= (release_data
*) g_malloc (sizeof (release_data
));
5110 g_timeout_add_full (1, G_PRIORITY_DEFAULT
, html_object_release_callback
, d
, NULL
);
5114 if (plugin
->HasShutdown ()) {
5115 // printf ("html_object_release (%p, %p): plugin has shut down, object has most probably been deleted already.\n", plugin, npobj);
5119 NPN_ReleaseObject (npobj
);
5123 html_object_retain (PluginInstance
*plugin
, NPObject
*npobj
)
5129 * trying to use a NPObject when the plugin has shut down is a very bad idea
5130 * since the NPObject has most probably been deleted already.
5132 g_return_if_fail (!plugin
->HasShutdown ());
5135 * we can't marshal this to the main thread (if we're not already executing
5136 * in it), since the object might end up deleted by the time the main thread
5140 NPN_RetainObject (npobj
);
5144 browser_do_alert (PluginInstance
*plugin
, char *msg
)
5146 NPVariant npresult
, npargs
;
5147 NPObject
*window
= NULL
;
5148 NPP npp
= plugin
->GetInstance ();
5149 NPIdentifier identifier
= NPN_GetStringIdentifier ("alert");
5151 NPN_GetValue (npp
, NPNVWindowNPObject
, &window
);
5152 string_to_npvariant (msg
, &npargs
);
5154 NPN_Invoke (npp
, window
, identifier
, &npargs
, 1, &npresult
);
5159 plugin_init_classes (void)
5162 * All classes that derive from MoonlightDependencyObject should be stored in the dependency_object_classes
5163 * array, so that we can verify arguments passed from JS code are valid dependency objects, and not random
5164 * JS objects. ie element.children.add (new Array ())
5167 dependency_object_classes
[COLLECTION_CLASS
] = new MoonlightCollectionType ();
5168 dependency_object_classes
[DEPENDENCY_OBJECT_CLASS
] = new MoonlightDependencyObjectType ();
5169 dependency_object_classes
[DOWNLOADER_CLASS
] = new MoonlightDownloaderType ();
5170 dependency_object_classes
[IMAGE_BRUSH_CLASS
] = new MoonlightImageBrushType ();
5171 dependency_object_classes
[IMAGE_CLASS
] = new MoonlightImageType ();
5172 dependency_object_classes
[MEDIA_ELEMENT_CLASS
] = new MoonlightMediaElementType ();
5173 dependency_object_classes
[STORYBOARD_CLASS
] = new MoonlightStoryboardType ();
5174 dependency_object_classes
[STYLUS_INFO_CLASS
] = new MoonlightStylusInfoType ();
5175 dependency_object_classes
[STYLUS_POINT_COLLECTION_CLASS
] = new MoonlightStylusPointCollectionType ();
5176 dependency_object_classes
[STROKE_COLLECTION_CLASS
] = new MoonlightStrokeCollectionType ();
5177 dependency_object_classes
[STROKE_CLASS
] = new MoonlightStrokeType ();
5178 dependency_object_classes
[TEXT_BLOCK_CLASS
] = new MoonlightTextBlockType ();
5179 dependency_object_classes
[UI_ELEMENT_CLASS
] = new MoonlightUIElementType ();
5180 dependency_object_classes
[CONTROL_CLASS
] = new MoonlightControlType ();
5181 dependency_object_classes
[TEXT_BOX_CLASS
] = new MoonlightTextBoxType ();
5182 dependency_object_classes
[PASSWORD_BOX_CLASS
] = new MoonlightPasswordBoxType ();
5183 dependency_object_classes
[MULTI_SCALE_IMAGE_CLASS
] = new MoonlightMultiScaleImageType ();
5184 /* Event Arg Types */
5185 dependency_object_classes
[EVENT_ARGS_CLASS
] = new MoonlightEventArgsType ();
5186 dependency_object_classes
[ROUTED_EVENT_ARGS_CLASS
] = new MoonlightRoutedEventArgsType ();
5187 dependency_object_classes
[ERROR_EVENT_ARGS_CLASS
] = new MoonlightErrorEventArgsType ();
5188 dependency_object_classes
[KEY_EVENT_ARGS_CLASS
] = new MoonlightKeyEventArgsType ();
5189 dependency_object_classes
[MARKER_REACHED_EVENT_ARGS_CLASS
] = new MoonlightMarkerReachedEventArgsType ();
5190 dependency_object_classes
[MOUSE_EVENT_ARGS_CLASS
] = new MoonlightMouseEventArgsType ();
5191 dependency_object_classes
[DOWNLOAD_PROGRESS_EVENT_ARGS_CLASS
] = new MoonlightDownloadProgressEventArgsType ();
5193 MoonlightContentClass
= new MoonlightContentType ();
5194 MoonlightDurationClass
= new MoonlightDurationType ();
5195 MoonlightEventObjectClass
= new MoonlightEventObjectType ();
5196 MoonlightObjectClass
= new MoonlightObjectType ();
5197 MoonlightPointClass
= new MoonlightPointType ();
5198 MoonlightRectClass
= new MoonlightRectType ();
5199 MoonlightScriptableObjectClass
= new MoonlightScriptableObjectType ();
5200 MoonlightScriptControlClass
= new MoonlightScriptControlType ();
5201 MoonlightSettingsClass
= new MoonlightSettingsType ();
5202 MoonlightTimeSpanClass
= new MoonlightTimeSpanType ();
5203 MoonlightKeyTimeClass
= new MoonlightKeyTimeType ();
5204 MoonlightThicknessClass
= new MoonlightThicknessType ();
5205 MoonlightCornerRadiusClass
= new MoonlightCornerRadiusType ();
5206 MoonlightGridLengthClass
= new MoonlightGridLengthType ();
5210 plugin_destroy_classes (void)
5212 for (int i
= 0; i
< DEPENDENCY_OBJECT_CLASS_NAMES_LAST
; i
++) {
5213 delete dependency_object_classes
[i
];
5214 dependency_object_classes
[i
] = NULL
;
5217 delete MoonlightContentClass
; MoonlightContentClass
= NULL
;
5218 delete MoonlightEventObjectClass
; MoonlightEventObjectClass
= NULL
;
5219 delete MoonlightErrorEventArgsClass
; MoonlightErrorEventArgsClass
= NULL
;
5220 delete MoonlightMouseEventArgsClass
; MoonlightMouseEventArgsClass
= NULL
;
5221 delete MoonlightDownloadProgressEventArgsClass
; MoonlightDownloadProgressEventArgsClass
= NULL
;
5222 delete MoonlightKeyEventArgsClass
; MoonlightKeyEventArgsClass
= NULL
;
5223 delete MoonlightObjectClass
; MoonlightObjectClass
= NULL
;
5224 delete MoonlightScriptableObjectClass
; MoonlightScriptableObjectClass
= NULL
;
5225 delete MoonlightScriptControlClass
; MoonlightScriptControlClass
= NULL
;
5226 delete MoonlightSettingsClass
; MoonlightSettingsClass
= NULL
;
5227 delete MoonlightRectClass
; MoonlightRectClass
= NULL
;
5228 delete MoonlightPointClass
; MoonlightPointClass
= NULL
;
5229 delete MoonlightDurationClass
; MoonlightDurationClass
= NULL
;
5230 delete MoonlightTimeSpanClass
; MoonlightTimeSpanClass
= NULL
;
5231 delete MoonlightKeyTimeClass
; MoonlightKeyTimeClass
= NULL
;
5232 delete MoonlightThicknessClass
; MoonlightThicknessClass
= NULL
;
5233 delete MoonlightCornerRadiusClass
; MoonlightCornerRadiusClass
= NULL
;
5234 delete MoonlightGridLengthClass
; MoonlightGridLengthClass
= NULL
;
5235 delete MoonlightMarkerReachedEventArgsClass
; MoonlightMarkerReachedEventArgsClass
= NULL
;