LCOV - code coverage report
Current view: top level - dom/plugins/ipc - PluginInstanceParent.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 6 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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_PluginInstanceParent_h
       8             : #define dom_plugins_PluginInstanceParent_h 1
       9             : 
      10             : #include "mozilla/plugins/PPluginInstanceParent.h"
      11             : #include "mozilla/plugins/PluginScriptableObjectParent.h"
      12             : #if defined(OS_WIN)
      13             : #include "mozilla/gfx/SharedDIBWin.h"
      14             : #include <d3d10_1.h>
      15             : #include "nsRefPtrHashtable.h"
      16             : #elif defined(MOZ_WIDGET_COCOA)
      17             : #include "mozilla/gfx/QuartzSupport.h"
      18             : #endif
      19             : 
      20             : #include "npfunctions.h"
      21             : #include "nsDataHashtable.h"
      22             : #include "nsHashKeys.h"
      23             : #include "nsRect.h"
      24             : 
      25             : #include "mozilla/Unused.h"
      26             : #include "mozilla/EventForwards.h"
      27             : 
      28             : class gfxASurface;
      29             : class gfxContext;
      30             : class nsPluginInstanceOwner;
      31             : 
      32             : namespace mozilla {
      33             : namespace layers {
      34             : class Image;
      35             : class ImageContainer;
      36             : class TextureClientRecycleAllocator;
      37             : } // namespace layers
      38             : namespace plugins {
      39             : 
      40             : class PBrowserStreamParent;
      41             : class PluginModuleParent;
      42             : class D3D11SurfaceHolder;
      43             : 
      44             : class PluginInstanceParent : public PPluginInstanceParent
      45             : {
      46             :     friend class PluginModuleParent;
      47             :     friend class BrowserStreamParent;
      48             :     friend class StreamNotifyParent;
      49             : 
      50             : #if defined(XP_WIN)
      51             : public:
      52             :     /**
      53             :      * Helper method for looking up instances based on a supplied id.
      54             :      */
      55             :     static PluginInstanceParent*
      56             :     LookupPluginInstanceByID(uintptr_t aId);
      57             : #endif // defined(XP_WIN)
      58             : 
      59             : public:
      60             :     typedef mozilla::gfx::DrawTarget DrawTarget;
      61             : 
      62             :     PluginInstanceParent(PluginModuleParent* parent,
      63             :                          NPP npp,
      64             :                          const nsCString& mimeType,
      65             :                          const NPNetscapeFuncs* npniface);
      66             : 
      67             :     virtual ~PluginInstanceParent();
      68             : 
      69             :     bool InitMetadata(const nsACString& aMimeType,
      70             :                       const nsACString& aSrcAttribute);
      71             :     NPError Destroy();
      72             : 
      73             :     virtual void ActorDestroy(ActorDestroyReason why) override;
      74             : 
      75             :     virtual PPluginScriptableObjectParent*
      76             :     AllocPPluginScriptableObjectParent() override;
      77             : 
      78             :     virtual mozilla::ipc::IPCResult
      79             :     RecvPPluginScriptableObjectConstructor(PPluginScriptableObjectParent* aActor) override;
      80             : 
      81             :     virtual bool
      82             :     DeallocPPluginScriptableObjectParent(PPluginScriptableObjectParent* aObject) override;
      83             :     virtual PBrowserStreamParent*
      84             :     AllocPBrowserStreamParent(const nsCString& url,
      85             :                               const uint32_t& length,
      86             :                               const uint32_t& lastmodified,
      87             :                               PStreamNotifyParent* notifyData,
      88             :                               const nsCString& headers) override;
      89             :     virtual bool
      90             :     DeallocPBrowserStreamParent(PBrowserStreamParent* stream) override;
      91             : 
      92             :     virtual mozilla::ipc::IPCResult
      93             :     AnswerNPN_GetValue_NPNVnetscapeWindow(NativeWindowHandle* value,
      94             :                                           NPError* result) override;
      95             :     virtual mozilla::ipc::IPCResult
      96             :     AnswerNPN_GetValue_NPNVWindowNPObject(
      97             :                                        PPluginScriptableObjectParent** value,
      98             :                                        NPError* result) override;
      99             :     virtual mozilla::ipc::IPCResult
     100             :     AnswerNPN_GetValue_NPNVPluginElementNPObject(
     101             :                                        PPluginScriptableObjectParent** value,
     102             :                                        NPError* result) override;
     103             :     virtual mozilla::ipc::IPCResult
     104             :     AnswerNPN_GetValue_NPNVprivateModeBool(bool* value, NPError* result) override;
     105             : 
     106             :     virtual mozilla::ipc::IPCResult
     107             :     AnswerNPN_GetValue_DrawingModelSupport(const NPNVariable& model, bool* value) override;
     108             : 
     109             :     virtual mozilla::ipc::IPCResult
     110             :     AnswerNPN_GetValue_NPNVdocumentOrigin(nsCString* value, NPError* result) override;
     111             : 
     112             :     virtual mozilla::ipc::IPCResult
     113             :     AnswerNPN_GetValue_SupportsAsyncBitmapSurface(bool* value) override;
     114             : 
     115             :     virtual mozilla::ipc::IPCResult
     116             :     AnswerNPN_GetValue_SupportsAsyncDXGISurface(bool* value) override;
     117             : 
     118             :     virtual mozilla::ipc::IPCResult
     119             :     AnswerNPN_GetValue_PreferredDXGIAdapter(DxgiAdapterDesc* desc) override;
     120             : 
     121             :     virtual mozilla::ipc::IPCResult
     122             :     AnswerNPN_SetValue_NPPVpluginWindow(const bool& windowed, NPError* result) override;
     123             :     virtual mozilla::ipc::IPCResult
     124             :     AnswerNPN_SetValue_NPPVpluginTransparent(const bool& transparent,
     125             :                                              NPError* result) override;
     126             :     virtual mozilla::ipc::IPCResult
     127             :     AnswerNPN_SetValue_NPPVpluginUsesDOMForCursor(const bool& useDOMForCursor,
     128             :                                                   NPError* result) override;
     129             :     virtual mozilla::ipc::IPCResult
     130             :     AnswerNPN_SetValue_NPPVpluginDrawingModel(const int& drawingModel,
     131             :                                               NPError* result) override;
     132             :     virtual mozilla::ipc::IPCResult
     133             :     AnswerNPN_SetValue_NPPVpluginEventModel(const int& eventModel,
     134             :                                              NPError* result) override;
     135             :     virtual mozilla::ipc::IPCResult
     136             :     AnswerNPN_SetValue_NPPVpluginIsPlayingAudio(const bool& isAudioPlaying,
     137             :                                                 NPError* result) override;
     138             : 
     139             :     virtual mozilla::ipc::IPCResult
     140             :     AnswerNPN_GetURL(const nsCString& url, const nsCString& target,
     141             :                      NPError *result) override;
     142             : 
     143             :     virtual mozilla::ipc::IPCResult
     144             :     AnswerNPN_PostURL(const nsCString& url, const nsCString& target,
     145             :                       const nsCString& buffer, const bool& file,
     146             :                       NPError* result) override;
     147             : 
     148             :     virtual PStreamNotifyParent*
     149             :     AllocPStreamNotifyParent(const nsCString& url, const nsCString& target,
     150             :                              const bool& post, const nsCString& buffer,
     151             :                              const bool& file,
     152             :                              NPError* result) override;
     153             : 
     154             :     virtual mozilla::ipc::IPCResult
     155             :     AnswerPStreamNotifyConstructor(PStreamNotifyParent* actor,
     156             :                                    const nsCString& url,
     157             :                                    const nsCString& target,
     158             :                                    const bool& post, const nsCString& buffer,
     159             :                                    const bool& file,
     160             :                                    NPError* result) override;
     161             : 
     162             :     virtual bool
     163             :     DeallocPStreamNotifyParent(PStreamNotifyParent* notifyData) override;
     164             : 
     165             :     virtual mozilla::ipc::IPCResult
     166             :     RecvNPN_InvalidateRect(const NPRect& rect) override;
     167             : 
     168             :     virtual mozilla::ipc::IPCResult
     169             :     RecvRevokeCurrentDirectSurface() override;
     170             : 
     171             :     virtual mozilla::ipc::IPCResult
     172             :     RecvInitDXGISurface(const gfx::SurfaceFormat& format,
     173             :                          const gfx::IntSize& size,
     174             :                          WindowsHandle* outHandle,
     175             :                          NPError* outError) override;
     176             :     virtual mozilla::ipc::IPCResult
     177             :     RecvFinalizeDXGISurface(const WindowsHandle& handle) override;
     178             : 
     179             :     virtual mozilla::ipc::IPCResult
     180             :     RecvShowDirectBitmap(Shmem&& buffer,
     181             :                          const gfx::SurfaceFormat& format,
     182             :                          const uint32_t& stride,
     183             :                          const gfx::IntSize& size,
     184             :                          const gfx::IntRect& dirty) override;
     185             : 
     186             :     virtual mozilla::ipc::IPCResult
     187             :     RecvShowDirectDXGISurface(const WindowsHandle& handle,
     188             :                                const gfx::IntRect& rect) override;
     189             : 
     190             :     // Async rendering
     191             :     virtual mozilla::ipc::IPCResult
     192             :     RecvShow(const NPRect& updatedRect,
     193             :              const SurfaceDescriptor& newSurface,
     194             :              SurfaceDescriptor* prevSurface) override;
     195             : 
     196             :     virtual PPluginSurfaceParent*
     197             :     AllocPPluginSurfaceParent(const WindowsSharedMemoryHandle& handle,
     198             :                               const mozilla::gfx::IntSize& size,
     199             :                               const bool& transparent) override;
     200             : 
     201             :     virtual bool
     202             :     DeallocPPluginSurfaceParent(PPluginSurfaceParent* s) override;
     203             : 
     204             :     virtual mozilla::ipc::IPCResult
     205             :     AnswerNPN_PushPopupsEnabledState(const bool& aState) override;
     206             : 
     207             :     virtual mozilla::ipc::IPCResult
     208             :     AnswerNPN_PopPopupsEnabledState() override;
     209             : 
     210             :     virtual mozilla::ipc::IPCResult
     211             :     AnswerNPN_GetValueForURL(const NPNURLVariable& variable,
     212             :                              const nsCString& url,
     213             :                              nsCString* value, NPError* result) override;
     214             : 
     215             :     virtual mozilla::ipc::IPCResult
     216             :     AnswerNPN_SetValueForURL(const NPNURLVariable& variable,
     217             :                              const nsCString& url,
     218             :                              const nsCString& value, NPError* result) override;
     219             : 
     220             :     virtual mozilla::ipc::IPCResult
     221             :     AnswerNPN_ConvertPoint(const double& sourceX,
     222             :                            const bool&   ignoreDestX,
     223             :                            const double& sourceY,
     224             :                            const bool&   ignoreDestY,
     225             :                            const NPCoordinateSpace& sourceSpace,
     226             :                            const NPCoordinateSpace& destSpace,
     227             :                            double *destX,
     228             :                            double *destY,
     229             :                            bool *result) override;
     230             : 
     231             :     virtual mozilla::ipc::IPCResult
     232             :     RecvRedrawPlugin() override;
     233             : 
     234             :     virtual mozilla::ipc::IPCResult
     235             :     RecvSetNetscapeWindowAsParent(const NativeWindowHandle& childWindow) override;
     236             : 
     237             :     NPError NPP_SetWindow(const NPWindow* aWindow);
     238             : 
     239             :     NPError NPP_GetValue(NPPVariable variable, void* retval);
     240             :     NPError NPP_SetValue(NPNVariable variable, void* value);
     241             : 
     242             :     void NPP_URLRedirectNotify(const char* url, int32_t status,
     243             :                                void* notifyData);
     244             : 
     245             :     NPError NPP_NewStream(NPMIMEType type, NPStream* stream,
     246             :                           NPBool seekable, uint16_t* stype);
     247             :     NPError NPP_DestroyStream(NPStream* stream, NPReason reason);
     248             : 
     249             :     void NPP_Print(NPPrint* platformPrint);
     250             : 
     251             :     int16_t NPP_HandleEvent(void* event);
     252             : 
     253             :     void NPP_URLNotify(const char* url, NPReason reason, void* notifyData);
     254             : 
     255           0 :     PluginModuleParent* Module()
     256             :     {
     257           0 :         return mParent;
     258             :     }
     259             : 
     260           0 :     const NPNetscapeFuncs* GetNPNIface()
     261             :     {
     262           0 :         return mNPNIface;
     263             :     }
     264             : 
     265             :     bool
     266             :     RegisterNPObjectForActor(NPObject* aObject,
     267             :                              PluginScriptableObjectParent* aActor);
     268             : 
     269             :     void
     270             :     UnregisterNPObject(NPObject* aObject);
     271             : 
     272             :     PluginScriptableObjectParent*
     273             :     GetActorForNPObject(NPObject* aObject);
     274             : 
     275             :     NPP
     276           0 :     GetNPP()
     277             :     {
     278           0 :       return mNPP;
     279             :     }
     280             : 
     281             :     void
     282             :     GetSrcAttribute(nsACString& aOutput) const
     283             :     {
     284             :         aOutput = mSrcAttribute;
     285             :     }
     286             : 
     287             :     virtual mozilla::ipc::IPCResult
     288             :     AnswerPluginFocusChange(const bool& gotFocus) override;
     289             : 
     290             :     nsresult AsyncSetWindow(NPWindow* window);
     291             :     nsresult GetImageContainer(mozilla::layers::ImageContainer** aContainer);
     292             :     nsresult GetImageSize(nsIntSize* aSize);
     293             : #ifdef XP_MACOSX
     294             :     nsresult IsRemoteDrawingCoreAnimation(bool *aDrawing);
     295             : #endif
     296             : #if defined(XP_MACOSX) || defined(XP_WIN)
     297             :     nsresult ContentsScaleFactorChanged(double aContentsScaleFactor);
     298             : #endif
     299             :     nsresult SetBackgroundUnknown();
     300             :     nsresult BeginUpdateBackground(const nsIntRect& aRect,
     301             :                                    DrawTarget** aDrawTarget);
     302             :     nsresult EndUpdateBackground(const nsIntRect& aRect);
     303             : #if defined(XP_WIN)
     304             :     nsresult SetScrollCaptureId(uint64_t aScrollCaptureId);
     305             :     nsresult GetScrollCaptureContainer(mozilla::layers::ImageContainer** aContainer);
     306             : #endif
     307             :     void DidComposite();
     308             : 
     309             :     bool IsUsingDirectDrawing();
     310             : 
     311             :     static PluginInstanceParent* Cast(NPP instance);
     312             : 
     313             :     // for IME hook
     314             :     virtual mozilla::ipc::IPCResult
     315             :     RecvGetCompositionString(const uint32_t& aIndex,
     316             :                              nsTArray<uint8_t>* aBuffer,
     317             :                              int32_t* aLength) override;
     318             :     virtual mozilla::ipc::IPCResult
     319             :     RecvSetCandidateWindow(
     320             :         const mozilla::widget::CandidateWindowPosition& aPosition) override;
     321             :     virtual mozilla::ipc::IPCResult
     322             :     RecvRequestCommitOrCancel(const bool& aCommitted) override;
     323             : 
     324             :     // for reserved shortcut key handling with windowed plugin on Windows
     325             :     nsresult HandledWindowedPluginKeyEvent(
     326             :       const mozilla::NativeEventData& aKeyEventData,
     327             :       bool aIsConsumed);
     328             :     virtual mozilla::ipc::IPCResult
     329             :     RecvOnWindowedPluginKeyEvent(
     330             :       const mozilla::NativeEventData& aKeyEventData) override;
     331             : 
     332             : private:
     333             :     // Create an appropriate platform surface for a background of size
     334             :     // |aSize|.  Return true if successful.
     335             :     bool CreateBackground(const nsIntSize& aSize);
     336             :     void DestroyBackground();
     337             :     SurfaceDescriptor BackgroundDescriptor() /*const*/;
     338             : 
     339             :     typedef mozilla::layers::ImageContainer ImageContainer;
     340             :     ImageContainer *GetImageContainer();
     341             : 
     342             :     virtual PPluginBackgroundDestroyerParent*
     343             :     AllocPPluginBackgroundDestroyerParent() override;
     344             : 
     345             :     virtual bool
     346             :     DeallocPPluginBackgroundDestroyerParent(PPluginBackgroundDestroyerParent* aActor) override;
     347             : 
     348             :     bool InternalGetValueForNPObject(NPNVariable aVariable,
     349             :                                      PPluginScriptableObjectParent** aValue,
     350             :                                      NPError* aResult);
     351             : 
     352             :     nsPluginInstanceOwner* GetOwner();
     353             : 
     354             :     void SetCurrentImage(layers::Image* aImage);
     355             : 
     356             :     // Update Telemetry with the current drawing model.
     357             :     void RecordDrawingModel();
     358             : 
     359             : private:
     360             :     PluginModuleParent* mParent;
     361             :     NPP mNPP;
     362             :     const NPNetscapeFuncs* mNPNIface;
     363             :     nsCString mSrcAttribute;
     364             :     NPWindowType mWindowType;
     365             :     int16_t mDrawingModel;
     366             : 
     367             :     // Since plugins may request different drawing models to find a compatible
     368             :     // one, we only record the drawing model after a SetWindow call and if the
     369             :     // drawing model has changed.
     370             :     int mLastRecordedDrawingModel;
     371             : 
     372             :     nsDataHashtable<nsPtrHashKey<NPObject>, PluginScriptableObjectParent*> mScriptableObjects;
     373             : 
     374             :     // This is used to tell the compositor that it should invalidate the ImageLayer.
     375             :     uint32_t mFrameID;
     376             : 
     377             : #if defined(XP_WIN)
     378             :     // Note: DXGI 1.1 surface handles are global across all processes, and are not
     379             :     // marshaled. As long as we haven't freed a texture its handle should be valid
     380             :     // as a unique cross-process identifier for the texture.
     381             :     nsRefPtrHashtable<nsPtrHashKey<void>, D3D11SurfaceHolder> mD3D11Surfaces;
     382             : #endif
     383             : 
     384             : #if defined(OS_WIN)
     385             : private:
     386             :     // Used in handling parent/child forwarding of events.
     387             :     static LRESULT CALLBACK PluginWindowHookProc(HWND hWnd, UINT message,
     388             :                                                  WPARAM wParam, LPARAM lParam);
     389             :     void SubclassPluginWindow(HWND aWnd);
     390             :     void UnsubclassPluginWindow();
     391             : 
     392             :     bool MaybeCreateAndParentChildPluginWindow();
     393             :     void MaybeCreateChildPopupSurrogate();
     394             : 
     395             : private:
     396             :     nsIntRect          mPluginPort;
     397             :     nsIntRect          mSharedSize;
     398             :     HWND               mPluginHWND;
     399             :     // This is used for the normal child plugin HWND for windowed plugins and,
     400             :     // if needed, also the child popup surrogate HWND for windowless plugins.
     401             :     HWND               mChildPluginHWND;
     402             :     HWND               mChildPluginsParentHWND;
     403             :     WNDPROC            mPluginWndProc;
     404             :     bool               mNestedEventState;
     405             : #endif // defined(XP_WIN)
     406             : #if defined(MOZ_WIDGET_COCOA)
     407             : private:
     408             :     Shmem                  mShSurface;
     409             :     uint16_t               mShWidth;
     410             :     uint16_t               mShHeight;
     411             :     CGColorSpaceRef        mShColorSpace;
     412             :     RefPtr<MacIOSurface> mIOSurface;
     413             :     RefPtr<MacIOSurface> mFrontIOSurface;
     414             : #endif // definied(MOZ_WIDGET_COCOA)
     415             : 
     416             :     // ObjectFrame layer wrapper
     417             :     RefPtr<gfxASurface>    mFrontSurface;
     418             :     // For windowless+transparent instances, this surface contains a
     419             :     // "pretty recent" copy of the pixels under its <object> frame.
     420             :     // On the plugin side, we use this surface to avoid doing alpha
     421             :     // recovery when possible.  This surface is created and owned by
     422             :     // the browser, but a "read-only" reference is sent to the plugin.
     423             :     //
     424             :     // We have explicitly chosen not to provide any guarantees about
     425             :     // the consistency of the pixels in |mBackground|.  A plugin may
     426             :     // be able to observe partial updates to the background.
     427             :     RefPtr<gfxASurface>    mBackground;
     428             : 
     429             :     RefPtr<ImageContainer> mImageContainer;
     430             : };
     431             : 
     432             : 
     433             : } // namespace plugins
     434             : } // namespace mozilla
     435             : 
     436             : #endif // ifndef dom_plugins_PluginInstanceParent_h

Generated by: LCOV version 1.13