Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/plugins/base/nsJSNPRuntime.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef nsJSNPRuntime_h_
7
#define nsJSNPRuntime_h_
8
9
#include "nscore.h"
10
#include "npapi.h"
11
#include "npruntime.h"
12
#include "PLDHashTable.h"
13
#include "js/RootingAPI.h"
14
15
class nsJSNPRuntime
16
{
17
public:
18
  static void OnPluginDestroy(NPP npp);
19
  static void OnPluginDestroyPending(NPP npp);
20
};
21
22
class nsJSObjWrapperKey
23
{
24
public:
25
  nsJSObjWrapperKey(JSObject *obj, NPP npp)
26
    : mJSObj(obj), mNpp(npp)
27
0
  {
28
0
  }
29
30
  bool operator==(const nsJSObjWrapperKey& other) const {
31
    return mJSObj == other.mJSObj && mNpp == other.mNpp;
32
  }
33
  bool operator!=(const nsJSObjWrapperKey& other) const {
34
    return !(*this == other);
35
  }
36
37
0
  void trace(JSTracer* trc) {
38
0
      JS::TraceEdge(trc, &mJSObj, "nsJSObjWrapperKey");
39
0
  }
40
41
  nsJSObjWrapperKey(const nsJSObjWrapperKey& other)
42
    : mJSObj(other.mJSObj),
43
      mNpp(other.mNpp)
44
0
  {}
45
0
  void operator=(const nsJSObjWrapperKey& other) {
46
0
    mJSObj = other.mJSObj;
47
0
    mNpp = other.mNpp;
48
0
  }
49
50
  JS::Heap<JSObject*> mJSObj;
51
  NPP mNpp;
52
};
53
54
class nsJSObjWrapper : public NPObject
55
{
56
public:
57
  JS::Heap<JSObject*> mJSObj;
58
  // Because mJSObj might be a cross-compartment wrapper, we can't use it to
59
  // enter the target realm. We use this global instead (it's always
60
  // same-compartment with mJSObj).
61
  JS::Heap<JSObject*> mJSObjGlobal;
62
  const NPP mNpp;
63
  bool mDestroyPending;
64
65
  static NPObject* GetNewOrUsed(NPP npp, JS::Handle<JSObject*> obj,
66
                                JS::Handle<JSObject*> objGlobal);
67
68
0
  void trace(JSTracer* trc) {
69
0
      JS::TraceEdge(trc, &mJSObj, "nsJSObjWrapper::mJSObj");
70
0
      JS::TraceEdge(trc, &mJSObjGlobal, "nsJSObjWrapper::mJSObjGlobal");
71
0
  }
72
73
protected:
74
  explicit nsJSObjWrapper(NPP npp);
75
  ~nsJSObjWrapper();
76
77
  static NPObject * NP_Allocate(NPP npp, NPClass *aClass);
78
  static void NP_Deallocate(NPObject *obj);
79
  static void NP_Invalidate(NPObject *obj);
80
  static bool NP_HasMethod(NPObject *, NPIdentifier identifier);
81
  static bool NP_Invoke(NPObject *obj, NPIdentifier method,
82
                        const NPVariant *args, uint32_t argCount,
83
                        NPVariant *result);
84
  static bool NP_InvokeDefault(NPObject *obj, const NPVariant *args,
85
                               uint32_t argCount, NPVariant *result);
86
  static bool NP_HasProperty(NPObject * obj, NPIdentifier property);
87
  static bool NP_GetProperty(NPObject *obj, NPIdentifier property,
88
                             NPVariant *result);
89
  static bool NP_SetProperty(NPObject *obj, NPIdentifier property,
90
                             const NPVariant *value);
91
  static bool NP_RemoveProperty(NPObject *obj, NPIdentifier property);
92
  static bool NP_Enumerate(NPObject *npobj, NPIdentifier **identifier,
93
                           uint32_t *count);
94
  static bool NP_Construct(NPObject *obj, const NPVariant *args,
95
                           uint32_t argCount, NPVariant *result);
96
97
public:
98
  static NPClass sJSObjWrapperNPClass;
99
};
100
101
class nsNPObjWrapper
102
{
103
public:
104
  static bool IsWrapper(JSObject *obj);
105
  static void OnDestroy(NPObject *npobj);
106
  static JSObject *GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj);
107
};
108
109
bool
110
JSValToNPVariant(NPP npp, JSContext *cx, const JS::Value& val, NPVariant *variant);
111
112
113
#endif // nsJSNPRuntime_h_