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"
19
class MoonlightScriptControlObject;
20
class PluginXamlLoader;
27
typedef void plugin_unload_callback (PluginInstance *plugin);
28
char *NPN_strdup (const char *val);
33
PluginInstance (NPMIMEType pluginType, NPP instance, uint16_t mode);
36
void SetUnloadCallback (plugin_unload_callback *puc);
37
void Initialize (int argc, char *const argn[], char *const argv[]);
40
// Mozilla plugin related methods
41
NPError GetValue (NPPVariable variable, void *result);
42
NPError SetValue (NPNVariable variable, void *value);
43
NPError SetWindow (NPWindow *window);
44
NPError NewStream (NPMIMEType type, NPStream *stream, NPBool seekable, uint16_t *stype);
45
NPError DestroyStream (NPStream *stream, NPError reason);
46
void StreamAsFile (NPStream *stream, const char *fname);
47
int32_t WriteReady (NPStream *stream);
48
int32_t Write (NPStream *stream, int32_t offset, int32_t len, void *buffer);
49
void UrlNotify (const char *url, NPReason reason, void *notifyData);
50
void Print (NPPrint *platformPrint);
51
int16_t EventHandle (void *event);
52
void ReportException (char *msg, char *details, char **stack_trace, int num_frames);
53
void *LoadUrl (char *url, int32_t *length);
54
void *Evaluate (const char *code);
58
void AddWrappedObject (EventObject *obj, NPObject *wrapper);
59
void RemoveWrappedObject (EventObject *obj);
60
NPObject *LookupWrappedObject (EventObject *obj);
62
void AddCleanupPointer (gpointer p);
63
void RemoveCleanupPointer (gpointer p);
65
// [Obselete (this is obsolete in SL b2)]
66
uint32_t TimeoutAdd (int32_t interval, GSourceFunc callback, gpointer data);
67
// [Obselete (this is obsolete in SL b2)]
68
void TimeoutStop (uint32_t source_id);
72
// Property getters and setters
73
char *GetInitParams () { return this->initParams; }
74
char *GetSource () { return this->source; }
75
char *GetSourceLocation () { return this->source_location; }
76
char *GetId () { return this->id; }
78
void SetSource (const char *value);
80
char *GetBackground ();
81
bool SetBackground (const char *value);
82
bool GetEnableFramerateCounter ();
83
bool GetEnableRedrawRegions ();
84
void SetEnableRedrawRegions (bool value);
85
bool GetEnableHtmlAccess ();
86
bool GetWindowless ();
87
void SetMaxFrameRate (int value);
88
int GetMaxFrameRate ();
90
BrowserBridge *GetBridge () { return bridge; }
92
MoonlightScriptControlObject *GetRootObject ();
94
NPWindow *GetWindow ();
95
Surface *GetSurface () { return surface; }
97
int32_t GetActualHeight ();
98
int32_t GetActualWidth ();
100
void GetBrowserInformation (char **name, char **version,
101
char **platform, char **userAgent,
102
bool *cookieEnabled);
103
bool IsSilverlight2 () { return silverlight2; }
105
static gboolean plugin_button_press_callback (GtkWidget *widget, GdkEventButton *event, gpointer user_data);
107
static Downloader *CreateDownloader (PluginInstance *instance);
110
struct moon_source : List::Node {
113
virtual ~moon_source ()
119
void AddSource (const char *uri, const char *filename);
129
GtkWidget *container; // plugin container object
130
Surface *surface; // plugin surface object
131
MoonWindow *moon_window;
136
uint16_t mode; // NP_EMBED, NP_FULL, or NP_BACKGROUND
137
NPWindow *window; // Mozilla window object
138
NPP instance; // Mozilla instance object
139
NPObject *rootobject; // Mozilla jscript object wrapper
140
bool xembed_supported; // XEmbed Extension supported
142
GHashTable *wrapped_objects; // wrapped object cache
144
GSList *cleanup_pointers;
149
char *source_location;
161
BrowserBridge *bridge;
163
GtkWidget *properties_fps_label;
164
GtkWidget *properties_cache_label;
167
// The XAML loader, contains a handle to a MonoObject *
169
PluginXamlLoader *xaml_loader;
175
// A (managed) callback to call when the plugin is unloaded.
177
plugin_unload_callback *plugin_unload;
179
// The name of the file that we are missing, and we requested to be loaded
180
char *vm_missing_file;
183
void CreateWindow ();
184
void UpdateSource ();
185
void UpdateSourceByReference (const char *value);
188
void LoadXAP (const char *fname);
189
void DestroyApplication ();
193
void TryLoadBridge (const char *prefix);
195
static gboolean IdleUpdateSourceByReference (gpointer data);
197
static void ReportFPS (Surface *surface, int nframes, float nsecs, void *user_data);
198
static void ReportCache (Surface *surface, long bytes, void *user_data);
199
static void properties_dialog_response (GtkWidget *dialog, int response, PluginInstance *plugin);
202
extern GSList *plugin_instances;
204
#define NPID(x) NPN_GetStringIdentifier (x)
206
#define STREAM_NOTIFY(x) ((StreamNotify*) x)
208
#define STREAM_NOTIFY_DATA(x) ((StreamNotify*) x)->pdata
210
#define IS_NOTIFY_SOURCE(x) \
211
(!x ? true : (((StreamNotify*) x)->type == StreamNotify::SOURCE))
213
#define IS_NOTIFY_DOWNLOADER(x) \
214
(!x ? StreamNotify::NONE : (((StreamNotify*) x)->type == StreamNotify::DOWNLOADER))
216
#define IS_NOTIFY_REQUEST(x) \
217
(!x ? StreamNotify::NONE : (((StreamNotify*) x)->type == StreamNotify::REQUEST))
222
enum StreamNotifyFlags {
229
StreamNotifyFlags type;
232
StreamNotify () : type (NONE), pdata (NULL) {};
233
StreamNotify (void *data) : type (NONE), pdata (data) {};
234
StreamNotify (StreamNotifyFlags type) : type (type), pdata (NULL) {};
235
StreamNotify (StreamNotifyFlags type, void *data) : type (type), pdata (data) {};
236
StreamNotify (StreamNotifyFlags type, DependencyObject *dob) : type (type), pdata (dob)
244
if (type == DOWNLOADER && pdata)
245
((DependencyObject *) pdata)->unref ();
249
class PluginXamlLoader : public XamlLoader
251
PluginXamlLoader (const char *filename, const char *str, PluginInstance *plugin, Surface *surface);
252
bool InitializeLoader ();
253
PluginInstance *plugin;
255
bool xaml_is_managed;
258
gpointer managed_loader;
262
virtual ~PluginXamlLoader ();
263
const char *TryLoad (int *error);
265
static PluginXamlLoader *FromFilename (const char *filename, PluginInstance *plugin, Surface *surface)
267
return new PluginXamlLoader (filename, NULL, plugin, surface);
270
static PluginXamlLoader *FromStr (const char *str, PluginInstance *plugin, Surface *surface)
272
return new PluginXamlLoader (NULL, str, plugin, surface);
275
bool IsManaged () { return xaml_is_managed; }
276
virtual bool HookupEvent (void *target, void *dest, const char *name, const char *value);
277
virtual bool LoadVM ();
282
int32_t plugin_instance_get_actual_width (PluginInstance *instance);
283
int32_t plugin_instance_get_actual_height (PluginInstance *instance);
285
Surface *plugin_instance_get_surface (PluginInstance *instance);
287
char *plugin_instance_get_init_params (PluginInstance *instance);
288
char *plugin_instance_get_source (PluginInstance *instance);
289
char *plugin_instance_get_source_location (PluginInstance *instance);
291
void plugin_instance_get_browser_information (PluginInstance *instance,
292
char **name, char **version,
293
char **platform, char **userAgent,
294
bool *cookieEnabled);
296
void plugin_instance_get_browser_runtime_settings (bool *debug, bool *html_access,
297
bool *httpnet_access, bool *script_access);
299
void plugin_instance_report_exception (PluginInstance *instance, char *msg, char *details, char **stack_trace, int num_frames);
300
void *plugin_instance_load_url (PluginInstance *instance, char *url, int32_t *length);
302
void *plugin_instance_evaluate (PluginInstance *instance, const char *code);
304
void plugin_set_unload_callback (PluginInstance *instance, plugin_unload_callback *puc);
305
PluginXamlLoader *plugin_xaml_loader_from_str (const char *str, PluginInstance *plugin, Surface *surface);
309
#endif /* MOON_PLUGIN */