Line data Source code
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 0 : class nsJSObjWrapperKey
23 : {
24 : public:
25 0 : nsJSObjWrapperKey(JSObject *obj, NPP npp)
26 0 : : mJSObj(obj), mNpp(npp)
27 : {
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 0 : nsJSObjWrapperKey(const nsJSObjWrapperKey& other)
42 0 : : mJSObj(other.mJSObj),
43 0 : 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 : const NPP mNpp;
59 : bool mDestroyPending;
60 :
61 : static NPObject* GetNewOrUsed(NPP npp, JS::Handle<JSObject*> obj);
62 : static bool HasOwnProperty(NPObject* npobj, NPIdentifier npid);
63 :
64 0 : void trace(JSTracer* trc) {
65 0 : JS::TraceEdge(trc, &mJSObj, "nsJSObjWrapper");
66 0 : }
67 :
68 : protected:
69 : explicit nsJSObjWrapper(NPP npp);
70 : ~nsJSObjWrapper();
71 :
72 : static NPObject * NP_Allocate(NPP npp, NPClass *aClass);
73 : static void NP_Deallocate(NPObject *obj);
74 : static void NP_Invalidate(NPObject *obj);
75 : static bool NP_HasMethod(NPObject *, NPIdentifier identifier);
76 : static bool NP_Invoke(NPObject *obj, NPIdentifier method,
77 : const NPVariant *args, uint32_t argCount,
78 : NPVariant *result);
79 : static bool NP_InvokeDefault(NPObject *obj, const NPVariant *args,
80 : uint32_t argCount, NPVariant *result);
81 : static bool NP_HasProperty(NPObject * obj, NPIdentifier property);
82 : static bool NP_GetProperty(NPObject *obj, NPIdentifier property,
83 : NPVariant *result);
84 : static bool NP_SetProperty(NPObject *obj, NPIdentifier property,
85 : const NPVariant *value);
86 : static bool NP_RemoveProperty(NPObject *obj, NPIdentifier property);
87 : static bool NP_Enumerate(NPObject *npobj, NPIdentifier **identifier,
88 : uint32_t *count);
89 : static bool NP_Construct(NPObject *obj, const NPVariant *args,
90 : uint32_t argCount, NPVariant *result);
91 :
92 : public:
93 : static NPClass sJSObjWrapperNPClass;
94 : };
95 :
96 : class nsNPObjWrapper
97 : {
98 : public:
99 : static bool IsWrapper(JSObject *obj);
100 : static void OnDestroy(NPObject *npobj);
101 : static JSObject *GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj);
102 : };
103 :
104 : bool
105 : JSValToNPVariant(NPP npp, JSContext *cx, const JS::Value& val, NPVariant *variant);
106 :
107 :
108 : #endif // nsJSNPRuntime_h_
|