1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * plugin.h: 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.
17 #include "moonlight.h"
20 #include <mono/jit/jit.h>
21 #include <mono/metadata/appdomain.h>
22 #include <mono/metadata/assembly.h>
23 #include <mono/metadata/debug-helpers.h>
25 /* because this header sucks */
26 #include <mono/metadata/mono-debug.h>
28 #include <mono/metadata/mono-config.h>
31 class MoonlightScriptControlObject
;
32 class PluginXamlLoader
;
39 char *NPN_strdup (const char *val
);
44 PluginInstance (NPMIMEType pluginType
, NPP instance
, guint16 mode
);
47 void Initialize (int argc
, char *const argn
[], char *const argv
[]);
50 // Mozilla plugin related methods
51 NPError
GetValue (NPPVariable variable
, void *result
);
52 NPError
SetValue (NPNVariable variable
, void *value
);
53 NPError
SetWindow (NPWindow
*window
);
54 NPError
NewStream (NPMIMEType type
, NPStream
*stream
, NPBool seekable
, guint16
*stype
);
55 NPError
DestroyStream (NPStream
*stream
, NPError reason
);
56 void StreamAsFile (NPStream
*stream
, const char *fname
);
57 gint32
WriteReady (NPStream
*stream
);
58 gint32
Write (NPStream
*stream
, gint32 offset
, gint32 len
, void *buffer
);
59 void UrlNotify (const char *url
, NPReason reason
, void *notifyData
);
62 void Print (NPPrint
*platformPrint
);
63 int16_t EventHandle (void *event
);
64 /* @GenerateCBinding,GeneratePInvoke */
65 void ReportException (char *msg
, char *details
, /* @MarshalAs=string[] */ char **stack_trace
, int num_frames
);
66 /* @GenerateCBinding,GeneratePInvoke */
67 void *Evaluate (const char *code
);
71 /* @GenerateCBinding,GeneratePInvoke */
72 void *GetBrowserHost () { return GetHost (); } // same as GetHost, just without bleeding NPObjects into the cbindings
74 void AddWrappedObject (EventObject
*obj
, NPObject
*wrapper
);
75 void RemoveWrappedObject (EventObject
*obj
);
76 NPObject
*LookupWrappedObject (EventObject
*obj
);
78 void AddCleanupPointer (gpointer p
);
79 void RemoveCleanupPointer (gpointer p
);
81 // [Obselete (this is obsolete in SL b2)]
82 guint32
TimeoutAdd (gint32 interval
, GSourceFunc callback
, gpointer data
);
83 // [Obselete (this is obsolete in SL b2)]
84 void TimeoutStop (guint32 source_id
);
88 // Property getters and setters
89 /* @GenerateCBinding,GeneratePInvoke */
90 const char *GetInitParams () { return this->initParams
; }
91 void SetInitParams (const char *value
);
92 /* @GenerateCBinding,GeneratePInvoke */
93 const char *GetSource () { return this->source
; }
94 /* @GenerateCBinding,GeneratePInvoke */
95 const char *GetSourceOriginal () { return this->source_original
; }
96 /* @GenerateCBinding,GeneratePInvoke */
97 const char *GetSourceLocation () { return this->source_location
; }
98 /* @GenerateCBinding,GeneratePInvoke */
99 const char *GetSourceLocationOriginal () { return this->source_location_original
; }
100 char *GetId () { return this->id
; }
102 void SetSource (const char *value
);
104 char *GetBackground ();
105 bool SetBackground (const char *value
);
106 bool GetEnableFramerateCounter ();
107 void SetEnableFramerateCounter (bool value
);
108 bool GetEnableRedrawRegions ();
109 void SetEnableRedrawRegions (bool value
);
110 /* @GenerateCBinding,GeneratePInvoke */
111 bool GetEnableHtmlAccess ();
112 /* @GenerateCBinding,GeneratePInvoke */
113 bool GetAllowHtmlPopupWindow ();
114 /* @GenerateCBinding,GeneratePInvoke */
115 bool GetWindowless ();
118 void SetMaxFrameRate (int value
);
119 int GetMaxFrameRate ();
120 Deployment
*GetDeployment ();
122 BrowserBridge
*GetBridge () { return bridge
; }
124 MoonlightScriptControlObject
*GetRootObject ();
126 NPWindow
*GetWindow ();
127 /* @GenerateCBinding,GeneratePInvoke */
128 Surface
*GetSurface () { return surface
; }
130 /* @GenerateCBinding,GeneratePInvoke */
131 gint32
GetActualHeight ();
132 /* @GenerateCBinding,GeneratePInvoke */
133 gint32
GetActualWidth ();
135 bool IsCrossDomainApplication () { return cross_domain_app
; }
137 static gboolean
plugin_button_press_callback (GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
);
139 static Downloader
*CreateDownloader (PluginInstance
*instance
);
142 struct moon_source
: List::Node
{
145 virtual ~moon_source ()
151 void AddSource (const char *uri
, const char *filename
);
156 static bool MonoIsLoaded ();
157 static bool DeploymentInit ();
159 bool InitializePluginAppDomain ();
160 bool CreatePluginDeployment ();
162 gpointer
ManagedCreateXamlLoaderForFile (XamlLoader
* loader
, const char *resourceBase
, const char *file
);
163 gpointer
ManagedCreateXamlLoaderForString (XamlLoader
* loader
, const char *resourceBase
, const char *str
);
164 void ManagedLoaderDestroy (gpointer loader_object
);
173 GtkWidget
*container
; // plugin container object
174 Surface
*surface
; // plugin surface object
175 MoonWindow
*moon_window
;
180 guint16 mode
; // NP_EMBED, NP_FULL, or NP_BACKGROUND
181 NPWindow
*window
; // Mozilla window object
182 NPP instance
; // Mozilla instance object
183 NPObject
*rootobject
; // Mozilla jscript object wrapper
184 guint32 xembed_supported
; // XEmbed Extension supported
186 GHashTable
*wrapped_objects
; // wrapped object cache
188 GSList
*cleanup_pointers
;
193 char *source_original
;
194 char *source_location
;
195 char *source_location_original
;
202 char *splashscreensource
;
203 char *onSourceDownloadProgressChanged
;
204 char *onSourceDownloadComplete
;
212 bool cross_domain_app
;
213 bool default_enable_html_access
;
214 bool enable_html_access
;
215 bool allow_html_popup_window
;
216 bool enable_framerate_counter
;
221 BrowserBridge
*bridge
;
223 GtkWidget
*properties_fps_label
;
224 GtkWidget
*properties_cache_label
;
227 // The XAML loader, contains a handle to a MonoObject *
229 PluginXamlLoader
*xaml_loader
;
230 Deployment
*deployment
;
232 MonoAssembly
*system_windows_assembly
;
234 static bool mono_is_loaded
;
237 MonoMethod
*moon_load_xaml
;
238 MonoMethod
*moon_initialize_deployment_xap
;
239 MonoMethod
*moon_initialize_deployment_xaml
;
240 MonoMethod
*moon_destroy_application
;
242 MonoClass
*moon_exception
;
243 MonoProperty
*moon_exception_message
;
244 MonoProperty
*moon_exception_error_code
;
246 void LoadXAP (const char*url
, const char *fname
);
247 void DestroyApplication ();
249 MonoMethod
*MonoGetMethodFromName (MonoClass
*klass
, const char *name
, int narg
);
250 MonoProperty
*MonoGetPropertyFromName (MonoClass
*klass
, const char *name
);
252 ErrorEventArgs
* ManagedExceptionToErrorEventArgs (MonoObject
*exc
);
254 bool ManagedInitializeDeployment (const char *file
);
255 void ManagedDestroyApplication ();
257 gpointer
ManagedCreateXamlLoader (XamlLoader
* native_loader
, const char *resourceBase
, const char *file
, const char *str
);
260 // The name of the file that we are missing, and we requested to be loaded
261 char *vm_missing_file
;
264 void CreateWindow ();
265 void UpdateSource ();
266 void UpdateSourceByReference (const char *value
);
269 char* GetPageLocation ();
270 void CrossDomainApplicationCheck (const char *source
);
272 void TryLoadBridge (const char *prefix
);
274 static gboolean
IdleUpdateSourceByReference (gpointer data
);
276 static void ReportFPS (Surface
*surface
, int nframes
, float nsecs
, void *user_data
);
277 static void ReportCache (Surface
*surface
, long bytes
, void *user_data
);
278 static void properties_dialog_response (GtkWidget
*dialog
, int response
, PluginInstance
*plugin
);
280 static void network_error_tickcall (EventObject
*data
);
281 static void splashscreen_error_tickcall (EventObject
*data
);
284 extern GSList
*plugin_instances
;
286 #define NPID(x) NPN_GetStringIdentifier (x)
288 #define STRDUP_FROM_VARIANT(v) (g_strndup ((char *) NPVARIANT_TO_STRING (v).utf8characters, NPVARIANT_TO_STRING (v).utf8length))
289 #define STRLEN_FROM_VARIANT(v) ((size_t) NPVARIANT_TO_STRING (v).utf8length)
291 #define STREAM_NOTIFY(x) ((StreamNotify*) x)
293 #define STREAM_NOTIFY_DATA(x) ((StreamNotify*) x)->pdata
295 #define IS_NOTIFY_SOURCE(x) \
296 (!x ? true : (((StreamNotify*) x)->type == StreamNotify::SOURCE))
298 #define IS_NOTIFY_SPLASHSOURCE(x) \
299 (!x ? true : (((StreamNotify*) x)->type == StreamNotify::SPLASHSOURCE))
301 #define IS_NOTIFY_DOWNLOADER(x) \
302 (!x ? StreamNotify::NONE : (((StreamNotify*) x)->type == StreamNotify::DOWNLOADER))
304 #define IS_NOTIFY_REQUEST(x) \
305 (!x ? StreamNotify::NONE : (((StreamNotify*) x)->type == StreamNotify::REQUEST))
310 enum StreamNotifyFlags
{
318 StreamNotifyFlags type
;
321 StreamNotify () : type (NONE
), pdata (NULL
) {};
322 StreamNotify (void *data
) : type (NONE
), pdata (data
) {};
323 StreamNotify (StreamNotifyFlags type
) : type (type
), pdata (NULL
) {};
324 StreamNotify (StreamNotifyFlags type
, void *data
) : type (type
), pdata (data
) {};
325 StreamNotify (StreamNotifyFlags type
, DependencyObject
*dob
) : type (type
), pdata (dob
)
333 if (type
== DOWNLOADER
&& pdata
)
334 ((DependencyObject
*) pdata
)->unref ();
338 class PluginXamlLoader
: public XamlLoader
340 PluginXamlLoader (const char *resourceBase
, const char *filename
, const char *str
, PluginInstance
*plugin
, Surface
*surface
);
341 bool InitializeLoader ();
342 PluginInstance
*plugin
;
344 bool xaml_is_managed
;
347 gpointer managed_loader
;
351 virtual ~PluginXamlLoader ();
352 const char *TryLoad (int *error
);
354 bool SetProperty (void *parser
, Value
*top_level
, const char *xmlns
, Value
*target
, void *target_data
, Value
*target_parent
, const char *prop_xmlns
, const char *name
, Value
* value
, void* value_data
, int flags
= 0);
356 static PluginXamlLoader
*FromFilename (const char *resourceBase
, const char *filename
, PluginInstance
*plugin
, Surface
*surface
)
358 return new PluginXamlLoader (resourceBase
, filename
, NULL
, plugin
, surface
);
361 static PluginXamlLoader
*FromStr (const char *resourceBase
, const char *str
, PluginInstance
*plugin
, Surface
*surface
)
363 return new PluginXamlLoader (resourceBase
, NULL
, str
, plugin
, surface
);
366 bool IsManaged () { return xaml_is_managed
; }
368 virtual bool LoadVM ();
373 const char *get_plugin_dir (void);
375 char *plugin_instance_get_id (PluginInstance
*instance
);
377 void plugin_instance_get_browser_runtime_settings (bool *debug
, bool *html_access
,
378 bool *httpnet_access
, bool *script_access
);
380 void *plugin_instance_load_url (PluginInstance
*instance
, char *url
, gint32
*length
);
382 PluginXamlLoader
*plugin_xaml_loader_from_str (const char *str
, const char *resourceBase
, PluginInstance
*plugin
, Surface
*surface
);
386 #endif /* MOON_PLUGIN */