summaryrefslogtreecommitdiff
path: root/trunk/browser-plugin/totemPlugin.h
blob: 4167ffde46300d72cf503b518e436935174f4c32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/* Totem browser plugin
 *
 * Copyright © 2004 Bastien Nocera <hadess@hadess.net>
 * Copyright © 2002 David A. Schleef <ds@schleef.org>
 * Copyright © 2006 Christian Persch
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __TOTEM_PLUGIN_H__
#define __TOTEM_PLUGIN_H__

#include <stdint.h>
#include <dbus/dbus-glib.h>
#include <npapi.h>

#include <nsStringAPI.h>

#ifdef NEED_STRING_GLUE
#include "totemStringGlue.h"
#endif

#if defined(TOTEM_COMPLEX_PLUGIN) && defined(HAVE_NSTARRAY_H)
#include <nsTArray.h>
#endif /* TOTEM_COMPLEX_PLUGIN */

#include "totem-plugin-viewer-commands.h"

class nsIDOMDocument;
class nsIDOMElement;
class nsIIOService;
class nsIServiceManager;
class nsITimer;
class nsIURI;
class nsVoidArray;
class totemScriptablePlugin;
struct _NPNetscapeFuncs;

class totemPlugin {
  public:
    totemPlugin (NPP aInstance);
    ~totemPlugin ();
  
    void* operator new (size_t aSize) CPP_THROW_NEW;

    /* Interface to scriptable */

    nsresult DoCommand (const char *aCommand);

    nsresult SetSrc (const nsACString &aURL);

    /* plugin glue */
    static _NPNetscapeFuncs sNPN;

    static NPError Initialise ();
    static NPError Shutdown ();

    NPError Init (NPMIMEType mimetype,
                  uint16_t mode,
                  int16_t argc,
                  char *argn[],
                  char *argv[],
                  NPSavedData *saved);
  
    NPError SetWindow (NPWindow *aWindow);
  
    NPError NewStream (NPMIMEType type,
                       NPStream* stream_ptr,
                       NPBool seekable,
                       uint16* stype);
    NPError DestroyStream (NPStream* stream,
                           NPError reason);
  
    int32 WriteReady (NPStream *stream);
    int32 Write (NPStream *stream,
                int32 offset,
                int32 len,
                void *buffer);
    void StreamAsFile (NPStream *stream,
                       const char* fname);

    void URLNotify (const char *url,
		    NPReason reason,
		    void *notifyData);

    NPError GetScriptable (void *_retval);

  private:

    static void PR_CALLBACK NameOwnerChangedCallback (DBusGProxy *proxy,
						      const char *svc,
						      const char *old_owner,
						      const char *new_owner,
						      void *aData);

    static void PR_CALLBACK ViewerForkTimeoutCallback (nsITimer *aTimer,
						       void *aData);

    static void PR_CALLBACK ButtonPressCallback (DBusGProxy  *proxy,
						 guint aTimestamp,
		    				 guint aButton,
					         void *aData);

    static void PR_CALLBACK StopStreamCallback (DBusGProxy  *proxy,
						void *aData);

    static void PR_CALLBACK ViewerSetWindowCallback (DBusGProxy *aProxy,
						     DBusGProxyCall *aCall,
						     void *aData);
    static void PR_CALLBACK ViewerOpenStreamCallback (DBusGProxy *aProxy,
						      DBusGProxyCall *aCall,
						      void *aData);
    static void PR_CALLBACK ViewerOpenURICallback (DBusGProxy *aProxy,
						   DBusGProxyCall *aCall,
						   void *aData);

    NPError ViewerFork ();
    void ViewerSetup ();
    void ViewerSetWindow ();
    void ViewerReady ();
    void ViewerCleanup ();

    void ViewerButtonPressed (guint aTimestamp,
		    	      guint aButton);
    void NameOwnerChanged (const char *aName,
			   const char *aOldOwner,
			   const char *aNewOwner);

    void ComputeRequest ();
    void ClearRequest ();
    void RequestStream (PRBool aForceViewer);
    void UnsetStream ();

    PRBool IsMimeTypeSupported (const char *aMimeType,
				const char *aURL);
    PRBool IsSchemeSupported (nsIURI *aURI);
    void GetRealMimeType (const char *aMimeType,
			  nsACString &_retval);
    PRBool ParseBoolean (const char *key,
			 const char *value,
			 PRBool default_val);
    PRBool GetBooleanValue (GHashTable *args,
			    const char *key,
			    PRBool default_val);
    PRUint32 GetEnumIndex (GHashTable *args,
			   const char *key,
			   const char *values[],
			   PRUint32 n_values,
			   PRUint32 default_value);

    NPP mInstance;

    /* FIXME make these use nsCOMPtr<> !! */
    totemScriptablePlugin *mScriptable;
    nsIServiceManager *mServiceManager;
    nsIIOService *mIOService;
    nsIDOMElement *mPluginDOMElement;
    nsITimer *mTimer;
    nsIURI *mBaseURI;

    nsIURI *mRequestBaseURI;
    nsIURI *mRequestURI;

    NPStream *mStream;
    PRUint32 mBytesStreamed;
    PRUint8 mStreamType;

    nsCString mMimeType;

    nsCString mSrc;
    nsIURI *mSrcURI;

    Window mWindow;
    PRInt32 mWidth;
    PRInt32 mHeight;

    DBusGConnection *mBusConnection;
    DBusGProxy *mBusProxy;
    DBusGProxy *mViewerProxy;
    DBusGProxyCall *mViewerPendingCall;
    nsCString mViewerBusAddress;
    nsCString mViewerServiceName;
    int mViewerPID;
    int mViewerFD;

#ifdef TOTEM_GMP_PLUGIN
  public:
    nsresult SetURL (const nsACString &aURL);

  private:
    nsIURI *mURLURI;
#endif

#ifdef TOTEM_NARROWSPACE_PLUGIN
  public:
    nsresult SetQtsrc (const nsCString &aURL);
    nsresult SetHref (const nsCString& aURL);

  private:
    PRBool ParseURLExtensions (const nsACString &aString,
			       nsACString &_url,
			       nsACString &_target);

    void LaunchTotem (const nsCString &aURL,
		      PRUint32 aTimestamp);

    nsIURI *mQtsrcURI;

    nsCString mHref;
    nsIURI *mHrefURI;

    nsCString mTarget;
#endif

#if defined(TOTEM_COMPLEX_PLUGIN) && defined(HAVE_NSTARRAY_H)
  public:

    nsresult SetConsole (const nsACString &aConsole);

  private:

    totemPlugin* FindConsoleClassRepresentant ();
    void TransferConsole ();

    void UnownedViewerSetup ();
    void UnownedViewerSetWindow ();
    void UnownedViewerUnsetWindow ();

    nsIDOMDocument *mPluginOwnerDocument;
    nsCString mConsole;
    nsCString mControls;

    /* nsnull if we're the representant ourself */
    totemPlugin *mConsoleClassRepresentant;

    static nsTArray<totemPlugin*> *sPlugins;

#endif /* TOTEM_COMPLEX_PLUGIN */

  private:

    PRUint32 mAutostart : 1;
    PRUint32 mCache : 1;
    PRUint32 mCheckedForPlaylist : 1;
    PRUint32 mControllerHidden : 1;
    PRUint32 mExpectingStream : 1;
    PRUint32 mHadStream : 1;
    PRUint32 mHidden : 1;
    PRUint32 mIsPlaylist : 1;
    PRUint32 mIsSupportedSrc : 1;
    PRUint32 mNeedViewer : 1;
    PRUint32 mRepeat : 1;
    PRUint32 mRequestIsSrc : 1;
    PRUint32 mShowStatusbar : 1;
    PRUint32 mTimerRunning : 1;
    PRUint32 mUnownedViewerSetUp : 1;
    PRUint32 mViewerReady : 1;
    PRUint32 mViewerSetUp : 1;
    PRUint32 mWaitingForButtonPress : 1;
    PRUint32 mWindowSet : 1;
    PRUint32 mAudioOnly : 1;
};

typedef struct {
  const char *mimetype;
  const char *extensions;
  const char *mime_alias;
  gboolean    ignore;
} totemPluginMimeEntry;

#endif /* __TOTEM_PLUGIN_H__ */