1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Mozilla Plugin App.
18 * The Initial Developer of the Original Code is
19 * Chris Jones <jones.chris.g@gmail.com>
20 * Portions created by the Initial Developer are Copyright (C) 2009
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef dom_plugins_PluginInstanceChild_h
40 #define dom_plugins_PluginInstanceChild_h 1
42 #include "mozilla/plugins/PPluginInstanceChild.h"
43 #include "mozilla/plugins/PluginScriptableObjectChild.h"
44 #include "mozilla/plugins/StreamNotifyChild.h"
46 #include "mozilla/gfx/SharedDIBWin.h"
47 #elif defined(OS_MACOSX)
48 #include "nsCoreAnimationSupport.h"
49 #include "base/timer.h"
52 #include "npfunctions.h"
53 #include "nsAutoPtr.h"
55 #include "ChildAsyncCall.h"
56 #include "ChildTimer.h"
58 #include "nsTHashtable.h"
59 #include "mozilla/PaintTracker.h"
60 #include "gfxASurface.h"
65 class PBrowserStreamChild
;
66 class BrowserStreamChild
;
67 class StreamNotifyChild
;
69 class PluginInstanceChild
: public PPluginInstanceChild
71 friend class BrowserStreamChild
;
72 friend class PluginStreamChild
;
73 friend class StreamNotifyChild
;
76 friend LRESULT CALLBACK
PluginWindowProc(HWND hWnd
,
83 virtual bool AnswerNPP_SetWindow(const NPRemoteWindow
& window
);
86 AnswerNPP_GetValue_NPPVpluginNeedsXEmbed(bool* needs
, NPError
* rv
);
88 AnswerNPP_GetValue_NPPVpluginScriptableNPObject(PPluginScriptableObjectChild
** value
,
92 AnswerNPP_SetValue_NPNVprivateModeBool(const bool& value
, NPError
* result
);
95 AnswerNPP_HandleEvent(const NPRemoteEvent
& event
, int16_t* handled
);
97 AnswerNPP_HandleEvent_Shmem(const NPRemoteEvent
& event
, Shmem
& mem
, int16_t* handled
, Shmem
* rtnmem
);
99 AnswerNPP_HandleEvent_IOSurface(const NPRemoteEvent
& event
, const uint32_t& surface
, int16_t* handled
);
103 RecvAsyncSetWindow(const gfxSurfaceType
& aSurfaceType
,
104 const NPRemoteWindow
& aWindow
);
107 DoAsyncSetWindow(const gfxSurfaceType
& aSurfaceType
,
108 const NPRemoteWindow
& aWindow
,
113 AnswerPaint(const NPRemoteEvent
& event
, int16_t* handled
)
116 return AnswerNPP_HandleEvent(event
, handled
);
121 RecvWindowPosChanged(const NPRemoteEvent
& event
);
124 AnswerNPP_Destroy(NPError
* result
);
126 virtual PPluginScriptableObjectChild
*
127 AllocPPluginScriptableObject();
130 DeallocPPluginScriptableObject(PPluginScriptableObjectChild
* aObject
);
132 NS_OVERRIDE
virtual bool
133 RecvPPluginScriptableObjectConstructor(PPluginScriptableObjectChild
* aActor
);
135 virtual PBrowserStreamChild
*
136 AllocPBrowserStream(const nsCString
& url
,
137 const uint32_t& length
,
138 const uint32_t& lastmodified
,
139 PStreamNotifyChild
* notifyData
,
140 const nsCString
& headers
,
141 const nsCString
& mimeType
,
142 const bool& seekable
,
147 AnswerPBrowserStreamConstructor(
148 PBrowserStreamChild
* aActor
,
149 const nsCString
& url
,
150 const uint32_t& length
,
151 const uint32_t& lastmodified
,
152 PStreamNotifyChild
* notifyData
,
153 const nsCString
& headers
,
154 const nsCString
& mimeType
,
155 const bool& seekable
,
160 DeallocPBrowserStream(PBrowserStreamChild
* stream
);
162 virtual PPluginStreamChild
*
163 AllocPPluginStream(const nsCString
& mimeType
,
164 const nsCString
& target
,
168 DeallocPPluginStream(PPluginStreamChild
* stream
);
170 virtual PStreamNotifyChild
*
171 AllocPStreamNotify(const nsCString
& url
, const nsCString
& target
,
172 const bool& post
, const nsCString
& buffer
,
176 NS_OVERRIDE
virtual bool
177 DeallocPStreamNotify(PStreamNotifyChild
* notifyData
);
180 AnswerSetPluginFocus();
183 AnswerUpdateWindow();
186 PluginInstanceChild(const NPPluginFuncs
* aPluginIface
);
188 virtual ~PluginInstanceChild();
198 NPN_GetValue(NPNVariable aVariable
, void* aValue
);
201 NPN_SetValue(NPPVariable aVariable
, void* aValue
);
203 PluginScriptableObjectChild
*
204 GetActorForNPObject(NPObject
* aObject
);
207 NPN_NewStream(NPMIMEType aMIMEType
, const char* aWindow
,
210 void InvalidateRect(NPRect
* aInvalidRect
);
212 uint32_t ScheduleTimer(uint32_t interval
, bool repeat
, TimerFunc func
);
213 void UnscheduleTimer(uint32_t id
);
215 void AsyncCall(PluginThreadCallback aFunc
, void* aUserData
);
220 friend class PluginModuleChild
;
223 InternalGetNPObjectForValue(NPNVariable aValue
,
227 static bool RegisterWindowClass();
228 bool CreatePluginWindow();
229 void DestroyPluginWindow();
230 void ReparentPluginWindow(HWND hWndParent
);
231 void SizePluginWindow(int width
, int height
);
232 int16_t WinlessHandleEvent(NPEvent
& event
);
233 void CreateWinlessPopupSurrogate();
234 void DestroyWinlessPopupSurrogate();
235 void InitPopupMenuHook();
236 void SetupFlashMsgThrottle();
237 void UnhookWinlessFlashThrottle();
238 void HookSetWindowLongPtr();
239 static inline PRBool
SetWindowLongHookCheck(HWND hWnd
,
242 void FlashThrottleMessage(HWND
, UINT
, WPARAM
, LPARAM
, bool);
243 static LRESULT CALLBACK
DummyWindowProc(HWND hWnd
,
247 static LRESULT CALLBACK
PluginWindowProc(HWND hWnd
,
251 static BOOL WINAPI
TrackPopupHookProc(HMENU hMenu
,
257 CONST RECT
*prcRect
);
258 static BOOL CALLBACK
EnumThreadWindowsCallback(HWND hWnd
,
260 static LRESULT CALLBACK
WinlessHiddenFlashWndProc(HWND hWnd
,
265 static LONG_PTR WINAPI
SetWindowLongPtrAHook(HWND hWnd
,
268 static LONG_PTR WINAPI
SetWindowLongPtrWHook(HWND hWnd
,
273 static LONG WINAPI
SetWindowLongAHook(HWND hWnd
,
276 static LONG WINAPI
SetWindowLongWHook(HWND hWnd
,
281 class FlashThrottleAsyncMsg
: public ChildAsyncCall
284 FlashThrottleAsyncMsg();
285 FlashThrottleAsyncMsg(PluginInstanceChild
* aInst
,
286 HWND aWnd
, UINT aMsg
,
287 WPARAM aWParam
, LPARAM aLParam
,
289 : ChildAsyncCall(aInst
, nsnull
, nsnull
),
294 mWindowed(isWindowed
)
297 NS_OVERRIDE
void Run();
300 HWND
GetWnd() { return mWnd
; }
301 UINT
GetMsg() { return mMsg
; }
302 WPARAM
GetWParam() { return mWParam
; }
303 LPARAM
GetLParam() { return mLParam
; }
315 const NPPluginFuncs
* mPluginIface
;
319 // Cached scriptable actors to avoid IPC churn
320 PluginScriptableObjectChild
* mCachedWindowActor
;
321 PluginScriptableObjectChild
* mCachedElementActor
;
323 #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
324 NPSetWindowCallbackStruct mWsInfo
;
325 #elif defined(OS_WIN)
326 HWND mPluginWindowHWND
;
327 WNDPROC mPluginWndProc
;
328 HWND mPluginParentHWND
;
329 int mNestedEventLevelDepth
;
330 HWND mCachedWinlessPluginHWND
;
331 HWND mWinlessPopupSurrogateHWND
;
332 nsIntPoint mPluginSize
;
333 WNDPROC mWinlessThrottleOldWndProc
;
334 HWND mWinlessHiddenMsgHWND
;
337 friend class ChildAsyncCall
;
339 Mutex mAsyncCallMutex
;
340 nsTArray
<ChildAsyncCall
*> mPendingAsyncCalls
;
341 nsTArray
<nsAutoPtr
<ChildTimer
> > mTimers
;
344 * During destruction we enumerate all remaining scriptable objects and
345 * invalidate/delete them. Enumeration can re-enter, so maintain a
346 * hash separate from PluginModuleChild.mObjectMap.
348 nsAutoPtr
< nsTHashtable
<DeletingObjectEntry
> > mDeletingHash
;
352 // Shared dib rendering management for windowless plugins.
353 bool SharedSurfaceSetWindow(const NPRemoteWindow
& aWindow
);
354 int16_t SharedSurfacePaint(NPEvent
& evcopy
);
355 void SharedSurfaceRelease();
356 bool AlphaExtractCacheSetup();
357 void AlphaExtractCacheRelease();
358 void UpdatePaintClipRect(RECT
* aRect
);
366 gfx::SharedDIBWin mSharedSurfaceDib
;
372 #endif // defined(OS_WIN)
373 #if defined(OS_MACOSX)
375 #if defined(__i386__)
376 NPEventModel mEventModel
;
378 CGColorSpaceRef mShColorSpace
;
379 CGContextRef mShContext
;
380 int16_t mDrawingModel
;
381 nsCARenderer mCARenderer
;
384 const NPCocoaEvent
* getCurrentEvent() {
385 return mCurrentEvent
;
388 #if defined(__i386__)
389 NPEventModel
EventModel() { return mEventModel
; }
393 const NPCocoaEvent
*mCurrentEvent
;
397 return mWindow
.clipRect
.top
!= 0 ||
398 mWindow
.clipRect
.left
!= 0 ||
399 mWindow
.clipRect
.bottom
!= 0 ||
400 mWindow
.clipRect
.right
!= 0;
403 // ShowPluginFrame - in general does four things:
404 // 1) Create mCurrentSurface optimized for rendering to parent process
405 // 2) Updated mCurrentSurface to be a complete copy of mBackSurface
406 // 3) Draw the invalidated plugin area into mCurrentSurface
407 // 4) Send it to parent process.
408 bool ShowPluginFrame(void);
410 // If we can read back safely from mBackSurface, copy
411 // mSurfaceDifferenceRect from mBackSurface to mFrontSurface.
412 // @return Whether the back surface could be read.
413 bool ReadbackDifferenceRect(const nsIntRect
& rect
);
415 // Post ShowPluginFrame task
416 void AsyncShowPluginFrame(void);
418 // In the PaintRect functions, aSurface is the size of the full plugin
419 // window. Each PaintRect function renders into the subrectangle aRect of
420 // aSurface (possibly more if we're working around a Flash bug).
422 // Paint plugin content rectangle to surface with bg color filling
423 void PaintRectToSurface(const nsIntRect
& aRect
,
424 gfxASurface
* aSurface
,
425 const gfxRGBA
& aColor
);
427 // Render plugin content to surface using
428 // white/black image alpha extraction algorithm
429 void PaintRectWithAlphaExtraction(const nsIntRect
& aRect
,
430 gfxASurface
* aSurface
);
432 // Call plugin NPAPI function to render plugin content to surface
433 // @param - aSurface - should be compatible with current platform plugin rendering
434 // @return - FALSE if plugin not painted to surface
435 void PaintRectToPlatformSurface(const nsIntRect
& aRect
,
436 gfxASurface
* aSurface
);
438 // Update NPWindow platform attributes and call plugin "setwindow"
439 // @param - aForceSetWindow - call setwindow even if platform attributes are the same
440 void UpdateWindowAttributes(bool aForceSetWindow
= false);
442 // Create optimized mCurrentSurface for parent process rendering
443 // @return FALSE if optimized surface not created
444 bool CreateOptSurface(void);
446 // Create mHelperSurface if mCurrentSurface non compatible with plugins
447 // @return TRUE if helper surface created successfully, or not needed
448 bool MaybeCreatePlatformHelperSurface(void);
450 // Make sure that we have surface for rendering
451 bool EnsureCurrentBuffer(void);
453 // Helper function for delayed InvalidateRect call
454 // non null mCurrentInvalidateTask will call this function
455 void InvalidateRectDelayed(void);
457 // Set as true when SetupLayer called
458 // and go with different path in InvalidateRect function
459 bool mLayersRendering
;
461 // Current surface available for rendering
462 nsRefPtr
<gfxASurface
> mCurrentSurface
;
464 // Back surface, just keeping reference to
465 // surface which is on ParentProcess side
466 nsRefPtr
<gfxASurface
> mBackSurface
;
468 // Accumulated invalidate rect, while back buffer is not accessible,
469 // in plugin coordinates.
470 nsIntRect mAccumulatedInvalidRect
;
472 // Plugin only call SetTransparent
473 // and does not remember their transparent state
474 // and p->getvalue return always false
477 // Surface type optimized of parent process
478 gfxSurfaceType mSurfaceType
;
480 // Keep InvalidateRect task pointer to be able Cancel it on Destroy
481 CancelableTask
*mCurrentInvalidateTask
;
483 // Keep AsyncSetWindow task pointer to be able to Cancel it on Destroy
484 CancelableTask
*mCurrentAsyncSetWindowTask
;
486 // True while plugin-child in plugin call
487 // Use to prevent plugin paint re-enter
488 bool mPendingPluginCall
;
490 // On some platforms, plugins may not support rendering to a surface with
491 // alpha, or not support rendering to an image surface.
492 // In those cases we need to draw to a temporary platform surface; we cache
493 // that surface here.
494 nsRefPtr
<gfxASurface
> mHelperSurface
;
496 // true when plugin does not support painting to ARGB32 surface
497 // this is false for maemo platform, and false if plugin
498 // supports NPPVpluginTransparentAlphaBool (which is not part of NPAPI yet)
499 bool mDoAlphaExtraction
;
501 // Cached rectangle rendered to previous surface(mBackSurface)
502 // Used for reading back to current surface and syncing data,
503 // in plugin coordinates.
504 nsIntRect mSurfaceDifferenceRect
;
507 // Used with windowless flash plugin only, see bug 574583
510 #if (MOZ_PLATFORM_MAEMO == 5) || (MOZ_PLATFORM_MAEMO == 6)
511 // Maemo5 Flash does not remember WindowlessLocal state
512 // we should listen for NPP values negotiation and remember it
513 PRPackedBool mMaemoImageRendering
;
517 } // namespace plugins
518 } // namespace mozilla
520 #endif // ifndef dom_plugins_PluginInstanceChild_h