diff options
Diffstat (limited to 'webkit/plugins/ppapi/npobject_var.h')
-rw-r--r-- | webkit/plugins/ppapi/npobject_var.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/webkit/plugins/ppapi/npobject_var.h b/webkit/plugins/ppapi/npobject_var.h new file mode 100644 index 0000000..d0ba122 --- /dev/null +++ b/webkit/plugins/ppapi/npobject_var.h @@ -0,0 +1,71 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_PLUGINS_PPAPI_NPOBJECT_VAR_H_ +#define WEBKIT_PLUGINS_PPAPI_NPOBJECT_VAR_H_ + +#include <string> + +#include "base/compiler_specific.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_module.h" +#include "ppapi/shared_impl/var.h" + +typedef struct NPObject NPObject; +typedef struct _NPVariant NPVariant; +typedef void* NPIdentifier; + +namespace ppapi { + +// NPObjectVar ----------------------------------------------------------------- + +// Represents a JavaScript object Var. By itself, this represents random +// NPObjects that a given plugin (identified by the resource's module) wants to +// reference. If two different modules reference the same NPObject (like the +// "window" object), then there will be different NPObjectVar's (and hence +// PP_Var IDs) for each module. This allows us to track all references owned by +// a given module and free them when the plugin exits independently of other +// plugins that may be running at the same time. +class NPObjectVar : public Var { + public: + // You should always use FromNPObject to create an NPObjectVar. This function + // guarantees that we maintain the 1:1 mapping between NPObject and + // NPObjectVar. + NPObjectVar(PP_Module module, PP_Instance instance, NPObject* np_object); + + virtual ~NPObjectVar(); + + // Var overrides. + virtual NPObjectVar* AsNPObjectVar() OVERRIDE; + virtual PP_Var GetPPVar() OVERRIDE; + + // Returns the underlying NPObject corresponding to this NPObjectVar. + // Guaranteed non-NULL. + NPObject* np_object() const { return np_object_; } + + // Notification that the instance was deleted, the internal reference will be + // zeroed out. + void InstanceDeleted(); + + // Possibly 0 if the object has outlived its instance. + PP_Instance pp_instance() const { return pp_instance_; } + + // Helper function that converts a PP_Var to an object. This will return NULL + // if the PP_Var is not of object type or the object is invalid. + static scoped_refptr<NPObjectVar> FromPPVar(PP_Var var); + + private: + // Possibly 0 if the object has outlived its instance. + PP_Instance pp_instance_; + + // Guaranteed non-NULL, this is the underlying object used by WebKit. We + // hold a reference to this object. + NPObject* np_object_; + + DISALLOW_COPY_AND_ASSIGN(NPObjectVar); +}; + +} // namespace + +#endif // WEBKIT_PLUGINS_PPAPI_NPOBJECT_VAR_H_ |