4 * Implementations of plugin API functions
8 NPP_GetMIMEDescription (void)
10 return (MIME_TYPES_HANDLED
);
13 /* TODO: set this variables at the right place to enable scriptability
14 * NPPVpluginScriptableInstance
15 * NPPVpluginScriptableIID
19 NPP_GetValue (NPP instance
, NPPVariable variable
, void *value
)
22 NPError err
= NPERR_NO_ERROR
;
25 case NPPVpluginNameString
:
26 *((char **) value
) = PLUGIN_NAME
;
28 case NPPVpluginDescriptionString
:
29 *((char **) value
) = PLUGIN_DESCRIPTION
;
31 case NPPVpluginScriptableNPObject
:
32 pi
= (PluginInstance
*) instance
->pdata
;
33 *(NPObject
**) value
= mep_getscriptableobject (pi
);
36 err
= NPERR_GENERIC_ERROR
;
42 NPP_HandleEvent (NPP instance
, void *event
)
45 * needed for windowless mode
47 XEvent
*ev
= (XEvent
*) event
;
48 printf ("event occured\n");
56 ecore_config_init ("mozilla_edje_plugin");
60 return NPERR_NO_ERROR
;
76 ecore_config_shutdown ();
81 NPP_New (NPMIMEType pluginType
,
90 return NPERR_INVALID_INSTANCE_ERROR
;
91 instance
->pdata
= NPN_MemAlloc (sizeof (PluginInstance
));
93 PluginInstance
*pi
= (PluginInstance
*) instance
->pdata
;
95 return NPERR_OUT_OF_MEMORY_ERROR
;
96 memset(pi
, 0, sizeof (PluginInstance
));
98 /* mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h) */
100 pi
->type
= strdup ("application/edje");
101 pi
->instance
= instance
;
103 pi
->pluginsPageUrl
= NULL
;
106 /* Parse argument list passed to plugin instance */
107 /* We are interested in these arguments
108 * PLUGINSPAGE = <url>
113 if (argv
[argc
] != NULL
)
115 if (!PL_strcasecmp (argn
[argc
], "PLUGINSPAGE"))
116 pi
->pluginsPageUrl
= strdup (argv
[argc
]);
117 else if (!PL_strcasecmp (argn
[argc
], "PLUGINURL"))
118 pi
->pluginsFileUrl
= strdup (argv
[argc
]);
119 else if (!PL_strcasecmp (argn
[argc
], "CODEBASE"))
120 pi
->pluginsPageUrl
= strdup (argv
[argc
]);
121 else if (!PL_strcasecmp (argn
[argc
], "CLASSID"))
122 pi
->pluginsFileUrl
= strdup (argv
[argc
]);
123 else if (!PL_strcasecmp (argn
[argc
], "HIDDEN"))
124 pi
->pluginsHidden
= (!PL_strcasecmp (argv
[argc
], "TRUE"));
125 else if (!PL_strcasecmp (argn
[argc
], "DATA"))
126 pi
->data
= strdup (argv
[argc
]);
127 else if (!PL_strcasecmp (argn
[argc
], "GROUP"))
128 pi
->group
= strdup (argv
[argc
]);
129 else if (!PL_strcasecmp (argn
[argc
], "THEME"))
130 pi
->theme
= strdup (argv
[argc
]);
134 // create evas for this plugin instance
135 pi
->evas
= evas_new ();
137 // configure plugin instance
142 if (NPN_SetValue (instance, NPPVpluginWindowBool, FALSE))
143 printf ("could not set windowless mode\n");
144 if (NPN_SetValue (instance, NPPVpluginTransparentBool, TRUE))
145 printf ("could not set transparent mode\n");
148 return NPERR_NO_ERROR
;
152 NPP_Destroy (NPP instance
, NPSavedData
** save
)
154 if (instance
== NULL
)
155 return NPERR_INVALID_INSTANCE_ERROR
;
157 PluginInstance
*pi
= (PluginInstance
*) instance
->pdata
;
163 NPN_MemFree(pi
->type
);
164 if (pi
->pluginsPageUrl
)
165 NPN_MemFree(pi
->pluginsPageUrl
);
166 if (pi
->pluginsFileUrl
)
167 NPN_MemFree(pi
->pluginsFileUrl
);
169 evas_object_del (pi
->edj
);
171 evas_object_del (pi
->skin
);
173 evas_free (pi
->evas
);
175 NPN_MemFree (pi
->data
);
177 NPN_MemFree (pi
->group
);
179 NPN_MemFree (pi
->theme
);
180 if (pi
->config_theme
)
181 NPN_MemFree (pi
->config_theme
);
182 if (pi
->config_engine
)
183 NPN_MemFree (pi
->config_engine
);
184 NPN_MemFree(instance
->pdata
);
185 instance
->pdata
= NULL
;
188 return NPERR_NO_ERROR
;
192 NPP_SetWindow (NPP instance
, NPWindow
*window
)
194 if (instance
== NULL
)
195 return NPERR_INVALID_INSTANCE_ERROR
;
197 PluginInstance
*pi
= (PluginInstance
*) instance
->pdata
;
199 return NPERR_INVALID_INSTANCE_ERROR
;
201 NPSetWindowCallbackStruct
*ws_info
= (NPSetWindowCallbackStruct
*) window
->ws_info
;
203 if (pi
->window
== (Window
) window
->window
) {
204 /* The page with the plugin is being resized.
205 Save any UI information because the next time
206 around expect a SetWindow with a new window
210 fprintf(stderr, "plugin received window resize.\n");
211 fprintf(stderr, "Window=(%i)\n", (int)window);
212 fprintf(stderr, "W=(%i) H=(%i)\n",
213 (int)window->width, (int)window->height);
216 return NPERR_NO_ERROR
;
218 pi
->window
= (Window
) window
->window
;
221 pi
->width
= window
->width
;
222 pi
->height
= window
->height
;
223 pi
->display
= ws_info
->display
;
224 pi
->visual
= ws_info
->visual
;
225 pi
->depth
= ws_info
->depth
;
226 pi
->colormap
= ws_info
->colormap
;
228 int output_method
= evas_render_method_lookup (pi
->config_engine
);
229 evas_output_method_set (pi
->evas
, output_method
);
230 evas_output_size_set (pi
->evas
, pi
->width
, pi
->height
);
231 evas_output_viewport_set (pi
->evas
, 0, 0, pi
->width
, pi
->height
);
232 if (output_method
== evas_render_method_lookup ("software_x11"))
234 Evas_Engine_Info_Software_X11
*einfo
= (Evas_Engine_Info_Software_X11
*) evas_engine_info_get (pi
->evas
);
235 /* the following is specific to the engine */
236 einfo
->info
.display
= pi
->display
;
237 einfo
->info
.visual
= pi
->visual
;
238 einfo
->info
.colormap
= pi
->colormap
;
239 einfo
->info
.drawable
= (Drawable
) pi
->window
;
240 einfo
->info
.depth
= pi
->depth
;
241 einfo
->info
.rotation
= 0;
242 einfo
->info
.debug
= 0;
243 evas_engine_info_set(pi
->evas
, (Evas_Engine_Info
*) einfo
);
245 else if (output_method
== evas_render_method_lookup ("gl_x11"))
247 Evas_Engine_Info_GL_X11
*einfo
= (Evas_Engine_Info_GL_X11
*) evas_engine_info_get (pi
->evas
);
248 /* the following is specific to the engine */
249 einfo
->info
.display
= pi
->display
;
250 einfo
->info
.visual
= pi
->visual
;
251 einfo
->info
.colormap
= pi
->colormap
;
252 einfo
->info
.drawable
= pi
->window
;
253 einfo
->info
.depth
= pi
->depth
;
254 evas_engine_info_set(pi
->evas
, (Evas_Engine_Info
*) einfo
);
257 printf ("no supported engine found\n");
259 // add animator to render evas
260 ecore_animator_add (mep_animator
, pi
);
261 ecore_animator_frametime_set (1.0 / (float) pi
->config_fps
);
262 edje_frametime_set (1.0 / (float) pi
->config_fps
);
264 // add theme skin if stated
265 if (!strcmp (pi
->theme
, "none"))
269 else if (!strcmp (pi
->theme
, "user"))
271 pi
->skin
= edje_object_add (pi
->evas
);
273 sprintf (PATH
, "%s/%s", THEMESDIR
, pi
->config_theme
);
274 edje_object_file_set (pi
->skin
, PATH
, "mozilla_edje_plugin/theme");
275 evas_object_resize (pi
->skin
, pi
->width
, pi
->height
);
276 evas_object_show (pi
->skin
);
277 evas_object_focus_set (pi
->skin
, 1);
281 pi
->skin
= edje_object_add (pi
->evas
);
282 edje_object_file_set (pi
->skin
, pi
->theme
, "mozilla_edje_plugin/theme");
283 evas_object_resize (pi
->skin
, pi
->width
, pi
->height
);
284 evas_object_show (pi
->skin
);
285 evas_object_focus_set (pi
->skin
, 1);
288 pi
->edj
= edje_object_add (pi
->evas
);
289 edje_object_file_set (pi
->edj
, pi
->data
, pi
->group
);
290 evas_object_data_set (pi
->edj
, "pi", (void *) pi
);
292 evas_object_resize (pi
->edj
, pi
->width
, pi
->height
);
293 evas_object_show (pi
->edj
);
294 evas_object_focus_set (pi
->edj
, 1);
295 evas_event_feed_mouse_in (pi
->evas
, 0, NULL
);
297 if (pi
->skin
) // if not none
299 edje_object_part_swallow (pi
->skin
, "data", pi
->edj
);
300 edje_object_signal_callback_add (pi
->skin
, "ui,play", "*", mep_cb_ui_play
, pi
);
301 edje_object_signal_callback_add (pi
->skin
, "ui,pause", "*", mep_cb_ui_pause
, pi
);
302 edje_object_signal_callback_add (pi
->skin
, "ui,config", "*", mep_cb_ui_config
, pi
);
303 edje_object_signal_callback_add (pi
->skin
, "ui,save", "*", mep_cb_ui_save
, pi
);
305 edje_object_signal_callback_add (pi
->edj
, "*", "*", mep_cb_all
, pi
);
307 // set up message system
308 Widget xtwidget
= XtWindowToWidget (pi
->display
, pi
->window
);
309 long event_mask
= NoEventMask
|
314 StructureNotifyMask
|
315 SubstructureNotifyMask
|
319 XSelectInput (pi
->display
, pi
->window
, event_mask
);
320 XtAddEventHandler (xtwidget
, event_mask
, True
, mep_event_handler
, pi
);
321 pi
->atom
= XInternAtom (pi
->display
, "edje_atom", False
);
323 pi
->msg
.type
= ClientMessage
;
324 pi
->msg
.display
= pi
->display
;
325 pi
->msg
.window
= pi
->window
;
326 pi
->msg
.message_type
= pi
->atom
;
328 pi
->msg
.data
.l
[0] = 0;
332 // initialize asynccallback loop
336 return NPERR_NO_ERROR
;
340 NPP_NewStream (NPP instance
,
346 if (instance
== NULL
)
347 return NPERR_INVALID_INSTANCE_ERROR
;
349 return NPERR_NO_ERROR
;
353 NPP_WriteReady (NPP instance
, NPStream
*stream
)
355 if (instance
== NULL
)
356 return NPERR_INVALID_INSTANCE_ERROR
;
358 /* We don't want any data, kill the stream */
359 NPN_DestroyStream(instance
, stream
, NPRES_DONE
);
361 /* Number of bytes ready to accept in NPP_Write() */
362 return -1L; /* don't accept any bytes in NPP_Write() */
366 NPP_Write (NPP instance
, NPStream
*stream
, int32 offset
, int32 len
, void *buffer
)
368 if (instance
== NULL
)
369 return NPERR_INVALID_INSTANCE_ERROR
;
371 /* We don't want any data, kill the stream */
372 NPN_DestroyStream(instance
, stream
, NPRES_DONE
);
374 return -1L; /* don't accept any bytes in NPP_Write() */
378 NPP_DestroyStream (NPP instance
, NPStream
*stream
, NPError reason
)
380 if (instance
== NULL
)
381 return NPERR_INVALID_INSTANCE_ERROR
;
383 /***** Insert NPP_DestroyStream code here *****\
385 pi = (PluginInstance*) instance->pdata;
386 \**********************************************/
388 return NPERR_NO_ERROR
;
392 NPP_StreamAsFile (NPP instance
, NPStream
*stream
, const char* fname
)
394 /***** Insert NPP_StreamAsFile code here *****\
396 if (instance != NULL)
397 pi = (PluginInstance*) instance->pdata;
398 \*********************************************/
402 NPP_URLNotify (NPP instance
, const char* url
,
403 NPReason reason
, void* notifyData
)
405 /***** Insert NPP_URLNotify code here *****\
407 if (instance != NULL)
408 pi = (PluginInstance*) instance->pdata;
409 \*********************************************/
413 NPP_Print (NPP instance
, NPPrint
* printInfo
)
415 if(printInfo
== NULL
)
418 if (instance
!= NULL
) {
419 /***** Insert NPP_Print code here *****\
420 PluginInstance* pi = (PluginInstance*) instance->pdata;
421 \**************************************/
423 if (printInfo
->mode
== NP_FULL
) {
426 * If your plugin would like to take over
427 * printing completely when it is in full-screen mode,
428 * set printInfo->pluginPrinted to TRUE and print your
429 * plugin as you see fit. If your plugin wants Netscape
430 * to handle printing in this case, set
431 * printInfo->pluginPrinted to FALSE (the default) and
432 * do nothing. If you do want to handle printing
433 * yourself, printOne is true if the print button
434 * (as opposed to the print menu) was clicked.
435 * On the Macintosh, platformPrint is a THPrint; on
436 * Windows, platformPrint is a structure
437 * (defined in npapi.h) containing the printer name, port,
441 /***** Insert NPP_Print code here *****\
442 void* platformPrint =
443 printInfo->print.fullPrint.platformPrint;
445 printInfo->print.fullPrint.printOne;
446 \**************************************/
449 printInfo
->print
.fullPrint
.pluginPrinted
= FALSE
;
451 else { /* If not fullscreen, we must be embedded */
454 * If your plugin is embedded, or is full-screen
455 * but you returned false in pluginPrinted above, NPP_Print
456 * will be called with mode == NP_EMBED. The NPWindow
457 * in the printInfo gives the location and dimensions of
458 * the embedded plugin on the printed page. On the
459 * Macintosh, platformPrint is the printer port; on
460 * Windows, platformPrint is the handle to the printing
464 /***** Insert NPP_Print code here *****\
465 NPWindow* printWindow =
466 &(printInfo->print.embedPrint.window);
467 void* platformPrint =
468 printInfo->print.embedPrint.platformPrint;
469 \**************************************/