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