~ubuntu-branches/ubuntu/karmic/moon/karmic

« back to all changes in this revision

Viewing changes to plugin/plugin.h

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-14 12:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090214120108-06539vb25vhbd8bn
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 * plugin.h: MoonLight browser plugin.
 
4
 *
 
5
 * Contact:
 
6
 *   Moonlight List (moonlight-list@lists.ximian.com)
 
7
 *
 
8
 * Copyright 2007 Novell, Inc. (http://www.novell.com)
 
9
 *
 
10
 * See the LICENSE file included with the distribution for details.
 
11
 *
 
12
 */
 
13
 
 
14
#ifndef MOON_PLUGIN
 
15
#define MOON_PLUGIN
 
16
 
 
17
#include "moonlight.h"
 
18
 
 
19
class MoonlightScriptControlObject;
 
20
class PluginXamlLoader;
 
21
class PluginInstance;
 
22
class BrowserBridge;
 
23
#if PLUGIN_SL_2_0
 
24
class Xap;
 
25
#endif
 
26
 
 
27
typedef void plugin_unload_callback (PluginInstance *plugin);
 
28
char *NPN_strdup (const char *val);
 
29
 
 
30
class PluginInstance
 
31
{
 
32
 public:
 
33
        PluginInstance (NPMIMEType pluginType, NPP instance, uint16_t mode);
 
34
        ~PluginInstance ();
 
35
        
 
36
        void SetUnloadCallback (plugin_unload_callback *puc);
 
37
        void Initialize (int argc, char *const argn[], char *const argv[]);
 
38
        void Finalize ();
 
39
        
 
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);
 
55
        
 
56
        NPObject *GetHost ();
 
57
        
 
58
        void      AddWrappedObject    (EventObject *obj, NPObject *wrapper);
 
59
        void      RemoveWrappedObject (EventObject *obj);
 
60
        NPObject *LookupWrappedObject (EventObject *obj);
 
61
        
 
62
        void      AddCleanupPointer    (gpointer p);
 
63
        void      RemoveCleanupPointer (gpointer p);
 
64
        
 
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);
 
69
        
 
70
        void Properties ();
 
71
        
 
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; }
 
77
        
 
78
        void SetSource (const char *value);
 
79
        
 
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 ();
 
89
        
 
90
        BrowserBridge *GetBridge () { return bridge; }
 
91
        
 
92
        MoonlightScriptControlObject *GetRootObject ();
 
93
        NPP GetInstance ();
 
94
        NPWindow *GetWindow ();
 
95
        Surface *GetSurface () { return surface; }
 
96
        
 
97
        int32_t GetActualHeight ();
 
98
        int32_t GetActualWidth ();
 
99
        
 
100
        void GetBrowserInformation (char **name, char **version,
 
101
                                    char **platform, char **userAgent,
 
102
                                    bool *cookieEnabled);
 
103
        bool IsSilverlight2 () { return silverlight2; } 
 
104
        
 
105
        static gboolean plugin_button_press_callback (GtkWidget *widget, GdkEventButton *event, gpointer user_data);
 
106
        
 
107
        static Downloader *CreateDownloader (PluginInstance *instance);
 
108
        
 
109
#if DEBUG
 
110
        struct moon_source : List::Node {
 
111
                char *uri;
 
112
                char *filename;
 
113
                virtual ~moon_source ()
 
114
                {
 
115
                        g_free (uri);
 
116
                        g_free (filename);
 
117
                }
 
118
        };
 
119
        void AddSource (const char *uri, const char *filename);
 
120
        List *GetSources ();
 
121
#endif
 
122
        
 
123
 private:
 
124
#if DEBUG
 
125
        List *moon_sources;
 
126
#endif
 
127
 
 
128
        // Gtk controls
 
129
        GtkWidget *container;  // plugin container object
 
130
        Surface *surface;      // plugin surface object
 
131
        MoonWindow *moon_window;
 
132
        GdkDisplay *display;
 
133
 
 
134
        GSList *timers;
 
135
 
 
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
 
141
 
 
142
        GHashTable *wrapped_objects; // wrapped object cache
 
143
 
 
144
        GSList *cleanup_pointers;
 
145
 
 
146
        // Property fields
 
147
        char *initParams;
 
148
        char *source;
 
149
        char *source_location;
 
150
        guint source_idle;
 
151
        char *onLoad;
 
152
        char *background;
 
153
        char *onError;
 
154
        char *onResize;
 
155
        char *id;
 
156
 
 
157
        bool windowless;
 
158
        bool silverlight2;
 
159
        int maxFrameRate;
 
160
 
 
161
        BrowserBridge *bridge;
 
162
 
 
163
        GtkWidget *properties_fps_label;
 
164
        GtkWidget *properties_cache_label;
 
165
 
 
166
        //
 
167
        // The XAML loader, contains a handle to a MonoObject *
 
168
        //
 
169
        PluginXamlLoader *xaml_loader;
 
170
#if PLUGIN_SL_2_0
 
171
        bool xap_loaded;
 
172
#endif
 
173
        
 
174
        //
 
175
        // A (managed) callback to call when the plugin is unloaded.
 
176
        //
 
177
        plugin_unload_callback *plugin_unload;
 
178
 
 
179
        // The name of the file that we are missing, and we requested to be loaded
 
180
        char *vm_missing_file;
 
181
 
 
182
        // Private methods
 
183
        void CreateWindow ();
 
184
        void UpdateSource ();
 
185
        void UpdateSourceByReference (const char *value);
 
186
        void LoadXAML ();
 
187
#if PLUGIN_SL_2_0
 
188
        void LoadXAP  (const char *fname);
 
189
        void DestroyApplication ();
 
190
#endif
 
191
        void SetPageURL ();
 
192
 
 
193
        void TryLoadBridge (const char *prefix);
 
194
        
 
195
        static gboolean IdleUpdateSourceByReference (gpointer data);
 
196
 
 
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);
 
200
};
 
201
 
 
202
extern GSList *plugin_instances;
 
203
 
 
204
#define NPID(x) NPN_GetStringIdentifier (x)
 
205
 
 
206
#define STREAM_NOTIFY(x) ((StreamNotify*) x)
 
207
 
 
208
#define STREAM_NOTIFY_DATA(x) ((StreamNotify*) x)->pdata
 
209
 
 
210
#define IS_NOTIFY_SOURCE(x) \
 
211
        (!x ? true : (((StreamNotify*) x)->type == StreamNotify::SOURCE))
 
212
 
 
213
#define IS_NOTIFY_DOWNLOADER(x) \
 
214
        (!x ? StreamNotify::NONE : (((StreamNotify*) x)->type == StreamNotify::DOWNLOADER))
 
215
 
 
216
#define IS_NOTIFY_REQUEST(x) \
 
217
        (!x ? StreamNotify::NONE : (((StreamNotify*) x)->type == StreamNotify::REQUEST))
 
218
 
 
219
class StreamNotify
 
220
{
 
221
 public:
 
222
        enum StreamNotifyFlags {
 
223
                NONE = 0,
 
224
                SOURCE = 1,
 
225
                DOWNLOADER = 2,
 
226
                REQUEST = 3
 
227
        };
 
228
        
 
229
        StreamNotifyFlags type;
 
230
        void *pdata;
 
231
        
 
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)
 
237
        {
 
238
                if (dob)
 
239
                        dob->ref ();
 
240
        }
 
241
        
 
242
        ~StreamNotify ()
 
243
        {
 
244
                if (type == DOWNLOADER && pdata)
 
245
                        ((DependencyObject *) pdata)->unref ();
 
246
        }
 
247
};
 
248
 
 
249
class PluginXamlLoader : public XamlLoader
 
250
{
 
251
        PluginXamlLoader (const char *filename, const char *str, PluginInstance *plugin, Surface *surface);
 
252
        bool InitializeLoader ();
 
253
        PluginInstance *plugin;
 
254
        bool initialized;
 
255
        bool xaml_is_managed;
 
256
        
 
257
#if PLUGIN_SL_2_0
 
258
        gpointer managed_loader;
 
259
        Xap *xap;
 
260
#endif
 
261
 public:
 
262
        virtual ~PluginXamlLoader ();
 
263
        const char *TryLoad (int *error);
 
264
        
 
265
        static PluginXamlLoader *FromFilename (const char *filename, PluginInstance *plugin, Surface *surface)
 
266
        {
 
267
                return new PluginXamlLoader (filename, NULL, plugin, surface);
 
268
        }
 
269
        
 
270
        static PluginXamlLoader *FromStr (const char *str, PluginInstance *plugin, Surface *surface)
 
271
        {
 
272
                return new PluginXamlLoader (NULL, str, plugin, surface);
 
273
        }
 
274
        
 
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 ();
 
278
};
 
279
 
 
280
G_BEGIN_DECLS
 
281
 
 
282
int32_t plugin_instance_get_actual_width  (PluginInstance *instance);
 
283
int32_t plugin_instance_get_actual_height (PluginInstance *instance);
 
284
 
 
285
Surface *plugin_instance_get_surface (PluginInstance *instance);
 
286
 
 
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);
 
290
 
 
291
void plugin_instance_get_browser_information (PluginInstance *instance,
 
292
                                              char **name, char **version,
 
293
                                              char **platform, char **userAgent,
 
294
                                              bool *cookieEnabled);
 
295
 
 
296
void plugin_instance_get_browser_runtime_settings (bool *debug, bool *html_access,
 
297
                                                   bool *httpnet_access, bool *script_access);
 
298
 
 
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);
 
301
 
 
302
void *plugin_instance_evaluate (PluginInstance *instance, const char *code);
 
303
 
 
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);
 
306
 
 
307
G_END_DECLS
 
308
 
 
309
#endif /* MOON_PLUGIN */