1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 : * Tim Copperfield <timecop@network.email.ne.jp>
24 : * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef nsNPAPIPluginInstance_h_
41 : #define nsNPAPIPluginInstance_h_
42 :
43 : #include "nsCOMPtr.h"
44 : #include "nsTArray.h"
45 : #include "nsPIDOMWindow.h"
46 : #include "nsITimer.h"
47 : #include "nsIPluginTagInfo.h"
48 : #include "nsIURI.h"
49 : #include "nsIChannel.h"
50 : #include "nsInterfaceHashtable.h"
51 : #include "nsHashKeys.h"
52 : #ifdef MOZ_WIDGET_ANDROID
53 : #include "nsIRunnable.h"
54 : #endif
55 :
56 : #include "mozilla/TimeStamp.h"
57 : #include "mozilla/PluginLibrary.h"
58 :
59 : struct JSObject;
60 :
61 : class nsPluginStreamListenerPeer; // browser-initiated stream class
62 : class nsNPAPIPluginStreamListener; // plugin-initiated stream class
63 : class nsIPluginInstanceOwner;
64 : class nsIPluginStreamListener;
65 : class nsIOutputStream;
66 :
67 : #if defined(OS_WIN)
68 : const NPDrawingModel kDefaultDrawingModel = NPDrawingModelSyncWin;
69 : #elif defined(MOZ_X11)
70 : const NPDrawingModel kDefaultDrawingModel = NPDrawingModelSyncX;
71 : #else
72 : #ifndef NP_NO_QUICKDRAW
73 : const NPDrawingModel kDefaultDrawingModel = NPDrawingModelQuickDraw;
74 : #else
75 : const NPDrawingModel kDefaultDrawingModel = NPDrawingModelCoreGraphics;
76 : #endif
77 : #endif
78 :
79 : class nsNPAPITimer
80 0 : {
81 : public:
82 : NPP npp;
83 : uint32_t id;
84 : nsCOMPtr<nsITimer> timer;
85 : void (*callback)(NPP npp, uint32_t timerID);
86 : bool inCallback;
87 : };
88 :
89 : class nsNPAPIPluginInstance : public nsISupports
90 : {
91 : private:
92 : typedef mozilla::PluginLibrary PluginLibrary;
93 :
94 : public:
95 : NS_DECL_ISUPPORTS
96 :
97 : nsresult Initialize(nsIPluginInstanceOwner* aOwner, const char* aMIMEType);
98 : nsresult Start();
99 : nsresult Stop();
100 : nsresult SetWindow(NPWindow* window);
101 : nsresult NewStreamFromPlugin(const char* type, const char* target, nsIOutputStream* *result);
102 : nsresult Print(NPPrint* platformPrint);
103 : #ifdef MOZ_WIDGET_ANDROID
104 : nsresult PostEvent(void* event) { return 0; };
105 : #endif
106 : nsresult HandleEvent(void* event, PRInt16* result);
107 : nsresult GetValueFromPlugin(NPPVariable variable, void* value);
108 : nsresult GetDrawingModel(PRInt32* aModel);
109 : nsresult IsRemoteDrawingCoreAnimation(bool* aDrawing);
110 : nsresult GetJSObject(JSContext *cx, JSObject** outObject);
111 : nsresult DefineJavaProperties();
112 : bool ShouldCache();
113 : nsresult IsWindowless(bool* isWindowless);
114 : nsresult AsyncSetWindow(NPWindow* window);
115 : nsresult GetImageContainer(ImageContainer **aContainer);
116 : nsresult GetImageSize(nsIntSize* aSize);
117 : nsresult NotifyPainted(void);
118 : nsresult UseAsyncPainting(bool* aIsAsync);
119 : nsresult SetBackgroundUnknown();
120 : nsresult BeginUpdateBackground(nsIntRect* aRect, gfxContext** aContext);
121 : nsresult EndUpdateBackground(gfxContext* aContext, nsIntRect* aRect);
122 : nsresult IsTransparent(bool* isTransparent);
123 : nsresult GetFormValue(nsAString& aValue);
124 : nsresult PushPopupsEnabledState(bool aEnabled);
125 : nsresult PopPopupsEnabledState();
126 : nsresult GetPluginAPIVersion(PRUint16* version);
127 : nsresult InvalidateRect(NPRect *invalidRect);
128 : nsresult InvalidateRegion(NPRegion invalidRegion);
129 : nsresult GetMIMEType(const char* *result);
130 : nsresult GetJSContext(JSContext* *outContext);
131 : nsresult GetOwner(nsIPluginInstanceOwner **aOwner);
132 : nsresult SetOwner(nsIPluginInstanceOwner *aOwner);
133 : nsresult ShowStatus(const char* message);
134 : nsresult InvalidateOwner();
135 : #if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
136 : nsresult HandleGUIEvent(const nsGUIEvent& anEvent, bool* handled);
137 : #endif
138 :
139 : nsNPAPIPlugin* GetPlugin();
140 :
141 : nsresult GetNPP(NPP * aNPP);
142 :
143 : NPError SetWindowless(bool aWindowless);
144 :
145 : NPError SetTransparent(bool aTransparent);
146 :
147 : NPError SetWantsAllNetworkStreams(bool aWantsAllNetworkStreams);
148 :
149 : NPError SetUsesDOMForCursor(bool aUsesDOMForCursor);
150 : bool UsesDOMForCursor();
151 :
152 : void SetDrawingModel(NPDrawingModel aModel);
153 : void RedrawPlugin();
154 : #ifdef XP_MACOSX
155 : void SetEventModel(NPEventModel aModel);
156 : #endif
157 :
158 : #ifdef MOZ_WIDGET_ANDROID
159 : void NotifyForeground(bool aForeground);
160 : void NotifyOnScreen(bool aOnScreen);
161 : void MemoryPressure();
162 :
163 : bool IsOnScreen() {
164 : return mOnScreen;
165 : }
166 :
167 : PRUint32 GetANPDrawingModel() { return mANPDrawingModel; }
168 : void SetANPDrawingModel(PRUint32 aModel);
169 :
170 : // This stuff is for kSurface_ANPDrawingModel
171 : void* GetJavaSurface();
172 : void SetJavaSurface(void* aSurface);
173 : void RequestJavaSurface();
174 : #endif
175 :
176 : nsresult NewStreamListener(const char* aURL, void* notifyData,
177 : nsIPluginStreamListener** listener);
178 :
179 : nsNPAPIPluginInstance(nsNPAPIPlugin* plugin);
180 : virtual ~nsNPAPIPluginInstance();
181 :
182 : // To be called when an instance becomes orphaned, when
183 : // it's plugin is no longer guaranteed to be around.
184 : void Destroy();
185 :
186 : // Indicates whether the plugin is running normally.
187 0 : bool IsRunning() {
188 0 : return RUNNING == mRunning;
189 : }
190 0 : bool HasStartedDestroying() {
191 0 : return mRunning >= DESTROYING;
192 : }
193 :
194 : // Indicates whether the plugin is running normally or being shut down
195 : bool CanFireNotifications() {
196 : return mRunning == RUNNING || mRunning == DESTROYING;
197 : }
198 :
199 : // return is only valid when the plugin is not running
200 : mozilla::TimeStamp StopTime();
201 :
202 : // cache this NPAPI plugin
203 : nsresult SetCached(bool aCache);
204 :
205 : already_AddRefed<nsPIDOMWindow> GetDOMWindow();
206 :
207 : nsresult PrivateModeStateChanged();
208 :
209 : nsresult GetDOMElement(nsIDOMElement* *result);
210 :
211 : nsNPAPITimer* TimerWithID(uint32_t id, PRUint32* index);
212 : uint32_t ScheduleTimer(uint32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID));
213 : void UnscheduleTimer(uint32_t timerID);
214 : NPError PopUpContextMenu(NPMenu* menu);
215 : NPBool ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace, double *destX, double *destY, NPCoordinateSpace destSpace);
216 :
217 :
218 : nsTArray<nsNPAPIPluginStreamListener*> *StreamListeners();
219 :
220 : nsTArray<nsPluginStreamListenerPeer*> *FileCachedStreamListeners();
221 :
222 : nsresult AsyncSetWindow(NPWindow& window);
223 :
224 : void URLRedirectResponse(void* notifyData, NPBool allow);
225 :
226 : NPError InitAsyncSurface(NPSize *size, NPImageFormat format,
227 : void *initData, NPAsyncSurface *surface);
228 : NPError FinalizeAsyncSurface(NPAsyncSurface *surface);
229 : void SetCurrentAsyncSurface(NPAsyncSurface *surface, NPRect *changed);
230 :
231 : // Called when the instance fails to instantiate beceause the Carbon
232 : // event model is not supported.
233 : void CarbonNPAPIFailure();
234 :
235 : protected:
236 : nsresult InitializePlugin();
237 :
238 : nsresult GetTagType(nsPluginTagType *result);
239 : nsresult GetAttributes(PRUint16& n, const char*const*& names,
240 : const char*const*& values);
241 : nsresult GetParameters(PRUint16& n, const char*const*& names,
242 : const char*const*& values);
243 : nsresult GetMode(PRInt32 *result);
244 :
245 : // The structure used to communicate between the plugin instance and
246 : // the browser.
247 : NPP_t mNPP;
248 :
249 : NPDrawingModel mDrawingModel;
250 :
251 : #ifdef MOZ_WIDGET_ANDROID
252 : PRUint32 mANPDrawingModel;
253 : nsCOMPtr<nsIRunnable> mSurfaceGetter;
254 : #endif
255 :
256 : enum {
257 : NOT_STARTED,
258 : RUNNING,
259 : DESTROYING,
260 : DESTROYED
261 : } mRunning;
262 :
263 : // these are used to store the windowless properties
264 : // which the browser will later query
265 : bool mWindowless;
266 : bool mTransparent;
267 : bool mCached;
268 : bool mUsesDOMForCursor;
269 :
270 : public:
271 : // True while creating the plugin, or calling NPP_SetWindow() on it.
272 : bool mInPluginInitCall;
273 :
274 : nsXPIDLCString mFakeURL;
275 :
276 : private:
277 : nsNPAPIPlugin* mPlugin;
278 :
279 : nsTArray<nsNPAPIPluginStreamListener*> mStreamListeners;
280 :
281 : nsTArray<nsPluginStreamListenerPeer*> mFileCachedStreamListeners;
282 :
283 : nsTArray<PopupControlState> mPopupStates;
284 :
285 : char* mMIMEType;
286 :
287 : // Weak pointer to the owner. The owner nulls this out (by calling
288 : // InvalidateOwner()) when it's no longer our owner.
289 : nsIPluginInstanceOwner *mOwner;
290 :
291 : nsTArray<nsNPAPITimer*> mTimers;
292 :
293 : // non-null during a HandleEvent call
294 : void* mCurrentPluginEvent;
295 :
296 : // Timestamp for the last time this plugin was stopped.
297 : // This is only valid when the plugin is actually stopped!
298 : mozilla::TimeStamp mStopTime;
299 :
300 : bool mUsePluginLayersPref;
301 : #ifdef MOZ_WIDGET_ANDROID
302 : void* mSurface;
303 : bool mOnScreen;
304 : #endif
305 : };
306 :
307 : #endif // nsNPAPIPluginInstance_h_
|