/work/obj-fuzz/dist/include/mozilla/plugins/PluginInstanceChild.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
2 | | * vim: sw=4 ts=4 et : |
3 | | * This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef dom_plugins_PluginInstanceChild_h |
8 | | #define dom_plugins_PluginInstanceChild_h 1 |
9 | | |
10 | | #include "mozilla/EventForwards.h" |
11 | | #include "mozilla/plugins/PPluginInstanceChild.h" |
12 | | #include "mozilla/plugins/PluginScriptableObjectChild.h" |
13 | | #include "mozilla/plugins/StreamNotifyChild.h" |
14 | | #include "mozilla/plugins/PPluginSurfaceChild.h" |
15 | | #include "mozilla/ipc/CrossProcessMutex.h" |
16 | | #include "nsRefPtrHashtable.h" |
17 | | #if defined(OS_WIN) |
18 | | #include "mozilla/gfx/SharedDIBWin.h" |
19 | | #elif defined(MOZ_WIDGET_COCOA) |
20 | | #include "PluginUtilsOSX.h" |
21 | | #include "mozilla/gfx/QuartzSupport.h" |
22 | | #include "base/timer.h" |
23 | | |
24 | | #endif |
25 | | |
26 | | #include "npfunctions.h" |
27 | | #include "nsAutoPtr.h" |
28 | | #include "nsTArray.h" |
29 | | #include "ChildTimer.h" |
30 | | #include "nsRect.h" |
31 | | #include "nsTHashtable.h" |
32 | | #include "mozilla/PaintTracker.h" |
33 | | #include "mozilla/gfx/Types.h" |
34 | | |
35 | | #include <map> |
36 | | |
37 | | #ifdef MOZ_WIDGET_GTK |
38 | | #include "gtk2xtbin.h" |
39 | | #endif |
40 | | |
41 | | class gfxASurface; |
42 | | |
43 | | namespace mozilla { |
44 | | namespace plugins { |
45 | | |
46 | | class PBrowserStreamChild; |
47 | | class BrowserStreamChild; |
48 | | class StreamNotifyChild; |
49 | | |
50 | | class PluginInstanceChild : public PPluginInstanceChild |
51 | | { |
52 | | friend class BrowserStreamChild; |
53 | | friend class PluginStreamChild; |
54 | | friend class StreamNotifyChild; |
55 | | friend class PluginScriptableObjectChild; |
56 | | |
57 | | #ifdef OS_WIN |
58 | | friend LRESULT CALLBACK PluginWindowProc(HWND hWnd, |
59 | | UINT message, |
60 | | WPARAM wParam, |
61 | | LPARAM lParam); |
62 | | static LRESULT CALLBACK PluginWindowProcInternal(HWND hWnd, |
63 | | UINT message, |
64 | | WPARAM wParam, |
65 | | LPARAM lParam); |
66 | | #endif |
67 | | |
68 | | protected: |
69 | | virtual mozilla::ipc::IPCResult |
70 | | AnswerCreateChildPluginWindow(NativeWindowHandle* aChildPluginWindow) override; |
71 | | |
72 | | virtual mozilla::ipc::IPCResult |
73 | | RecvCreateChildPopupSurrogate(const NativeWindowHandle& aNetscapeWindow) override; |
74 | | |
75 | | virtual mozilla::ipc::IPCResult |
76 | | AnswerNPP_SetWindow(const NPRemoteWindow& window) override; |
77 | | |
78 | | virtual mozilla::ipc::IPCResult |
79 | | AnswerNPP_GetValue_NPPVpluginWantsAllNetworkStreams(bool* wantsAllStreams, NPError* rv) override; |
80 | | virtual mozilla::ipc::IPCResult |
81 | | AnswerNPP_GetValue_NPPVpluginScriptableNPObject(PPluginScriptableObjectChild** value, |
82 | | NPError* result) override; |
83 | | virtual mozilla::ipc::IPCResult |
84 | | AnswerNPP_GetValue_NPPVpluginNativeAccessibleAtkPlugId(nsCString* aPlugId, |
85 | | NPError* aResult) override; |
86 | | virtual mozilla::ipc::IPCResult |
87 | | AnswerNPP_SetValue_NPNVprivateModeBool(const bool& value, NPError* result) override; |
88 | | virtual mozilla::ipc::IPCResult |
89 | | AnswerNPP_SetValue_NPNVmuteAudioBool(const bool& value, NPError* result) override; |
90 | | virtual mozilla::ipc::IPCResult |
91 | | AnswerNPP_SetValue_NPNVCSSZoomFactor(const double& value, NPError* result) override; |
92 | | |
93 | | virtual mozilla::ipc::IPCResult |
94 | | AnswerNPP_HandleEvent(const NPRemoteEvent& event, int16_t* handled) override; |
95 | | virtual mozilla::ipc::IPCResult |
96 | | AnswerNPP_HandleEvent_Shmem(const NPRemoteEvent& event, |
97 | | Shmem&& mem, |
98 | | int16_t* handled, |
99 | | Shmem* rtnmem) override; |
100 | | virtual mozilla::ipc::IPCResult |
101 | | AnswerNPP_HandleEvent_IOSurface(const NPRemoteEvent& event, |
102 | | const uint32_t& surface, |
103 | | int16_t* handled) override; |
104 | | |
105 | | // Async rendering |
106 | | virtual mozilla::ipc::IPCResult |
107 | | RecvAsyncSetWindow(const gfxSurfaceType& aSurfaceType, |
108 | | const NPRemoteWindow& aWindow) override; |
109 | | |
110 | | virtual void |
111 | | DoAsyncSetWindow(const gfxSurfaceType& aSurfaceType, |
112 | | const NPRemoteWindow& aWindow, |
113 | | bool aIsAsync); |
114 | | |
115 | | virtual PPluginSurfaceChild* |
116 | | AllocPPluginSurfaceChild(const WindowsSharedMemoryHandle&, |
117 | 0 | const gfx::IntSize&, const bool&) override { |
118 | 0 | return new PPluginSurfaceChild(); |
119 | 0 | } |
120 | | |
121 | 0 | virtual bool DeallocPPluginSurfaceChild(PPluginSurfaceChild* s) override { |
122 | 0 | delete s; |
123 | 0 | return true; |
124 | 0 | } |
125 | | |
126 | | virtual mozilla::ipc::IPCResult |
127 | | AnswerPaint(const NPRemoteEvent& event, int16_t* handled) override |
128 | 0 | { |
129 | 0 | PaintTracker pt; |
130 | 0 | if (!AnswerNPP_HandleEvent(event, handled)) { |
131 | 0 | return IPC_FAIL_NO_REASON(this); |
132 | 0 | } |
133 | 0 | return IPC_OK(); |
134 | 0 | } |
135 | | |
136 | | virtual mozilla::ipc::IPCResult |
137 | | RecvWindowPosChanged(const NPRemoteEvent& event) override; |
138 | | |
139 | | virtual mozilla::ipc::IPCResult |
140 | | RecvContentsScaleFactorChanged(const double& aContentsScaleFactor) override; |
141 | | |
142 | | virtual mozilla::ipc::IPCResult |
143 | | AnswerNPP_Destroy(NPError* result) override; |
144 | | |
145 | | virtual PPluginScriptableObjectChild* |
146 | | AllocPPluginScriptableObjectChild() override; |
147 | | |
148 | | virtual bool |
149 | | DeallocPPluginScriptableObjectChild(PPluginScriptableObjectChild* aObject) override; |
150 | | |
151 | | virtual mozilla::ipc::IPCResult |
152 | | RecvPPluginScriptableObjectConstructor(PPluginScriptableObjectChild* aActor) override; |
153 | | |
154 | | virtual mozilla::ipc::IPCResult |
155 | | RecvPBrowserStreamConstructor(PBrowserStreamChild* aActor, const nsCString& aURL, |
156 | | const uint32_t& aLength, const uint32_t& aLastmodified, |
157 | | PStreamNotifyChild* aNotifyData, const nsCString& aHeaders) override; |
158 | | |
159 | | virtual mozilla::ipc::IPCResult |
160 | | AnswerNPP_NewStream( |
161 | | PBrowserStreamChild* actor, |
162 | | const nsCString& mimeType, |
163 | | const bool& seekable, |
164 | | NPError* rv, |
165 | | uint16_t* stype) override; |
166 | | |
167 | | virtual PBrowserStreamChild* |
168 | | AllocPBrowserStreamChild(const nsCString& url, |
169 | | const uint32_t& length, |
170 | | const uint32_t& lastmodified, |
171 | | PStreamNotifyChild* notifyData, |
172 | | const nsCString& headers) override; |
173 | | |
174 | | virtual bool |
175 | | DeallocPBrowserStreamChild(PBrowserStreamChild* stream) override; |
176 | | |
177 | | virtual PStreamNotifyChild* |
178 | | AllocPStreamNotifyChild(const nsCString& url, const nsCString& target, |
179 | | const bool& post, const nsCString& buffer, |
180 | | const bool& file, |
181 | | NPError* result) override; |
182 | | |
183 | | virtual bool |
184 | | DeallocPStreamNotifyChild(PStreamNotifyChild* notifyData) override; |
185 | | |
186 | | virtual mozilla::ipc::IPCResult |
187 | | AnswerSetPluginFocus() override; |
188 | | |
189 | | virtual mozilla::ipc::IPCResult |
190 | | AnswerUpdateWindow() override; |
191 | | |
192 | | virtual mozilla::ipc::IPCResult |
193 | | RecvNPP_DidComposite() override; |
194 | | |
195 | | public: |
196 | | PluginInstanceChild(const NPPluginFuncs* aPluginIface, |
197 | | const nsCString& aMimeType, |
198 | | const InfallibleTArray<nsCString>& aNames, |
199 | | const InfallibleTArray<nsCString>& aValues); |
200 | | |
201 | | virtual ~PluginInstanceChild(); |
202 | | |
203 | | NPError DoNPP_New(); |
204 | | |
205 | | // Common sync+async implementation of NPP_NewStream |
206 | | NPError DoNPP_NewStream(BrowserStreamChild* actor, |
207 | | const nsCString& mimeType, |
208 | | const bool& seekable, |
209 | | uint16_t* stype); |
210 | | |
211 | | bool Initialize(); |
212 | | |
213 | | NPP GetNPP() |
214 | 0 | { |
215 | 0 | return &mData; |
216 | 0 | } |
217 | | |
218 | | NPError |
219 | | NPN_GetValue(NPNVariable aVariable, void* aValue); |
220 | | |
221 | | NPError |
222 | | NPN_SetValue(NPPVariable aVariable, void* aValue); |
223 | | |
224 | | PluginScriptableObjectChild* |
225 | | GetActorForNPObject(NPObject* aObject); |
226 | | |
227 | | NPError |
228 | | NPN_NewStream(NPMIMEType aMIMEType, const char* aWindow, |
229 | | NPStream** aStream); |
230 | | |
231 | | void InvalidateRect(NPRect* aInvalidRect); |
232 | | |
233 | | #ifdef MOZ_WIDGET_COCOA |
234 | | void Invalidate(); |
235 | | #endif // definied(MOZ_WIDGET_COCOA) |
236 | | |
237 | | uint32_t ScheduleTimer(uint32_t interval, bool repeat, TimerFunc func); |
238 | | void UnscheduleTimer(uint32_t id); |
239 | | |
240 | | int GetQuirks(); |
241 | | |
242 | | void NPN_URLRedirectResponse(void* notifyData, NPBool allow); |
243 | | |
244 | | |
245 | | NPError NPN_InitAsyncSurface(NPSize *size, NPImageFormat format, |
246 | | void *initData, NPAsyncSurface *surface); |
247 | | NPError NPN_FinalizeAsyncSurface(NPAsyncSurface *surface); |
248 | | |
249 | | void NPN_SetCurrentAsyncSurface(NPAsyncSurface *surface, NPRect *changed); |
250 | | |
251 | | void DoAsyncRedraw(); |
252 | | |
253 | | virtual mozilla::ipc::IPCResult RecvHandledWindowedPluginKeyEvent( |
254 | | const NativeEventData& aKeyEventData, |
255 | | const bool& aIsConsumed) override; |
256 | | |
257 | | #if defined(XP_WIN) |
258 | | NPError DefaultAudioDeviceChanged(NPAudioDeviceChangeDetails& details); |
259 | | NPError AudioDeviceStateChanged(NPAudioDeviceStateChanged& aDeviceState); |
260 | | #endif |
261 | | |
262 | | private: |
263 | | friend class PluginModuleChild; |
264 | | |
265 | | NPError |
266 | | InternalGetNPObjectForValue(NPNVariable aValue, |
267 | | NPObject** aObject); |
268 | | |
269 | | bool IsUsingDirectDrawing(); |
270 | | |
271 | | virtual mozilla::ipc::IPCResult RecvUpdateBackground(const SurfaceDescriptor& aBackground, |
272 | | const nsIntRect& aRect) override; |
273 | | |
274 | | virtual PPluginBackgroundDestroyerChild* |
275 | | AllocPPluginBackgroundDestroyerChild() override; |
276 | | |
277 | | virtual mozilla::ipc::IPCResult |
278 | | RecvPPluginBackgroundDestroyerConstructor(PPluginBackgroundDestroyerChild* aActor) override; |
279 | | |
280 | | virtual bool |
281 | | DeallocPPluginBackgroundDestroyerChild(PPluginBackgroundDestroyerChild* aActor) override; |
282 | | |
283 | | #if defined(OS_WIN) |
284 | | static bool RegisterWindowClass(); |
285 | | bool CreatePluginWindow(); |
286 | | void DestroyPluginWindow(); |
287 | | void SizePluginWindow(int width, int height); |
288 | | int16_t WinlessHandleEvent(NPEvent& event); |
289 | | void CreateWinlessPopupSurrogate(); |
290 | | void DestroyWinlessPopupSurrogate(); |
291 | | void InitPopupMenuHook(); |
292 | | void SetupFlashMsgThrottle(); |
293 | | void UnhookWinlessFlashThrottle(); |
294 | | void HookSetWindowLongPtr(); |
295 | | void InitImm32Hook(); |
296 | | static inline bool SetWindowLongHookCheck(HWND hWnd, |
297 | | int nIndex, |
298 | | LONG_PTR newLong); |
299 | | void FlashThrottleMessage(HWND, UINT, WPARAM, LPARAM, bool); |
300 | | static LRESULT CALLBACK DummyWindowProc(HWND hWnd, |
301 | | UINT message, |
302 | | WPARAM wParam, |
303 | | LPARAM lParam); |
304 | | static LRESULT CALLBACK PluginWindowProc(HWND hWnd, |
305 | | UINT message, |
306 | | WPARAM wParam, |
307 | | LPARAM lParam); |
308 | | static BOOL WINAPI TrackPopupHookProc(HMENU hMenu, |
309 | | UINT uFlags, |
310 | | int x, |
311 | | int y, |
312 | | int nReserved, |
313 | | HWND hWnd, |
314 | | CONST RECT *prcRect); |
315 | | static BOOL CALLBACK EnumThreadWindowsCallback(HWND hWnd, |
316 | | LPARAM aParam); |
317 | | static LRESULT CALLBACK WinlessHiddenFlashWndProc(HWND hWnd, |
318 | | UINT message, |
319 | | WPARAM wParam, |
320 | | LPARAM lParam); |
321 | | #ifdef _WIN64 |
322 | | static LONG_PTR WINAPI SetWindowLongPtrAHook(HWND hWnd, |
323 | | int nIndex, |
324 | | LONG_PTR newLong); |
325 | | static LONG_PTR WINAPI SetWindowLongPtrWHook(HWND hWnd, |
326 | | int nIndex, |
327 | | LONG_PTR newLong); |
328 | | |
329 | | #else |
330 | | static LONG WINAPI SetWindowLongAHook(HWND hWnd, |
331 | | int nIndex, |
332 | | LONG newLong); |
333 | | static LONG WINAPI SetWindowLongWHook(HWND hWnd, |
334 | | int nIndex, |
335 | | LONG newLong); |
336 | | #endif |
337 | | |
338 | | static HIMC WINAPI ImmGetContextProc(HWND aWND); |
339 | | static LONG WINAPI ImmGetCompositionStringProc(HIMC aIMC, DWORD aIndex, |
340 | | LPVOID aBuf, DWORD aLen); |
341 | | static BOOL WINAPI ImmSetCandidateWindowProc(HIMC hIMC, |
342 | | LPCANDIDATEFORM plCandidate); |
343 | | static BOOL WINAPI ImmNotifyIME(HIMC aIMC, DWORD aAction, DWORD aIndex, |
344 | | DWORD aValue); |
345 | | static BOOL WINAPI ImmAssociateContextExProc(HWND hWnd, HIMC aIMC, |
346 | | DWORD dwFlags); |
347 | | |
348 | | class FlashThrottleMsg : public CancelableRunnable |
349 | | { |
350 | | public: |
351 | | FlashThrottleMsg(PluginInstanceChild* aInstance, HWND aWnd, UINT aMsg, |
352 | | WPARAM aWParam, LPARAM aLParam, bool isWindowed) |
353 | | : CancelableRunnable("FlashThrottleMsg"), |
354 | | mInstance(aInstance), |
355 | | mWnd(aWnd), |
356 | | mMsg(aMsg), |
357 | | mWParam(aWParam), |
358 | | mLParam(aLParam), |
359 | | mWindowed(isWindowed) |
360 | | {} |
361 | | |
362 | | NS_IMETHOD Run() override; |
363 | | nsresult Cancel() override; |
364 | | |
365 | | WNDPROC GetProc(); |
366 | | HWND GetWnd() { return mWnd; } |
367 | | UINT GetMsg() { return mMsg; } |
368 | | WPARAM GetWParam() { return mWParam; } |
369 | | LPARAM GetLParam() { return mLParam; } |
370 | | |
371 | | private: |
372 | | PluginInstanceChild* mInstance; |
373 | | HWND mWnd; |
374 | | UINT mMsg; |
375 | | WPARAM mWParam; |
376 | | LPARAM mLParam; |
377 | | bool mWindowed; |
378 | | }; |
379 | | |
380 | | bool ShouldPostKeyMessage(UINT message, WPARAM wParam, LPARAM lParam); |
381 | | bool MaybePostKeyMessage(UINT message, WPARAM wParam, LPARAM lParam); |
382 | | #endif // #if defined(OS_WIN) |
383 | | const NPPluginFuncs* mPluginIface; |
384 | | nsCString mMimeType; |
385 | | InfallibleTArray<nsCString> mNames; |
386 | | InfallibleTArray<nsCString> mValues; |
387 | | NPP_t mData; |
388 | | NPWindow mWindow; |
389 | | #if defined(XP_DARWIN) || defined(XP_WIN) |
390 | | double mContentsScaleFactor; |
391 | | #endif |
392 | | double mCSSZoomFactor; |
393 | | uint32_t mPostingKeyEvents; |
394 | | uint32_t mPostingKeyEventsOutdated; |
395 | | int16_t mDrawingModel; |
396 | | |
397 | | NPAsyncSurface* mCurrentDirectSurface; |
398 | | |
399 | | // The surface hashtables below serve a few purposes. They let us verify |
400 | | // and retain extra information about plugin surfaces, and they let us |
401 | | // free shared memory that the plugin might forget to release. |
402 | | struct DirectBitmap { |
403 | | DirectBitmap(PluginInstanceChild* aOwner, const Shmem& shmem, |
404 | | const gfx::IntSize& size, uint32_t stride, SurfaceFormat format); |
405 | | |
406 | | private: |
407 | | ~DirectBitmap(); |
408 | | |
409 | | public: |
410 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DirectBitmap); |
411 | | |
412 | | PluginInstanceChild* mOwner; |
413 | | Shmem mShmem; |
414 | | gfx::SurfaceFormat mFormat; |
415 | | gfx::IntSize mSize; |
416 | | uint32_t mStride; |
417 | | }; |
418 | | nsRefPtrHashtable<nsPtrHashKey<NPAsyncSurface>, DirectBitmap> mDirectBitmaps; |
419 | | |
420 | | #if defined(XP_WIN) |
421 | | nsDataHashtable<nsPtrHashKey<NPAsyncSurface>, WindowsHandle> mDxgiSurfaces; |
422 | | #endif |
423 | | |
424 | | mozilla::Mutex mAsyncInvalidateMutex; |
425 | | CancelableRunnable *mAsyncInvalidateTask; |
426 | | |
427 | | // Cached scriptable actors to avoid IPC churn |
428 | | PluginScriptableObjectChild* mCachedWindowActor; |
429 | | PluginScriptableObjectChild* mCachedElementActor; |
430 | | |
431 | | #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX) |
432 | | NPSetWindowCallbackStruct mWsInfo; |
433 | | #ifdef MOZ_WIDGET_GTK |
434 | | XtClient mXtClient; |
435 | | #endif |
436 | | #elif defined(OS_WIN) |
437 | | HWND mPluginWindowHWND; |
438 | | WNDPROC mPluginWndProc; |
439 | | HWND mPluginParentHWND; |
440 | | int mNestedEventLevelDepth; |
441 | | HWND mCachedWinlessPluginHWND; |
442 | | HWND mWinlessPopupSurrogateHWND; |
443 | | nsIntPoint mPluginSize; |
444 | | WNDPROC mWinlessThrottleOldWndProc; |
445 | | HWND mWinlessHiddenMsgHWND; |
446 | | #endif |
447 | | |
448 | | #if defined(OS_WIN) |
449 | | nsTArray<FlashThrottleMsg*> mPendingFlashThrottleMsgs; |
450 | | #endif |
451 | | nsTArray<nsAutoPtr<ChildTimer> > mTimers; |
452 | | |
453 | | /** |
454 | | * During destruction we enumerate all remaining scriptable objects and |
455 | | * invalidate/delete them. Enumeration can re-enter, so maintain a |
456 | | * hash separate from PluginModuleChild.mObjectMap. |
457 | | */ |
458 | | nsAutoPtr< nsTHashtable<DeletingObjectEntry> > mDeletingHash; |
459 | | |
460 | | #if defined(MOZ_WIDGET_COCOA) |
461 | | private: |
462 | | #if defined(__i386__) |
463 | | NPEventModel mEventModel; |
464 | | #endif |
465 | | CGColorSpaceRef mShColorSpace; |
466 | | CGContextRef mShContext; |
467 | | RefPtr<nsCARenderer> mCARenderer; |
468 | | void *mCGLayer; |
469 | | |
470 | | // Core Animation drawing model requires a refresh timer. |
471 | | uint32_t mCARefreshTimer; |
472 | | |
473 | | public: |
474 | | const NPCocoaEvent* getCurrentEvent() { |
475 | | return mCurrentEvent; |
476 | | } |
477 | | |
478 | | bool CGDraw(CGContextRef ref, nsIntRect aUpdateRect); |
479 | | |
480 | | #if defined(__i386__) |
481 | | NPEventModel EventModel() { return mEventModel; } |
482 | | #endif |
483 | | |
484 | | private: |
485 | | const NPCocoaEvent *mCurrentEvent; |
486 | | #endif |
487 | | |
488 | | bool CanPaintOnBackground(); |
489 | | |
490 | 0 | bool IsVisible() { |
491 | | #ifdef XP_MACOSX |
492 | | return mWindow.clipRect.top != mWindow.clipRect.bottom && |
493 | | mWindow.clipRect.left != mWindow.clipRect.right; |
494 | | #else |
495 | 0 | return mWindow.clipRect.top != 0 || |
496 | 0 | mWindow.clipRect.left != 0 || |
497 | 0 | mWindow.clipRect.bottom != 0 || |
498 | 0 | mWindow.clipRect.right != 0; |
499 | 0 | #endif |
500 | 0 | } |
501 | | |
502 | | // ShowPluginFrame - in general does four things: |
503 | | // 1) Create mCurrentSurface optimized for rendering to parent process |
504 | | // 2) Updated mCurrentSurface to be a complete copy of mBackSurface |
505 | | // 3) Draw the invalidated plugin area into mCurrentSurface |
506 | | // 4) Send it to parent process. |
507 | | bool ShowPluginFrame(void); |
508 | | |
509 | | // If we can read back safely from mBackSurface, copy |
510 | | // mSurfaceDifferenceRect from mBackSurface to mFrontSurface. |
511 | | // @return Whether the back surface could be read. |
512 | | bool ReadbackDifferenceRect(const nsIntRect& rect); |
513 | | |
514 | | // Post ShowPluginFrame task |
515 | | void AsyncShowPluginFrame(void); |
516 | | |
517 | | // In the PaintRect functions, aSurface is the size of the full plugin |
518 | | // window. Each PaintRect function renders into the subrectangle aRect of |
519 | | // aSurface (possibly more if we're working around a Flash bug). |
520 | | |
521 | | // Paint plugin content rectangle to surface with bg color filling |
522 | | void PaintRectToSurface(const nsIntRect& aRect, |
523 | | gfxASurface* aSurface, |
524 | | const gfx::Color& aColor); |
525 | | |
526 | | // Render plugin content to surface using |
527 | | // white/black image alpha extraction algorithm |
528 | | void PaintRectWithAlphaExtraction(const nsIntRect& aRect, |
529 | | gfxASurface* aSurface); |
530 | | |
531 | | // Call plugin NPAPI function to render plugin content to surface |
532 | | // @param - aSurface - should be compatible with current platform plugin rendering |
533 | | // @return - FALSE if plugin not painted to surface |
534 | | void PaintRectToPlatformSurface(const nsIntRect& aRect, |
535 | | gfxASurface* aSurface); |
536 | | |
537 | | // Update NPWindow platform attributes and call plugin "setwindow" |
538 | | // @param - aForceSetWindow - call setwindow even if platform attributes are the same |
539 | | void UpdateWindowAttributes(bool aForceSetWindow = false); |
540 | | |
541 | | // Create optimized mCurrentSurface for parent process rendering |
542 | | // @return FALSE if optimized surface not created |
543 | | bool CreateOptSurface(void); |
544 | | |
545 | | // Create mHelperSurface if mCurrentSurface non compatible with plugins |
546 | | // @return TRUE if helper surface created successfully, or not needed |
547 | | bool MaybeCreatePlatformHelperSurface(void); |
548 | | |
549 | | // Make sure that we have surface for rendering |
550 | | bool EnsureCurrentBuffer(void); |
551 | | |
552 | | // Helper function for delayed InvalidateRect call |
553 | | // non null mCurrentInvalidateTask will call this function |
554 | | void InvalidateRectDelayed(void); |
555 | | |
556 | | // Clear mCurrentSurface/mCurrentSurfaceActor/mHelperSurface |
557 | | void ClearCurrentSurface(); |
558 | | |
559 | | // Swap mCurrentSurface/mBackSurface and their associated actors |
560 | | void SwapSurfaces(); |
561 | | |
562 | | // Clear all surfaces in response to NPP_Destroy |
563 | | void ClearAllSurfaces(); |
564 | | |
565 | | void Destroy(); |
566 | | |
567 | | void ActorDestroy(ActorDestroyReason aWhy) override; |
568 | | |
569 | | // Set as true when SetupLayer called |
570 | | // and go with different path in InvalidateRect function |
571 | | bool mLayersRendering; |
572 | | |
573 | | // Current surface available for rendering |
574 | | RefPtr<gfxASurface> mCurrentSurface; |
575 | | |
576 | | // Back surface, just keeping reference to |
577 | | // surface which is on ParentProcess side |
578 | | RefPtr<gfxASurface> mBackSurface; |
579 | | |
580 | | #ifdef XP_MACOSX |
581 | | // Current IOSurface available for rendering |
582 | | // We can't use thebes gfxASurface like other platforms. |
583 | | PluginUtilsOSX::nsDoubleBufferCARenderer mDoubleBufferCARenderer; |
584 | | #endif |
585 | | |
586 | | // (Not to be confused with mBackSurface). This is a recent copy |
587 | | // of the opaque pixels under our object frame, if |
588 | | // |mIsTransparent|. We ask the plugin render directly onto a |
589 | | // copy of the background pixels if available, and fall back on |
590 | | // alpha recovery otherwise. |
591 | | RefPtr<gfxASurface> mBackground; |
592 | | |
593 | | #ifdef XP_WIN |
594 | | // These actors mirror mCurrentSurface/mBackSurface |
595 | | PPluginSurfaceChild* mCurrentSurfaceActor; |
596 | | PPluginSurfaceChild* mBackSurfaceActor; |
597 | | #endif |
598 | | |
599 | | // Accumulated invalidate rect, while back buffer is not accessible, |
600 | | // in plugin coordinates. |
601 | | nsIntRect mAccumulatedInvalidRect; |
602 | | |
603 | | // Plugin only call SetTransparent |
604 | | // and does not remember their transparent state |
605 | | // and p->getvalue return always false |
606 | | bool mIsTransparent; |
607 | | |
608 | | // Surface type optimized of parent process |
609 | | gfxSurfaceType mSurfaceType; |
610 | | |
611 | | // Keep InvalidateRect task pointer to be able Cancel it on Destroy |
612 | | RefPtr<CancelableRunnable> mCurrentInvalidateTask; |
613 | | |
614 | | // Keep AsyncSetWindow task pointer to be able to Cancel it on Destroy |
615 | | RefPtr<CancelableRunnable> mCurrentAsyncSetWindowTask; |
616 | | |
617 | | // True while plugin-child in plugin call |
618 | | // Use to prevent plugin paint re-enter |
619 | | bool mPendingPluginCall; |
620 | | |
621 | | // On some platforms, plugins may not support rendering to a surface with |
622 | | // alpha, or not support rendering to an image surface. |
623 | | // In those cases we need to draw to a temporary platform surface; we cache |
624 | | // that surface here. |
625 | | RefPtr<gfxASurface> mHelperSurface; |
626 | | |
627 | | // true when plugin does not support painting to ARGB32 |
628 | | // surface this is false if plugin supports |
629 | | // NPPVpluginTransparentAlphaBool (which is not part of |
630 | | // NPAPI yet) |
631 | | bool mDoAlphaExtraction; |
632 | | |
633 | | // true when the plugin has painted at least once. We use this to ensure |
634 | | // that we ask a plugin to paint at least once even if it's invisible; |
635 | | // some plugin (instances) rely on this in order to work properly. |
636 | | bool mHasPainted; |
637 | | |
638 | | // Cached rectangle rendered to previous surface(mBackSurface) |
639 | | // Used for reading back to current surface and syncing data, |
640 | | // in plugin coordinates. |
641 | | nsIntRect mSurfaceDifferenceRect; |
642 | | |
643 | | // Has this instance been destroyed, either by ActorDestroy or NPP_Destroy? |
644 | | bool mDestroyed; |
645 | | |
646 | | #ifdef XP_WIN |
647 | | // WM_*CHAR messages are never consumed by chrome process's widget. |
648 | | // So, if preceding keydown or keyup event is consumed by reserved |
649 | | // shortcut key in the chrome process, we shouldn't send the following |
650 | | // WM_*CHAR messages to the plugin. |
651 | | bool mLastKeyEventConsumed; |
652 | | |
653 | | // Store the last IME state by ImmAssociateContextEx. This will reset by |
654 | | // WM_KILLFOCUS; |
655 | | bool mLastEnableIMEState; |
656 | | #endif // #ifdef XP_WIN |
657 | | |
658 | | // While IME in the process has composition, this is set to true. |
659 | | // Otherwise, false. |
660 | | static bool sIsIMEComposing; |
661 | | |
662 | | // A counter is incremented by AutoStackHelper to indicate that there is an |
663 | | // active plugin call which should be preventing shutdown. |
664 | | public: |
665 | | class AutoStackHelper { |
666 | | public: |
667 | | explicit AutoStackHelper(PluginInstanceChild* instance) |
668 | | : mInstance(instance) |
669 | 0 | { |
670 | 0 | ++mInstance->mStackDepth; |
671 | 0 | } |
672 | 0 | ~AutoStackHelper() { |
673 | 0 | --mInstance->mStackDepth; |
674 | 0 | } |
675 | | private: |
676 | | PluginInstanceChild *const mInstance; |
677 | | }; |
678 | | private: |
679 | | int32_t mStackDepth; |
680 | | }; |
681 | | |
682 | | } // namespace plugins |
683 | | } // namespace mozilla |
684 | | |
685 | | #endif // ifndef dom_plugins_PluginInstanceChild_h |