This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
/
plugin-glue.cpp
261 lines (200 loc) · 5.98 KB
/
plugin-glue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* plugin-glue.cpp: MoonLight browser plugin.
*
* Contact:
* Moonlight List (moonlight-list@lists.ximian.com)
*
* Copyright 2007 Novell, Inc. (http://www.novell.com)
*
* See the LICENSE file included with the distribution for details.
*
*/
#include <config.h>
#include "moonlight.h"
#include "plugin.h"
#include "plugin-class.h"
#include "plugin-downloader.h"
/* the number of plugin instances running in the browser */
static int browser_plugins = 0;
NPError
MOON_NPP_New (NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved)
{
if (!instance)
return NPERR_INVALID_INSTANCE_ERROR;
PluginInstance *plugin = new PluginInstance (instance, mode);
if (plugin == NULL)
return NPERR_OUT_OF_MEMORY_ERROR;
browser_plugins++;
plugin->Initialize (argc, argn, argv);
instance->pdata = plugin;
return NPERR_NO_ERROR;
}
NPError
MOON_NPP_Destroy (NPP instance, NPSavedData **save)
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
Deployment::SetCurrent (plugin->GetDeployment ());
plugin->Shutdown ();
instance->pdata = NULL;
plugin->unref ();
browser_plugins--;
return NPERR_NO_ERROR;
}
NPError
MOON_NPP_SetWindow (NPP instance, NPWindow *window)
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
return plugin->SetWindow (window);
}
NPError
MOON_NPP_NewStream (NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16_t *stype)
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
return plugin->NewStream (type, stream, seekable, stype);
}
NPError
MOON_NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason)
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
return plugin->DestroyStream (stream, reason);
}
void
MOON_NPP_StreamAsFile (NPP instance, NPStream *stream, const char *fname)
{
if (instance == NULL)
return;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
plugin->StreamAsFile (stream, fname);
}
int32_t
MOON_NPP_WriteReady (NPP instance, NPStream *stream)
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
return plugin->WriteReady (stream);
}
int32_t
MOON_NPP_Write (NPP instance, NPStream *stream, int32_t offset, int32_t len, void *buffer)
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
return plugin->Write (stream, offset, len, buffer);
}
void
MOON_NPP_Print (NPP instance, NPPrint *platformPrint)
{
if (instance == NULL)
return;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
plugin->Print (platformPrint);
}
void
MOON_NPP_URLNotify (NPP instance, const char *url, NPReason reason, void *notifyData)
{
if (instance == NULL)
return;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
plugin->UrlNotify (url, reason, notifyData);
}
int16_t
MOON_NPP_HandleEvent (NPP instance, void *event)
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
return plugin->EventHandle (event);
}
NPError
MOON_NPP_GetValue (NPP instance, NPPVariable variable, void *result)
{
NPError err = NPERR_NO_ERROR;
switch (variable) {
case NPPVpluginNeedsXEmbed:
*((NPBool *)result) = true;
break;
case NPPVpluginNameString:
*((char **)result) = (char *) PLUGIN_NAME;
break;
case NPPVpluginDescriptionString:
*((char **)result) = (char *) PLUGIN_DESCRIPTION;
break;
default:
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
err = plugin->GetValue (variable, result);
break;
}
return err;
}
NPError
MOON_NPP_SetValue (NPP instance, NPNVariable variable, void *value)
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
PluginInstance *plugin = (PluginInstance *) instance->pdata;
return plugin->SetValue (variable, value);
}
char *
MOON_NPP_GetMIMEDescription (void)
{
return (char *) (MIME_TYPES_HANDLED);
}
static bool runtime_initialized = false;
NPError
MOON_NPP_Initialize (void)
{
NPNToolkitType toolkit = (NPNToolkitType)0;
MOON_NPN_GetValue (NULL, NPNVToolkit, &toolkit);
if (toolkit != (NPNToolkitType)NPNVGtk2) {
g_warning ("we don't have the toolkit we need");
return NPERR_INCOMPATIBLE_VERSION_ERROR;
}
// We dont need to initialize mono vm and gtk more than one time.
if (!g_thread_supported ()) {
g_warning ("host has not initialized threads");
//g_thread_init (NULL);
}
downloader_initialize ();
if (!runtime_initialized) {
runtime_initialized = true;
runtime_init_browser (get_plugin_dir ());
}
plugin_init_classes ();
return NPERR_NO_ERROR;
}
static gboolean
shutdown_moonlight (gpointer data)
{
/* check if we still should be shutting down */
if (browser_plugins != 0)
return false; /* another plugin instance has been created after shutting down the last one earlier */
/* check if all deployments and all plugins have been freed. */
if (Deployment::GetDeploymentCount () != 0 || PluginInstance::GetPluginCount () != 0) {
// printf ("shutdown_moonlight (): there are %i deployments and %i plugins left, postponing shutdown a bit.\n", Deployment::GetDeploymentCount (), PluginInstance::GetPluginCount ());
g_timeout_add_full (100, G_PRIORITY_DEFAULT_IDLE, shutdown_moonlight, NULL, NULL);
return FALSE;
}
// printf ("shutdown_moonlight (): proceeding with shutdown, there are no more deployments nor plugins left.\n");
downloader_destroy ();
plugin_destroy_classes ();
runtime_shutdown ();
runtime_initialized = false;
return FALSE;
}
void
MOON_NPP_Shutdown (void)
{
shutdown_moonlight (NULL);
}