Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/plugins/ipc/PluginInstanceParent.h
Line
Count
Source (jump to first uncovered line)
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
    PluginModuleParent* Module()
256
0
    {
257
0
        return mParent;
258
0
    }
259
260
    const NPNetscapeFuncs* GetNPNIface()
261
0
    {
262
0
        return mNPNIface;
263
0
    }
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
    GetNPP()
277
0
    {
278
0
      return mNPP;
279
0
    }
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
    virtual mozilla::ipc::IPCResult RecvEnableIME(const bool& aEnable) override;
324
325
    // for reserved shortcut key handling with windowed plugin on Windows
326
    nsresult HandledWindowedPluginKeyEvent(
327
      const mozilla::NativeEventData& aKeyEventData,
328
      bool aIsConsumed);
329
    virtual mozilla::ipc::IPCResult
330
    RecvOnWindowedPluginKeyEvent(
331
      const mozilla::NativeEventData& aKeyEventData) override;
332
333
private:
334
    // Create an appropriate platform surface for a background of size
335
    // |aSize|.  Return true if successful.
336
    bool CreateBackground(const nsIntSize& aSize);
337
    void DestroyBackground();
338
    SurfaceDescriptor BackgroundDescriptor() /*const*/;
339
340
    typedef mozilla::layers::ImageContainer ImageContainer;
341
    ImageContainer *GetImageContainer();
342
343
    virtual PPluginBackgroundDestroyerParent*
344
    AllocPPluginBackgroundDestroyerParent() override;
345
346
    virtual bool
347
    DeallocPPluginBackgroundDestroyerParent(PPluginBackgroundDestroyerParent* aActor) override;
348
349
    bool InternalGetValueForNPObject(NPNVariable aVariable,
350
                                     PPluginScriptableObjectParent** aValue,
351
                                     NPError* aResult);
352
353
    nsPluginInstanceOwner* GetOwner();
354
355
    void SetCurrentImage(layers::Image* aImage);
356
357
    // Update Telemetry with the current drawing model.
358
    void RecordDrawingModel();
359
360
private:
361
    PluginModuleParent* mParent;
362
    NPP mNPP;
363
    const NPNetscapeFuncs* mNPNIface;
364
    nsCString mSrcAttribute;
365
    NPWindowType mWindowType;
366
    int16_t mDrawingModel;
367
368
    // Since plugins may request different drawing models to find a compatible
369
    // one, we only record the drawing model after a SetWindow call and if the
370
    // drawing model has changed.
371
    int mLastRecordedDrawingModel;
372
373
    nsDataHashtable<nsPtrHashKey<NPObject>, PluginScriptableObjectParent*> mScriptableObjects;
374
375
    // This is used to tell the compositor that it should invalidate the ImageLayer.
376
    uint32_t mFrameID;
377
378
#if defined(XP_WIN)
379
    // Note: DXGI 1.1 surface handles are global across all processes, and are not
380
    // marshaled. As long as we haven't freed a texture its handle should be valid
381
    // as a unique cross-process identifier for the texture.
382
    nsRefPtrHashtable<nsPtrHashKey<void>, D3D11SurfaceHolder> mD3D11Surfaces;
383
#endif
384
385
#if defined(OS_WIN)
386
private:
387
    // Used in handling parent/child forwarding of events.
388
    static LRESULT CALLBACK PluginWindowHookProc(HWND hWnd, UINT message,
389
                                                 WPARAM wParam, LPARAM lParam);
390
    void SubclassPluginWindow(HWND aWnd);
391
    void UnsubclassPluginWindow();
392
393
    bool MaybeCreateAndParentChildPluginWindow();
394
    void MaybeCreateChildPopupSurrogate();
395
396
private:
397
    nsIntRect          mPluginPort;
398
    nsIntRect          mSharedSize;
399
    HWND               mPluginHWND;
400
    // This is used for the normal child plugin HWND for windowed plugins and,
401
    // if needed, also the child popup surrogate HWND for windowless plugins.
402
    HWND               mChildPluginHWND;
403
    HWND               mChildPluginsParentHWND;
404
    WNDPROC            mPluginWndProc;
405
    bool               mNestedEventState;
406
#endif // defined(XP_WIN)
407
#if defined(MOZ_WIDGET_COCOA)
408
private:
409
    Shmem                  mShSurface;
410
    uint16_t               mShWidth;
411
    uint16_t               mShHeight;
412
    CGColorSpaceRef        mShColorSpace;
413
    RefPtr<MacIOSurface> mIOSurface;
414
    RefPtr<MacIOSurface> mFrontIOSurface;
415
#endif // definied(MOZ_WIDGET_COCOA)
416
417
    // ObjectFrame layer wrapper
418
    RefPtr<gfxASurface>    mFrontSurface;
419
    // For windowless+transparent instances, this surface contains a
420
    // "pretty recent" copy of the pixels under its <object> frame.
421
    // On the plugin side, we use this surface to avoid doing alpha
422
    // recovery when possible.  This surface is created and owned by
423
    // the browser, but a "read-only" reference is sent to the plugin.
424
    //
425
    // We have explicitly chosen not to provide any guarantees about
426
    // the consistency of the pixels in |mBackground|.  A plugin may
427
    // be able to observe partial updates to the background.
428
    RefPtr<gfxASurface>    mBackground;
429
430
    RefPtr<ImageContainer> mImageContainer;
431
};
432
433
434
} // namespace plugins
435
} // namespace mozilla
436
437
#endif // ifndef dom_plugins_PluginInstanceParent_h