|
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 "nsAutoPtr.h" |
|
22 #include "nsDataHashtable.h" |
|
23 #include "nsHashKeys.h" |
|
24 #include "nsRect.h" |
|
25 |
|
26 #ifdef MOZ_X11 |
|
27 class gfxXlibSurface; |
|
28 #endif |
|
29 #include "mozilla/unused.h" |
|
30 |
|
31 class gfxASurface; |
|
32 class gfxContext; |
|
33 |
|
34 namespace mozilla { |
|
35 namespace layers { |
|
36 class ImageContainer; |
|
37 class CompositionNotifySink; |
|
38 } |
|
39 namespace plugins { |
|
40 |
|
41 class PBrowserStreamParent; |
|
42 class PluginModuleParent; |
|
43 |
|
44 class PluginInstanceParent : public PPluginInstanceParent |
|
45 { |
|
46 friend class PluginModuleParent; |
|
47 friend class BrowserStreamParent; |
|
48 friend class PluginStreamParent; |
|
49 friend class StreamNotifyParent; |
|
50 |
|
51 public: |
|
52 PluginInstanceParent(PluginModuleParent* parent, |
|
53 NPP npp, |
|
54 const nsCString& mimeType, |
|
55 const NPNetscapeFuncs* npniface); |
|
56 |
|
57 virtual ~PluginInstanceParent(); |
|
58 |
|
59 bool Init(); |
|
60 NPError Destroy(); |
|
61 |
|
62 virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; |
|
63 |
|
64 virtual PPluginScriptableObjectParent* |
|
65 AllocPPluginScriptableObjectParent() MOZ_OVERRIDE; |
|
66 |
|
67 virtual bool |
|
68 RecvPPluginScriptableObjectConstructor(PPluginScriptableObjectParent* aActor) MOZ_OVERRIDE; |
|
69 |
|
70 virtual bool |
|
71 DeallocPPluginScriptableObjectParent(PPluginScriptableObjectParent* aObject) MOZ_OVERRIDE; |
|
72 virtual PBrowserStreamParent* |
|
73 AllocPBrowserStreamParent(const nsCString& url, |
|
74 const uint32_t& length, |
|
75 const uint32_t& lastmodified, |
|
76 PStreamNotifyParent* notifyData, |
|
77 const nsCString& headers, |
|
78 const nsCString& mimeType, |
|
79 const bool& seekable, |
|
80 NPError* rv, |
|
81 uint16_t *stype) MOZ_OVERRIDE; |
|
82 virtual bool |
|
83 DeallocPBrowserStreamParent(PBrowserStreamParent* stream) MOZ_OVERRIDE; |
|
84 |
|
85 virtual PPluginStreamParent* |
|
86 AllocPPluginStreamParent(const nsCString& mimeType, |
|
87 const nsCString& target, |
|
88 NPError* result) MOZ_OVERRIDE; |
|
89 virtual bool |
|
90 DeallocPPluginStreamParent(PPluginStreamParent* stream) MOZ_OVERRIDE; |
|
91 |
|
92 virtual bool |
|
93 AnswerNPN_GetValue_NPNVnetscapeWindow(NativeWindowHandle* value, |
|
94 NPError* result) MOZ_OVERRIDE; |
|
95 virtual bool |
|
96 AnswerNPN_GetValue_NPNVWindowNPObject( |
|
97 PPluginScriptableObjectParent** value, |
|
98 NPError* result) MOZ_OVERRIDE; |
|
99 virtual bool |
|
100 AnswerNPN_GetValue_NPNVPluginElementNPObject( |
|
101 PPluginScriptableObjectParent** value, |
|
102 NPError* result) MOZ_OVERRIDE; |
|
103 virtual bool |
|
104 AnswerNPN_GetValue_NPNVprivateModeBool(bool* value, NPError* result) MOZ_OVERRIDE; |
|
105 |
|
106 virtual bool |
|
107 AnswerNPN_GetValue_DrawingModelSupport(const NPNVariable& model, bool* value) MOZ_OVERRIDE; |
|
108 |
|
109 virtual bool |
|
110 AnswerNPN_GetValue_NPNVdocumentOrigin(nsCString* value, NPError* result) MOZ_OVERRIDE; |
|
111 |
|
112 virtual bool |
|
113 AnswerNPN_SetValue_NPPVpluginWindow(const bool& windowed, NPError* result) MOZ_OVERRIDE; |
|
114 virtual bool |
|
115 AnswerNPN_SetValue_NPPVpluginTransparent(const bool& transparent, |
|
116 NPError* result) MOZ_OVERRIDE; |
|
117 virtual bool |
|
118 AnswerNPN_SetValue_NPPVpluginUsesDOMForCursor(const bool& useDOMForCursor, |
|
119 NPError* result) MOZ_OVERRIDE; |
|
120 virtual bool |
|
121 AnswerNPN_SetValue_NPPVpluginDrawingModel(const int& drawingModel, |
|
122 OptionalShmem *remoteImageData, |
|
123 CrossProcessMutexHandle *mutex, |
|
124 NPError* result) MOZ_OVERRIDE; |
|
125 virtual bool |
|
126 AnswerNPN_SetValue_NPPVpluginEventModel(const int& eventModel, |
|
127 NPError* result) MOZ_OVERRIDE; |
|
128 |
|
129 virtual bool |
|
130 AnswerNPN_GetURL(const nsCString& url, const nsCString& target, |
|
131 NPError *result) MOZ_OVERRIDE; |
|
132 |
|
133 virtual bool |
|
134 AnswerNPN_PostURL(const nsCString& url, const nsCString& target, |
|
135 const nsCString& buffer, const bool& file, |
|
136 NPError* result) MOZ_OVERRIDE; |
|
137 |
|
138 virtual PStreamNotifyParent* |
|
139 AllocPStreamNotifyParent(const nsCString& url, const nsCString& target, |
|
140 const bool& post, const nsCString& buffer, |
|
141 const bool& file, |
|
142 NPError* result) MOZ_OVERRIDE; |
|
143 |
|
144 virtual bool |
|
145 AnswerPStreamNotifyConstructor(PStreamNotifyParent* actor, |
|
146 const nsCString& url, |
|
147 const nsCString& target, |
|
148 const bool& post, const nsCString& buffer, |
|
149 const bool& file, |
|
150 NPError* result) MOZ_OVERRIDE; |
|
151 |
|
152 virtual bool |
|
153 DeallocPStreamNotifyParent(PStreamNotifyParent* notifyData) MOZ_OVERRIDE; |
|
154 |
|
155 virtual bool |
|
156 RecvNPN_InvalidateRect(const NPRect& rect) MOZ_OVERRIDE; |
|
157 |
|
158 // Async rendering |
|
159 virtual bool |
|
160 RecvShow(const NPRect& updatedRect, |
|
161 const SurfaceDescriptor& newSurface, |
|
162 SurfaceDescriptor* prevSurface) MOZ_OVERRIDE; |
|
163 |
|
164 virtual PPluginSurfaceParent* |
|
165 AllocPPluginSurfaceParent(const WindowsSharedMemoryHandle& handle, |
|
166 const gfxIntSize& size, |
|
167 const bool& transparent) MOZ_OVERRIDE; |
|
168 |
|
169 virtual bool |
|
170 DeallocPPluginSurfaceParent(PPluginSurfaceParent* s) MOZ_OVERRIDE; |
|
171 |
|
172 virtual bool |
|
173 AnswerNPN_PushPopupsEnabledState(const bool& aState) MOZ_OVERRIDE; |
|
174 |
|
175 virtual bool |
|
176 AnswerNPN_PopPopupsEnabledState() MOZ_OVERRIDE; |
|
177 |
|
178 virtual bool |
|
179 AnswerNPN_GetValueForURL(const NPNURLVariable& variable, |
|
180 const nsCString& url, |
|
181 nsCString* value, NPError* result) MOZ_OVERRIDE; |
|
182 |
|
183 virtual bool |
|
184 AnswerNPN_SetValueForURL(const NPNURLVariable& variable, |
|
185 const nsCString& url, |
|
186 const nsCString& value, NPError* result) MOZ_OVERRIDE; |
|
187 |
|
188 virtual bool |
|
189 AnswerNPN_GetAuthenticationInfo(const nsCString& protocol, |
|
190 const nsCString& host, |
|
191 const int32_t& port, |
|
192 const nsCString& scheme, |
|
193 const nsCString& realm, |
|
194 nsCString* username, |
|
195 nsCString* password, |
|
196 NPError* result) MOZ_OVERRIDE; |
|
197 |
|
198 virtual bool |
|
199 AnswerNPN_ConvertPoint(const double& sourceX, |
|
200 const bool& ignoreDestX, |
|
201 const double& sourceY, |
|
202 const bool& ignoreDestY, |
|
203 const NPCoordinateSpace& sourceSpace, |
|
204 const NPCoordinateSpace& destSpace, |
|
205 double *destX, |
|
206 double *destY, |
|
207 bool *result) MOZ_OVERRIDE; |
|
208 |
|
209 virtual bool |
|
210 AnswerNPN_InitAsyncSurface(const gfxIntSize& size, |
|
211 const NPImageFormat& format, |
|
212 NPRemoteAsyncSurface* surfData, |
|
213 bool* result) MOZ_OVERRIDE; |
|
214 |
|
215 virtual bool |
|
216 RecvRedrawPlugin() MOZ_OVERRIDE; |
|
217 |
|
218 virtual bool |
|
219 RecvNegotiatedCarbon() MOZ_OVERRIDE; |
|
220 |
|
221 virtual bool RecvReleaseDXGISharedSurface(const DXGISharedSurfaceHandle &aHandle) MOZ_OVERRIDE; |
|
222 |
|
223 NPError NPP_SetWindow(const NPWindow* aWindow); |
|
224 |
|
225 NPError NPP_GetValue(NPPVariable variable, void* retval); |
|
226 NPError NPP_SetValue(NPNVariable variable, void* value); |
|
227 |
|
228 void NPP_URLRedirectNotify(const char* url, int32_t status, |
|
229 void* notifyData); |
|
230 |
|
231 NPError NPP_NewStream(NPMIMEType type, NPStream* stream, |
|
232 NPBool seekable, uint16_t* stype); |
|
233 NPError NPP_DestroyStream(NPStream* stream, NPReason reason); |
|
234 |
|
235 void NPP_Print(NPPrint* platformPrint); |
|
236 |
|
237 int16_t NPP_HandleEvent(void* event); |
|
238 |
|
239 void NPP_URLNotify(const char* url, NPReason reason, void* notifyData); |
|
240 |
|
241 PluginModuleParent* Module() |
|
242 { |
|
243 return mParent; |
|
244 } |
|
245 |
|
246 const NPNetscapeFuncs* GetNPNIface() |
|
247 { |
|
248 return mNPNIface; |
|
249 } |
|
250 |
|
251 bool |
|
252 RegisterNPObjectForActor(NPObject* aObject, |
|
253 PluginScriptableObjectParent* aActor); |
|
254 |
|
255 void |
|
256 UnregisterNPObject(NPObject* aObject); |
|
257 |
|
258 PluginScriptableObjectParent* |
|
259 GetActorForNPObject(NPObject* aObject); |
|
260 |
|
261 NPP |
|
262 GetNPP() |
|
263 { |
|
264 return mNPP; |
|
265 } |
|
266 |
|
267 virtual bool |
|
268 AnswerPluginFocusChange(const bool& gotFocus) MOZ_OVERRIDE; |
|
269 |
|
270 nsresult AsyncSetWindow(NPWindow* window); |
|
271 nsresult GetImageContainer(mozilla::layers::ImageContainer** aContainer); |
|
272 nsresult GetImageSize(nsIntSize* aSize); |
|
273 #ifdef XP_MACOSX |
|
274 nsresult IsRemoteDrawingCoreAnimation(bool *aDrawing); |
|
275 nsresult ContentsScaleFactorChanged(double aContentsScaleFactor); |
|
276 #endif |
|
277 nsresult SetBackgroundUnknown(); |
|
278 nsresult BeginUpdateBackground(const nsIntRect& aRect, |
|
279 gfxContext** aCtx); |
|
280 nsresult EndUpdateBackground(gfxContext* aCtx, |
|
281 const nsIntRect& aRect); |
|
282 void DidComposite() { unused << SendNPP_DidComposite(); } |
|
283 |
|
284 private: |
|
285 // Create an appropriate platform surface for a background of size |
|
286 // |aSize|. Return true if successful. |
|
287 bool CreateBackground(const nsIntSize& aSize); |
|
288 void DestroyBackground(); |
|
289 SurfaceDescriptor BackgroundDescriptor() /*const*/; |
|
290 |
|
291 typedef mozilla::layers::ImageContainer ImageContainer; |
|
292 ImageContainer *GetImageContainer(); |
|
293 |
|
294 virtual PPluginBackgroundDestroyerParent* |
|
295 AllocPPluginBackgroundDestroyerParent() MOZ_OVERRIDE; |
|
296 |
|
297 virtual bool |
|
298 DeallocPPluginBackgroundDestroyerParent(PPluginBackgroundDestroyerParent* aActor) MOZ_OVERRIDE; |
|
299 |
|
300 bool InternalGetValueForNPObject(NPNVariable aVariable, |
|
301 PPluginScriptableObjectParent** aValue, |
|
302 NPError* aResult); |
|
303 |
|
304 bool IsAsyncDrawing(); |
|
305 |
|
306 private: |
|
307 PluginModuleParent* mParent; |
|
308 NPP mNPP; |
|
309 const NPNetscapeFuncs* mNPNIface; |
|
310 NPWindowType mWindowType; |
|
311 Shmem mRemoteImageDataShmem; |
|
312 nsAutoPtr<CrossProcessMutex> mRemoteImageDataMutex; |
|
313 int16_t mDrawingModel; |
|
314 nsAutoPtr<mozilla::layers::CompositionNotifySink> mNotifySink; |
|
315 |
|
316 nsDataHashtable<nsPtrHashKey<NPObject>, PluginScriptableObjectParent*> mScriptableObjects; |
|
317 |
|
318 #if defined(OS_WIN) |
|
319 private: |
|
320 // Used in rendering windowless plugins in other processes. |
|
321 bool SharedSurfaceSetWindow(const NPWindow* aWindow, NPRemoteWindow& aRemoteWindow); |
|
322 void SharedSurfaceBeforePaint(RECT &rect, NPRemoteEvent& npremoteevent); |
|
323 void SharedSurfaceAfterPaint(NPEvent* npevent); |
|
324 void SharedSurfaceRelease(); |
|
325 // Used in handling parent/child forwarding of events. |
|
326 static LRESULT CALLBACK PluginWindowHookProc(HWND hWnd, UINT message, |
|
327 WPARAM wParam, LPARAM lParam); |
|
328 void SubclassPluginWindow(HWND aWnd); |
|
329 void UnsubclassPluginWindow(); |
|
330 |
|
331 private: |
|
332 gfx::SharedDIBWin mSharedSurfaceDib; |
|
333 nsIntRect mPluginPort; |
|
334 nsIntRect mSharedSize; |
|
335 HWND mPluginHWND; |
|
336 WNDPROC mPluginWndProc; |
|
337 bool mNestedEventState; |
|
338 |
|
339 // This will automatically release the textures when this object goes away. |
|
340 nsRefPtrHashtable<nsPtrHashKey<void>, ID3D10Texture2D> mTextureMap; |
|
341 #endif // defined(XP_WIN) |
|
342 #if defined(MOZ_WIDGET_COCOA) |
|
343 private: |
|
344 Shmem mShSurface; |
|
345 uint16_t mShWidth; |
|
346 uint16_t mShHeight; |
|
347 CGColorSpaceRef mShColorSpace; |
|
348 RefPtr<MacIOSurface> mIOSurface; |
|
349 RefPtr<MacIOSurface> mFrontIOSurface; |
|
350 #endif // definied(MOZ_WIDGET_COCOA) |
|
351 |
|
352 // ObjectFrame layer wrapper |
|
353 nsRefPtr<gfxASurface> mFrontSurface; |
|
354 // For windowless+transparent instances, this surface contains a |
|
355 // "pretty recent" copy of the pixels under its <object> frame. |
|
356 // On the plugin side, we use this surface to avoid doing alpha |
|
357 // recovery when possible. This surface is created and owned by |
|
358 // the browser, but a "read-only" reference is sent to the plugin. |
|
359 // |
|
360 // We have explicitly chosen not to provide any guarantees about |
|
361 // the consistency of the pixels in |mBackground|. A plugin may |
|
362 // be able to observe partial updates to the background. |
|
363 nsRefPtr<gfxASurface> mBackground; |
|
364 |
|
365 nsRefPtr<ImageContainer> mImageContainer; |
|
366 }; |
|
367 |
|
368 |
|
369 } // namespace plugins |
|
370 } // namespace mozilla |
|
371 |
|
372 #endif // ifndef dom_plugins_PluginInstanceParent_h |