1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
41
#include "plugin_list.h"
42
#include "plugin_setup.h"
43
#include "plugin_types.h"
44
#include "plugin_dbus.h"
45
#include <nsIPrefBranch.h>
46
#include <nsIPrefService.h>
47
#include <nsIServiceManager.h>
50
nsIPrefBranch *prefBranch = NULL;
51
nsIPrefService *prefService = NULL;
52
static NPObject *sWindowObj;
54
//#include "nsIServiceManager.h"
55
//#include "nsISupportsUtils.h" // some usefule macros are defined here
57
#define MIME_TYPES_HANDLED "application/scriptable-plugin"
58
#define PLUGIN_NAME "Scriptable Example Plugin for Mozilla"
59
#define MIME_TYPES_DESCRIPTION MIME_TYPES_HANDLED":scr:"PLUGIN_NAME
60
#define PLUGIN_DESCRIPTION PLUGIN_NAME " (Plug-ins SDK sample)"
62
int32 STREAMBUFSIZE = 0X0FFFFFFF;
65
static NPIdentifier Play_id;
66
static NPIdentifier PlayAt_id;
67
static NPIdentifier Pause_id;
68
static NPIdentifier PlayPause_id;
69
static NPIdentifier Stop_id;
70
static NPIdentifier quit_id;
71
static NPIdentifier DoPlay_id;
72
static NPIdentifier DoPause_id;
73
static NPIdentifier FastForward_id;
74
static NPIdentifier FastReverse_id;
75
static NPIdentifier ff_id;
76
static NPIdentifier rew_id;
77
static NPIdentifier rewind_id;
78
static NPIdentifier Seek_id;
79
static NPIdentifier Open_id;
80
static NPIdentifier SetVolume_id;
81
static NPIdentifier GetVolume_id;
82
static NPIdentifier SetFileName_id;
83
static NPIdentifier GetFileName_id;
84
static NPIdentifier SetIsLooping_id;
85
static NPIdentifier GetIsLooping_id;
86
static NPIdentifier SetAutoPlay_id;
87
static NPIdentifier GetAutoPlay_id;
88
static NPIdentifier SetHREF_id;
89
static NPIdentifier GetHREF_id;
90
static NPIdentifier SetURL_id;
91
static NPIdentifier GetURL_id;
92
static NPIdentifier GetMIMEType_id;
93
static NPIdentifier getTime_id;
94
static NPIdentifier getDuration_id;
95
static NPIdentifier getPercent_id;
96
static NPIdentifier isplaying_id;
97
static NPIdentifier playlistAppend_id;
98
static NPIdentifier playlistClear_id;
99
static NPIdentifier onClick_id;
100
static NPIdentifier onMediaComplete_id;
101
static NPIdentifier onMouseUp_id;
102
static NPIdentifier onMouseDown_id;
103
static NPIdentifier onMouseOut_id;
104
static NPIdentifier onMouseOver_id;
105
static NPIdentifier onDestroy_id;
107
static NPIdentifier controls_play_id;
108
static NPIdentifier controls_pause_id;
109
static NPIdentifier controls_stop_id;
110
static NPIdentifier controls_fastForward_id;
111
static NPIdentifier controls_fastReverse_id;
112
static NPIdentifier controls_step_id;
116
static NPIdentifier filename_id;
117
static NPIdentifier src_id;
118
static NPIdentifier ShowControls_id;
119
static NPIdentifier fullscreen_id;
120
static NPIdentifier showlogo_id;
121
static NPIdentifier playState_id;
122
static NPIdentifier controls_id;
124
static NPIdentifier controls_currentPosition_id;
125
//////////////////////////////////////
127
// general initialization and shutdown
129
NPError NS_PluginInitialize()
131
return NPERR_NO_ERROR;
134
void NS_PluginShutdown()
138
// get values per plugin
139
NPError NS_PluginGetValue(NPPVariable aVariable, void *aValue)
142
return PluginGetValue(aVariable, aValue);
146
/////////////////////////////////////////////////////////////
148
// construction and destruction of our plugin instance object
151
CPlugin *NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct)
153
if (!aCreateDataStruct)
156
CPlugin *plugin = new CPlugin(aCreateDataStruct->instance);
158
new_instance(plugin, aCreateDataStruct);
162
void NS_DestroyPluginInstance(CPlugin * aPlugin)
165
delete(CPlugin *) aPlugin;
170
void postDOMEvent(NPP mInstance, const gchar * id, const gchar * event)
174
jscript = g_strdup_printf("javascript:obj_gmp=document.getElementById('%s');"
175
"e_gmp=document.createEvent('Events');"
176
"e_gmp.initEvent('%s',true,true);" "obj_gmp.dispatchEvent(e_gmp);",
178
NPN_GetURL(mInstance, jscript, NULL);
182
void setPreference(CPlugin * instance, const gchar * name, const gchar * value)
184
nsIServiceManager *sm = NULL;
185
nsIServiceManager *ServiceManager = NULL;
187
void (*get_sm)(nsIServiceManager**);
189
get_sm = (void (*)(nsIServiceManager**))dlsym(RTLD_DEFAULT,"NS_GetServiceManager");
193
NPN_GetValue(NULL, NPNVserviceManager, &sm);
197
sm->QueryInterface(NS_GET_IID(nsIServiceManager), (void **) (&ServiceManager));
201
if (ServiceManager) {
202
ServiceManager->GetServiceByContractID(NS_PREFSERVICE_CONTRACTID, NS_GET_IID(nsIPrefBranch),
203
(void **) &prefBranch);
205
instance->user_agent = g_new0(gchar, 1024);
206
prefBranch->PrefHasUserValue(name, &v);
208
prefBranch->GetCharPref(name, &(instance->user_agent));
209
prefBranch->ClearUserPref(name);
211
prefBranch->SetCharPref(name, value);
212
printf("Set preference %s to %s, old value was '%s'\n", name, value,
213
instance->user_agent);
215
NS_RELEASE(ServiceManager);
220
void clearPreference(CPlugin * instance, const gchar * name)
222
nsIServiceManager *sm = NULL;
223
nsIServiceManager *ServiceManager = NULL;
225
void (*get_sm)(nsIServiceManager**);
227
get_sm = (void (*)(nsIServiceManager**))dlsym(RTLD_DEFAULT,"NS_GetServiceManager");
231
NPN_GetValue(NULL, NPNVserviceManager, &sm);
235
sm->QueryInterface(NS_GET_IID(nsIServiceManager), (void **) (&ServiceManager));
239
if (ServiceManager) {
240
ServiceManager->GetServiceByContractID(NS_PREFSERVICE_CONTRACTID, NS_GET_IID(nsIPrefBranch),
241
(void **) &prefBranch);
243
if (instance->user_agent == NULL || strlen(instance->user_agent) == 0) {
244
prefBranch->ClearUserPref(name);
246
if (g_strrstr(instance->user_agent, "QuickTime/7.6.4")) {
247
prefBranch->ClearUserPref(name);
249
prefBranch->ClearUserPref(name);
250
prefBranch->SetCharPref(name, instance->user_agent);
253
g_free(instance->user_agent);
255
NS_RELEASE(ServiceManager);
259
////////////////////////////////////////
261
// CPlugin class implementation
263
CPlugin::CPlugin(NPP pNPInstance):
264
mInstance(pNPInstance),
267
m_pScriptableObject(NULL),
268
m_pScriptableObjectControls(NULL),
272
player_launched(FALSE),
291
player_backend(NULL),
292
disable_context_menu(FALSE),
293
disable_fullscreen(FALSE),
294
post_dom_events(FALSE),
295
event_mediacomplete(NULL),
297
event_mousedown(NULL),
299
event_mouseclicked(NULL), event_enterwindow(NULL), event_leavewindow(NULL), debug(FALSE),
300
tv_driver(NULL), tv_device(NULL), tv_input(NULL), tv_width(0), tv_height(0)
306
NPN_GetValue(mInstance, NPNVWindowNPObject, &sWindowObj);
308
// get the page plugin was called from
309
// found at https://developer.mozilla.org/en/Getting_the_page_URL_in_NPAPI_plugin
310
NPIdentifier identifier = NPN_GetStringIdentifier( "location" );
311
// Declare a local variant value.
312
NPVariant variantValue;
313
// Get the location property from the window object (which is another object).
314
b = NPN_GetProperty( mInstance, sWindowObj, identifier, &variantValue );
315
// Get a pointer to the "location" object.
316
NPObject *locationObj = variantValue.value.objectValue;
317
// Create a "href" identifier.
318
identifier = NPN_GetStringIdentifier( "href" );
319
// Get the location property from the location object.
320
b = NPN_GetProperty( mInstance, locationObj, identifier, &variantValue );
321
#ifdef HAVE_NEW_XULRUNNER
322
page_url = g_strdup_printf("%s",NPVARIANT_TO_STRING(variantValue).UTF8Characters);
324
page_url = g_strdup_printf("%s",NPVARIANT_TO_STRING(variantValue).utf8characters);
328
Play_id = NPN_GetStringIdentifier("Play");
329
PlayAt_id = NPN_GetStringIdentifier("PlayAt");
330
Pause_id = NPN_GetStringIdentifier("Pause");
331
PlayPause_id = NPN_GetStringIdentifier("PlayPause");
332
Stop_id = NPN_GetStringIdentifier("Stop");
333
quit_id = NPN_GetStringIdentifier("quit");
334
DoPlay_id = NPN_GetStringIdentifier("DoPlay");
335
DoPause_id = NPN_GetStringIdentifier("DoPause");
336
FastForward_id = NPN_GetStringIdentifier("FastForward");
337
FastReverse_id = NPN_GetStringIdentifier("FastReverse");
338
ff_id = NPN_GetStringIdentifier("ff");
339
rew_id = NPN_GetStringIdentifier("rew");
340
rewind_id = NPN_GetStringIdentifier("rewind");
341
Seek_id = NPN_GetStringIdentifier("Seek");
342
Open_id = NPN_GetStringIdentifier("Open");
343
SetVolume_id = NPN_GetStringIdentifier("SetVolume");
344
GetVolume_id = NPN_GetStringIdentifier("GetVolume");
345
SetFileName_id = NPN_GetStringIdentifier("SetFileName");
346
GetFileName_id = NPN_GetStringIdentifier("GetFileName");
347
SetIsLooping_id = NPN_GetStringIdentifier("SetIsLooping");
348
GetIsLooping_id = NPN_GetStringIdentifier("GetIsLooping");
349
SetAutoPlay_id = NPN_GetStringIdentifier("SetAutoPlay");
350
GetAutoPlay_id = NPN_GetStringIdentifier("GetAutoPlay");
351
SetHREF_id = NPN_GetStringIdentifier("SetHREF");
352
GetHREF_id = NPN_GetStringIdentifier("GetHREF");
353
SetURL_id = NPN_GetStringIdentifier("SetURL");
354
GetURL_id = NPN_GetStringIdentifier("GetURL");
355
GetMIMEType_id = NPN_GetStringIdentifier("GetMIMEType");
356
getTime_id = NPN_GetStringIdentifier("getTime");
357
getDuration_id = NPN_GetStringIdentifier("getDuration");
358
getPercent_id = NPN_GetStringIdentifier("getPercent");
359
isplaying_id = NPN_GetStringIdentifier("isplaying");
360
playlistAppend_id = NPN_GetStringIdentifier("playlistAppend");
361
playlistClear_id = NPN_GetStringIdentifier("playlistClear");
362
onClick_id = NPN_GetStringIdentifier("onClick");
363
onMediaComplete_id = NPN_GetStringIdentifier("onMediaComplete");
364
onMouseUp_id = NPN_GetStringIdentifier("onMouseUp");
365
onMouseDown_id = NPN_GetStringIdentifier("onMouseDown");
366
onMouseOut_id = NPN_GetStringIdentifier("onMouseOut");
367
onMouseOver_id = NPN_GetStringIdentifier("onMouseOver");
368
onDestroy_id = NPN_GetStringIdentifier("onDestroy");
370
controls_play_id = NPN_GetStringIdentifier("play");
371
controls_pause_id = NPN_GetStringIdentifier("pause");
372
controls_stop_id = NPN_GetStringIdentifier("stop");
373
controls_fastForward_id = NPN_GetStringIdentifier("fastForward");
374
controls_fastReverse_id = NPN_GetStringIdentifier("fastReverse");
375
controls_step_id = NPN_GetStringIdentifier("step");
377
// register properties
378
filename_id = NPN_GetStringIdentifier("filename");
379
src_id = NPN_GetStringIdentifier("src");
380
ShowControls_id = NPN_GetStringIdentifier("ShowControls");
381
fullscreen_id = NPN_GetStringIdentifier("fullscreen");
382
showlogo_id = NPN_GetStringIdentifier("showlogo");
383
playState_id = NPN_GetStringIdentifier("playState");
384
controls_id = NPN_GetStringIdentifier("controls");
386
controls_currentPosition_id = NPN_GetStringIdentifier("currentPosition");
388
// generate a random controlid
390
controlid = g_rand_int_range(rand, 0, 65535);
394
path = g_strdup_printf("/control/%i", controlid);
395
// printf("using path %s\n",path);
398
bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
399
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
400
textdomain(GETTEXT_PACKAGE);
402
printf(_("gecko mediaplayer v%s\n"), VERSION);
405
store = gm_pref_store_new("gecko-mediaplayer");
407
debug_level = gm_pref_store_get_int(store, DEBUG_LEVEL);
408
player_backend = gm_pref_store_get_string(store, PLAYER_BACKEND);
409
printf("Using player backend of '%s'\n", player_backend);
410
gm_pref_store_free(store);
414
if (connection == NULL) {
415
connection = dbus_hookup(this);
417
pluginSpecific(this);
424
// mScriptablePeer may be also held by the browser
425
// so releasing it here does not guarantee that it is over
426
// we should take precaution in case it will be called later
427
// and zero its mPlugin member
428
// mScriptablePeer->SetInstance(NULL);
429
// NS_IF_RELEASE(mScriptablePeer);
434
NPN_ReleaseObject(sWindowObj);
438
if (mControlsScriptablePeer != NULL) {
439
mControlsScriptablePeer->SetInstance(NULL);
440
mControlsScriptablePeer->Release();
441
NS_IF_RELEASE(mControlsScriptablePeer);
444
clearPreference(this, "general.useragent.override");
446
if (m_pScriptableObjectControls) {
447
NPN_ReleaseObject(m_pScriptableObjectControls);
450
if (m_pScriptableObject) {
451
NPN_ReleaseObject(m_pScriptableObject);
457
NPBool CPlugin::init(NPWindow * pNPWindow)
459
if (pNPWindow == NULL)
462
m_Window = pNPWindow;
468
int16 CPlugin::handleEvent(void *event)
471
NPEvent *ev = (NPEvent *) event;
473
Rect box = { m_Window->y, m_Window->x,
474
m_Window->y + m_Window->height, m_Window->x + m_Window->width
476
if (ev->what == updateEvt) {
477
::TETextBox(m_String, strlen(m_String), &box, teJustCenter);
484
NPError CPlugin::SetWindow(NPWindow * aWindow)
486
GError *error = NULL;
494
return NPERR_NO_ERROR;
497
return NPERR_NO_ERROR;
501
mWidth = aWindow->width;
502
mHeight = aWindow->height;
503
if (mWindow != (Window) aWindow->window) {
504
mWindow = (Window) aWindow->window;
505
NPSetWindowCallbackStruct *ws_info = (NPSetWindowCallbackStruct *) aWindow->ws_info;
509
if (player_launched && mWidth > 0 && mHeight > 0) {
510
resize_window(this, NULL, mWidth, mHeight);
513
if (!player_launched && mWidth > 0 && mHeight > 0) {
515
if (player_backend != NULL) {
516
app_name = g_find_program_in_path(player_backend);
518
if (app_name == NULL) {
519
app_name = g_find_program_in_path("gnome-mplayer");
520
if (app_name == NULL)
521
app_name = g_find_program_in_path("gnome-mplayer-minimal");
524
argvn[arg++] = g_strdup_printf("%s", app_name);
525
argvn[arg++] = g_strdup_printf("--window=%i", (gint) mWindow);
526
argvn[arg++] = g_strdup_printf("--controlid=%i", controlid);
527
argvn[arg++] = g_strdup_printf("--width=%i", mWidth);
528
argvn[arg++] = g_strdup_printf("--height=%i", mHeight);
529
argvn[arg++] = g_strdup_printf("--autostart=%i", autostart);
530
argvn[arg++] = g_strdup_printf("--showcontrols=%i", show_controls);
531
if (disable_context_menu == TRUE)
532
argvn[arg++] = g_strdup_printf("--disablecontextmenu");
533
if (disable_fullscreen == TRUE)
534
argvn[arg++] = g_strdup_printf("--disablefullscreen");
536
argvn[arg++] = g_strdup_printf("--verbose");
538
argvn[arg++] = g_strdup_printf("--rpname=%s", name);
540
argvn[arg++] = g_strdup_printf("--rpconsole=%s", console);
541
if (controls != NULL) {
542
argvn[arg++] = g_strdup_printf("--rpcontrols=%s", controls);
544
if (tv_device != NULL) {
545
argvn[arg++] = g_strdup_printf("--tvdevice=%s", tv_device);
547
if (tv_driver != NULL) {
548
argvn[arg++] = g_strdup_printf("--tvdriver=%s", tv_driver);
550
if (tv_input != NULL) {
551
argvn[arg++] = g_strdup_printf("--tvinput=%s", tv_input);
554
argvn[arg++] = g_strdup_printf("--tvwidth=%i", tv_width);
557
argvn[arg++] = g_strdup_printf("--tvheight=%i", tv_height);
562
ok = g_spawn_async(NULL, argvn, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
565
player_launched = TRUE;
567
printf("Unable to launch %s: %s\n", app_name, error->message);
574
if (post_dom_events && id != NULL) {
575
postDOMEvent(mInstance, id, "qt_begin");
579
if (playlist != NULL) {
580
item = (ListItem *) playlist->data;
582
item = list_find_next_playable(playlist);
583
if (!item->requested) {
584
item->cancelled = FALSE;
585
if (item->streaming) {
586
printf("Calling open_location with item = %p src = %s\n", item, item->src);
587
open_location(this, item, FALSE);
591
printf("Calling GetURLNotify with item = %p src = %s\n", item, item->src);
592
NPN_GetURLNotify(mInstance, item->src, NULL, item);
596
return NPERR_NO_ERROR;
606
mInitialized = FALSE;
608
if (playlist != NULL) {
609
for (iter = playlist; iter != NULL; iter = g_list_next(iter)) {
610
item = (ListItem *) iter->data;
612
if (item->controlid != 0) {
613
send_signal_when_ready(this, item, "Terminate");
618
send_signal_when_ready(this, NULL, "Terminate");
620
playlist = list_clear(playlist);
622
if (event_destroy != NULL) {
623
NPN_GetURL(mInstance, event_destroy, NULL);
626
if (connection != NULL) {
627
connection = dbus_unhook(connection, this);
631
NPBool CPlugin::isInitialized()
636
NPError CPlugin::NewStream(NPMIMEType type, NPStream * stream, NPBool seekable, uint16 * stype)
638
if (g_strrstr(stream->url, "javascript") == NULL) {
639
printf("New Stream Requested - %s\n", stream->url);
642
if (g_strrstr(stream->url, "javascript") == NULL && stream->notifyData == NULL) {
643
printf("item is NULL for %s\n", stream->url);
646
return NPERR_NO_ERROR;
649
NPError CPlugin::DestroyStream(NPStream * stream, NPError reason)
658
if (g_strrstr(stream->url, "javascript") == NULL)
659
printf("Entering destroy stream reason = %i for %s\n", reason, stream->url);
661
if (reason == NPERR_NO_ERROR) {
662
item = (ListItem *) stream->notifyData;
663
// item = list_find(playlist, (gchar*)stream->url);
666
printf("Leaving destroy stream - item not found\n");
667
return NPERR_NO_ERROR;
671
fclose(item->localfp);
672
item->retrieved = TRUE;
674
send_signal_with_double(this, item, "SetCachePercent", 1.0);
675
text = g_strdup_printf(_("Cache fill: %2.2f%%"), 100.0);
676
send_signal_with_string(this, item, "SetProgressText", text);
678
if (post_dom_events && this->id != NULL) {
679
postDOMEvent(mInstance, this->id, "qt_progress");
683
if (!item->opened && item->play) {
684
id = item->controlid;
685
path = g_strdup(item->path);
686
ready = item->playerready;
687
newwindow = item->newwindow;
688
if (!item->streaming)
689
item->streaming = streaming(item->src);
690
if (!item->streaming) {
691
printf("in Destroy Stream\n");
692
playlist = list_parse_qt(playlist, item);
693
playlist = list_parse_qt2(playlist, item);
694
playlist = list_parse_asx(playlist, item);
695
playlist = list_parse_qml(playlist, item);
696
playlist = list_parse_ram(playlist, item);
698
// printf("item->play = %i\n",item->play);
699
// printf("item->src = %s\n", item->src);
700
// printf("item->streaming = %i\n", item->streaming);
701
// printf("calling open_location from DestroyStream\n");
703
item->requested = TRUE;
704
open_location(this, item, TRUE);
705
if (post_dom_events && this->id != NULL) {
706
postDOMEvent(mInstance, this->id, "qt_play");
709
item = list_find_next_playable(playlist);
711
// printf("item->play = %i\n",item->play);
712
// printf("item->src = %s\n", item->src);
713
// printf("item->streaming = %i\n", item->streaming);
714
if (!item->streaming) {
715
item->controlid = id;
716
g_strlcpy(item->path, path, 1024);
717
item->playerready = ready;
718
item->newwindow = newwindow;
719
item->cancelled = FALSE;
720
item->requested = TRUE;
722
NPN_GetURLNotify(mInstance, item->src, NULL, item);
724
open_location(this, item, FALSE);
725
item->requested = TRUE;
726
if (post_dom_events && this->id != NULL) {
727
postDOMEvent(mInstance, this->id, "qt_play");
734
//printf("Leaving destroy stream src = %s\n", item->src);
736
} else if (reason == NPERR_INVALID_URL) {
737
item = (ListItem *) stream->notifyData;
739
printf("Destroy Stream, invalid url, item is %s\n", item->src);
741
if (g_strrstr(stream->url, "javascript") == NULL) {
742
printf("Destroy Stream, network error, item is NULL\n");
746
item = (ListItem *) stream->notifyData;
747
// item = list_find(playlist, (gchar*)stream->url);
748
if (g_strrstr(stream->url, "javascript") == NULL)
749
printf("Exiting destroy stream reason = %i for %s\n", reason, stream->url);
751
return NPERR_NO_ERROR;
753
if (post_dom_events && this->id != NULL) {
754
postDOMEvent(mInstance, this->id, "qt_load");
759
fclose(item->localfp);
760
item->retrieved = FALSE;
765
// list_dump(playlist);
766
return NPERR_NO_ERROR;
769
void CPlugin::URLNotify(const char *url, NPReason reason, void *notifyData)
771
ListItem *item = (ListItem *) notifyData;
772
//DBusMessage *message;
775
printf("URL Notify url = '%s'\nreason = %i\n%s\n%s\n%s\n", url, reason, item->src, item->local,
777
if (reason == NPRES_DONE) {
780
// open_location(this,item, TRUE);
783
file = g_strdup(item->local);
784
while (!playerready) {
785
// printf("waiting for player\n");
786
g_main_context_iteration(NULL,FALSE);
788
message = dbus_message_new_signal(path,"com.gnome.mplayer","Open");
789
dbus_message_append_args(message, DBUS_TYPE_STRING, &file, DBUS_TYPE_INVALID);
790
dbus_connection_send(connection,message,NULL);
791
dbus_message_unref(message);
797
if (!item->streaming) {
798
item = list_find_next_playable(playlist);
800
if (item->retrieved || item->streaming) {
801
open_location(this, item, TRUE);
802
item->requested = TRUE;
804
NPN_GetURLNotify(mInstance, item->src, NULL, item);
805
item->requested = TRUE;
810
item = list_find_next_playable(playlist);
812
if (item->retrieved || item->streaming) {
813
open_location(this, item, TRUE);
814
item->requested = TRUE;
816
NPN_GetURLNotify(mInstance, item->src, NULL, item);
817
item->requested = TRUE;
824
} else if (reason == NPRES_NETWORK_ERR) {
825
printf("URL Notify result is Network Error\n");
826
} else if (reason == NPRES_USER_BREAK) {
827
printf("URL Notify result is User Break\n");
829
printf("%i is an invalid reason code in URLNotify\n", reason);
833
int32 CPlugin::WriteReady(NPStream * stream)
839
// printf("WriteReady called\n");
841
printf("Not accepting data\n");
842
NPN_DestroyStream(mInstance, stream, NPERR_GENERIC_ERROR);
847
item = (ListItem *) stream->notifyData;
848
// item = list_find(playlist, (gchar*)stream->url);
851
if (mode == NP_FULL) {
852
// printf("adding new item %s\n",stream->url);
853
item = g_new0(ListItem, 1);
854
g_strlcpy(item->src, stream->url, 1024);
855
item->requested = TRUE;
857
if (!item->streaming)
858
item->streaming = streaming(item->src);
859
playlist = g_list_append(playlist, item);
860
stream->notifyData = item;
862
printf("item is null\nstream url %s\n", stream->url);
863
NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
867
if (g_ascii_strcasecmp(item->src, stream->url) != 0) {
868
g_strlcpy(item->src, stream->url, 4096);
872
// printf("Write Ready item url = %s\n%s\n",item->src,stream->url);
874
if (item->cancelled) {
875
printf("cancelling WriteReady\n");
876
NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
880
if (strlen(item->local) == 0) {
881
path = g_strdup_printf("%s/gnome-mplayer/plugin", g_get_user_cache_dir());
882
if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {
883
g_mkdir_with_parents(path, 0775);
885
tmp = gm_tempname(path, "gecko-mediaplayerXXXXXX");
886
g_snprintf(item->local, 1024, "%s", tmp);
889
if (strstr(mimetype, "midi") != NULL) {
890
g_strlcat(item->local, ".mid", 1024);
892
if (strstr(mimetype, "mp3") != NULL) {
893
g_strlcat(item->local, ".mp3", 1024);
895
if (strstr(mimetype, "audio/mpeg") != NULL) {
896
g_strlcat(item->local, ".mp3", 1024);
898
if (strstr(mimetype, "audio/x-mod") != NULL) {
899
g_strlcat(item->local, ".mod", 1024);
901
if (strstr(mimetype, "flac") != NULL) {
902
g_strlcat(item->local, ".flac", 1024);
907
if (item->retrieved) {
908
printf("Duplicate request, item already retrieved\n");
909
NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
913
return STREAMBUFSIZE;
916
int32 CPlugin::Write(NPStream * stream, int32 offset, int32 len, void *buffer)
919
int32 wrotebytes = -1;
921
gdouble percent = 0.0;
927
gboolean ok_to_play = FALSE;
929
// printf("Write Called\n");
931
printf("not accepting data\n");
932
NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
936
item = (ListItem *) stream->notifyData;
939
printf("item is NULL\n");
940
printf(_("Write unable to write because item is NULL\n"));
941
NPN_DestroyStream(mInstance, stream, NPERR_GENERIC_ERROR);
945
if (item->cancelled || item->retrieved) {
946
printf("cancelled\n");
947
NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
951
if (strstr((char *) buffer, "ICY 200 OK") != NULL
952
|| strstr((char *) buffer, "Content-length:") != NULL // If item is a block of jpeg images, just stream it
953
|| strstr((char *) buffer, "<HTML>") != NULL
954
|| item->streaming == TRUE ) {
955
// || stream->lastmodified == 0) { this is not valid for many sites
957
// printf("BUFFER='%s'\n", buffer);
959
// printf("item->streaming = %i\n", item->streaming);
960
// printf("stream->lastmodified = %i\n", stream->lastmodified);
961
// printf("stream->end = %i\n", stream->end);
963
item->streaming = TRUE;
964
open_location(this, item, FALSE);
965
if (post_dom_events && this->id != NULL) {
966
postDOMEvent(mInstance, this->id, "qt_play");
968
item->requested = TRUE;
970
fclose(item->localfp);
972
printf("Got IceCast Stream, let mplayer stream it\n");
973
NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
977
if ((!item->localfp) && (!item->retrieved)) {
978
// printf("opening %s for localcache\n", item->local);
979
item->localfp = fopen(item->local, "w+");
981
// printf("Write item url = %s\n",item->src);
983
if (item->localfp == NULL) {
984
printf("Local cache file is not open, cannot write data\n");
985
NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
988
fseek(item->localfp, offset, SEEK_SET);
989
wrotebytes = fwrite(buffer, 1, len, item->localfp);
990
item->localsize += wrotebytes;
992
if (item->mediasize != stream->end)
993
item->mediasize = stream->end;
997
if (item->mediasize > 0) {
999
percent = (gdouble) item->localsize / (gdouble) item->mediasize;
1000
if (difftime(time(NULL), lastupdate) > 0.5) {
1001
send_signal_with_double(this, item, "SetCachePercent", percent);
1003
(gdouble) ((item->localsize -
1004
item->lastsize) / 1024.0) / (gdouble) difftime(time(NULL),
1006
if (percent > 0.99) {
1008
g_strdup_printf(_("Caching %iK (%0.1f K/s)"), item->mediasize / 1024, rate);
1011
g_strdup_printf(_("Cache fill: %2.2f%% (%0.1f K/s)"), percent * 100.0,
1014
send_signal_with_string(this, item, "SetProgressText", text);
1016
send_signal_with_string(this, item, "SetURL", item->src);
1017
if (post_dom_events && this->id != NULL) {
1018
postDOMEvent(mInstance, this->id, "qt_progress");
1019
postDOMEvent(mInstance, this->id, "qt_durationchange");
1023
item->lastsize = item->localsize;
1026
if (!item->opened) {
1027
if ((item->localsize >= (cache_size * 1024)) && (percent >= 0.2)) {
1028
printf("Setting to play because %i > %i\n", item->localsize, cache_size * 1024);
1031
if (ok_to_play == FALSE && (item->localsize > (cache_size * 2 * 1024))
1032
&& (cache_size >= 512)) {
1033
printf("Setting to play because %i > %i (double cache)\n", item->localsize,
1034
cache_size * 2 * 1024);
1037
if (ok_to_play == FALSE) {
1038
if (item->bitrate == 0 && item->bitrate_requests < 5
1039
&& ((gint) (percent * 100) > item->bitrate_requests)) {
1040
item->bitrate = request_bitrate(this, item, item->local);
1041
item->bitrate_requests++;
1043
if (item->bitrate > 0) {
1044
if (item->localsize / item->bitrate >= 10 && (percent >= 0.2)) {
1045
printf("Setting to play becuase %i >= 10\n",
1046
item->localsize / item->bitrate);
1048
if (post_dom_events && this->id != NULL) {
1049
postDOMEvent(mInstance, this->id, "qt_canplay");
1056
// if not opened, over cache level and not an href target then try and open it
1057
if ((!item->opened) && ok_to_play == TRUE) {
1058
id = item->controlid;
1059
path = g_strdup(item->path);
1060
ready = item->playerready;
1061
newwindow = item->newwindow;
1062
if (!item->streaming)
1063
item->streaming = streaming(item->src);
1064
if (!item->streaming) {
1065
printf("in Write\n");
1066
playlist = list_parse_qt(playlist, item);
1067
playlist = list_parse_asx(playlist, item);
1068
playlist = list_parse_qml(playlist, item);
1069
playlist = list_parse_ram(playlist, item);
1071
// printf("item->play = %i\n",item->play);
1072
// printf("item->src = %i\n", item->src);
1073
// printf("calling open_location from Write\n");
1075
send_signal_with_integer(this, item, "SetGUIState", PLAYING);
1076
open_location(this, item, TRUE);
1077
item->requested = TRUE;
1078
if (post_dom_events && this->id != NULL) {
1079
postDOMEvent(mInstance, this->id, "qt_loadedfirstframe");
1080
postDOMEvent(mInstance, this->id, "qt_canplay");
1081
postDOMEvent(mInstance, this->id, "qt_play");
1084
item = list_find_next_playable(playlist);
1086
item->controlid = id;
1087
g_strlcpy(item->path, path, 1024);
1088
item->playerready = ready;
1089
item->newwindow = newwindow;
1090
item->cancelled = FALSE;
1091
// printf("opening next playable items on the playlist\n");
1092
if (item->streaming) {
1093
open_location(this, item, FALSE);
1094
item->requested = TRUE;
1096
NPN_GetURLNotify(mInstance, item->src, NULL, item);
1097
item->requested = TRUE;
1110
void CPlugin::Play()
1112
send_signal(this, this->lastopened, "Play");
1113
if (post_dom_events && this->id != NULL) {
1114
postDOMEvent(mInstance, this->id, "qt_play");
1118
void CPlugin::Pause()
1120
send_signal(this, this->lastopened, "Pause");
1121
if (post_dom_events && this->id != NULL) {
1122
postDOMEvent(mInstance, this->id, "qt_pause");
1126
void CPlugin::Stop()
1128
send_signal(this, this->lastopened, "Stop");
1131
void CPlugin::FastForward()
1133
send_signal(this, this->lastopened, "FastForward");
1136
void CPlugin::FastReverse()
1138
send_signal(this, this->lastopened, "FastReverse");
1141
void CPlugin::Seek(double counter)
1143
send_signal_with_double(this, this->lastopened, "Seek", counter);
1146
void CPlugin::SetShowControls(bool value)
1148
send_signal_with_boolean(this, this->lastopened, "SetShowControls", value);
1151
void CPlugin::SetFullScreen(bool value)
1153
send_signal_with_boolean(this, this->lastopened, "SetFullScreen", value);
1156
void CPlugin::SetVolume(double value)
1158
send_signal_with_double(this, this->lastopened, "Volume", value);
1159
if (post_dom_events && this->id != NULL) {
1160
postDOMEvent(mInstance, this->id, "qt_volumechange");
1164
void CPlugin::GetVolume(double *_retval)
1166
*_retval = request_double_value(this, this->lastopened, "GetVolume");
1169
void CPlugin::GetFullScreen(bool * _retval)
1171
*_retval = request_boolean_value(this, this->lastopened, "GetFullScreen");
1174
void CPlugin::GetShowControls(bool * _retval)
1176
*_retval = request_boolean_value(this, this->lastopened, "GetShowControls");
1179
void CPlugin::GetTime(double *_retval)
1181
*_retval = request_double_value(this, this->lastopened, "GetTime");
1184
void CPlugin::GetDuration(double *_retval)
1186
*_retval = request_double_value(this, this->lastopened, "GetDuration");
1189
void CPlugin::GetPercent(double *_retval)
1191
*_retval = request_double_value(this, this->lastopened, "GetPercent");
1194
void CPlugin::SetFilename(const char *filename)
1198
if (filename == NULL)
1201
item = g_new0(ListItem, 1);
1202
g_strlcpy(item->src, filename, 1024);
1203
item->streaming = streaming(item->src);
1205
item->id = nextid++;
1206
playlist = g_list_append(playlist, item);
1208
send_signal(this, this->lastopened, "Quit");
1210
if (item->streaming) {
1211
open_location(this, item, FALSE);
1212
item->requested = 1;
1214
item->requested = 1;
1215
NPN_GetURLNotify(mInstance, item->src, NULL, item);
1219
void CPlugin::GetFilename(char **filename)
1222
if (this->lastopened != NULL) {
1223
*filename = g_strdup(this->lastopened->src);
1225
item = (ListItem *) playlist->data;
1227
*filename = g_strdup(item->src);
1234
void CPlugin::GetMIMEType(char **_retval)
1236
*_retval = g_strdup(mimetype);
1239
void CPlugin::GetPlayState(PRInt32 * playstate)
1241
*playstate = request_int_value(this, this->lastopened, "GetPlayState");
1244
void CPlugin::GetLoop(bool * _retval)
1246
if (lastopened != NULL) {
1247
*_retval = (bool) lastopened->loop;
1254
void CPlugin::SetLoop(bool value)
1256
if (lastopened != NULL) {
1257
lastopened->loop = (int) value;
1258
lastopened->loopcount = -1;
1262
void CPlugin::PlayPause()
1266
state = request_int_value(this, this->lastopened, "GetPlayState");
1267
if (state == STATE_PAUSED) {
1268
send_signal(this, this->lastopened, "Play");
1271
if (state == STATE_PLAYING) {
1272
send_signal(this, this->lastopened, "Pause");
1277
void CPlugin::SetOnClick(const char *event)
1279
if (event_mouseclicked != NULL) {
1280
g_free(event_mouseclicked);
1283
if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1284
event_mouseclicked = g_strdup_printf("%s", event);
1286
event_mouseclicked = g_strdup_printf("javascript:%s", event);
1290
void CPlugin::SetOnMediaComplete(const char *event)
1292
if (event_mediacomplete != NULL) {
1293
g_free(event_mediacomplete);
1296
if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1297
event_mediacomplete = g_strdup_printf("%s", event);
1299
event_mediacomplete = g_strdup_printf("javascript:%s", event);
1303
void CPlugin::SetOnMouseUp(const char *event)
1305
if (event_mouseup != NULL) {
1306
g_free(event_mouseup);
1309
if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1310
event_mouseup = g_strdup_printf("%s", event);
1312
event_mouseup = g_strdup_printf("javascript:%s", event);
1316
void CPlugin::SetOnMouseDown(const char *event)
1318
if (event_mousedown != NULL) {
1319
g_free(event_mousedown);
1322
if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1323
event_mousedown = g_strdup_printf("%s", event);
1325
event_mousedown = g_strdup_printf("javascript:%s", event);
1329
void CPlugin::SetOnMouseOut(const char *event)
1331
if (event_leavewindow != NULL) {
1332
g_free(event_leavewindow);
1335
if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1336
event_leavewindow = g_strdup_printf("%s", event);
1338
event_leavewindow = g_strdup_printf("javascript:%s", event);
1342
void CPlugin::SetOnMouseOver(const char *event)
1344
if (event_enterwindow != NULL) {
1345
g_free(event_enterwindow);
1348
if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1349
event_enterwindow = g_strdup_printf("%s", event);
1351
event_enterwindow = g_strdup_printf("javascript:%s", event);
1355
void CPlugin::SetOnDestroy(const char *event)
1357
if (event_destroy != NULL) {
1358
g_free(event_destroy);
1361
if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1362
event_destroy = g_strdup_printf("%s", event);
1364
event_destroy = g_strdup_printf("javascript:%s", event);
1368
// ==============================
1369
// ! Scriptability related code !
1370
// ==============================
1372
// here the plugin is asked by Mozilla to tell if it is scriptable
1373
// we should return a valid interface id and a pointer to
1374
// nsScriptablePeer interface which we should have implemented
1375
// and which should be defined in the corressponding *.xpt file
1376
// in the bin/components folder
1377
class ScriptablePluginObjectBase:public NPObject {
1379
ScriptablePluginObjectBase(NPP npp)
1381
} virtual ~ ScriptablePluginObjectBase() {
1384
// Virtual NPObject hooks called through this base class. Override
1387
virtual void Invalidate();
1388
virtual bool HasMethod(NPIdentifier name);
1389
virtual bool Invoke(NPIdentifier name, const NPVariant * args,
1390
uint32_t argCount, NPVariant * result);
1391
virtual bool InvokeDefault(const NPVariant * args, uint32_t argCount, NPVariant * result);
1392
virtual bool HasProperty(NPIdentifier name);
1393
virtual bool GetProperty(NPIdentifier name, NPVariant * result);
1394
virtual bool SetProperty(NPIdentifier name, const NPVariant * value);
1395
virtual bool RemoveProperty(NPIdentifier name);
1399
static void _Deallocate(NPObject * npobj);
1400
static void _Invalidate(NPObject * npobj);
1401
static bool _HasMethod(NPObject * npobj, NPIdentifier name);
1402
static bool _Invoke(NPObject * npobj, NPIdentifier name,
1403
const NPVariant * args, uint32_t argCount, NPVariant * result);
1404
static bool _InvokeDefault(NPObject * npobj, const NPVariant * args,
1405
uint32_t argCount, NPVariant * result);
1406
static bool _HasProperty(NPObject * npobj, NPIdentifier name);
1407
static bool _GetProperty(NPObject * npobj, NPIdentifier name, NPVariant * result);
1408
static bool _SetProperty(NPObject * npobj, NPIdentifier name, const NPVariant * value);
1409
static bool _RemoveProperty(NPObject * npobj, NPIdentifier name);
1415
#define DECLARE_NPOBJECT_CLASS_WITH_BASE(_class, ctor) \
1416
static NPClass s##_class##_NPClass = { \
1417
NP_CLASS_STRUCT_VERSION, \
1419
ScriptablePluginObjectBase::_Deallocate, \
1420
ScriptablePluginObjectBase::_Invalidate, \
1421
ScriptablePluginObjectBase::_HasMethod, \
1422
ScriptablePluginObjectBase::_Invoke, \
1423
ScriptablePluginObjectBase::_InvokeDefault, \
1424
ScriptablePluginObjectBase::_HasProperty, \
1425
ScriptablePluginObjectBase::_GetProperty, \
1426
ScriptablePluginObjectBase::_SetProperty, \
1427
ScriptablePluginObjectBase::_RemoveProperty \
1430
#define GET_NPOBJECT_CLASS(_class) &s##_class##_NPClass
1432
void ScriptablePluginObjectBase::Invalidate()
1436
bool ScriptablePluginObjectBase::HasMethod(NPIdentifier name)
1441
bool ScriptablePluginObjectBase::Invoke(NPIdentifier name, const NPVariant * args,
1442
uint32_t argCount, NPVariant * result)
1447
bool ScriptablePluginObjectBase::InvokeDefault(const NPVariant * args,
1448
uint32_t argCount, NPVariant * result)
1453
bool ScriptablePluginObjectBase::HasProperty(NPIdentifier name)
1458
bool ScriptablePluginObjectBase::GetProperty(NPIdentifier name, NPVariant * result)
1461
VOID_TO_NPVARIANT(*result);
1466
bool ScriptablePluginObjectBase::SetProperty(NPIdentifier name, const NPVariant * value)
1471
bool ScriptablePluginObjectBase::RemoveProperty(NPIdentifier name)
1477
void ScriptablePluginObjectBase::_Deallocate(NPObject * npobj)
1479
// Call the virtual destructor.
1480
delete(ScriptablePluginObjectBase *) npobj;
1484
void ScriptablePluginObjectBase::_Invalidate(NPObject * npobj)
1486
((ScriptablePluginObjectBase *) npobj)->Invalidate();
1490
bool ScriptablePluginObjectBase::_HasMethod(NPObject * npobj, NPIdentifier name)
1492
return ((ScriptablePluginObjectBase *) npobj)->HasMethod(name);
1496
bool ScriptablePluginObjectBase::_Invoke(NPObject * npobj, NPIdentifier name,
1497
const NPVariant * args, uint32_t argCount,
1500
return ((ScriptablePluginObjectBase *) npobj)->Invoke(name, args, argCount, result);
1504
bool ScriptablePluginObjectBase::_InvokeDefault(NPObject * npobj,
1505
const NPVariant * args,
1506
uint32_t argCount, NPVariant * result)
1508
return ((ScriptablePluginObjectBase *) npobj)->InvokeDefault(args, argCount, result);
1512
bool ScriptablePluginObjectBase::_HasProperty(NPObject * npobj, NPIdentifier name)
1514
return ((ScriptablePluginObjectBase *) npobj)->HasProperty(name);
1518
bool ScriptablePluginObjectBase::_GetProperty(NPObject * npobj, NPIdentifier name,
1521
return ((ScriptablePluginObjectBase *) npobj)->GetProperty(name, result);
1525
bool ScriptablePluginObjectBase::_SetProperty(NPObject * npobj, NPIdentifier name,
1526
const NPVariant * value)
1528
return ((ScriptablePluginObjectBase *) npobj)->SetProperty(name, value);
1532
bool ScriptablePluginObjectBase::_RemoveProperty(NPObject * npobj, NPIdentifier name)
1534
return ((ScriptablePluginObjectBase *) npobj)->RemoveProperty(name);
1537
class ScriptablePluginObjectControls:public ScriptablePluginObjectBase {
1539
ScriptablePluginObjectControls(NPP npp)
1540
:ScriptablePluginObjectBase(npp) {
1541
} virtual bool HasMethod(NPIdentifier name);
1542
virtual bool Invoke(NPIdentifier name, const NPVariant * args,
1543
uint32_t argCount, NPVariant * result);
1544
virtual bool InvokeDefault(const NPVariant * args, uint32_t argCount, NPVariant * result);
1545
virtual bool HasProperty(NPIdentifier name);
1546
virtual bool GetProperty(NPIdentifier name, NPVariant * result);
1547
virtual bool SetProperty(NPIdentifier name, const NPVariant * value);
1551
static NPObject *AllocateScriptablePluginObjectControls(NPP npp, NPClass * aClass)
1553
return new ScriptablePluginObjectControls(npp);
1556
DECLARE_NPOBJECT_CLASS_WITH_BASE(ScriptablePluginObjectControls,
1557
AllocateScriptablePluginObjectControls);
1559
bool ScriptablePluginObjectControls::HasMethod(NPIdentifier name)
1561
if (name == controls_play_id ||
1562
name == controls_pause_id ||
1563
name == controls_stop_id ||
1564
name == controls_fastForward_id ||
1565
name == controls_fastReverse_id || name == controls_step_id) {
1572
bool ScriptablePluginObjectControls::Invoke(NPIdentifier name, const NPVariant * args,
1573
uint32_t argCount, NPVariant * result)
1575
CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
1576
if (pPlugin == NULL) {
1577
printf("Can't find plugin pointer\n");
1581
if (name == controls_play_id) {
1586
if (name == controls_pause_id) {
1591
if (name == controls_stop_id) {
1599
bool ScriptablePluginObjectControls::InvokeDefault(const NPVariant * args, uint32_t argCount,
1602
printf("ScriptablePluginObject default method called!\n");
1604
STRINGZ_TO_NPVARIANT(strdup("default method return val"), *result);
1609
bool ScriptablePluginObjectControls::HasProperty(NPIdentifier name)
1611
if (name == controls_currentPosition_id) {
1618
bool ScriptablePluginObjectControls::GetProperty(NPIdentifier name, NPVariant * result)
1622
CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
1623
if (pPlugin == NULL) {
1624
printf("Can't find plugin pointer\n");
1625
VOID_TO_NPVARIANT(*result);
1629
if (name == controls_currentPosition_id) {
1630
pPlugin->GetTime(&position);
1631
DOUBLE_TO_NPVARIANT(position, *result);
1635
VOID_TO_NPVARIANT(*result);
1639
bool ScriptablePluginObjectControls::SetProperty(NPIdentifier name, const NPVariant * value)
1641
CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
1642
if (pPlugin == NULL) {
1643
printf("Can't find plugin pointer\n");
1647
if (name == controls_currentPosition_id) {
1648
pPlugin->Seek(NPVARIANT_TO_DOUBLE(*value));
1656
class ScriptablePluginObject:public ScriptablePluginObjectBase {
1658
ScriptablePluginObject(NPP npp)
1659
:ScriptablePluginObjectBase(npp) {
1660
} virtual bool HasMethod(NPIdentifier name);
1661
virtual bool Invoke(NPIdentifier name, const NPVariant * args,
1662
uint32_t argCount, NPVariant * result);
1663
virtual bool InvokeDefault(const NPVariant * args, uint32_t argCount, NPVariant * result);
1664
virtual bool HasProperty(NPIdentifier name);
1665
virtual bool GetProperty(NPIdentifier name, NPVariant * result);
1666
virtual bool SetProperty(NPIdentifier name, const NPVariant * value);
1670
static NPObject *AllocateScriptablePluginObject(NPP npp, NPClass * aClass)
1672
return new ScriptablePluginObject(npp);
1675
DECLARE_NPOBJECT_CLASS_WITH_BASE(ScriptablePluginObject, AllocateScriptablePluginObject);
1678
bool ScriptablePluginObject::HasMethod(NPIdentifier name)
1680
if (name == Play_id ||
1681
name == PlayAt_id ||
1683
name == PlayPause_id ||
1686
name == DoPlay_id ||
1687
name == DoPause_id ||
1688
name == FastForward_id ||
1689
name == FastReverse_id ||
1692
name == rewind_id ||
1695
name == SetVolume_id ||
1696
name == GetVolume_id ||
1697
name == SetFileName_id ||
1698
name == GetFileName_id ||
1699
name == SetIsLooping_id ||
1700
name == GetIsLooping_id ||
1701
name == SetAutoPlay_id ||
1702
name == GetAutoPlay_id ||
1703
name == SetHREF_id ||
1704
name == GetHREF_id ||
1705
name == SetURL_id ||
1706
name == GetURL_id ||
1707
name == GetMIMEType_id ||
1708
name == getTime_id ||
1709
name == getDuration_id ||
1710
name == getPercent_id ||
1711
name == isplaying_id ||
1712
name == playlistAppend_id ||
1713
name == playlistClear_id ||
1714
name == onClick_id ||
1715
name == onMediaComplete_id ||
1716
name == onMouseUp_id ||
1717
name == onMouseDown_id ||
1718
name == onMouseOut_id || name == onMouseOver_id || name == onDestroy_id) {
1725
bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant * args,
1726
uint32_t argCount, NPVariant * result)
1732
CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
1733
if (pPlugin == NULL) {
1734
printf("Can't find plugin pointer\n");
1738
if (name == Play_id || name == DoPlay_id) {
1743
if (name == PlayAt_id) {
1745
if ((int)NPVARIANT_TO_DOUBLE(args[0]) == 0 && NPVARIANT_TO_INT32(args[0]) > 0) {
1746
pPlugin->Seek((double)NPVARIANT_TO_INT32(args[0]));
1748
pPlugin->Seek(NPVARIANT_TO_DOUBLE(args[0]));
1753
if (name == Pause_id || name == DoPause_id) {
1758
if (name == PlayPause_id) {
1759
pPlugin->PlayPause();
1763
if (name == Stop_id) {
1768
if (name == FastForward_id || name == ff_id) {
1769
pPlugin->FastForward();
1773
if (name == FastReverse_id || name == rew_id || name == rewind_id) {
1774
pPlugin->FastReverse();
1778
if (name == Seek_id) {
1780
if ((int)NPVARIANT_TO_DOUBLE(args[0]) == 0 && NPVARIANT_TO_INT32(args[0]) > 0) {
1781
pPlugin->Seek((double)NPVARIANT_TO_INT32(args[0]));
1783
pPlugin->Seek(NPVARIANT_TO_DOUBLE(args[0]));
1788
if (name == Open_id || name == SetFileName_id || name == SetHREF_id || name == SetURL_id) {
1789
#ifdef HAVE_NEW_XULRUNNER
1790
pPlugin->SetFilename(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1792
pPlugin->SetFilename(NPVARIANT_TO_STRING(args[0]).utf8characters);
1797
if (name == GetFileName_id || name == GetHREF_id || name == GetURL_id) {
1798
pPlugin->GetFilename(&s);
1799
STRINGZ_TO_NPVARIANT(s, *result);
1804
if (name == SetVolume_id) {
1805
pPlugin->SetVolume(NPVARIANT_TO_DOUBLE(args[0]));
1809
if (name == GetVolume_id) {
1810
pPlugin->GetVolume(&d);
1811
DOUBLE_TO_NPVARIANT(d, *result);
1815
if (name == SetIsLooping_id) {
1816
pPlugin->SetLoop(NPVARIANT_TO_BOOLEAN(args[0]));
1820
if (name == GetIsLooping_id) {
1821
pPlugin->GetLoop(&b);
1822
BOOLEAN_TO_NPVARIANT(b, *result);
1826
if (name == SetAutoPlay_id) {
1827
pPlugin->autostart = NPVARIANT_TO_BOOLEAN(args[0]);
1831
if (name == GetAutoPlay_id) {
1832
BOOLEAN_TO_NPVARIANT(pPlugin->autostart, *result);
1836
if (name == GetMIMEType_id) {
1837
pPlugin->GetMIMEType(&s);
1838
STRINGZ_TO_NPVARIANT(s, *result);
1843
if (name == getTime_id) {
1844
pPlugin->GetTime(&d);
1845
DOUBLE_TO_NPVARIANT(d, *result);
1849
if (name == getDuration_id) {
1850
pPlugin->GetDuration(&d);
1851
DOUBLE_TO_NPVARIANT(d, *result);
1855
if (name == getPercent_id) {
1856
pPlugin->GetPercent(&d);
1857
DOUBLE_TO_NPVARIANT(d, *result);
1861
if (name == isplaying_id || name == playlistAppend_id || name == playlistClear_id) {
1865
if (name == onClick_id) {
1866
#ifdef HAVE_NEW_XULRUNNER
1867
pPlugin->SetOnClick(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1869
pPlugin->SetOnClick(NPVARIANT_TO_STRING(args[0]).utf8characters);
1874
if (name == onMediaComplete_id) {
1875
#ifdef HAVE_NEW_XULRUNNER
1876
pPlugin->SetOnMediaComplete(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1878
pPlugin->SetOnMediaComplete(NPVARIANT_TO_STRING(args[0]).utf8characters);
1883
if (name == onMouseUp_id) {
1884
#ifdef HAVE_NEW_XULRUNNER
1885
pPlugin->SetOnMouseUp(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1887
pPlugin->SetOnMouseUp(NPVARIANT_TO_STRING(args[0]).utf8characters);
1892
if (name == onMouseDown_id) {
1893
#ifdef HAVE_NEW_XULRUNNER
1894
pPlugin->SetOnMouseDown(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1896
pPlugin->SetOnMouseDown(NPVARIANT_TO_STRING(args[0]).utf8characters);
1901
if (name == onMouseOut_id) {
1902
#ifdef HAVE_NEW_XULRUNNER
1903
pPlugin->SetOnMouseOut(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1905
pPlugin->SetOnMouseOut(NPVARIANT_TO_STRING(args[0]).utf8characters);
1910
if (name == onMouseOver_id) {
1911
#ifdef HAVE_NEW_XULRUNNER
1912
pPlugin->SetOnMouseOver(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1914
pPlugin->SetOnMouseOver(NPVARIANT_TO_STRING(args[0]).utf8characters);
1919
if (name == onDestroy_id) {
1920
#ifdef HAVE_NEW_XULRUNNER
1921
pPlugin->SetOnDestroy(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1923
pPlugin->SetOnDestroy(NPVARIANT_TO_STRING(args[0]).utf8characters);
1931
bool ScriptablePluginObject::InvokeDefault(const NPVariant * args, uint32_t argCount,
1934
printf("ScriptablePluginObject default method called!\n");
1936
STRINGZ_TO_NPVARIANT(strdup("default method return val"), *result);
1941
bool ScriptablePluginObject::HasProperty(NPIdentifier name)
1943
if (name == filename_id ||
1945
name == ShowControls_id ||
1946
name == fullscreen_id ||
1947
name == showlogo_id || name == playState_id || name == controls_id) {
1954
bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant * result)
1960
CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
1961
if (pPlugin == NULL) {
1962
printf("Can't find plugin pointer\n");
1963
VOID_TO_NPVARIANT(*result);
1967
if (name == filename_id || name == src_id) {
1968
pPlugin->GetFilename(&filename);
1969
STRINGZ_TO_NPVARIANT(filename, *result);
1973
if (name == ShowControls_id) {
1974
pPlugin->GetShowControls(&setting);
1975
BOOLEAN_TO_NPVARIANT(setting, *result);
1979
if (name == fullscreen_id) {
1980
pPlugin->GetFullScreen(&setting);
1981
BOOLEAN_TO_NPVARIANT(setting, *result);
1985
if (name == showlogo_id) {
1987
BOOLEAN_TO_NPVARIANT(setting, *result);
1991
if (name == playState_id) {
1992
pPlugin->GetPlayState(&state);
1993
INT32_TO_NPVARIANT(state, *result);
1997
if (name == controls_id) {
1998
OBJECT_TO_NPVARIANT(pPlugin->GetScriptableObjectControls(), *result);
2002
VOID_TO_NPVARIANT(*result);
2006
bool ScriptablePluginObject::SetProperty(NPIdentifier name, const NPVariant * value)
2008
CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
2009
if (pPlugin == NULL) {
2010
printf("Can't find plugin pointer\n");
2014
if (name == filename_id || name == src_id) {
2015
#ifdef HAVE_NEW_XULRUNNER
2016
pPlugin->SetFilename(NPVARIANT_TO_STRING(*value).UTF8Characters);
2018
pPlugin->SetFilename(NPVARIANT_TO_STRING(*value).utf8characters);
2023
if (name == ShowControls_id) {
2024
pPlugin->SetShowControls(NPVARIANT_TO_BOOLEAN(*value));
2028
if (name == fullscreen_id) {
2029
pPlugin->SetFullScreen(NPVARIANT_TO_BOOLEAN(*value));
2033
if (name == showlogo_id) {
2037
if (name == playState_id) {
2038
// readonly property
2045
NPObject *CPlugin::GetScriptableObject()
2047
if (!m_pScriptableObject) {
2048
m_pScriptableObject =
2049
NPN_CreateObject(mInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject));
2052
if (m_pScriptableObject) {
2053
NPN_RetainObject(m_pScriptableObject);
2056
return m_pScriptableObject;
2059
NPObject *CPlugin::GetScriptableObjectControls()
2061
if (!m_pScriptableObjectControls) {
2062
m_pScriptableObjectControls =
2063
NPN_CreateObject(mInstance, GET_NPOBJECT_CLASS(ScriptablePluginObjectControls));
2066
if (m_pScriptableObjectControls) {
2067
NPN_RetainObject(m_pScriptableObjectControls);
2070
return m_pScriptableObjectControls;