~ubuntu-branches/ubuntu/quantal/gecko-mediaplayer/quantal

« back to all changes in this revision

Viewing changes to .pc/90_svn420_fix_null.patch/src/plugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2011-07-17 22:24:37 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20110717222437-f0skmzay316o4rve
Tags: 1.0.4-0ubuntu1
* New upstream release.
* debian/patches:
 - 90_svn420_fix_null.patch: Remove, merged upstream.
 - 91_svn421_disable_npp_initialize.patch: Remove, merged upstream.
 - dont_use_libxul.patch: Remove, fixed upstream.
 - autotools.patch: Remove, not needed now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
4
 
 *
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/
9
 
 *
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
13
 
 * License.
14
 
 *
15
 
 * The Original Code is mozilla.org code.
16
 
 *
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.
21
 
 *
22
 
 * Contributor(s):
23
 
 *
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.
35
 
 *
36
 
 * ***** END LICENSE BLOCK ***** */
37
 
 
38
 
 
39
 
#include "plugin.h"
40
 
//#include "npupp.h"
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>
48
 
#include <dlfcn.h>
49
 
 
50
 
nsIPrefBranch *prefBranch = NULL;
51
 
nsIPrefService *prefService = NULL;
52
 
static NPObject *sWindowObj;
53
 
 
54
 
//#include "nsIServiceManager.h"
55
 
//#include "nsISupportsUtils.h"   // some usefule macros are defined here
56
 
 
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)"
61
 
 
62
 
int32 STREAMBUFSIZE = 0X0FFFFFFF;
63
 
 
64
 
// methods
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;
106
 
 
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;
113
 
 
114
 
 
115
 
// properties
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;
123
 
 
124
 
static NPIdentifier controls_currentPosition_id;
125
 
//////////////////////////////////////
126
 
//
127
 
// general initialization and shutdown
128
 
//
129
 
NPError NS_PluginInitialize()
130
 
{
131
 
    return NPERR_NO_ERROR;
132
 
}
133
 
 
134
 
void NS_PluginShutdown()
135
 
{
136
 
}
137
 
 
138
 
// get values per plugin
139
 
NPError NS_PluginGetValue(NPPVariable aVariable, void *aValue)
140
 
{
141
 
 
142
 
    return PluginGetValue(aVariable, aValue);
143
 
}
144
 
 
145
 
 
146
 
/////////////////////////////////////////////////////////////
147
 
//
148
 
// construction and destruction of our plugin instance object
149
 
//
150
 
/*
151
 
CPlugin *NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct)
152
 
{
153
 
    if (!aCreateDataStruct)
154
 
        return NULL;
155
 
 
156
 
    CPlugin *plugin = new CPlugin(aCreateDataStruct->instance);
157
 
 
158
 
    new_instance(plugin, aCreateDataStruct);
159
 
    return plugin;
160
 
}
161
 
 
162
 
void NS_DestroyPluginInstance(CPlugin * aPlugin)
163
 
{
164
 
    if (aPlugin)
165
 
        delete(CPlugin *) aPlugin;
166
 
}
167
 
 
168
 
 
169
 
*/
170
 
void postDOMEvent(NPP mInstance, const gchar * id, const gchar * event)
171
 
{
172
 
    gchar *jscript;
173
 
 
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);",
177
 
                              id, event);
178
 
    NPN_GetURL(mInstance, jscript, NULL);
179
 
    g_free(jscript);
180
 
}
181
 
 
182
 
void setPreference(CPlugin * instance, const gchar * name, const gchar * value)
183
 
{
184
 
    nsIServiceManager *sm = NULL;
185
 
    nsIServiceManager *ServiceManager = NULL;
186
 
    PRBool v;
187
 
    void (*get_sm)(nsIServiceManager**);
188
 
 
189
 
    get_sm = (void (*)(nsIServiceManager**))dlsym(RTLD_DEFAULT,"NS_GetServiceManager");
190
 
    if (get_sm) {
191
 
        (*get_sm)(&sm);
192
 
    } else {
193
 
        NPN_GetValue(NULL, NPNVserviceManager, &sm);
194
 
    }
195
 
 
196
 
    if (sm) {
197
 
        sm->QueryInterface(NS_GET_IID(nsIServiceManager), (void **) (&ServiceManager));
198
 
        NS_RELEASE(sm);
199
 
    }
200
 
 
201
 
    if (ServiceManager) {
202
 
        ServiceManager->GetServiceByContractID(NS_PREFSERVICE_CONTRACTID, NS_GET_IID(nsIPrefBranch),
203
 
                                               (void **) &prefBranch);
204
 
        if (prefBranch) {
205
 
            instance->user_agent = g_new0(gchar, 1024);
206
 
            prefBranch->PrefHasUserValue(name, &v);
207
 
            if (v) {
208
 
                prefBranch->GetCharPref(name, &(instance->user_agent));
209
 
                prefBranch->ClearUserPref(name);
210
 
            }
211
 
            prefBranch->SetCharPref(name, value);
212
 
            printf("Set preference %s to %s, old value was '%s'\n", name, value,
213
 
                   instance->user_agent);
214
 
        }
215
 
        NS_RELEASE(ServiceManager);
216
 
    }
217
 
 
218
 
}
219
 
 
220
 
void clearPreference(CPlugin * instance, const gchar * name)
221
 
{
222
 
    nsIServiceManager *sm = NULL;
223
 
    nsIServiceManager *ServiceManager = NULL;
224
 
    PRBool v;
225
 
    void (*get_sm)(nsIServiceManager**);
226
 
 
227
 
    get_sm = (void (*)(nsIServiceManager**))dlsym(RTLD_DEFAULT,"NS_GetServiceManager");
228
 
    if (get_sm) {
229
 
        (*get_sm)(&sm);
230
 
    } else {
231
 
        NPN_GetValue(NULL, NPNVserviceManager, &sm);
232
 
    }
233
 
 
234
 
    if (sm) {
235
 
        sm->QueryInterface(NS_GET_IID(nsIServiceManager), (void **) (&ServiceManager));
236
 
        NS_RELEASE(sm);
237
 
    }
238
 
 
239
 
    if (ServiceManager) {
240
 
        ServiceManager->GetServiceByContractID(NS_PREFSERVICE_CONTRACTID, NS_GET_IID(nsIPrefBranch),
241
 
                                               (void **) &prefBranch);
242
 
        if (prefBranch) {
243
 
            if (instance->user_agent == NULL || strlen(instance->user_agent) == 0) {
244
 
                prefBranch->ClearUserPref(name);
245
 
            } else {
246
 
                if (g_strrstr(instance->user_agent, "QuickTime/7.6.4")) {
247
 
                    prefBranch->ClearUserPref(name);
248
 
                } else {
249
 
                    prefBranch->ClearUserPref(name);
250
 
                    prefBranch->SetCharPref(name, instance->user_agent);
251
 
                }
252
 
            }
253
 
            g_free(instance->user_agent);
254
 
        }
255
 
        NS_RELEASE(ServiceManager);
256
 
    }
257
 
}
258
 
 
259
 
////////////////////////////////////////
260
 
//
261
 
// CPlugin class implementation
262
 
//
263
 
CPlugin::CPlugin(NPP pNPInstance):
264
 
mInstance(pNPInstance),
265
 
m_pNPStream(NULL),
266
 
mInitialized(FALSE),
267
 
m_pScriptableObject(NULL),
268
 
m_pScriptableObjectControls(NULL),
269
 
mWindow(0),
270
 
windowless(FALSE),
271
 
playlist(NULL),
272
 
player_launched(FALSE),
273
 
connection(NULL),
274
 
dbus_dispatch(NULL),
275
 
path(NULL),
276
 
acceptdata(TRUE),
277
 
playerready(FALSE),
278
 
nextid(1),
279
 
lastopened(NULL),
280
 
cache_size(2048),
281
 
hidden(FALSE),
282
 
autostart(1),
283
 
lastupdate(0),
284
 
show_controls(1),
285
 
name(NULL),
286
 
id(NULL),
287
 
console(NULL),
288
 
controls(NULL),
289
 
user_agent(NULL),
290
 
page_url(NULL),
291
 
player_backend(NULL),
292
 
disable_context_menu(FALSE),
293
 
disable_fullscreen(FALSE),
294
 
post_dom_events(FALSE),
295
 
event_mediacomplete(NULL),
296
 
event_destroy(NULL),
297
 
event_mousedown(NULL),
298
 
event_mouseup(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)
301
 
{
302
 
    GRand *rand;
303
 
    GmPrefStore *store;
304
 
    gboolean b;
305
 
 
306
 
    NPN_GetValue(mInstance, NPNVWindowNPObject, &sWindowObj);
307
 
    
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);
323
 
#else
324
 
    page_url = g_strdup_printf("%s",NPVARIANT_TO_STRING(variantValue).utf8characters);
325
 
#endif    
326
 
 
327
 
    // register methods
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");
369
 
 
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");
376
 
 
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");
385
 
 
386
 
    controls_currentPosition_id = NPN_GetStringIdentifier("currentPosition");
387
 
 
388
 
    // generate a random controlid
389
 
    rand = g_rand_new();
390
 
    controlid = g_rand_int_range(rand, 0, 65535);
391
 
    g_rand_free(rand);
392
 
 
393
 
    if (path == NULL) {
394
 
        path = g_strdup_printf("/control/%i", controlid);
395
 
        // printf("using path %s\n",path);
396
 
    }
397
 
#ifdef ENABLE_NLS
398
 
    bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
399
 
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
400
 
    textdomain(GETTEXT_PACKAGE);
401
 
#endif
402
 
   printf(_("gecko mediaplayer v%s\n"), VERSION);
403
 
 
404
 
    g_type_init();
405
 
    store = gm_pref_store_new("gecko-mediaplayer");
406
 
    if (store != NULL) {
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);
411
 
    }
412
 
 
413
 
 
414
 
    if (connection == NULL) {
415
 
        connection = dbus_hookup(this);
416
 
    }
417
 
    pluginSpecific(this);
418
 
 
419
 
    mInitialized = TRUE;
420
 
}
421
 
 
422
 
CPlugin::~CPlugin()
423
 
{
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);
430
 
 
431
 
    if (mInitialized)
432
 
        shut();
433
 
    if (sWindowObj)
434
 
        NPN_ReleaseObject(sWindowObj);
435
 
 
436
 
    mInstance = NULL;
437
 
/*
438
 
    if (mControlsScriptablePeer != NULL) {
439
 
        mControlsScriptablePeer->SetInstance(NULL);
440
 
        mControlsScriptablePeer->Release();
441
 
        NS_IF_RELEASE(mControlsScriptablePeer);
442
 
    }
443
 
*/
444
 
    clearPreference(this, "general.useragent.override");
445
 
 
446
 
    if (m_pScriptableObjectControls) {
447
 
        NPN_ReleaseObject(m_pScriptableObjectControls);
448
 
    }
449
 
 
450
 
    if (m_pScriptableObject) {
451
 
        NPN_ReleaseObject(m_pScriptableObject);
452
 
    }
453
 
}
454
 
 
455
 
 
456
 
 
457
 
NPBool CPlugin::init(NPWindow * pNPWindow)
458
 
{
459
 
    if (pNPWindow == NULL)
460
 
        return FALSE;
461
 
 
462
 
    m_Window = pNPWindow;
463
 
    mInitialized = TRUE;
464
 
 
465
 
    return mInitialized;
466
 
}
467
 
 
468
 
int16 CPlugin::handleEvent(void *event)
469
 
{
470
 
#ifdef XP_MAC
471
 
    NPEvent *ev = (NPEvent *) event;
472
 
    if (m_Window) {
473
 
        Rect box = { m_Window->y, m_Window->x,
474
 
            m_Window->y + m_Window->height, m_Window->x + m_Window->width
475
 
        };
476
 
        if (ev->what == updateEvt) {
477
 
            ::TETextBox(m_String, strlen(m_String), &box, teJustCenter);
478
 
        }
479
 
    }
480
 
#endif
481
 
    return 0;
482
 
}
483
 
 
484
 
NPError CPlugin::SetWindow(NPWindow * aWindow)
485
 
{
486
 
    GError *error = NULL;
487
 
    gchar *argvn[255];
488
 
    gint arg = 0;
489
 
    gint ok;
490
 
    ListItem *item;
491
 
    gchar *app_name;
492
 
 
493
 
    if (!acceptdata)
494
 
        return NPERR_NO_ERROR;
495
 
 
496
 
    if (aWindow == NULL)
497
 
        return NPERR_NO_ERROR;
498
 
 
499
 
    mX = aWindow->x;
500
 
    mY = aWindow->y;
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;
506
 
    }
507
 
 
508
 
 
509
 
    if (player_launched && mWidth > 0 && mHeight > 0) {
510
 
        resize_window(this, NULL, mWidth, mHeight);
511
 
    }
512
 
 
513
 
    if (!player_launched && mWidth > 0 && mHeight > 0) {
514
 
        app_name = NULL;
515
 
        if (player_backend != NULL) {
516
 
            app_name = g_find_program_in_path(player_backend);
517
 
        }
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");
522
 
        }
523
 
 
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");
535
 
        if (debug == TRUE)
536
 
            argvn[arg++] = g_strdup_printf("--verbose");
537
 
        if (name != NULL)
538
 
            argvn[arg++] = g_strdup_printf("--rpname=%s", name);
539
 
        if (console != NULL)
540
 
            argvn[arg++] = g_strdup_printf("--rpconsole=%s", console);
541
 
        if (controls != NULL) {
542
 
            argvn[arg++] = g_strdup_printf("--rpcontrols=%s", controls);
543
 
        }
544
 
        if (tv_device != NULL) {
545
 
            argvn[arg++] = g_strdup_printf("--tvdevice=%s", tv_device);
546
 
        }
547
 
        if (tv_driver != NULL) {
548
 
            argvn[arg++] = g_strdup_printf("--tvdriver=%s", tv_driver);
549
 
        }
550
 
        if (tv_input != NULL) {
551
 
            argvn[arg++] = g_strdup_printf("--tvinput=%s", tv_input);
552
 
        }
553
 
        if (tv_width > 0) {
554
 
            argvn[arg++] = g_strdup_printf("--tvwidth=%i", tv_width);
555
 
        }
556
 
        if (tv_height > 0) {
557
 
            argvn[arg++] = g_strdup_printf("--tvheight=%i", tv_height);
558
 
        }
559
 
 
560
 
        argvn[arg] = NULL;
561
 
        playerready = FALSE;
562
 
        ok = g_spawn_async(NULL, argvn, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
563
 
 
564
 
        if (ok) {
565
 
            player_launched = TRUE;
566
 
        } else {
567
 
            printf("Unable to launch %s: %s\n", app_name, error->message);
568
 
            g_error_free(error);
569
 
            error = NULL;
570
 
        }
571
 
 
572
 
        g_free(app_name);
573
 
 
574
 
        if (post_dom_events && id != NULL) {
575
 
            postDOMEvent(mInstance, id, "qt_begin");
576
 
        }
577
 
    }
578
 
 
579
 
    if (playlist != NULL) {
580
 
        item = (ListItem *) playlist->data;
581
 
        if (!item->play)
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);
588
 
                item->requested = 1;
589
 
            } else {
590
 
                item->requested = 1;
591
 
                printf("Calling GetURLNotify with item = %p src = %s\n", item, item->src);
592
 
                NPN_GetURLNotify(mInstance, item->src, NULL, item);
593
 
            }
594
 
        }
595
 
    }
596
 
    return NPERR_NO_ERROR;
597
 
}
598
 
 
599
 
 
600
 
void CPlugin::shut()
601
 
{
602
 
    ListItem *item;
603
 
    GList *iter;
604
 
 
605
 
    acceptdata = FALSE;
606
 
    mInitialized = FALSE;
607
 
 
608
 
    if (playlist != NULL) {
609
 
        for (iter = playlist; iter != NULL; iter = g_list_next(iter)) {
610
 
            item = (ListItem *) iter->data;
611
 
            if (item != NULL) {
612
 
                if (item->controlid != 0) {
613
 
                    send_signal_when_ready(this, item, "Terminate");
614
 
                }
615
 
            }
616
 
        }
617
 
    }
618
 
    send_signal_when_ready(this, NULL, "Terminate");
619
 
    playerready = FALSE;
620
 
    playlist = list_clear(playlist);
621
 
 
622
 
    if (event_destroy != NULL) {
623
 
        NPN_GetURL(mInstance, event_destroy, NULL);
624
 
    }
625
 
 
626
 
    if (connection != NULL) {
627
 
        connection = dbus_unhook(connection, this);
628
 
    }
629
 
}
630
 
 
631
 
NPBool CPlugin::isInitialized()
632
 
{
633
 
    return mInitialized;
634
 
}
635
 
 
636
 
NPError CPlugin::NewStream(NPMIMEType type, NPStream * stream, NPBool seekable, uint16 * stype)
637
 
{
638
 
    if (g_strrstr(stream->url, "javascript") == NULL) {
639
 
        printf("New Stream Requested - %s\n", stream->url);
640
 
    }
641
 
 
642
 
    if (g_strrstr(stream->url, "javascript") == NULL && stream->notifyData == NULL) {
643
 
        printf("item is NULL for %s\n", stream->url);
644
 
    }
645
 
 
646
 
    return NPERR_NO_ERROR;
647
 
}
648
 
 
649
 
NPError CPlugin::DestroyStream(NPStream * stream, NPError reason)
650
 
{
651
 
    ListItem *item;
652
 
    gint id;
653
 
    gchar *path;
654
 
    gchar *text;
655
 
    gboolean ready;
656
 
    gboolean newwindow;
657
 
 
658
 
    if (g_strrstr(stream->url, "javascript") == NULL)
659
 
        printf("Entering destroy stream reason = %i for %s\n", reason, stream->url);
660
 
 
661
 
    if (reason == NPERR_NO_ERROR) {
662
 
        item = (ListItem *) stream->notifyData;
663
 
        // item = list_find(playlist, (gchar*)stream->url);
664
 
 
665
 
        if (item == NULL) {
666
 
            printf("Leaving destroy stream - item not found\n");
667
 
            return NPERR_NO_ERROR;
668
 
        }
669
 
 
670
 
        if (item->localfp) {
671
 
            fclose(item->localfp);
672
 
            item->retrieved = TRUE;
673
 
            item->localfp = 0;
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);
677
 
            g_free(text);
678
 
            if (post_dom_events && this->id != NULL) {
679
 
                postDOMEvent(mInstance, this->id, "qt_progress");
680
 
            }
681
 
        }
682
 
 
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);
697
 
            }
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");
702
 
            if (item->play) {
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");
707
 
                }
708
 
            } else {
709
 
                item = list_find_next_playable(playlist);
710
 
                if (item != NULL) {
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;
721
 
                        if (item != NULL)
722
 
                            NPN_GetURLNotify(mInstance, item->src, NULL, item);
723
 
                    } else {
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");
728
 
                        }
729
 
                    }
730
 
                }
731
 
            }
732
 
            g_free(path);
733
 
        }
734
 
        //printf("Leaving destroy stream src = %s\n", item->src);
735
 
 
736
 
    } else if (reason == NPERR_INVALID_URL) {
737
 
        item = (ListItem *) stream->notifyData;
738
 
        if (item) {
739
 
            printf("Destroy Stream, invalid url, item is %s\n", item->src);
740
 
        } else {
741
 
            if (g_strrstr(stream->url, "javascript") == NULL) {
742
 
                printf("Destroy Stream, network error, item is NULL\n");
743
 
            }
744
 
        }
745
 
    } else {
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);
750
 
        if (item == NULL) {
751
 
            return NPERR_NO_ERROR;
752
 
        } else {
753
 
            if (post_dom_events && this->id != NULL) {
754
 
                postDOMEvent(mInstance, this->id, "qt_load");
755
 
            }
756
 
        }
757
 
 
758
 
        if (item->localfp) {
759
 
            fclose(item->localfp);
760
 
            item->retrieved = FALSE;
761
 
            item->localfp = 0;
762
 
        }
763
 
    }
764
 
 
765
 
    // list_dump(playlist);
766
 
    return NPERR_NO_ERROR;
767
 
}
768
 
 
769
 
void CPlugin::URLNotify(const char *url, NPReason reason, void *notifyData)
770
 
{
771
 
    ListItem *item = (ListItem *) notifyData;
772
 
    //DBusMessage *message;
773
 
    //const char *file;
774
 
 
775
 
    printf("URL Notify url = '%s'\nreason = %i\n%s\n%s\n%s\n", url, reason, item->src, item->local,
776
 
           path);
777
 
    if (reason == NPRES_DONE) {
778
 
 
779
 
        if (!item->opened) {
780
 
            // open_location(this,item, TRUE);
781
 
 
782
 
            /*
783
 
               file = g_strdup(item->local);
784
 
               while (!playerready) {
785
 
               // printf("waiting for player\n");
786
 
               g_main_context_iteration(NULL,FALSE);   
787
 
               }
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);
792
 
             */
793
 
        }
794
 
 
795
 
        if (item) {
796
 
            item->played = TRUE;
797
 
            if (!item->streaming) {
798
 
                item = list_find_next_playable(playlist);
799
 
                if (item) {
800
 
                    if (item->retrieved || item->streaming) {
801
 
                        open_location(this, item, TRUE);
802
 
                        item->requested = TRUE;
803
 
                    } else {
804
 
                        NPN_GetURLNotify(mInstance, item->src, NULL, item);
805
 
                        item->requested = TRUE;
806
 
                    }
807
 
                }
808
 
            }
809
 
        } else {
810
 
            item = list_find_next_playable(playlist);
811
 
            if (item) {
812
 
                if (item->retrieved || item->streaming) {
813
 
                    open_location(this, item, TRUE);
814
 
                    item->requested = TRUE;
815
 
                } else {
816
 
                    NPN_GetURLNotify(mInstance, item->src, NULL, item);
817
 
                    item->requested = TRUE;
818
 
                }
819
 
            }
820
 
        }
821
 
 
822
 
 
823
 
 
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");
828
 
    } else {
829
 
        printf("%i is an invalid reason code in URLNotify\n", reason);
830
 
    }
831
 
}
832
 
 
833
 
int32 CPlugin::WriteReady(NPStream * stream)
834
 
{
835
 
    ListItem *item;
836
 
    gchar *path;
837
 
    gchar *tmp;
838
 
 
839
 
    // printf("WriteReady called\n");
840
 
    if (!acceptdata) {
841
 
        printf("Not accepting data\n");
842
 
        NPN_DestroyStream(mInstance, stream, NPERR_GENERIC_ERROR);
843
 
        return -1;
844
 
    }
845
 
 
846
 
 
847
 
    item = (ListItem *) stream->notifyData;
848
 
    // item = list_find(playlist, (gchar*)stream->url);
849
 
    if (item == NULL) {
850
 
 
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;
856
 
            item->play = TRUE;
857
 
            if (!item->streaming)
858
 
                item->streaming = streaming(item->src);
859
 
            playlist = g_list_append(playlist, item);
860
 
            stream->notifyData = item;
861
 
        } else {
862
 
            printf("item is null\nstream url %s\n", stream->url);
863
 
            NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
864
 
            return -1;
865
 
        }
866
 
    } else {
867
 
        if (g_ascii_strcasecmp(item->src, stream->url) != 0) {
868
 
            g_strlcpy(item->src, stream->url, 4096);
869
 
        }
870
 
    }
871
 
 
872
 
    // printf("Write Ready item url = %s\n%s\n",item->src,stream->url);
873
 
 
874
 
    if (item->cancelled) {
875
 
        printf("cancelling WriteReady\n");
876
 
        NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
877
 
        return -1;
878
 
    }
879
 
 
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);
884
 
        }
885
 
        tmp = gm_tempname(path, "gecko-mediaplayerXXXXXX");
886
 
        g_snprintf(item->local, 1024, "%s", tmp);
887
 
        g_free(tmp);
888
 
        g_free(path);
889
 
        if (strstr(mimetype, "midi") != NULL) {
890
 
            g_strlcat(item->local, ".mid", 1024);
891
 
        }
892
 
        if (strstr(mimetype, "mp3") != NULL) {
893
 
            g_strlcat(item->local, ".mp3", 1024);
894
 
        }
895
 
        if (strstr(mimetype, "audio/mpeg") != NULL) {
896
 
            g_strlcat(item->local, ".mp3", 1024);
897
 
        }
898
 
        if (strstr(mimetype, "audio/x-mod") != NULL) {
899
 
            g_strlcat(item->local, ".mod", 1024);
900
 
        }
901
 
        if (strstr(mimetype, "flac") != NULL) {
902
 
            g_strlcat(item->local, ".flac", 1024);
903
 
        }
904
 
 
905
 
    }
906
 
 
907
 
    if (item->retrieved) {
908
 
        printf("Duplicate request, item already retrieved\n");
909
 
        NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
910
 
        return -1;
911
 
    }
912
 
 
913
 
    return STREAMBUFSIZE;
914
 
}
915
 
 
916
 
int32 CPlugin::Write(NPStream * stream, int32 offset, int32 len, void *buffer)
917
 
{
918
 
    ListItem *item;
919
 
    int32 wrotebytes = -1;
920
 
    gchar *text;
921
 
    gdouble percent = 0.0;
922
 
    gdouble rate = 0.0;
923
 
    gint id;
924
 
    gchar *path;
925
 
    gboolean ready;
926
 
    gboolean newwindow;
927
 
    gboolean ok_to_play = FALSE;
928
 
 
929
 
    // printf("Write Called\n");
930
 
    if (!acceptdata) {
931
 
        printf("not accepting data\n");
932
 
        NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
933
 
        return -1;
934
 
    }
935
 
 
936
 
    item = (ListItem *) stream->notifyData;
937
 
 
938
 
    if (item == NULL) {
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);
942
 
        return -1;
943
 
    }
944
 
 
945
 
    if (item->cancelled || item->retrieved) {
946
 
        printf("cancelled\n");
947
 
        NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
948
 
        return -1;
949
 
    }
950
 
 
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
956
 
 
957
 
        // printf("BUFFER='%s'\n", buffer);
958
 
 
959
 
        // printf("item->streaming = %i\n", item->streaming);
960
 
        // printf("stream->lastmodified = %i\n", stream->lastmodified);
961
 
        // printf("stream->end = %i\n", stream->end);
962
 
 
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");
967
 
        }
968
 
        item->requested = TRUE;
969
 
        if (item->localfp) {
970
 
            fclose(item->localfp);
971
 
        }
972
 
        printf("Got IceCast Stream, let mplayer stream it\n");
973
 
        NPN_DestroyStream(mInstance, stream, NPERR_NO_ERROR);
974
 
        return -1;
975
 
    }
976
 
 
977
 
    if ((!item->localfp) && (!item->retrieved)) {
978
 
        // printf("opening %s for localcache\n", item->local);
979
 
        item->localfp = fopen(item->local, "w+");
980
 
    }
981
 
    // printf("Write item url = %s\n",item->src);
982
 
 
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);
986
 
        return -1;
987
 
    }
988
 
    fseek(item->localfp, offset, SEEK_SET);
989
 
    wrotebytes = fwrite(buffer, 1, len, item->localfp);
990
 
    item->localsize += wrotebytes;
991
 
 
992
 
    if (item->mediasize != stream->end)
993
 
        item->mediasize = stream->end;
994
 
 
995
 
    if (playerready) {
996
 
        percent = 0.0;
997
 
        if (item->mediasize > 0) {
998
 
 
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);
1002
 
                rate =
1003
 
                    (gdouble) ((item->localsize -
1004
 
                                item->lastsize) / 1024.0) / (gdouble) difftime(time(NULL),
1005
 
                                                                               lastupdate);
1006
 
                if (percent > 0.99) {
1007
 
                    text =
1008
 
                        g_strdup_printf(_("Caching %iK (%0.1f K/s)"), item->mediasize / 1024, rate);
1009
 
                } else {
1010
 
                    text =
1011
 
                        g_strdup_printf(_("Cache fill: %2.2f%% (%0.1f K/s)"), percent * 100.0,
1012
 
                                        rate);
1013
 
                }
1014
 
                send_signal_with_string(this, item, "SetProgressText", text);
1015
 
                if (!item->opened)
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");
1020
 
                }
1021
 
 
1022
 
                time(&lastupdate);
1023
 
                item->lastsize = item->localsize;
1024
 
            }
1025
 
        }
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);
1029
 
                ok_to_play = TRUE;
1030
 
            }
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);
1035
 
                ok_to_play = TRUE;
1036
 
            }
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++;
1042
 
                }
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);
1047
 
                        ok_to_play = TRUE;
1048
 
                        if (post_dom_events && this->id != NULL) {
1049
 
                            postDOMEvent(mInstance, this->id, "qt_canplay");
1050
 
                        }
1051
 
                    }
1052
 
                }
1053
 
            }
1054
 
 
1055
 
        }
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);
1070
 
            }
1071
 
            // printf("item->play = %i\n",item->play);
1072
 
            // printf("item->src = %i\n", item->src);
1073
 
            // printf("calling open_location from Write\n"); 
1074
 
            if (item->play) {
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");
1082
 
                }
1083
 
            } else {
1084
 
                item = list_find_next_playable(playlist);
1085
 
                if (item != NULL) {
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;
1095
 
                    } else {
1096
 
                        NPN_GetURLNotify(mInstance, item->src, NULL, item);
1097
 
                        item->requested = TRUE;
1098
 
                    }
1099
 
                }
1100
 
            }
1101
 
            g_free(path);
1102
 
        }
1103
 
 
1104
 
    }
1105
 
 
1106
 
    return wrotebytes;
1107
 
}
1108
 
 
1109
 
 
1110
 
void CPlugin::Play()
1111
 
{
1112
 
    send_signal(this, this->lastopened, "Play");
1113
 
    if (post_dom_events && this->id != NULL) {
1114
 
        postDOMEvent(mInstance, this->id, "qt_play");
1115
 
    }
1116
 
}
1117
 
 
1118
 
void CPlugin::Pause()
1119
 
{
1120
 
    send_signal(this, this->lastopened, "Pause");
1121
 
    if (post_dom_events && this->id != NULL) {
1122
 
        postDOMEvent(mInstance, this->id, "qt_pause");
1123
 
    }
1124
 
}
1125
 
 
1126
 
void CPlugin::Stop()
1127
 
{
1128
 
    send_signal(this, this->lastopened, "Stop");
1129
 
}
1130
 
 
1131
 
void CPlugin::FastForward()
1132
 
{
1133
 
    send_signal(this, this->lastopened, "FastForward");
1134
 
}
1135
 
 
1136
 
void CPlugin::FastReverse()
1137
 
{
1138
 
    send_signal(this, this->lastopened, "FastReverse");
1139
 
}
1140
 
 
1141
 
void CPlugin::Seek(double counter)
1142
 
{
1143
 
    send_signal_with_double(this, this->lastopened, "Seek", counter);
1144
 
}
1145
 
 
1146
 
void CPlugin::SetShowControls(bool value)
1147
 
{
1148
 
    send_signal_with_boolean(this, this->lastopened, "SetShowControls", value);
1149
 
}
1150
 
 
1151
 
void CPlugin::SetFullScreen(bool value)
1152
 
{
1153
 
    send_signal_with_boolean(this, this->lastopened, "SetFullScreen", value);
1154
 
}
1155
 
 
1156
 
void CPlugin::SetVolume(double value)
1157
 
{
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");
1161
 
    }
1162
 
}
1163
 
 
1164
 
void CPlugin::GetVolume(double *_retval)
1165
 
{
1166
 
    *_retval = request_double_value(this, this->lastopened, "GetVolume");
1167
 
}
1168
 
 
1169
 
void CPlugin::GetFullScreen(bool * _retval)
1170
 
{
1171
 
    *_retval = request_boolean_value(this, this->lastopened, "GetFullScreen");
1172
 
}
1173
 
 
1174
 
void CPlugin::GetShowControls(bool * _retval)
1175
 
{
1176
 
    *_retval = request_boolean_value(this, this->lastopened, "GetShowControls");
1177
 
}
1178
 
 
1179
 
void CPlugin::GetTime(double *_retval)
1180
 
{
1181
 
    *_retval = request_double_value(this, this->lastopened, "GetTime");
1182
 
}
1183
 
 
1184
 
void CPlugin::GetDuration(double *_retval)
1185
 
{
1186
 
    *_retval = request_double_value(this, this->lastopened, "GetDuration");
1187
 
}
1188
 
 
1189
 
void CPlugin::GetPercent(double *_retval)
1190
 
{
1191
 
    *_retval = request_double_value(this, this->lastopened, "GetPercent");
1192
 
}
1193
 
 
1194
 
void CPlugin::SetFilename(const char *filename)
1195
 
{
1196
 
    ListItem *item;
1197
 
 
1198
 
    if (filename == NULL)
1199
 
        return;
1200
 
 
1201
 
    item = g_new0(ListItem, 1);
1202
 
    g_strlcpy(item->src, filename, 1024);
1203
 
    item->streaming = streaming(item->src);
1204
 
    item->play = TRUE;
1205
 
    item->id = nextid++;
1206
 
    playlist = g_list_append(playlist, item);
1207
 
 
1208
 
    send_signal(this, this->lastopened, "Quit");
1209
 
 
1210
 
    if (item->streaming) {
1211
 
        open_location(this, item, FALSE);
1212
 
        item->requested = 1;
1213
 
    } else {
1214
 
        item->requested = 1;
1215
 
        NPN_GetURLNotify(mInstance, item->src, NULL, item);
1216
 
    }
1217
 
}
1218
 
 
1219
 
void CPlugin::GetFilename(char **filename)
1220
 
{
1221
 
    ListItem *item;
1222
 
    if (this->lastopened != NULL) {
1223
 
        *filename = g_strdup(this->lastopened->src);
1224
 
    } else {
1225
 
        item = (ListItem *) playlist->data;
1226
 
        if (item != NULL) {
1227
 
            *filename = g_strdup(item->src);
1228
 
        } else {
1229
 
            *filename = NULL;
1230
 
        }
1231
 
    }
1232
 
}
1233
 
 
1234
 
void CPlugin::GetMIMEType(char **_retval)
1235
 
{
1236
 
    *_retval = g_strdup(mimetype);
1237
 
}
1238
 
 
1239
 
void CPlugin::GetPlayState(PRInt32 * playstate)
1240
 
{
1241
 
    *playstate = request_int_value(this, this->lastopened, "GetPlayState");
1242
 
}
1243
 
 
1244
 
void CPlugin::GetLoop(bool * _retval)
1245
 
{
1246
 
    if (lastopened != NULL) {
1247
 
        *_retval = (bool) lastopened->loop;
1248
 
    } else {
1249
 
        *_retval = FALSE;
1250
 
    }
1251
 
 
1252
 
}
1253
 
 
1254
 
void CPlugin::SetLoop(bool value)
1255
 
{
1256
 
    if (lastopened != NULL) {
1257
 
        lastopened->loop = (int) value;
1258
 
        lastopened->loopcount = -1;
1259
 
    }
1260
 
}
1261
 
 
1262
 
void CPlugin::PlayPause()
1263
 
{
1264
 
    gint state;
1265
 
 
1266
 
    state = request_int_value(this, this->lastopened, "GetPlayState");
1267
 
    if (state == STATE_PAUSED) {
1268
 
        send_signal(this, this->lastopened, "Play");
1269
 
    }
1270
 
 
1271
 
    if (state == STATE_PLAYING) {
1272
 
        send_signal(this, this->lastopened, "Pause");
1273
 
    }
1274
 
}
1275
 
 
1276
 
 
1277
 
void CPlugin::SetOnClick(const char *event)
1278
 
{
1279
 
    if (event_mouseclicked != NULL) {
1280
 
        g_free(event_mouseclicked);
1281
 
    }
1282
 
 
1283
 
    if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1284
 
        event_mouseclicked = g_strdup_printf("%s", event);
1285
 
    } else {
1286
 
        event_mouseclicked = g_strdup_printf("javascript:%s", event);
1287
 
    }
1288
 
}
1289
 
 
1290
 
void CPlugin::SetOnMediaComplete(const char *event)
1291
 
{
1292
 
    if (event_mediacomplete != NULL) {
1293
 
        g_free(event_mediacomplete);
1294
 
    }
1295
 
 
1296
 
    if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1297
 
        event_mediacomplete = g_strdup_printf("%s", event);
1298
 
    } else {
1299
 
        event_mediacomplete = g_strdup_printf("javascript:%s", event);
1300
 
    }
1301
 
}
1302
 
 
1303
 
void CPlugin::SetOnMouseUp(const char *event)
1304
 
{
1305
 
    if (event_mouseup != NULL) {
1306
 
        g_free(event_mouseup);
1307
 
    }
1308
 
 
1309
 
    if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1310
 
        event_mouseup = g_strdup_printf("%s", event);
1311
 
    } else {
1312
 
        event_mouseup = g_strdup_printf("javascript:%s", event);
1313
 
    }
1314
 
}
1315
 
 
1316
 
void CPlugin::SetOnMouseDown(const char *event)
1317
 
{
1318
 
    if (event_mousedown != NULL) {
1319
 
        g_free(event_mousedown);
1320
 
    }
1321
 
 
1322
 
    if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1323
 
        event_mousedown = g_strdup_printf("%s", event);
1324
 
    } else {
1325
 
        event_mousedown = g_strdup_printf("javascript:%s", event);
1326
 
    }
1327
 
}
1328
 
 
1329
 
void CPlugin::SetOnMouseOut(const char *event)
1330
 
{
1331
 
    if (event_leavewindow != NULL) {
1332
 
        g_free(event_leavewindow);
1333
 
    }
1334
 
 
1335
 
    if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1336
 
        event_leavewindow = g_strdup_printf("%s", event);
1337
 
    } else {
1338
 
        event_leavewindow = g_strdup_printf("javascript:%s", event);
1339
 
    }
1340
 
}
1341
 
 
1342
 
void CPlugin::SetOnMouseOver(const char *event)
1343
 
{
1344
 
    if (event_enterwindow != NULL) {
1345
 
        g_free(event_enterwindow);
1346
 
    }
1347
 
 
1348
 
    if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1349
 
        event_enterwindow = g_strdup_printf("%s", event);
1350
 
    } else {
1351
 
        event_enterwindow = g_strdup_printf("javascript:%s", event);
1352
 
    }
1353
 
}
1354
 
 
1355
 
void CPlugin::SetOnDestroy(const char *event)
1356
 
{
1357
 
    if (event_destroy != NULL) {
1358
 
        g_free(event_destroy);
1359
 
    }
1360
 
 
1361
 
    if (g_ascii_strncasecmp(event, "javascript:", 11) == 0) {
1362
 
        event_destroy = g_strdup_printf("%s", event);
1363
 
    } else {
1364
 
        event_destroy = g_strdup_printf("javascript:%s", event);
1365
 
    }
1366
 
}
1367
 
 
1368
 
// ==============================
1369
 
// ! Scriptability related code !
1370
 
// ==============================
1371
 
//
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 {
1378
 
  public:
1379
 
    ScriptablePluginObjectBase(NPP npp)
1380
 
    :mNpp(npp) {
1381
 
    } virtual ~ ScriptablePluginObjectBase() {
1382
 
    }
1383
 
 
1384
 
    // Virtual NPObject hooks called through this base class. Override
1385
 
    // as you see fit.
1386
 
 
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);
1396
 
 
1397
 
  public:
1398
 
 
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);
1410
 
 
1411
 
  protected:
1412
 
    NPP mNpp;
1413
 
};
1414
 
 
1415
 
#define DECLARE_NPOBJECT_CLASS_WITH_BASE(_class, ctor)                        \
1416
 
static NPClass s##_class##_NPClass = {                                        \
1417
 
  NP_CLASS_STRUCT_VERSION,                                                    \
1418
 
  ctor,                                                                       \
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                                 \
1428
 
}
1429
 
 
1430
 
#define GET_NPOBJECT_CLASS(_class) &s##_class##_NPClass
1431
 
 
1432
 
void ScriptablePluginObjectBase::Invalidate()
1433
 
{
1434
 
}
1435
 
 
1436
 
bool ScriptablePluginObjectBase::HasMethod(NPIdentifier name)
1437
 
{
1438
 
    return false;
1439
 
}
1440
 
 
1441
 
bool ScriptablePluginObjectBase::Invoke(NPIdentifier name, const NPVariant * args,
1442
 
                                        uint32_t argCount, NPVariant * result)
1443
 
{
1444
 
    return false;
1445
 
}
1446
 
 
1447
 
bool ScriptablePluginObjectBase::InvokeDefault(const NPVariant * args,
1448
 
                                               uint32_t argCount, NPVariant * result)
1449
 
{
1450
 
    return false;
1451
 
}
1452
 
 
1453
 
bool ScriptablePluginObjectBase::HasProperty(NPIdentifier name)
1454
 
{
1455
 
    return false;
1456
 
}
1457
 
 
1458
 
bool ScriptablePluginObjectBase::GetProperty(NPIdentifier name, NPVariant * result)
1459
 
{
1460
 
 
1461
 
    VOID_TO_NPVARIANT(*result);
1462
 
 
1463
 
    return false;
1464
 
}
1465
 
 
1466
 
bool ScriptablePluginObjectBase::SetProperty(NPIdentifier name, const NPVariant * value)
1467
 
{
1468
 
    return false;
1469
 
}
1470
 
 
1471
 
bool ScriptablePluginObjectBase::RemoveProperty(NPIdentifier name)
1472
 
{
1473
 
    return false;
1474
 
}
1475
 
 
1476
 
// static
1477
 
void ScriptablePluginObjectBase::_Deallocate(NPObject * npobj)
1478
 
{
1479
 
    // Call the virtual destructor.
1480
 
    delete(ScriptablePluginObjectBase *) npobj;
1481
 
}
1482
 
 
1483
 
// static
1484
 
void ScriptablePluginObjectBase::_Invalidate(NPObject * npobj)
1485
 
{
1486
 
    ((ScriptablePluginObjectBase *) npobj)->Invalidate();
1487
 
}
1488
 
 
1489
 
// static
1490
 
bool ScriptablePluginObjectBase::_HasMethod(NPObject * npobj, NPIdentifier name)
1491
 
{
1492
 
    return ((ScriptablePluginObjectBase *) npobj)->HasMethod(name);
1493
 
}
1494
 
 
1495
 
// static
1496
 
bool ScriptablePluginObjectBase::_Invoke(NPObject * npobj, NPIdentifier name,
1497
 
                                         const NPVariant * args, uint32_t argCount,
1498
 
                                         NPVariant * result)
1499
 
{
1500
 
    return ((ScriptablePluginObjectBase *) npobj)->Invoke(name, args, argCount, result);
1501
 
}
1502
 
 
1503
 
// static
1504
 
bool ScriptablePluginObjectBase::_InvokeDefault(NPObject * npobj,
1505
 
                                                const NPVariant * args,
1506
 
                                                uint32_t argCount, NPVariant * result)
1507
 
{
1508
 
    return ((ScriptablePluginObjectBase *) npobj)->InvokeDefault(args, argCount, result);
1509
 
}
1510
 
 
1511
 
// static
1512
 
bool ScriptablePluginObjectBase::_HasProperty(NPObject * npobj, NPIdentifier name)
1513
 
{
1514
 
    return ((ScriptablePluginObjectBase *) npobj)->HasProperty(name);
1515
 
}
1516
 
 
1517
 
// static
1518
 
bool ScriptablePluginObjectBase::_GetProperty(NPObject * npobj, NPIdentifier name,
1519
 
                                              NPVariant * result)
1520
 
{
1521
 
    return ((ScriptablePluginObjectBase *) npobj)->GetProperty(name, result);
1522
 
}
1523
 
 
1524
 
// static
1525
 
bool ScriptablePluginObjectBase::_SetProperty(NPObject * npobj, NPIdentifier name,
1526
 
                                              const NPVariant * value)
1527
 
{
1528
 
    return ((ScriptablePluginObjectBase *) npobj)->SetProperty(name, value);
1529
 
}
1530
 
 
1531
 
// static
1532
 
bool ScriptablePluginObjectBase::_RemoveProperty(NPObject * npobj, NPIdentifier name)
1533
 
{
1534
 
    return ((ScriptablePluginObjectBase *) npobj)->RemoveProperty(name);
1535
 
}
1536
 
 
1537
 
class ScriptablePluginObjectControls:public ScriptablePluginObjectBase {
1538
 
  public:
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);
1548
 
 
1549
 
};
1550
 
 
1551
 
static NPObject *AllocateScriptablePluginObjectControls(NPP npp, NPClass * aClass)
1552
 
{
1553
 
    return new ScriptablePluginObjectControls(npp);
1554
 
}
1555
 
 
1556
 
DECLARE_NPOBJECT_CLASS_WITH_BASE(ScriptablePluginObjectControls,
1557
 
                                 AllocateScriptablePluginObjectControls);
1558
 
 
1559
 
bool ScriptablePluginObjectControls::HasMethod(NPIdentifier name)
1560
 
{
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) {
1566
 
        return true;
1567
 
    } else {
1568
 
        return false;
1569
 
    }
1570
 
}
1571
 
 
1572
 
bool ScriptablePluginObjectControls::Invoke(NPIdentifier name, const NPVariant * args,
1573
 
                                            uint32_t argCount, NPVariant * result)
1574
 
{
1575
 
    CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
1576
 
    if (pPlugin == NULL) {
1577
 
        printf("Can't find plugin pointer\n");
1578
 
        return PR_FALSE;
1579
 
    }
1580
 
 
1581
 
    if (name == controls_play_id) {
1582
 
        pPlugin->Play();
1583
 
        return PR_TRUE;
1584
 
    }
1585
 
 
1586
 
    if (name == controls_pause_id) {
1587
 
        pPlugin->Pause();
1588
 
        return PR_TRUE;
1589
 
    }
1590
 
 
1591
 
    if (name == controls_stop_id) {
1592
 
        pPlugin->Stop();
1593
 
        return PR_TRUE;
1594
 
    }
1595
 
 
1596
 
    return false;
1597
 
}
1598
 
 
1599
 
bool ScriptablePluginObjectControls::InvokeDefault(const NPVariant * args, uint32_t argCount,
1600
 
                                                   NPVariant * result)
1601
 
{
1602
 
    printf("ScriptablePluginObject default method called!\n");
1603
 
 
1604
 
    STRINGZ_TO_NPVARIANT(strdup("default method return val"), *result);
1605
 
 
1606
 
    return PR_TRUE;
1607
 
}
1608
 
 
1609
 
bool ScriptablePluginObjectControls::HasProperty(NPIdentifier name)
1610
 
{
1611
 
    if (name == controls_currentPosition_id) {
1612
 
        return true;
1613
 
    } else {
1614
 
        return false;
1615
 
    }
1616
 
}
1617
 
 
1618
 
bool ScriptablePluginObjectControls::GetProperty(NPIdentifier name, NPVariant * result)
1619
 
{
1620
 
    double position;
1621
 
 
1622
 
    CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
1623
 
    if (pPlugin == NULL) {
1624
 
        printf("Can't find plugin pointer\n");
1625
 
        VOID_TO_NPVARIANT(*result);
1626
 
        return false;
1627
 
    }
1628
 
 
1629
 
    if (name == controls_currentPosition_id) {
1630
 
        pPlugin->GetTime(&position);
1631
 
        DOUBLE_TO_NPVARIANT(position, *result);
1632
 
        return true;
1633
 
    }
1634
 
 
1635
 
    VOID_TO_NPVARIANT(*result);
1636
 
    return false;
1637
 
}
1638
 
 
1639
 
bool ScriptablePluginObjectControls::SetProperty(NPIdentifier name, const NPVariant * value)
1640
 
{
1641
 
    CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
1642
 
    if (pPlugin == NULL) {
1643
 
        printf("Can't find plugin pointer\n");
1644
 
        return false;
1645
 
    }
1646
 
 
1647
 
    if (name == controls_currentPosition_id) {
1648
 
        pPlugin->Seek(NPVARIANT_TO_DOUBLE(*value));
1649
 
        return true;
1650
 
    }
1651
 
 
1652
 
    return false;
1653
 
}
1654
 
 
1655
 
 
1656
 
class ScriptablePluginObject:public ScriptablePluginObjectBase {
1657
 
  public:
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);
1667
 
 
1668
 
};
1669
 
 
1670
 
static NPObject *AllocateScriptablePluginObject(NPP npp, NPClass * aClass)
1671
 
{
1672
 
    return new ScriptablePluginObject(npp);
1673
 
}
1674
 
 
1675
 
DECLARE_NPOBJECT_CLASS_WITH_BASE(ScriptablePluginObject, AllocateScriptablePluginObject);
1676
 
 
1677
 
 
1678
 
bool ScriptablePluginObject::HasMethod(NPIdentifier name)
1679
 
{
1680
 
    if (name == Play_id ||
1681
 
        name == PlayAt_id ||
1682
 
        name == Pause_id ||
1683
 
        name == PlayPause_id ||
1684
 
        name == Stop_id ||
1685
 
        name == quit_id ||
1686
 
        name == DoPlay_id ||
1687
 
        name == DoPause_id ||
1688
 
        name == FastForward_id ||
1689
 
        name == FastReverse_id ||
1690
 
        name == ff_id ||
1691
 
        name == rew_id ||
1692
 
        name == rewind_id ||
1693
 
        name == Seek_id ||
1694
 
        name == Open_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) {
1719
 
        return true;
1720
 
    } else {
1721
 
        return false;
1722
 
    }
1723
 
}
1724
 
 
1725
 
bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant * args,
1726
 
                                    uint32_t argCount, NPVariant * result)
1727
 
{
1728
 
    double d;
1729
 
    char *s;
1730
 
    bool b;
1731
 
 
1732
 
    CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
1733
 
    if (pPlugin == NULL) {
1734
 
        printf("Can't find plugin pointer\n");
1735
 
        return PR_FALSE;
1736
 
    }
1737
 
 
1738
 
    if (name == Play_id || name == DoPlay_id) {
1739
 
        pPlugin->Play();
1740
 
        return PR_TRUE;
1741
 
    }
1742
 
 
1743
 
    if (name == PlayAt_id) {
1744
 
        pPlugin->Play();
1745
 
        if ((int)NPVARIANT_TO_DOUBLE(args[0]) == 0 && NPVARIANT_TO_INT32(args[0]) > 0) {
1746
 
            pPlugin->Seek((double)NPVARIANT_TO_INT32(args[0]));
1747
 
        } else {
1748
 
            pPlugin->Seek(NPVARIANT_TO_DOUBLE(args[0]));
1749
 
        }
1750
 
        return PR_TRUE;
1751
 
    }
1752
 
 
1753
 
    if (name == Pause_id || name == DoPause_id) {
1754
 
        pPlugin->Pause();
1755
 
        return PR_TRUE;
1756
 
    }
1757
 
 
1758
 
    if (name == PlayPause_id) {
1759
 
        pPlugin->PlayPause();
1760
 
        return PR_TRUE;
1761
 
    }
1762
 
 
1763
 
    if (name == Stop_id) {
1764
 
        pPlugin->Stop();
1765
 
        return PR_TRUE;
1766
 
    }
1767
 
 
1768
 
    if (name == FastForward_id || name == ff_id) {
1769
 
        pPlugin->FastForward();
1770
 
        return PR_TRUE;
1771
 
    }
1772
 
 
1773
 
    if (name == FastReverse_id || name == rew_id || name == rewind_id) {
1774
 
        pPlugin->FastReverse();
1775
 
        return PR_TRUE;
1776
 
    }
1777
 
 
1778
 
    if (name == Seek_id) {
1779
 
        
1780
 
        if ((int)NPVARIANT_TO_DOUBLE(args[0]) == 0 && NPVARIANT_TO_INT32(args[0]) > 0) {
1781
 
            pPlugin->Seek((double)NPVARIANT_TO_INT32(args[0]));
1782
 
        } else {
1783
 
            pPlugin->Seek(NPVARIANT_TO_DOUBLE(args[0]));
1784
 
        }
1785
 
        return PR_TRUE;
1786
 
    }
1787
 
 
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);
1791
 
#else
1792
 
        pPlugin->SetFilename(NPVARIANT_TO_STRING(args[0]).utf8characters);
1793
 
#endif
1794
 
        return PR_TRUE;
1795
 
    }
1796
 
 
1797
 
    if (name == GetFileName_id || name == GetHREF_id || name == GetURL_id) {
1798
 
        pPlugin->GetFilename(&s);
1799
 
        STRINGZ_TO_NPVARIANT(s, *result);
1800
 
        g_free(s);
1801
 
        return PR_TRUE;
1802
 
    }
1803
 
 
1804
 
    if (name == SetVolume_id) {
1805
 
        pPlugin->SetVolume(NPVARIANT_TO_DOUBLE(args[0]));
1806
 
        return PR_TRUE;
1807
 
    }
1808
 
 
1809
 
    if (name == GetVolume_id) {
1810
 
        pPlugin->GetVolume(&d);
1811
 
        DOUBLE_TO_NPVARIANT(d, *result);
1812
 
        return PR_TRUE;
1813
 
    }
1814
 
 
1815
 
    if (name == SetIsLooping_id) {
1816
 
        pPlugin->SetLoop(NPVARIANT_TO_BOOLEAN(args[0]));
1817
 
        return PR_TRUE;
1818
 
    }
1819
 
 
1820
 
    if (name == GetIsLooping_id) {
1821
 
        pPlugin->GetLoop(&b);
1822
 
        BOOLEAN_TO_NPVARIANT(b, *result);
1823
 
        return PR_TRUE;
1824
 
    }
1825
 
 
1826
 
    if (name == SetAutoPlay_id) {
1827
 
        pPlugin->autostart = NPVARIANT_TO_BOOLEAN(args[0]);
1828
 
        return PR_TRUE;
1829
 
    }
1830
 
 
1831
 
    if (name == GetAutoPlay_id) {
1832
 
        BOOLEAN_TO_NPVARIANT(pPlugin->autostart, *result);
1833
 
        return PR_TRUE;
1834
 
    }
1835
 
 
1836
 
    if (name == GetMIMEType_id) {
1837
 
        pPlugin->GetMIMEType(&s);
1838
 
        STRINGZ_TO_NPVARIANT(s, *result);
1839
 
        g_free(s);
1840
 
        return PR_TRUE;
1841
 
    }
1842
 
 
1843
 
    if (name == getTime_id) {
1844
 
        pPlugin->GetTime(&d);
1845
 
        DOUBLE_TO_NPVARIANT(d, *result);
1846
 
        return PR_TRUE;
1847
 
    }
1848
 
 
1849
 
    if (name == getDuration_id) {
1850
 
        pPlugin->GetDuration(&d);
1851
 
        DOUBLE_TO_NPVARIANT(d, *result);
1852
 
        return PR_TRUE;
1853
 
    }
1854
 
 
1855
 
    if (name == getPercent_id) {
1856
 
        pPlugin->GetPercent(&d);
1857
 
        DOUBLE_TO_NPVARIANT(d, *result);
1858
 
        return PR_TRUE;
1859
 
    }
1860
 
 
1861
 
    if (name == isplaying_id || name == playlistAppend_id || name == playlistClear_id) {
1862
 
        return PR_TRUE;
1863
 
    }
1864
 
 
1865
 
    if (name == onClick_id) {
1866
 
#ifdef HAVE_NEW_XULRUNNER
1867
 
        pPlugin->SetOnClick(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1868
 
#else
1869
 
        pPlugin->SetOnClick(NPVARIANT_TO_STRING(args[0]).utf8characters);
1870
 
#endif
1871
 
        return PR_TRUE;
1872
 
    }
1873
 
 
1874
 
    if (name == onMediaComplete_id) {
1875
 
#ifdef HAVE_NEW_XULRUNNER
1876
 
        pPlugin->SetOnMediaComplete(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1877
 
#else
1878
 
        pPlugin->SetOnMediaComplete(NPVARIANT_TO_STRING(args[0]).utf8characters);
1879
 
#endif
1880
 
        return PR_TRUE;
1881
 
    }
1882
 
 
1883
 
    if (name == onMouseUp_id) {
1884
 
#ifdef HAVE_NEW_XULRUNNER
1885
 
        pPlugin->SetOnMouseUp(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1886
 
#else
1887
 
        pPlugin->SetOnMouseUp(NPVARIANT_TO_STRING(args[0]).utf8characters);
1888
 
#endif
1889
 
        return PR_TRUE;
1890
 
    }
1891
 
 
1892
 
    if (name == onMouseDown_id) {
1893
 
#ifdef HAVE_NEW_XULRUNNER
1894
 
        pPlugin->SetOnMouseDown(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1895
 
#else
1896
 
        pPlugin->SetOnMouseDown(NPVARIANT_TO_STRING(args[0]).utf8characters);
1897
 
#endif
1898
 
        return PR_TRUE;
1899
 
    }
1900
 
 
1901
 
    if (name == onMouseOut_id) {
1902
 
#ifdef HAVE_NEW_XULRUNNER
1903
 
        pPlugin->SetOnMouseOut(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1904
 
#else
1905
 
        pPlugin->SetOnMouseOut(NPVARIANT_TO_STRING(args[0]).utf8characters);
1906
 
#endif
1907
 
        return PR_TRUE;
1908
 
    }
1909
 
 
1910
 
    if (name == onMouseOver_id) {
1911
 
#ifdef HAVE_NEW_XULRUNNER
1912
 
        pPlugin->SetOnMouseOver(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1913
 
#else
1914
 
        pPlugin->SetOnMouseOver(NPVARIANT_TO_STRING(args[0]).utf8characters);
1915
 
#endif
1916
 
        return PR_TRUE;
1917
 
    }
1918
 
 
1919
 
    if (name == onDestroy_id) {
1920
 
#ifdef HAVE_NEW_XULRUNNER
1921
 
        pPlugin->SetOnDestroy(NPVARIANT_TO_STRING(args[0]).UTF8Characters);
1922
 
#else
1923
 
        pPlugin->SetOnDestroy(NPVARIANT_TO_STRING(args[0]).utf8characters);
1924
 
#endif
1925
 
        return PR_TRUE;
1926
 
    }
1927
 
 
1928
 
    return PR_FALSE;
1929
 
}
1930
 
 
1931
 
bool ScriptablePluginObject::InvokeDefault(const NPVariant * args, uint32_t argCount,
1932
 
                                           NPVariant * result)
1933
 
{
1934
 
    printf("ScriptablePluginObject default method called!\n");
1935
 
 
1936
 
    STRINGZ_TO_NPVARIANT(strdup("default method return val"), *result);
1937
 
 
1938
 
    return PR_TRUE;
1939
 
}
1940
 
 
1941
 
bool ScriptablePluginObject::HasProperty(NPIdentifier name)
1942
 
{
1943
 
    if (name == filename_id ||
1944
 
        name == src_id ||
1945
 
        name == ShowControls_id ||
1946
 
        name == fullscreen_id ||
1947
 
        name == showlogo_id || name == playState_id || name == controls_id) {
1948
 
        return true;
1949
 
    } else {
1950
 
        return false;
1951
 
    }
1952
 
}
1953
 
 
1954
 
bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant * result)
1955
 
{
1956
 
    char *filename;
1957
 
    bool setting;
1958
 
    PRInt32 state;
1959
 
 
1960
 
    CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
1961
 
    if (pPlugin == NULL) {
1962
 
        printf("Can't find plugin pointer\n");
1963
 
        VOID_TO_NPVARIANT(*result);
1964
 
        return false;
1965
 
    }
1966
 
 
1967
 
    if (name == filename_id || name == src_id) {
1968
 
        pPlugin->GetFilename(&filename);
1969
 
        STRINGZ_TO_NPVARIANT(filename, *result);
1970
 
        return true;
1971
 
    }
1972
 
 
1973
 
    if (name == ShowControls_id) {
1974
 
        pPlugin->GetShowControls(&setting);
1975
 
        BOOLEAN_TO_NPVARIANT(setting, *result);
1976
 
        return true;
1977
 
    }
1978
 
 
1979
 
    if (name == fullscreen_id) {
1980
 
        pPlugin->GetFullScreen(&setting);
1981
 
        BOOLEAN_TO_NPVARIANT(setting, *result);
1982
 
        return true;
1983
 
    }
1984
 
 
1985
 
    if (name == showlogo_id) {
1986
 
        setting = true;
1987
 
        BOOLEAN_TO_NPVARIANT(setting, *result);
1988
 
        return true;
1989
 
    }
1990
 
 
1991
 
    if (name == playState_id) {
1992
 
        pPlugin->GetPlayState(&state);
1993
 
        INT32_TO_NPVARIANT(state, *result);
1994
 
        return true;
1995
 
    }
1996
 
 
1997
 
    if (name == controls_id) {
1998
 
        OBJECT_TO_NPVARIANT(pPlugin->GetScriptableObjectControls(), *result);
1999
 
        return true;
2000
 
    }
2001
 
 
2002
 
    VOID_TO_NPVARIANT(*result);
2003
 
    return false;
2004
 
}
2005
 
 
2006
 
bool ScriptablePluginObject::SetProperty(NPIdentifier name, const NPVariant * value)
2007
 
{
2008
 
    CPlugin *pPlugin = (CPlugin *) mNpp->pdata;
2009
 
    if (pPlugin == NULL) {
2010
 
        printf("Can't find plugin pointer\n");
2011
 
        return false;
2012
 
    }
2013
 
 
2014
 
    if (name == filename_id || name == src_id) {
2015
 
#ifdef HAVE_NEW_XULRUNNER
2016
 
        pPlugin->SetFilename(NPVARIANT_TO_STRING(*value).UTF8Characters);
2017
 
#else
2018
 
        pPlugin->SetFilename(NPVARIANT_TO_STRING(*value).utf8characters);
2019
 
#endif
2020
 
        return true;
2021
 
    }
2022
 
 
2023
 
    if (name == ShowControls_id) {
2024
 
        pPlugin->SetShowControls(NPVARIANT_TO_BOOLEAN(*value));
2025
 
        return true;
2026
 
    }
2027
 
 
2028
 
    if (name == fullscreen_id) {
2029
 
        pPlugin->SetFullScreen(NPVARIANT_TO_BOOLEAN(*value));
2030
 
        return true;
2031
 
    }
2032
 
 
2033
 
    if (name == showlogo_id) {
2034
 
        return true;
2035
 
    }
2036
 
 
2037
 
    if (name == playState_id) {
2038
 
        // readonly property
2039
 
        return true;
2040
 
    }
2041
 
 
2042
 
    return false;
2043
 
}
2044
 
 
2045
 
NPObject *CPlugin::GetScriptableObject()
2046
 
{
2047
 
    if (!m_pScriptableObject) {
2048
 
        m_pScriptableObject =
2049
 
            NPN_CreateObject(mInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject));
2050
 
    }
2051
 
 
2052
 
    if (m_pScriptableObject) {
2053
 
        NPN_RetainObject(m_pScriptableObject);
2054
 
    }
2055
 
 
2056
 
    return m_pScriptableObject;
2057
 
}
2058
 
 
2059
 
NPObject *CPlugin::GetScriptableObjectControls()
2060
 
{
2061
 
    if (!m_pScriptableObjectControls) {
2062
 
        m_pScriptableObjectControls =
2063
 
            NPN_CreateObject(mInstance, GET_NPOBJECT_CLASS(ScriptablePluginObjectControls));
2064
 
    }
2065
 
 
2066
 
    if (m_pScriptableObjectControls) {
2067
 
        NPN_RetainObject(m_pScriptableObjectControls);
2068
 
    }
2069
 
 
2070
 
    return m_pScriptableObjectControls;
2071
 
}