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