Author: jackson
Date: 2008-02-06 12:32:17 -0500 (Wed, 06 Feb 2008)
New Revision: 95051
Modified:
trunk/moon/plugin/ChangeLog
trunk/moon/plugin/plugin-class.cpp
trunk/moon/plugin/plugin-class.h
Log:
* plugin-class.cpp|h: Store all MoonlightDependencyObject
* classes
in an array so that we can easily check if a type passed in from
JS is actually a DO.
- Add one check to verify that an object is a DO, I am sure we
will need many more.
Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2008-02-06 17:31:10 UTC (rev 95050)
+++ trunk/moon/plugin/ChangeLog 2008-02-06 17:32:17 UTC (rev 95051)
@@ -1,3 +1,11 @@
+2008-02-06 Jackson Harper <[EMAIL PROTECTED]>
+
+ * plugin-class.cpp|h: Store all MoonlightDependencyObject classes
+ in an array so that we can easily check if a type passed in from
+ JS is actually a DO.
+ - Add one check to verify that an object is a DO, I am sure we
+ will need many more.
+
2008-02-06 Fernando Herrera <[EMAIL PROTECTED]>
* plugin-debug.cpp: set default size and scroll bars policy in the
Modified: trunk/moon/plugin/plugin-class.cpp
===================================================================
--- trunk/moon/plugin/plugin-class.cpp 2008-02-06 17:31:10 UTC (rev 95050)
+++ trunk/moon/plugin/plugin-class.cpp 2008-02-06 17:32:17 UTC (rev 95051)
@@ -361,6 +361,36 @@
}
}
+enum DependencyObjectClassNames {
+ COLLECTION_CLASS,
+ CONTROL_CLASS,
+ DEPENDENCY_OBJECT_CLASS,
+ DOWNLOADER_CLASS,
+ IMAGE_BRUSH_CLASS,
+ IMAGE_CLASS,
+ MEDIA_ELEMENT_CLASS,
+ STORYBOARD_CLASS,
+ STYLUS_INFO_CLASS,
+ STYLUS_POINT_COLLECTION_CLASS,
+ STROKE_COLLECTION_CLASS,
+ STROKE_CLASS,
+ TEXT_BLOCK_CLASS,
+
+ DEPENDENCY_OBJECT_CLASS_NAMES_LAST
+};
+
+NPClass* dependency_object_classes [DEPENDENCY_OBJECT_CLASS_NAMES_LAST];
+
+static bool
+npobject_is_dependency_object (NPObject *obj)
+{
+ for (int i = 0; i < DEPENDENCY_OBJECT_CLASS_NAMES_LAST; i++) {
+ if (dependency_object_classes [i] == obj->_class)
+ return true;
+ }
+ return false;
+}
+
EventListenerProxy::EventListenerProxy (NPP instance, const char *event_name,
const char *cb_name)
{
this->instance = instance;
@@ -2168,7 +2198,7 @@
THROW_JS_EXCEPTION ("equals");
NPObject *o = NPVARIANT_TO_OBJECT (args[0]);
- if (o->_class != MoonlightDependencyObjectClass)
+ if (!npobject_is_dependency_object (o))
BOOLEAN_TO_NPVARIANT (false, *result);
else {
MoonlightDependencyObjectObject *obj =
(MoonlightDependencyObjectObject *) o;
@@ -2306,7 +2336,6 @@
AddMapping (moonlight_dependency_object_mapping, COUNT
(moonlight_dependency_object_mapping));
}
-MoonlightDependencyObjectType *MoonlightDependencyObjectClass;
/*** MoonlightEventObjectClass
***************************************************/
@@ -2377,47 +2406,47 @@
Type::Kind kind = obj->GetObjectType ();
switch (kind) {
case Type::STORYBOARD:
- np_class = MoonlightStoryboardClass;
+ np_class = dependency_object_classes [STORYBOARD_CLASS];
break;
case Type::MEDIAELEMENT:
- np_class = MoonlightMediaElementClass;
+ np_class = dependency_object_classes [MEDIA_ELEMENT_CLASS];
break;
case Type::DOWNLOADER:
- np_class = MoonlightDownloaderClass;
+ np_class = dependency_object_classes [DOWNLOADER_CLASS];
break;
case Type::CONTROL:
- np_class = MoonlightControlClass;
+ np_class = dependency_object_classes [CONTROL_CLASS];
break;
case Type::IMAGE:
- np_class = MoonlightImageClass;
+ np_class = dependency_object_classes [IMAGE_CLASS];
break;
case Type::IMAGEBRUSH:
- np_class = MoonlightImageBrushClass;
+ np_class = dependency_object_classes [IMAGE_BRUSH_CLASS];
break;
case Type::TEXTBLOCK:
- np_class = MoonlightTextBlockClass;
+ np_class = dependency_object_classes [TEXT_BLOCK_CLASS];
break;
case Type::EVENTOBJECT:
case Type::SURFACE:
np_class = MoonlightEventObjectClass;
break;
case Type::STYLUSINFO:
- np_class = MoonlightStylusInfoClass;
+ np_class = dependency_object_classes [STYLUS_INFO_CLASS];
break;
case Type::STYLUSPOINT_COLLECTION:
- np_class = MoonlightStylusPointCollectionClass;
+ np_class = dependency_object_classes
[STYLUS_POINT_COLLECTION_CLASS];
break;
case Type::STROKE_COLLECTION:
- np_class = MoonlightStrokeCollectionClass;
+ np_class = dependency_object_classes [STROKE_COLLECTION_CLASS];
break;
case Type::STROKE:
- np_class = MoonlightStrokeClass;
+ np_class = dependency_object_classes [STROKE_CLASS];
break;
default:
if (Type::Find (kind)->IsSubclassOf (Type::COLLECTION))
- np_class = MoonlightCollectionClass;
+ np_class = dependency_object_classes [COLLECTION_CLASS];
else
- np_class = MoonlightDependencyObjectClass;
+ np_class = dependency_object_classes
[DEPENDENCY_OBJECT_CLASS];
}
depobj = (MoonlightEventObjectObject *) NPN_CreateObject (instance,
np_class);
@@ -2503,6 +2532,9 @@
return true;
}
+ if (!npobject_is_dependency_object (NPVARIANT_TO_OBJECT (args
[0])))
+ THROW_JS_EXCEPTION ("remove");
+
MoonlightDependencyObjectObject *el =
(MoonlightDependencyObjectObject *) NPVARIANT_TO_OBJECT (args[0]);
bool res = col->Remove (el->GetDependencyObject ());
@@ -2601,9 +2633,7 @@
allocate = moonlight_collection_allocate;
}
-MoonlightCollectionType *MoonlightCollectionClass;
-
/*** MoonlightStoryboardClass
***************************************************/
static NPObject *
@@ -2697,7 +2727,6 @@
allocate = moonlight_storyboard_allocate;
}
-MoonlightStoryboardType *MoonlightStoryboardClass;
/*** MoonlightMediaElementClass
***************************************************/
@@ -2790,7 +2819,6 @@
allocate = moonlight_media_element_allocate;
}
-MoonlightMediaElementType *MoonlightMediaElementClass;
/*** MoonlightImageClass ***************************************************/
@@ -2847,7 +2875,6 @@
allocate = moonlight_image_allocate;
}
-MoonlightImageType *MoonlightImageClass;
/*** MoonlightImageBrushClass
***************************************************/
@@ -2904,9 +2931,7 @@
allocate = moonlight_image_brush_allocate;
}
-MoonlightImageBrushType *MoonlightImageBrushClass;
-
/*** MoonlightTextBlockClass
***************************************************/
static NPObject *
@@ -2956,7 +2981,6 @@
allocate = moonlight_text_block_allocate;
}
-MoonlightTextBlockType *MoonlightTextBlockClass;
/*** MoonlightStylusInfoClass
***************************************************/
@@ -3011,7 +3035,6 @@
allocate = moonlight_stylus_info_allocate;
}
-MoonlightStylusInfoType *MoonlightStylusInfoClass;
/*** MoonlightStylusPointCollectionClass
****************************************/
@@ -3054,7 +3077,6 @@
allocate = moonlight_stylus_point_collection_allocate;
}
-MoonlightStylusPointCollectionType *MoonlightStylusPointCollectionClass;
/*** MoonlightStrokeCollectionClass ****************************************/
@@ -3113,7 +3135,6 @@
allocate = moonlight_stroke_collection_allocate;
}
-MoonlightStrokeCollectionType *MoonlightStrokeCollectionClass;
/*** MoonlightStrokeClass ****************************************/
@@ -3172,7 +3193,6 @@
allocate = moonlight_stroke_allocate;
}
-MoonlightStrokeType *MoonlightStrokeClass;
/*** MoonlightDownloaderClass
***************************************************/
@@ -3300,7 +3320,6 @@
allocate = moonlight_downloader_allocate;
}
-MoonlightDownloaderType *MoonlightDownloaderClass;
/*** MoonlightControlClass ***************************************************/
@@ -3393,7 +3412,6 @@
allocate = moonlight_control_allocate;
}
-MoonlightControlType *MoonlightControlClass;
/*** MoonlightScriptableObjectClass
***************************************************/
@@ -4001,19 +4019,32 @@
void
plugin_init_classes (void)
{
- MoonlightCollectionClass = new MoonlightCollectionType ();
+ /*
+ * All classes that derive from MoonlightDependencyObject should be
stored in the dependency_object_classes
+ * array, so that we can verify arguments passed from JS code are valid
dependency objects, and not random
+ * JS objects. ie element.children.add (new Array ())
+ */
+
+ dependency_object_classes [COLLECTION_CLASS] = new
MoonlightCollectionType ();
+ dependency_object_classes [CONTROL_CLASS] = new MoonlightControlType ();
+ dependency_object_classes [DEPENDENCY_OBJECT_CLASS] = new
MoonlightDependencyObjectType ();
+ dependency_object_classes [DOWNLOADER_CLASS] = new
MoonlightDownloaderType ();
+ dependency_object_classes [IMAGE_BRUSH_CLASS] = new
MoonlightImageBrushType ();
+ dependency_object_classes [IMAGE_CLASS] = new MoonlightImageType ();
+ dependency_object_classes [MEDIA_ELEMENT_CLASS] = new
MoonlightMediaElementType ();
+ dependency_object_classes [STORYBOARD_CLASS] = new
MoonlightStoryboardType ();
+ dependency_object_classes [STYLUS_INFO_CLASS] = new
MoonlightStylusInfoType ();
+ dependency_object_classes [STYLUS_POINT_COLLECTION_CLASS] = new
MoonlightStylusPointCollectionType ();
+ dependency_object_classes [STROKE_COLLECTION_CLASS] = new
MoonlightStrokeCollectionType ();
+ dependency_object_classes [STROKE_CLASS] = new MoonlightStrokeType ();
+ dependency_object_classes [TEXT_BLOCK_CLASS] = new
MoonlightTextBlockType ();
+
MoonlightContentClass = new MoonlightContentType ();
- MoonlightControlClass = new MoonlightControlType ();
- MoonlightDependencyObjectClass = new MoonlightDependencyObjectType ();
- MoonlightDownloaderClass = new MoonlightDownloaderType ();
MoonlightDurationClass = new MoonlightDurationType ();
MoonlightErrorEventArgsClass = new MoonlightErrorEventArgsType ();
MoonlightEventObjectClass = new MoonlightEventObjectType ();
- MoonlightImageBrushClass = new MoonlightImageBrushType ();
- MoonlightImageClass = new MoonlightImageType ();
MoonlightKeyboardEventArgsClass = new MoonlightKeyboardEventArgsType ();
MoonlightMarkerReachedEventArgsClass = new
MoonlightMarkerReachedEventArgsType ();
- MoonlightMediaElementClass = new MoonlightMediaElementType ();
MoonlightMouseEventArgsClass = new MoonlightMouseEventArgsType ();
MoonlightObjectClass = new MoonlightObjectType ();
MoonlightPointClass = new MoonlightPointType ();
@@ -4021,41 +4052,26 @@
MoonlightScriptableObjectClass = new MoonlightScriptableObjectType ();
MoonlightScriptControlClass = new MoonlightScriptControlType ();
MoonlightSettingsClass = new MoonlightSettingsType ();
- MoonlightStoryboardClass = new MoonlightStoryboardType ();
- MoonlightStylusInfoClass = new MoonlightStylusInfoType ();
- MoonlightStylusPointCollectionClass = new
MoonlightStylusPointCollectionType ();
- MoonlightStrokeCollectionClass = new MoonlightStrokeCollectionType ();
- MoonlightStrokeClass = new MoonlightStrokeType ();
- MoonlightTextBlockClass = new MoonlightTextBlockType ();
MoonlightTimeSpanClass = new MoonlightTimeSpanType ();
}
void
plugin_destroy_classes (void)
{
+ for (int i = 0; i < DEPENDENCY_OBJECT_CLASS_NAMES_LAST; i++) {
+ delete dependency_object_classes [i];
+ dependency_object_classes [i] = NULL;
+ }
- delete MoonlightCollectionClass; MoonlightCollectionClass = NULL;
delete MoonlightContentClass; MoonlightContentClass = NULL;
- delete MoonlightControlClass; MoonlightControlClass = NULL;
delete MoonlightEventObjectClass; MoonlightEventObjectClass = NULL;
- delete MoonlightDependencyObjectClass; MoonlightDependencyObjectClass =
NULL;
- delete MoonlightDownloaderClass; MoonlightDownloaderClass = NULL;
delete MoonlightErrorEventArgsClass; MoonlightErrorEventArgsClass =
NULL;
- delete MoonlightImageBrushClass; MoonlightImageBrushClass = NULL;
- delete MoonlightImageClass; MoonlightImageClass = NULL;
- delete MoonlightMediaElementClass; MoonlightMediaElementClass = NULL;
delete MoonlightMouseEventArgsClass; MoonlightMouseEventArgsClass =
NULL;
delete MoonlightKeyboardEventArgsClass; MoonlightKeyboardEventArgsClass
= NULL;
delete MoonlightObjectClass; MoonlightObjectClass = NULL;
delete MoonlightScriptableObjectClass; MoonlightScriptableObjectClass =
NULL;
delete MoonlightScriptControlClass; MoonlightScriptControlClass = NULL;
delete MoonlightSettingsClass; MoonlightSettingsClass = NULL;
- delete MoonlightStoryboardClass; MoonlightStoryboardClass = NULL;
- delete MoonlightStylusInfoClass; MoonlightStylusInfoClass = NULL;
- delete MoonlightStylusPointCollectionClass;
MoonlightStylusPointCollectionClass = NULL;
- delete MoonlightStrokeCollectionClass; MoonlightStrokeCollectionClass =
NULL;
- delete MoonlightStrokeClass; MoonlightStrokeClass = NULL;
- delete MoonlightTextBlockClass; MoonlightTextBlockClass = NULL;
delete MoonlightRectClass; MoonlightRectClass = NULL;
delete MoonlightPointClass; MoonlightPointClass = NULL;
delete MoonlightDurationClass; MoonlightDurationClass = NULL;
Modified: trunk/moon/plugin/plugin-class.h
===================================================================
--- trunk/moon/plugin/plugin-class.h 2008-02-06 17:31:10 UTC (rev 95050)
+++ trunk/moon/plugin/plugin-class.h 2008-02-06 17:32:17 UTC (rev 95051)
@@ -391,8 +391,8 @@
struct MoonlightDependencyObjectType : MoonlightEventObjectType {
MoonlightDependencyObjectType ();
};
-extern MoonlightDependencyObjectType *MoonlightDependencyObjectClass;
+
struct MoonlightDependencyObjectObject : public MoonlightEventObjectObject
{
MoonlightDependencyObjectObject (NPP instance) :
MoonlightEventObjectObject (instance)
@@ -429,7 +429,6 @@
struct MoonlightCollectionType : MoonlightDependencyObjectType {
MoonlightCollectionType ();
};
-extern MoonlightCollectionType* MoonlightCollectionClass;
struct MoonlightCollectionObject : public MoonlightDependencyObjectObject {
MoonlightCollectionObject (NPP instance) :
MoonlightDependencyObjectObject (instance)
@@ -449,8 +448,6 @@
MoonlightStoryboardType ();
};
-extern MoonlightStoryboardType* MoonlightStoryboardClass;
-
struct MoonlightStoryboardObject : MoonlightDependencyObjectObject {
MoonlightStoryboardObject (NPP instance)
: MoonlightDependencyObjectObject (instance)
@@ -468,7 +465,6 @@
MoonlightMediaElementType ();
};
-extern MoonlightMediaElementType* MoonlightMediaElementClass;
struct MoonlightMediaElementObject : MoonlightDependencyObjectObject {
MoonlightMediaElementObject (NPP instance)
@@ -487,7 +483,6 @@
MoonlightImageType ();
};
-extern MoonlightImageType* MoonlightImageClass;
struct MoonlightImageObject : MoonlightDependencyObjectObject {
MoonlightImageObject (NPP instance)
@@ -506,7 +501,6 @@
MoonlightImageBrushType ();
};
-extern MoonlightImageBrushType* MoonlightImageBrushClass;
struct MoonlightImageBrushObject : MoonlightDependencyObjectObject {
MoonlightImageBrushObject (NPP instance)
@@ -525,7 +519,6 @@
MoonlightDownloaderType ();
};
-extern MoonlightDownloaderType* MoonlightDownloaderClass;
struct MoonlightDownloaderObject : public MoonlightDependencyObjectObject {
MoonlightDownloaderObject (NPP instance) :
MoonlightDependencyObjectObject (instance)
@@ -544,7 +537,6 @@
MoonlightTextBlockType ();
};
-extern MoonlightTextBlockType* MoonlightTextBlockClass;
struct MoonlightTextBlockObject : MoonlightDependencyObjectObject {
MoonlightTextBlockObject (NPP instance)
@@ -563,7 +555,6 @@
MoonlightStylusInfoType ();
};
-extern MoonlightStylusInfoType *MoonlightStylusInfoClass;
struct MoonlightStylusInfoObject : MoonlightDependencyObjectObject {
@@ -582,7 +573,6 @@
MoonlightStylusPointCollectionType ();
};
-extern MoonlightStylusPointCollectionType *MoonlightStylusPointCollectionClass;
struct MoonlightStylusPointCollectionObject : MoonlightCollectionObject {
@@ -603,7 +593,6 @@
MoonlightStrokeCollectionType ();
};
-extern MoonlightStrokeCollectionType *MoonlightStrokeCollectionClass;
struct MoonlightStrokeCollectionObject : MoonlightCollectionObject {
@@ -624,7 +613,6 @@
MoonlightStrokeType ();
};
-extern MoonlightStrokeType *MoonlightStrokeClass;
struct MoonlightStrokeObject : MoonlightDependencyObjectObject {
@@ -644,7 +632,6 @@
MoonlightControlType ();
};
-extern MoonlightControlType* MoonlightControlClass;;
struct MoonlightControlObject : MoonlightDependencyObjectObject {
MoonlightControlObject (NPP instance) : MoonlightDependencyObjectObject
(instance)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches