1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/ipc/PluginInstanceParent.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,372 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: sw=4 ts=4 et : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef dom_plugins_PluginInstanceParent_h 1.11 +#define dom_plugins_PluginInstanceParent_h 1 1.12 + 1.13 +#include "mozilla/plugins/PPluginInstanceParent.h" 1.14 +#include "mozilla/plugins/PluginScriptableObjectParent.h" 1.15 +#if defined(OS_WIN) 1.16 +#include "mozilla/gfx/SharedDIBWin.h" 1.17 +#include <d3d10_1.h> 1.18 +#include "nsRefPtrHashtable.h" 1.19 +#elif defined(MOZ_WIDGET_COCOA) 1.20 +#include "mozilla/gfx/QuartzSupport.h" 1.21 +#endif 1.22 + 1.23 +#include "npfunctions.h" 1.24 +#include "nsAutoPtr.h" 1.25 +#include "nsDataHashtable.h" 1.26 +#include "nsHashKeys.h" 1.27 +#include "nsRect.h" 1.28 + 1.29 +#ifdef MOZ_X11 1.30 +class gfxXlibSurface; 1.31 +#endif 1.32 +#include "mozilla/unused.h" 1.33 + 1.34 +class gfxASurface; 1.35 +class gfxContext; 1.36 + 1.37 +namespace mozilla { 1.38 +namespace layers { 1.39 +class ImageContainer; 1.40 +class CompositionNotifySink; 1.41 +} 1.42 +namespace plugins { 1.43 + 1.44 +class PBrowserStreamParent; 1.45 +class PluginModuleParent; 1.46 + 1.47 +class PluginInstanceParent : public PPluginInstanceParent 1.48 +{ 1.49 + friend class PluginModuleParent; 1.50 + friend class BrowserStreamParent; 1.51 + friend class PluginStreamParent; 1.52 + friend class StreamNotifyParent; 1.53 + 1.54 +public: 1.55 + PluginInstanceParent(PluginModuleParent* parent, 1.56 + NPP npp, 1.57 + const nsCString& mimeType, 1.58 + const NPNetscapeFuncs* npniface); 1.59 + 1.60 + virtual ~PluginInstanceParent(); 1.61 + 1.62 + bool Init(); 1.63 + NPError Destroy(); 1.64 + 1.65 + virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; 1.66 + 1.67 + virtual PPluginScriptableObjectParent* 1.68 + AllocPPluginScriptableObjectParent() MOZ_OVERRIDE; 1.69 + 1.70 + virtual bool 1.71 + RecvPPluginScriptableObjectConstructor(PPluginScriptableObjectParent* aActor) MOZ_OVERRIDE; 1.72 + 1.73 + virtual bool 1.74 + DeallocPPluginScriptableObjectParent(PPluginScriptableObjectParent* aObject) MOZ_OVERRIDE; 1.75 + virtual PBrowserStreamParent* 1.76 + AllocPBrowserStreamParent(const nsCString& url, 1.77 + const uint32_t& length, 1.78 + const uint32_t& lastmodified, 1.79 + PStreamNotifyParent* notifyData, 1.80 + const nsCString& headers, 1.81 + const nsCString& mimeType, 1.82 + const bool& seekable, 1.83 + NPError* rv, 1.84 + uint16_t *stype) MOZ_OVERRIDE; 1.85 + virtual bool 1.86 + DeallocPBrowserStreamParent(PBrowserStreamParent* stream) MOZ_OVERRIDE; 1.87 + 1.88 + virtual PPluginStreamParent* 1.89 + AllocPPluginStreamParent(const nsCString& mimeType, 1.90 + const nsCString& target, 1.91 + NPError* result) MOZ_OVERRIDE; 1.92 + virtual bool 1.93 + DeallocPPluginStreamParent(PPluginStreamParent* stream) MOZ_OVERRIDE; 1.94 + 1.95 + virtual bool 1.96 + AnswerNPN_GetValue_NPNVnetscapeWindow(NativeWindowHandle* value, 1.97 + NPError* result) MOZ_OVERRIDE; 1.98 + virtual bool 1.99 + AnswerNPN_GetValue_NPNVWindowNPObject( 1.100 + PPluginScriptableObjectParent** value, 1.101 + NPError* result) MOZ_OVERRIDE; 1.102 + virtual bool 1.103 + AnswerNPN_GetValue_NPNVPluginElementNPObject( 1.104 + PPluginScriptableObjectParent** value, 1.105 + NPError* result) MOZ_OVERRIDE; 1.106 + virtual bool 1.107 + AnswerNPN_GetValue_NPNVprivateModeBool(bool* value, NPError* result) MOZ_OVERRIDE; 1.108 + 1.109 + virtual bool 1.110 + AnswerNPN_GetValue_DrawingModelSupport(const NPNVariable& model, bool* value) MOZ_OVERRIDE; 1.111 + 1.112 + virtual bool 1.113 + AnswerNPN_GetValue_NPNVdocumentOrigin(nsCString* value, NPError* result) MOZ_OVERRIDE; 1.114 + 1.115 + virtual bool 1.116 + AnswerNPN_SetValue_NPPVpluginWindow(const bool& windowed, NPError* result) MOZ_OVERRIDE; 1.117 + virtual bool 1.118 + AnswerNPN_SetValue_NPPVpluginTransparent(const bool& transparent, 1.119 + NPError* result) MOZ_OVERRIDE; 1.120 + virtual bool 1.121 + AnswerNPN_SetValue_NPPVpluginUsesDOMForCursor(const bool& useDOMForCursor, 1.122 + NPError* result) MOZ_OVERRIDE; 1.123 + virtual bool 1.124 + AnswerNPN_SetValue_NPPVpluginDrawingModel(const int& drawingModel, 1.125 + OptionalShmem *remoteImageData, 1.126 + CrossProcessMutexHandle *mutex, 1.127 + NPError* result) MOZ_OVERRIDE; 1.128 + virtual bool 1.129 + AnswerNPN_SetValue_NPPVpluginEventModel(const int& eventModel, 1.130 + NPError* result) MOZ_OVERRIDE; 1.131 + 1.132 + virtual bool 1.133 + AnswerNPN_GetURL(const nsCString& url, const nsCString& target, 1.134 + NPError *result) MOZ_OVERRIDE; 1.135 + 1.136 + virtual bool 1.137 + AnswerNPN_PostURL(const nsCString& url, const nsCString& target, 1.138 + const nsCString& buffer, const bool& file, 1.139 + NPError* result) MOZ_OVERRIDE; 1.140 + 1.141 + virtual PStreamNotifyParent* 1.142 + AllocPStreamNotifyParent(const nsCString& url, const nsCString& target, 1.143 + const bool& post, const nsCString& buffer, 1.144 + const bool& file, 1.145 + NPError* result) MOZ_OVERRIDE; 1.146 + 1.147 + virtual bool 1.148 + AnswerPStreamNotifyConstructor(PStreamNotifyParent* actor, 1.149 + const nsCString& url, 1.150 + const nsCString& target, 1.151 + const bool& post, const nsCString& buffer, 1.152 + const bool& file, 1.153 + NPError* result) MOZ_OVERRIDE; 1.154 + 1.155 + virtual bool 1.156 + DeallocPStreamNotifyParent(PStreamNotifyParent* notifyData) MOZ_OVERRIDE; 1.157 + 1.158 + virtual bool 1.159 + RecvNPN_InvalidateRect(const NPRect& rect) MOZ_OVERRIDE; 1.160 + 1.161 + // Async rendering 1.162 + virtual bool 1.163 + RecvShow(const NPRect& updatedRect, 1.164 + const SurfaceDescriptor& newSurface, 1.165 + SurfaceDescriptor* prevSurface) MOZ_OVERRIDE; 1.166 + 1.167 + virtual PPluginSurfaceParent* 1.168 + AllocPPluginSurfaceParent(const WindowsSharedMemoryHandle& handle, 1.169 + const gfxIntSize& size, 1.170 + const bool& transparent) MOZ_OVERRIDE; 1.171 + 1.172 + virtual bool 1.173 + DeallocPPluginSurfaceParent(PPluginSurfaceParent* s) MOZ_OVERRIDE; 1.174 + 1.175 + virtual bool 1.176 + AnswerNPN_PushPopupsEnabledState(const bool& aState) MOZ_OVERRIDE; 1.177 + 1.178 + virtual bool 1.179 + AnswerNPN_PopPopupsEnabledState() MOZ_OVERRIDE; 1.180 + 1.181 + virtual bool 1.182 + AnswerNPN_GetValueForURL(const NPNURLVariable& variable, 1.183 + const nsCString& url, 1.184 + nsCString* value, NPError* result) MOZ_OVERRIDE; 1.185 + 1.186 + virtual bool 1.187 + AnswerNPN_SetValueForURL(const NPNURLVariable& variable, 1.188 + const nsCString& url, 1.189 + const nsCString& value, NPError* result) MOZ_OVERRIDE; 1.190 + 1.191 + virtual bool 1.192 + AnswerNPN_GetAuthenticationInfo(const nsCString& protocol, 1.193 + const nsCString& host, 1.194 + const int32_t& port, 1.195 + const nsCString& scheme, 1.196 + const nsCString& realm, 1.197 + nsCString* username, 1.198 + nsCString* password, 1.199 + NPError* result) MOZ_OVERRIDE; 1.200 + 1.201 + virtual bool 1.202 + AnswerNPN_ConvertPoint(const double& sourceX, 1.203 + const bool& ignoreDestX, 1.204 + const double& sourceY, 1.205 + const bool& ignoreDestY, 1.206 + const NPCoordinateSpace& sourceSpace, 1.207 + const NPCoordinateSpace& destSpace, 1.208 + double *destX, 1.209 + double *destY, 1.210 + bool *result) MOZ_OVERRIDE; 1.211 + 1.212 + virtual bool 1.213 + AnswerNPN_InitAsyncSurface(const gfxIntSize& size, 1.214 + const NPImageFormat& format, 1.215 + NPRemoteAsyncSurface* surfData, 1.216 + bool* result) MOZ_OVERRIDE; 1.217 + 1.218 + virtual bool 1.219 + RecvRedrawPlugin() MOZ_OVERRIDE; 1.220 + 1.221 + virtual bool 1.222 + RecvNegotiatedCarbon() MOZ_OVERRIDE; 1.223 + 1.224 + virtual bool RecvReleaseDXGISharedSurface(const DXGISharedSurfaceHandle &aHandle) MOZ_OVERRIDE; 1.225 + 1.226 + NPError NPP_SetWindow(const NPWindow* aWindow); 1.227 + 1.228 + NPError NPP_GetValue(NPPVariable variable, void* retval); 1.229 + NPError NPP_SetValue(NPNVariable variable, void* value); 1.230 + 1.231 + void NPP_URLRedirectNotify(const char* url, int32_t status, 1.232 + void* notifyData); 1.233 + 1.234 + NPError NPP_NewStream(NPMIMEType type, NPStream* stream, 1.235 + NPBool seekable, uint16_t* stype); 1.236 + NPError NPP_DestroyStream(NPStream* stream, NPReason reason); 1.237 + 1.238 + void NPP_Print(NPPrint* platformPrint); 1.239 + 1.240 + int16_t NPP_HandleEvent(void* event); 1.241 + 1.242 + void NPP_URLNotify(const char* url, NPReason reason, void* notifyData); 1.243 + 1.244 + PluginModuleParent* Module() 1.245 + { 1.246 + return mParent; 1.247 + } 1.248 + 1.249 + const NPNetscapeFuncs* GetNPNIface() 1.250 + { 1.251 + return mNPNIface; 1.252 + } 1.253 + 1.254 + bool 1.255 + RegisterNPObjectForActor(NPObject* aObject, 1.256 + PluginScriptableObjectParent* aActor); 1.257 + 1.258 + void 1.259 + UnregisterNPObject(NPObject* aObject); 1.260 + 1.261 + PluginScriptableObjectParent* 1.262 + GetActorForNPObject(NPObject* aObject); 1.263 + 1.264 + NPP 1.265 + GetNPP() 1.266 + { 1.267 + return mNPP; 1.268 + } 1.269 + 1.270 + virtual bool 1.271 + AnswerPluginFocusChange(const bool& gotFocus) MOZ_OVERRIDE; 1.272 + 1.273 + nsresult AsyncSetWindow(NPWindow* window); 1.274 + nsresult GetImageContainer(mozilla::layers::ImageContainer** aContainer); 1.275 + nsresult GetImageSize(nsIntSize* aSize); 1.276 +#ifdef XP_MACOSX 1.277 + nsresult IsRemoteDrawingCoreAnimation(bool *aDrawing); 1.278 + nsresult ContentsScaleFactorChanged(double aContentsScaleFactor); 1.279 +#endif 1.280 + nsresult SetBackgroundUnknown(); 1.281 + nsresult BeginUpdateBackground(const nsIntRect& aRect, 1.282 + gfxContext** aCtx); 1.283 + nsresult EndUpdateBackground(gfxContext* aCtx, 1.284 + const nsIntRect& aRect); 1.285 + void DidComposite() { unused << SendNPP_DidComposite(); } 1.286 + 1.287 +private: 1.288 + // Create an appropriate platform surface for a background of size 1.289 + // |aSize|. Return true if successful. 1.290 + bool CreateBackground(const nsIntSize& aSize); 1.291 + void DestroyBackground(); 1.292 + SurfaceDescriptor BackgroundDescriptor() /*const*/; 1.293 + 1.294 + typedef mozilla::layers::ImageContainer ImageContainer; 1.295 + ImageContainer *GetImageContainer(); 1.296 + 1.297 + virtual PPluginBackgroundDestroyerParent* 1.298 + AllocPPluginBackgroundDestroyerParent() MOZ_OVERRIDE; 1.299 + 1.300 + virtual bool 1.301 + DeallocPPluginBackgroundDestroyerParent(PPluginBackgroundDestroyerParent* aActor) MOZ_OVERRIDE; 1.302 + 1.303 + bool InternalGetValueForNPObject(NPNVariable aVariable, 1.304 + PPluginScriptableObjectParent** aValue, 1.305 + NPError* aResult); 1.306 + 1.307 + bool IsAsyncDrawing(); 1.308 + 1.309 +private: 1.310 + PluginModuleParent* mParent; 1.311 + NPP mNPP; 1.312 + const NPNetscapeFuncs* mNPNIface; 1.313 + NPWindowType mWindowType; 1.314 + Shmem mRemoteImageDataShmem; 1.315 + nsAutoPtr<CrossProcessMutex> mRemoteImageDataMutex; 1.316 + int16_t mDrawingModel; 1.317 + nsAutoPtr<mozilla::layers::CompositionNotifySink> mNotifySink; 1.318 + 1.319 + nsDataHashtable<nsPtrHashKey<NPObject>, PluginScriptableObjectParent*> mScriptableObjects; 1.320 + 1.321 +#if defined(OS_WIN) 1.322 +private: 1.323 + // Used in rendering windowless plugins in other processes. 1.324 + bool SharedSurfaceSetWindow(const NPWindow* aWindow, NPRemoteWindow& aRemoteWindow); 1.325 + void SharedSurfaceBeforePaint(RECT &rect, NPRemoteEvent& npremoteevent); 1.326 + void SharedSurfaceAfterPaint(NPEvent* npevent); 1.327 + void SharedSurfaceRelease(); 1.328 + // Used in handling parent/child forwarding of events. 1.329 + static LRESULT CALLBACK PluginWindowHookProc(HWND hWnd, UINT message, 1.330 + WPARAM wParam, LPARAM lParam); 1.331 + void SubclassPluginWindow(HWND aWnd); 1.332 + void UnsubclassPluginWindow(); 1.333 + 1.334 +private: 1.335 + gfx::SharedDIBWin mSharedSurfaceDib; 1.336 + nsIntRect mPluginPort; 1.337 + nsIntRect mSharedSize; 1.338 + HWND mPluginHWND; 1.339 + WNDPROC mPluginWndProc; 1.340 + bool mNestedEventState; 1.341 + 1.342 + // This will automatically release the textures when this object goes away. 1.343 + nsRefPtrHashtable<nsPtrHashKey<void>, ID3D10Texture2D> mTextureMap; 1.344 +#endif // defined(XP_WIN) 1.345 +#if defined(MOZ_WIDGET_COCOA) 1.346 +private: 1.347 + Shmem mShSurface; 1.348 + uint16_t mShWidth; 1.349 + uint16_t mShHeight; 1.350 + CGColorSpaceRef mShColorSpace; 1.351 + RefPtr<MacIOSurface> mIOSurface; 1.352 + RefPtr<MacIOSurface> mFrontIOSurface; 1.353 +#endif // definied(MOZ_WIDGET_COCOA) 1.354 + 1.355 + // ObjectFrame layer wrapper 1.356 + nsRefPtr<gfxASurface> mFrontSurface; 1.357 + // For windowless+transparent instances, this surface contains a 1.358 + // "pretty recent" copy of the pixels under its <object> frame. 1.359 + // On the plugin side, we use this surface to avoid doing alpha 1.360 + // recovery when possible. This surface is created and owned by 1.361 + // the browser, but a "read-only" reference is sent to the plugin. 1.362 + // 1.363 + // We have explicitly chosen not to provide any guarantees about 1.364 + // the consistency of the pixels in |mBackground|. A plugin may 1.365 + // be able to observe partial updates to the background. 1.366 + nsRefPtr<gfxASurface> mBackground; 1.367 + 1.368 + nsRefPtr<ImageContainer> mImageContainer; 1.369 +}; 1.370 + 1.371 + 1.372 +} // namespace plugins 1.373 +} // namespace mozilla 1.374 + 1.375 +#endif // ifndef dom_plugins_PluginInstanceParent_h