dom/plugins/base/nsJSNPRuntime.h
author Jon Coppeard <jcoppeard@mozilla.com>
Tue, 27 May 2014 10:35:13 +0100
changeset 193438 69853748c1d7f3887e3f387c6b681e0375fedf5c
parent 172198 4e06fcbbba8e3873bbf48113842a66b884b5181b
child 193441 f24c36fc3a763764f3507168495bcc8d1bb0fed3
permissions -rw-r--r--
Bug 1013972 - Take account of reentrancy when removing entries from sJSObjWrappers. r=bsmedberg, a=lsblakk

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsJSNPRuntime_h_
#define nsJSNPRuntime_h_

#include "nscore.h"
#include "npapi.h"
#include "npruntime.h"
#include "pldhash.h"

class nsJSNPRuntime
{
public:
  static void OnPluginDestroy(NPP npp);
};

class nsJSObjWrapperKey
{
public:
  nsJSObjWrapperKey(JSObject *obj, NPP npp)
    : mJSObj(obj), mNpp(npp)
  {
  }

  bool operator==(const nsJSObjWrapperKey& other) const {
    return mJSObj == other.mJSObj && mNpp == other.mNpp;
  }
  bool operator!=(const nsJSObjWrapperKey& other) const {
    return !(*this == other);
  }

  JSObject * mJSObj;
  const NPP mNpp;
};

extern const JSClass sNPObjectJSWrapperClass;

class nsJSObjWrapper : public NPObject
{
public:
  JSObject *mJSObj;  /* Added as a GC root. */
  const NPP mNpp;

  static NPObject *GetNewOrUsed(NPP npp, JSContext *cx,
                                JS::Handle<JSObject*> obj);

protected:
  nsJSObjWrapper(NPP npp);
  ~nsJSObjWrapper();

  static NPObject * NP_Allocate(NPP npp, NPClass *aClass);
  static void NP_Deallocate(NPObject *obj);
  static void NP_Invalidate(NPObject *obj);
  static bool NP_HasMethod(NPObject *, NPIdentifier identifier);
  static bool NP_Invoke(NPObject *obj, NPIdentifier method,
                        const NPVariant *args, uint32_t argCount,
                        NPVariant *result);
  static bool NP_InvokeDefault(NPObject *obj, const NPVariant *args,
                               uint32_t argCount, NPVariant *result);
  static bool NP_HasProperty(NPObject * obj, NPIdentifier property);
  static bool NP_GetProperty(NPObject *obj, NPIdentifier property,
                             NPVariant *result);
  static bool NP_SetProperty(NPObject *obj, NPIdentifier property,
                             const NPVariant *value);
  static bool NP_RemoveProperty(NPObject *obj, NPIdentifier property);
  static bool NP_Enumerate(NPObject *npobj, NPIdentifier **identifier,
                           uint32_t *count);
  static bool NP_Construct(NPObject *obj, const NPVariant *args,
                           uint32_t argCount, NPVariant *result);

public:
  static NPClass sJSObjWrapperNPClass;
};

class nsNPObjWrapper
{
public:
  static void OnDestroy(NPObject *npobj);
  static JSObject *GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj);
};

bool
JSValToNPVariant(NPP npp, JSContext *cx, JS::Value val, NPVariant *variant);


#endif // nsJSNPRuntime_h_