/work/obj-fuzz/dist/include/nsNPAPIPluginInstance.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #ifndef nsNPAPIPluginInstance_h_ |
7 | | #define nsNPAPIPluginInstance_h_ |
8 | | |
9 | | #include "nsSize.h" |
10 | | #include "nsCOMPtr.h" |
11 | | #include "nsTArray.h" |
12 | | #include "nsPIDOMWindow.h" |
13 | | #include "nsITimer.h" |
14 | | #include "nsIPluginInstanceOwner.h" |
15 | | #include "nsIURI.h" |
16 | | #include "nsIChannel.h" |
17 | | #include "nsHashKeys.h" |
18 | | #include <prinrval.h> |
19 | | #include "js/TypeDecls.h" |
20 | | #include "nsIAudioChannelAgent.h" |
21 | | |
22 | | #include "mozilla/EventForwards.h" |
23 | | #include "mozilla/TimeStamp.h" |
24 | | #include "mozilla/PluginLibrary.h" |
25 | | #include "mozilla/RefPtr.h" |
26 | | #include "mozilla/WeakPtr.h" |
27 | | |
28 | | class nsPluginStreamListenerPeer; // browser-initiated stream class |
29 | | class nsNPAPIPluginStreamListener; // plugin-initiated stream class |
30 | | class nsIPluginInstanceOwner; |
31 | | class nsIOutputStream; |
32 | | class nsPluginInstanceOwner; |
33 | | |
34 | | namespace mozilla { |
35 | | namespace dom { |
36 | | class Element; |
37 | | } // namespace dom |
38 | | } // namespace mozilla |
39 | | |
40 | | #if defined(OS_WIN) |
41 | | const NPDrawingModel kDefaultDrawingModel = NPDrawingModelSyncWin; |
42 | | #elif defined(MOZ_X11) |
43 | | const NPDrawingModel kDefaultDrawingModel = NPDrawingModelSyncX; |
44 | | #elif defined(XP_MACOSX) |
45 | | #ifndef NP_NO_QUICKDRAW |
46 | | const NPDrawingModel kDefaultDrawingModel = NPDrawingModelQuickDraw; // Not supported |
47 | | #else |
48 | | const NPDrawingModel kDefaultDrawingModel = NPDrawingModelCoreGraphics; |
49 | | #endif |
50 | | #else |
51 | | const NPDrawingModel kDefaultDrawingModel = static_cast<NPDrawingModel>(0); |
52 | | #endif |
53 | | |
54 | | /** |
55 | | * Used to indicate whether it's OK to reenter Gecko and repaint, flush frames, |
56 | | * run scripts, etc, during this plugin call. |
57 | | * When NS_PLUGIN_CALL_UNSAFE_TO_REENTER_GECKO is set, we try to avoid dangerous |
58 | | * Gecko activities when the plugin spins a nested event loop, on a best-effort |
59 | | * basis. |
60 | | */ |
61 | | enum NSPluginCallReentry { |
62 | | NS_PLUGIN_CALL_SAFE_TO_REENTER_GECKO, |
63 | | NS_PLUGIN_CALL_UNSAFE_TO_REENTER_GECKO |
64 | | }; |
65 | | |
66 | | class nsNPAPITimer |
67 | | { |
68 | | public: |
69 | | NPP npp; |
70 | | uint32_t id; |
71 | | nsCOMPtr<nsITimer> timer; |
72 | | void (*callback)(NPP npp, uint32_t timerID); |
73 | | bool inCallback; |
74 | | bool needUnschedule; |
75 | | }; |
76 | | |
77 | | class nsNPAPIPluginInstance final : public nsIAudioChannelAgentCallback |
78 | | , public mozilla::SupportsWeakPtr<nsNPAPIPluginInstance> |
79 | | { |
80 | | private: |
81 | | typedef mozilla::PluginLibrary PluginLibrary; |
82 | | |
83 | | public: |
84 | | typedef mozilla::gfx::DrawTarget DrawTarget; |
85 | | |
86 | | MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsNPAPIPluginInstance) |
87 | | NS_DECL_THREADSAFE_ISUPPORTS |
88 | | NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK |
89 | | |
90 | | nsresult Initialize(nsNPAPIPlugin *aPlugin, nsPluginInstanceOwner* aOwner, const nsACString& aMIMEType); |
91 | | nsresult Start(); |
92 | | nsresult Stop(); |
93 | | nsresult SetWindow(NPWindow* window); |
94 | | nsresult NewStreamFromPlugin(const char* type, const char* target, nsIOutputStream* *result); |
95 | | nsresult Print(NPPrint* platformPrint); |
96 | | nsresult HandleEvent(void* event, int16_t* result, |
97 | | NSPluginCallReentry aSafeToReenterGecko = NS_PLUGIN_CALL_UNSAFE_TO_REENTER_GECKO); |
98 | | nsresult GetValueFromPlugin(NPPVariable variable, void* value); |
99 | | nsresult GetDrawingModel(int32_t* aModel); |
100 | | nsresult IsRemoteDrawingCoreAnimation(bool* aDrawing); |
101 | | nsresult ContentsScaleFactorChanged(double aContentsScaleFactor); |
102 | | nsresult CSSZoomFactorChanged(float aCSSZoomFactor); |
103 | | nsresult GetJSObject(JSContext *cx, JSObject** outObject); |
104 | | bool ShouldCache(); |
105 | | nsresult IsWindowless(bool* isWindowless); |
106 | | nsresult AsyncSetWindow(NPWindow* window); |
107 | | nsresult GetImageContainer(mozilla::layers::ImageContainer **aContainer); |
108 | | nsresult GetImageSize(nsIntSize* aSize); |
109 | | nsresult NotifyPainted(void); |
110 | | nsresult GetIsOOP(bool* aIsOOP); |
111 | | nsresult SetBackgroundUnknown(); |
112 | | nsresult BeginUpdateBackground(nsIntRect* aRect, DrawTarget** aContext); |
113 | | nsresult EndUpdateBackground(nsIntRect* aRect); |
114 | | nsresult IsTransparent(bool* isTransparent); |
115 | | nsresult GetFormValue(nsAString& aValue); |
116 | | nsresult PushPopupsEnabledState(bool aEnabled); |
117 | | nsresult PopPopupsEnabledState(); |
118 | | nsresult GetPluginAPIVersion(uint16_t* version); |
119 | | nsresult InvalidateRect(NPRect *invalidRect); |
120 | | nsresult InvalidateRegion(NPRegion invalidRegion); |
121 | | nsresult GetMIMEType(const char* *result); |
122 | | #if defined(XP_WIN) |
123 | | nsresult GetScrollCaptureContainer(mozilla::layers::ImageContainer **aContainer); |
124 | | #endif |
125 | | nsresult HandledWindowedPluginKeyEvent( |
126 | | const mozilla::NativeEventData& aKeyEventData, |
127 | | bool aIsConsumed); |
128 | | nsPluginInstanceOwner* GetOwner(); |
129 | | void SetOwner(nsPluginInstanceOwner *aOwner); |
130 | | void DidComposite(); |
131 | | |
132 | | bool HasAudioChannelAgent() const |
133 | | { |
134 | | return !!mAudioChannelAgent; |
135 | | } |
136 | | |
137 | | void NotifyStartedPlaying(); |
138 | | void NotifyStoppedPlaying(); |
139 | | |
140 | | nsresult SetMuted(bool aIsMuted); |
141 | | |
142 | | nsNPAPIPlugin* GetPlugin(); |
143 | | |
144 | | nsresult GetNPP(NPP * aNPP); |
145 | | |
146 | | NPError SetWindowless(bool aWindowless); |
147 | | |
148 | | NPError SetTransparent(bool aTransparent); |
149 | | |
150 | | NPError SetWantsAllNetworkStreams(bool aWantsAllNetworkStreams); |
151 | | |
152 | | NPError SetUsesDOMForCursor(bool aUsesDOMForCursor); |
153 | | bool UsesDOMForCursor(); |
154 | | |
155 | | void SetDrawingModel(NPDrawingModel aModel); |
156 | | void RedrawPlugin(); |
157 | | #ifdef XP_MACOSX |
158 | | void SetEventModel(NPEventModel aModel); |
159 | | |
160 | | void* GetCurrentEvent() { |
161 | | return mCurrentPluginEvent; |
162 | | } |
163 | | #endif |
164 | | |
165 | | nsresult NewStreamListener(const char* aURL, void* notifyData, |
166 | | nsNPAPIPluginStreamListener** listener); |
167 | | |
168 | | nsNPAPIPluginInstance(); |
169 | | |
170 | | // To be called when an instance becomes orphaned, when |
171 | | // it's plugin is no longer guaranteed to be around. |
172 | | void Destroy(); |
173 | | |
174 | | // Indicates whether the plugin is running normally. |
175 | | bool IsRunning() { |
176 | | return RUNNING == mRunning; |
177 | | } |
178 | | bool HasStartedDestroying() { |
179 | | return mRunning >= DESTROYING; |
180 | | } |
181 | | |
182 | | // Indicates whether the plugin is running normally or being shut down |
183 | | bool CanFireNotifications() { |
184 | | return mRunning == RUNNING || mRunning == DESTROYING; |
185 | | } |
186 | | |
187 | | // return is only valid when the plugin is not running |
188 | | mozilla::TimeStamp StopTime(); |
189 | | |
190 | | // cache this NPAPI plugin |
191 | | void SetCached(bool aCache); |
192 | | |
193 | | already_AddRefed<nsPIDOMWindowOuter> GetDOMWindow(); |
194 | | |
195 | | nsresult PrivateModeStateChanged(bool aEnabled); |
196 | | |
197 | | nsresult IsPrivateBrowsing(bool *aEnabled); |
198 | | |
199 | | nsresult GetDOMElement(mozilla::dom::Element* *result); |
200 | | |
201 | | nsNPAPITimer* TimerWithID(uint32_t id, uint32_t* index); |
202 | | uint32_t ScheduleTimer(uint32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID)); |
203 | | void UnscheduleTimer(uint32_t timerID); |
204 | | NPBool ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace, double *destX, double *destY, NPCoordinateSpace destSpace); |
205 | | |
206 | | |
207 | | nsTArray<nsNPAPIPluginStreamListener*> *StreamListeners(); |
208 | | |
209 | | nsTArray<nsPluginStreamListenerPeer*> *FileCachedStreamListeners(); |
210 | | |
211 | | nsresult AsyncSetWindow(NPWindow& window); |
212 | | |
213 | | void URLRedirectResponse(void* notifyData, NPBool allow); |
214 | | |
215 | | NPError InitAsyncSurface(NPSize *size, NPImageFormat format, |
216 | | void *initData, NPAsyncSurface *surface); |
217 | | NPError FinalizeAsyncSurface(NPAsyncSurface *surface); |
218 | | void SetCurrentAsyncSurface(NPAsyncSurface *surface, NPRect *changed); |
219 | | |
220 | | // Returns the contents scale factor of the screen the plugin is drawn on. |
221 | | double GetContentsScaleFactor(); |
222 | | |
223 | | // Returns the css zoom factor of the document the plugin is drawn on. |
224 | | float GetCSSZoomFactor(); |
225 | | |
226 | | nsresult GetRunID(uint32_t *aRunID); |
227 | | |
228 | 0 | static bool InPluginCallUnsafeForReentry() { return gInUnsafePluginCalls > 0; } |
229 | | static void BeginPluginCall(NSPluginCallReentry aReentryState) |
230 | | { |
231 | | if (aReentryState == NS_PLUGIN_CALL_UNSAFE_TO_REENTER_GECKO) { |
232 | | ++gInUnsafePluginCalls; |
233 | | } |
234 | | } |
235 | | static void EndPluginCall(NSPluginCallReentry aReentryState) |
236 | | { |
237 | | if (aReentryState == NS_PLUGIN_CALL_UNSAFE_TO_REENTER_GECKO) { |
238 | | NS_ASSERTION(gInUnsafePluginCalls > 0, "Must be in plugin call"); |
239 | | --gInUnsafePluginCalls; |
240 | | } |
241 | | } |
242 | | |
243 | | protected: |
244 | | |
245 | | virtual ~nsNPAPIPluginInstance(); |
246 | | |
247 | | nsresult GetTagType(nsPluginTagType *result); |
248 | | |
249 | | nsresult CreateAudioChannelAgentIfNeeded(); |
250 | | |
251 | | // The structure used to communicate between the plugin instance and |
252 | | // the browser. |
253 | | NPP_t mNPP; |
254 | | |
255 | | NPDrawingModel mDrawingModel; |
256 | | |
257 | | enum { |
258 | | NOT_STARTED, |
259 | | RUNNING, |
260 | | DESTROYING, |
261 | | DESTROYED |
262 | | } mRunning; |
263 | | |
264 | | // these are used to store the windowless properties |
265 | | // which the browser will later query |
266 | | bool mWindowless; |
267 | | bool mTransparent; |
268 | | bool mCached; |
269 | | bool mUsesDOMForCursor; |
270 | | |
271 | | public: |
272 | | // True while creating the plugin, or calling NPP_SetWindow() on it. |
273 | | bool mInPluginInitCall; |
274 | | |
275 | | private: |
276 | | RefPtr<nsNPAPIPlugin> mPlugin; |
277 | | |
278 | | nsTArray<nsNPAPIPluginStreamListener*> mStreamListeners; |
279 | | |
280 | | nsTArray<nsPluginStreamListenerPeer*> mFileCachedStreamListeners; |
281 | | |
282 | | nsTArray<PopupControlState> mPopupStates; |
283 | | |
284 | | char* mMIMEType; |
285 | | |
286 | | // Weak pointer to the owner. The owner nulls this out (by calling |
287 | | // InvalidateOwner()) when it's no longer our owner. |
288 | | nsPluginInstanceOwner *mOwner; |
289 | | |
290 | | nsTArray<nsNPAPITimer*> mTimers; |
291 | | |
292 | | #ifdef XP_MACOSX |
293 | | // non-null during a HandleEvent call |
294 | | void* mCurrentPluginEvent; |
295 | | #endif |
296 | | |
297 | | // Timestamp for the last time this plugin was stopped. |
298 | | // This is only valid when the plugin is actually stopped! |
299 | | mozilla::TimeStamp mStopTime; |
300 | | |
301 | | static uint32_t gInUnsafePluginCalls; |
302 | | |
303 | | // The arrays can only be released when the plugin instance is destroyed, |
304 | | // because the plugin, in in-process mode, might keep a reference to them. |
305 | | uint32_t mCachedParamLength; |
306 | | char **mCachedParamNames; |
307 | | char **mCachedParamValues; |
308 | | |
309 | | nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent; |
310 | | bool mMuted; |
311 | | }; |
312 | | |
313 | | void NS_NotifyBeginPluginCall(NSPluginCallReentry aReentryState); |
314 | | void NS_NotifyPluginCall(NSPluginCallReentry aReentryState); |
315 | | |
316 | | #define NS_TRY_SAFE_CALL_RETURN(ret, fun, pluginInst, pluginCallReentry) \ |
317 | | PR_BEGIN_MACRO \ |
318 | | NS_NotifyBeginPluginCall(pluginCallReentry); \ |
319 | | ret = fun; \ |
320 | | NS_NotifyPluginCall(pluginCallReentry); \ |
321 | | PR_END_MACRO |
322 | | |
323 | | #define NS_TRY_SAFE_CALL_VOID(fun, pluginInst, pluginCallReentry) \ |
324 | | PR_BEGIN_MACRO \ |
325 | | NS_NotifyBeginPluginCall(pluginCallReentry); \ |
326 | | fun; \ |
327 | | NS_NotifyPluginCall(pluginCallReentry); \ |
328 | | PR_END_MACRO |
329 | | |
330 | | #endif // nsNPAPIPluginInstance_h_ |