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 ***** */
38
// ==============================
39
// ! Scriptability related code !
40
// ==============================
42
/////////////////////////////////////////////////////
44
// This file implements the nsScriptablePeer object
45
// The native methods of this class are supposed to
46
// be callable from JavaScript
50
static NS_DEFINE_IID(kIScriptableIID, NS_ISCRIPTABLEGECKOMEDIAPLAYER_IID);
51
static NS_DEFINE_IID(kIScriptableControlIID, NS_ISCRIPTABLEGECKOMEDIAPLAYERCONTROLS_IID);
52
static NS_DEFINE_IID(kIClassInfoIID, NS_ICLASSINFO_IID);
53
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
55
nsScriptablePeer::nsScriptablePeer(nsPluginInstance * aPlugin)
62
nsScriptablePeer::~nsScriptablePeer()
66
void nsScriptablePeer::InitControls(nsControlsScriptablePeer * aControls)
68
mControls = aControls;
71
// AddRef, Release and QueryInterface are common methods and must
72
// be implemented for any interface
73
NS_IMETHODIMP_(nsrefcnt) nsScriptablePeer::AddRef()
79
NS_IMETHODIMP_(nsrefcnt) nsScriptablePeer::Release()
89
// here nsScriptablePeer should return three interfaces it can be asked for by their iid's
90
// static casts are necessary to ensure that correct pointer is returned
91
NS_IMETHODIMP nsScriptablePeer::QueryInterface(const nsIID & aIID, void **aInstancePtr)
94
return NS_ERROR_NULL_POINTER;
96
if (aIID.Equals(kIScriptableIID)) {
97
*aInstancePtr = static_cast < nsIScriptableGeckoMediaPlayer * >(this);
102
if (aIID.Equals(kIClassInfoIID)) {
103
*aInstancePtr = static_cast < nsIClassInfo * >(this);
108
if (aIID.Equals(kISupportsIID)) {
110
static_cast < nsISupports * >(static_cast < nsIScriptableGeckoMediaPlayer * >(this));
115
return NS_NOINTERFACE;
118
void nsScriptablePeer::SetInstance(nsPluginInstance * plugin)
124
// the following methods will be callable from JavaScript
127
NS_IMETHODIMP nsScriptablePeer::Play(void)
129
printf("JS Play issued\n");
134
/* void PlayAt (in double value); */
135
NS_IMETHODIMP nsScriptablePeer::PlayAt(double value)
137
printf("JS Play issued\n");
138
// mPlugin->PlayAt(value);
142
NS_IMETHODIMP nsScriptablePeer::Pause(void)
144
printf("JS Pause issued\n");
149
NS_IMETHODIMP nsScriptablePeer::PlayPause(void)
151
printf("JS playPause issued\n");
152
mPlugin->PlayPause();
156
NS_IMETHODIMP nsScriptablePeer::Stop(void)
158
printf("JS Stop issued\n");
163
NS_IMETHODIMP nsScriptablePeer::Quit(void)
165
printf("JS Quit issued\n");
170
NS_IMETHODIMP nsScriptablePeer::DoPlay(void)
172
printf("JS DoPlay issued\n");
177
NS_IMETHODIMP nsScriptablePeer::DoPause(void)
179
printf("JS DoPause issued\n");
184
NS_IMETHODIMP nsScriptablePeer::FastForward(void)
186
printf("JS FastForward issued\n");
187
mPlugin->FastForward();
191
NS_IMETHODIMP nsScriptablePeer::FastReverse(void)
193
printf("JS FastReverse issued\n");
194
mPlugin->FastReverse();
198
NS_IMETHODIMP nsScriptablePeer::Ff(void)
200
printf("JS ff issued\n");
201
mPlugin->FastForward();
205
NS_IMETHODIMP nsScriptablePeer::Rew(void)
207
printf("JS rew issued\n");
208
mPlugin->FastReverse();
212
NS_IMETHODIMP nsScriptablePeer::Rewind(void)
214
printf("JS Quit issued\n");
215
mPlugin->FastReverse();
219
NS_IMETHODIMP nsScriptablePeer::Seek(double counter)
221
printf("JS Seek issued\n");
222
mPlugin->Seek(counter);
226
NS_IMETHODIMP nsScriptablePeer::GetPlayState(PRInt32 * aPlayState)
228
printf("JS playState issued\n");
229
if (mPlugin != NULL) {
230
mPlugin->GetPlayState(aPlayState);
232
*aPlayState = STATE_UNDEFINED;
237
NS_IMETHODIMP nsScriptablePeer::GetTime(double *_retval)
239
printf("JS getTime issued\n");
240
mPlugin->GetTime(_retval);
244
NS_IMETHODIMP nsScriptablePeer::GetDuration(double *_retval)
246
printf("JS getDuration issued\n");
247
mPlugin->GetDuration(_retval);
251
NS_IMETHODIMP nsScriptablePeer::GetPercent(double *_retval)
253
printf("JS getPercent issued\n");
254
mPlugin->GetPercent(_retval);
258
NS_IMETHODIMP nsScriptablePeer::GetFilename(char **aFilename)
260
printf("JS filename issued\n");
261
mPlugin->GetFilename(aFilename);
265
NS_IMETHODIMP nsScriptablePeer::SetFilename(const char *aFilename)
267
printf("JS filename issued\n");
268
mPlugin->SetFilename(aFilename);
272
NS_IMETHODIMP nsScriptablePeer::GetSrc(char **aSrc)
274
printf("JS src requested\n");
275
mPlugin->GetFilename(aSrc);
279
NS_IMETHODIMP nsScriptablePeer::SetSrc(const char *aSrc)
281
printf("JS src issued to %s\n",aSrc);
282
mPlugin->SetFilename(aSrc);
286
NS_IMETHODIMP nsScriptablePeer::Open(const char *filename)
288
printf("JS filename issued\n");
289
mPlugin->SetFilename(filename);
293
/* void SetVolume (in double value); */
294
NS_IMETHODIMP nsScriptablePeer::SetVolume(double value)
296
printf("JS SetVolume issued\n");
297
mPlugin->SetVolume(value);
301
/* double GetVolume (); */
302
NS_IMETHODIMP nsScriptablePeer::GetVolume(double *_retval)
304
printf("JS GetVolume issued\n");
305
mPlugin->GetVolume(_retval);
310
NS_IMETHODIMP nsScriptablePeer::SetFileName(const char *filename)
312
printf("JS filename issued\n");
313
mPlugin->SetFilename(filename);
317
/* void SetIsLooping (in boolean loop); */
318
NS_IMETHODIMP nsScriptablePeer::SetIsLooping(PRBool loop)
320
printf("JS SetIsLooping issued\n");
321
mPlugin->SetLoop(loop);
325
/* boolean GetIsLooping (); */
326
NS_IMETHODIMP nsScriptablePeer::GetIsLooping(PRBool * _retval)
328
printf("JS GetIsLooping issued\n");
329
mPlugin->GetLoop(_retval);
333
/* void SetAutoPlay (in boolean autoPlay); */
334
NS_IMETHODIMP nsScriptablePeer::SetAutoPlay(PRBool autoPlay)
336
printf("JS SetAutoPlay issued\n");
337
// mPlugin->SetAutoPlay(autoPlay);
341
/* boolean GetAutoPlay (); */
342
NS_IMETHODIMP nsScriptablePeer::GetAutoPlay(PRBool * _retval)
344
printf("JS GetAutoPlay issued\n");
345
// mPlugin->GetAutoPlay(_retval);
349
/* boolean isplaying (); */
350
NS_IMETHODIMP nsScriptablePeer::Isplaying(PRBool * _retval)
352
printf("JS isplaying issued\n");
353
// mPlugin->GetPlaying(_retval);
357
/* void playlistAppend (in string filename); */
358
NS_IMETHODIMP nsScriptablePeer::PlaylistAppend(const char *item)
360
printf("JS playlistAppend issued\n");
361
// mPlugin->PlaylistAppend(item);
365
/* void playlistClear (PRInt32 *_retval; */
366
NS_IMETHODIMP nsScriptablePeer::PlaylistClear(PRBool * _retval)
368
printf("JS playlistClear issued\n");
369
// mPlugin->PlaylistClear(_retval);
374
/* void SetHREF (in string url); */
375
NS_IMETHODIMP nsScriptablePeer::SetHREF(const char *url)
377
printf("JS filename issued\n");
378
mPlugin->SetFilename(url);
382
/* string GetHREF (); */
383
NS_IMETHODIMP nsScriptablePeer::GetHREF(char **_retval)
385
printf("JS filename issued\n");
386
mPlugin->GetFilename(_retval);
390
/* void SetURL (in string url); */
391
NS_IMETHODIMP nsScriptablePeer::SetURL(const char *url)
393
printf("JS filename issued\n");
394
mPlugin->SetFilename(url);
398
/* string GetURL (); */
399
NS_IMETHODIMP nsScriptablePeer::GetURL(char **_retval)
401
printf("JS filename issued\n");
402
mPlugin->GetFilename(_retval);
406
/* string GetMIMEType (); */
407
NS_IMETHODIMP nsScriptablePeer::GetMIMEType(char **_retval)
409
printf("JS GetMIMEType issued\n");
410
mPlugin->GetMIMEType(_retval);
414
NS_IMETHODIMP nsScriptablePeer::GetShowControls(PRBool * aShowControls)
416
printf("JS GetShowControls issued\n");
417
mPlugin->GetShowControls(aShowControls);
421
NS_IMETHODIMP nsScriptablePeer::SetShowControls(PRBool aShowControls)
423
printf("JS SetShowControls issued\n");
424
mPlugin->SetShowControls(aShowControls);
428
NS_IMETHODIMP nsScriptablePeer::GetFullscreen(PRBool * aFullscreen)
430
printf("JS GetFullscreen issued\n");
431
mPlugin->GetFullScreen(aFullscreen);
435
NS_IMETHODIMP nsScriptablePeer::SetFullscreen(PRBool aFullscreen)
437
printf("JS SetFullscreen issued\n");
438
mPlugin->SetFullScreen(aFullscreen);
442
NS_IMETHODIMP nsScriptablePeer::GetShowlogo(PRBool * aShowlogo)
444
printf("JS GetShowlogo issued\n");
445
// mPlugin->GetShowlogo(aShowlogo);
449
NS_IMETHODIMP nsScriptablePeer::SetShowlogo(PRBool aShowlogo)
451
printf("JS SetShowlogo issued\n");
452
// mPlugin->SetShowlogo(aShowlogo);
456
NS_IMETHODIMP nsScriptablePeer::OnClick(const char *event)
458
mPlugin->SetOnClick(event);
462
NS_IMETHODIMP nsScriptablePeer::OnMediaComplete(const char *event)
464
mPlugin->SetOnMediaComplete(event);
468
NS_IMETHODIMP nsScriptablePeer::OnMouseUp(const char *event)
470
mPlugin->SetOnMouseUp(event);
474
NS_IMETHODIMP nsScriptablePeer::OnMouseDown(const char *event)
476
mPlugin->SetOnMouseDown(event);
480
NS_IMETHODIMP nsScriptablePeer::OnMouseOut(const char *event)
482
mPlugin->SetOnMouseOut(event);
486
NS_IMETHODIMP nsScriptablePeer::OnMouseOver(const char *event)
488
mPlugin->SetOnMouseOver(event);
492
NS_IMETHODIMP nsScriptablePeer::OnDestroy(const char *event)
494
mPlugin->SetOnDestroy(event);
498
// WMP Controls subset
500
NS_IMETHODIMP nsScriptablePeer::GetControls(nsIScriptableGeckoMediaPlayerControls * *aControls)
502
*aControls = mControls;
503
if (mControls == NULL)
504
return NS_ERROR_NULL_POINTER;
510
nsControlsScriptablePeer::nsControlsScriptablePeer(nsPluginInstance * aPlugin)
516
nsControlsScriptablePeer::~nsControlsScriptablePeer()
518
//printf("~nsScriptablePeer called\n");
521
// AddRef, Release and QueryInterface are common methods and must
522
// be implemented for any interface
523
NS_IMETHODIMP_(nsrefcnt) nsControlsScriptablePeer::AddRef()
529
NS_IMETHODIMP_(nsrefcnt) nsControlsScriptablePeer::Release()
539
// here nsScriptablePeer should return three interfaces it can be asked for by their iid's
540
// static casts are necessary to ensure that correct pointer is returned
541
NS_IMETHODIMP nsControlsScriptablePeer::QueryInterface(const nsIID & aIID, void **aInstancePtr)
544
return NS_ERROR_NULL_POINTER;
546
if (aIID.Equals(kIScriptableControlIID)) {
547
*aInstancePtr = NS_STATIC_CAST(nsIScriptableGeckoMediaPlayerControls *, this);
552
if (aIID.Equals(kIClassInfoIID)) {
553
*aInstancePtr = NS_STATIC_CAST(nsIClassInfo *, this);
558
if (aIID.Equals(kISupportsIID)) {
560
NS_STATIC_CAST(nsISupports *,
561
(NS_STATIC_CAST(nsIScriptableGeckoMediaPlayerControls *, this)));
566
return NS_NOINTERFACE;
569
void nsControlsScriptablePeer::SetInstance(nsPluginInstance * plugin)
574
NS_IMETHODIMP nsControlsScriptablePeer::Play(void)
576
printf("JS Play issued\n");
581
NS_IMETHODIMP nsControlsScriptablePeer::Pause(void)
583
printf("JS Pause issued\n");
588
NS_IMETHODIMP nsControlsScriptablePeer::Stop(void)
590
printf("JS Stop issued\n");
595
NS_IMETHODIMP nsControlsScriptablePeer::FastForward(void)
597
printf("JS ff issued\n");
598
mPlugin->FastForward();
602
NS_IMETHODIMP nsControlsScriptablePeer::FastReverse(void)
604
printf("JS rew issued\n");
605
mPlugin->FastReverse();
609
NS_IMETHODIMP nsControlsScriptablePeer::Step(void)
616
NS_IMETHODIMP nsControlsScriptablePeer::GetCurrentPosition(double *aCurrentPosition)
618
mPlugin->GetTime(aCurrentPosition);
622
NS_IMETHODIMP nsControlsScriptablePeer::SetCurrentPosition(double aCurrentPosition)
624
mPlugin->Seek(aCurrentPosition);