Commit a9d77326 authored by raymes's avatar raymes Committed by Commit bot

Remove the unused remnants of NPObject from Pepper

BUG=351636

Review URL: https://codereview.chromium.org/524353002

Cr-Commit-Position: refs/heads/master@{#293844}
parent 4898820b
......@@ -101,7 +101,7 @@ TEST_F(HostVarTrackerTest, DeleteObjectVarWithInstance) {
EXPECT_EQ(0, tracker().GetLiveV8ObjectVarsForTest(pp_instance2));
}
// Make sure that using the same NPObject should give the same PP_Var
// Make sure that using the same v8 object should give the same PP_Var
// each time.
TEST_F(HostVarTrackerTest, ReuseVar) {
PepperTryCatchForTest try_catch(instance());
......
// 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.
#include "content/renderer/pepper/npapi_glue.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/strings/string_util.h"
#include "content/renderer/pepper/host_array_buffer_var.h"
#include "content/renderer/pepper/host_globals.h"
#include "content/renderer/pepper/host_var_tracker.h"
#include "content/renderer/pepper/npobject_var.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
#include "content/renderer/pepper/plugin_module.h"
#include "content/renderer/pepper/plugin_object.h"
#include "ppapi/c/pp_var.h"
#include "third_party/npapi/bindings/npapi.h"
#include "third_party/npapi/bindings/npruntime.h"
#include "third_party/WebKit/public/web/WebBindings.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebPluginContainer.h"
#include "v8/include/v8.h"
using ppapi::NPObjectVar;
using ppapi::PpapiGlobals;
using ppapi::StringVar;
using ppapi::Var;
using blink::WebArrayBuffer;
using blink::WebBindings;
using blink::WebLocalFrame;
using blink::WebPluginContainer;
namespace content {
namespace {
const char kInvalidPluginValue[] = "Error: Plugin returned invalid value.";
PP_Var NPObjectToPPVarImpl(PepperPluginInstanceImpl* instance,
NPObject* object,
v8::Local<v8::Context> context) {
DCHECK(object);
if (context.IsEmpty())
return PP_MakeUndefined();
v8::Context::Scope context_scope(context);
WebArrayBuffer buffer;
// TODO(dmichael): Should I protect against duplicate Vars representing the
// same array buffer? It's probably not worth the trouble, since it will only
// affect in-process plugins.
if (WebBindings::getArrayBuffer(object, &buffer)) {
scoped_refptr<HostArrayBufferVar> buffer_var(
new HostArrayBufferVar(buffer));
return buffer_var->GetPPVar();
}
scoped_refptr<NPObjectVar> object_var(
HostGlobals::Get()->host_var_tracker()->NPObjectVarForNPObject(
instance->pp_instance(), object));
if (!object_var.get()) { // No object for this module yet, make a new one.
object_var = new NPObjectVar(instance->pp_instance(), object);
}
return object_var->GetPPVar();
}
} // namespace
// Utilities -------------------------------------------------------------------
bool PPVarToNPVariant(PP_Var var, NPVariant* result) {
switch (var.type) {
case PP_VARTYPE_UNDEFINED:
VOID_TO_NPVARIANT(*result);
break;
case PP_VARTYPE_NULL:
NULL_TO_NPVARIANT(*result);
break;
case PP_VARTYPE_BOOL:
BOOLEAN_TO_NPVARIANT(var.value.as_bool, *result);
break;
case PP_VARTYPE_INT32:
INT32_TO_NPVARIANT(var.value.as_int, *result);
break;
case PP_VARTYPE_DOUBLE:
DOUBLE_TO_NPVARIANT(var.value.as_double, *result);
break;
case PP_VARTYPE_STRING: {
StringVar* string = StringVar::FromPPVar(var);
if (!string) {
VOID_TO_NPVARIANT(*result);
return false;
}
const std::string& value = string->value();
char* c_string = static_cast<char*>(malloc(value.size()));
memcpy(c_string, value.data(), value.size());
STRINGN_TO_NPVARIANT(c_string, value.size(), *result);
break;
}
case PP_VARTYPE_OBJECT: {
scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(var));
if (!object.get()) {
VOID_TO_NPVARIANT(*result);
return false;
}
OBJECT_TO_NPVARIANT(WebBindings::retainObject(object->np_object()),
*result);
break;
}
// The following types are not supported for use with PPB_Var_Deprecated,
// because PPB_Var_Deprecated is only for trusted plugins, and the trusted
// plugins we have don't need these types. We can add support in the future
// if it becomes necessary.
case PP_VARTYPE_ARRAY:
case PP_VARTYPE_DICTIONARY:
case PP_VARTYPE_ARRAY_BUFFER:
case PP_VARTYPE_RESOURCE:
VOID_TO_NPVARIANT(*result);
break;
}
return true;
}
PP_Var NPVariantToPPVar(PepperPluginInstanceImpl* instance,
const NPVariant* variant) {
switch (variant->type) {
case NPVariantType_Void:
return PP_MakeUndefined();
case NPVariantType_Null:
return PP_MakeNull();
case NPVariantType_Bool:
return PP_MakeBool(PP_FromBool(NPVARIANT_TO_BOOLEAN(*variant)));
case NPVariantType_Int32:
return PP_MakeInt32(NPVARIANT_TO_INT32(*variant));
case NPVariantType_Double:
return PP_MakeDouble(NPVARIANT_TO_DOUBLE(*variant));
case NPVariantType_String:
return StringVar::StringToPPVar(
NPVARIANT_TO_STRING(*variant).UTF8Characters,
NPVARIANT_TO_STRING(*variant).UTF8Length);
case NPVariantType_Object:
return NPObjectToPPVar(instance, NPVARIANT_TO_OBJECT(*variant));
}
NOTREACHED();
return PP_MakeUndefined();
}
NPIdentifier PPVarToNPIdentifier(PP_Var var) {
switch (var.type) {
case PP_VARTYPE_STRING: {
StringVar* string = StringVar::FromPPVar(var);
if (!string)
return NULL;
return WebBindings::getStringIdentifier(string->value().c_str());
}
case PP_VARTYPE_INT32:
return WebBindings::getIntIdentifier(var.value.as_int);
default:
return NULL;
}
}
PP_Var NPIdentifierToPPVar(NPIdentifier id) {
const NPUTF8* string_value = NULL;
int32_t int_value = 0;
bool is_string = false;
WebBindings::extractIdentifierData(id, string_value, int_value, is_string);
if (is_string)
return StringVar::StringToPPVar(string_value);
return PP_MakeInt32(int_value);
}
PP_Var NPObjectToPPVar(PepperPluginInstanceImpl* instance, NPObject* object) {
WebPluginContainer* container = instance->container();
// It's possible that container() is NULL if the plugin has been removed from
// the DOM (but the PluginInstance is not destroyed yet).
if (!container)
return PP_MakeUndefined();
WebLocalFrame* frame = container->element().document().frame();
if (!frame)
return PP_MakeUndefined();
v8::HandleScope scope(instance->GetIsolate());
v8::Local<v8::Context> context = frame->mainWorldScriptContext();
return NPObjectToPPVarImpl(instance, object, context);
}
PP_Var NPObjectToPPVarForTest(PepperPluginInstanceImpl* instance,
NPObject* object) {
PP_Var result = PP_MakeUndefined();
v8::HandleScope scope(instance->GetIsolate());
v8::Local<v8::Context> context = v8::Context::New(instance->GetIsolate());
result = NPObjectToPPVarImpl(instance, object, context);
return result;
}
// PPResultAndExceptionToNPResult ----------------------------------------------
PPResultAndExceptionToNPResult::PPResultAndExceptionToNPResult(
NPObject* object_var,
NPVariant* np_result)
: object_var_(object_var),
np_result_(np_result),
exception_(PP_MakeUndefined()),
success_(false),
checked_exception_(false) {}
PPResultAndExceptionToNPResult::~PPResultAndExceptionToNPResult() {
// The user should have called SetResult or CheckExceptionForNoResult
// before letting this class go out of scope, or the exception will have
// been lost.
DCHECK(checked_exception_);
PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(exception_);
}
// Call this with the return value of the PPAPI function. It will convert
// the result to the NPVariant output parameter and pass any exception on to
// the JS engine. It will update the success flag and return it.
bool PPResultAndExceptionToNPResult::SetResult(PP_Var result) {
DCHECK(!checked_exception_); // Don't call more than once.
DCHECK(np_result_); // Should be expecting a result.
checked_exception_ = true;
if (has_exception()) {
ThrowException();
success_ = false;
} else if (!PPVarToNPVariant(result, np_result_)) {
WebBindings::setException(object_var_, kInvalidPluginValue);
success_ = false;
} else {
success_ = true;
}
// No matter what happened, we need to release the reference to the
// value passed in. On success, a reference to this value will be in
// the np_result_.
PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(result);
return success_;
}
// Call this after calling a PPAPI function that could have set the
// exception. It will pass the exception on to the JS engine and update
// the success flag.
//
// The success flag will be returned.
bool PPResultAndExceptionToNPResult::CheckExceptionForNoResult() {
DCHECK(!checked_exception_); // Don't call more than once.
DCHECK(!np_result_); // Can't have a result when doing this.
checked_exception_ = true;
if (has_exception()) {
ThrowException();
success_ = false;
return false;
}
success_ = true;
return true;
}
// Call this to ignore any exception. This prevents the DCHECK from failing
// in the destructor.
void PPResultAndExceptionToNPResult::IgnoreException() {
checked_exception_ = true;
}
// Throws the current exception to JS. The exception must be set.
void PPResultAndExceptionToNPResult::ThrowException() {
StringVar* string = StringVar::FromPPVar(exception_);
if (string)
WebBindings::setException(object_var_, string->value().c_str());
}
// PPVarArrayFromNPVariantArray ------------------------------------------------
PPVarArrayFromNPVariantArray::PPVarArrayFromNPVariantArray(
PepperPluginInstanceImpl* instance,
size_t size,
const NPVariant* variants)
: size_(size) {
if (size_ > 0) {
array_.reset(new PP_Var[size_]);
for (size_t i = 0; i < size_; i++)
array_[i] = NPVariantToPPVar(instance, &variants[i]);
}
}
PPVarArrayFromNPVariantArray::~PPVarArrayFromNPVariantArray() {
ppapi::VarTracker* var_tracker = PpapiGlobals::Get()->GetVarTracker();
for (size_t i = 0; i < size_; i++)
var_tracker->ReleaseVar(array_[i]);
}
// PPVarFromNPObject -----------------------------------------------------------
PPVarFromNPObject::PPVarFromNPObject(PepperPluginInstanceImpl* instance,
NPObject* object)
: var_(NPObjectToPPVar(instance, object)) {}
PPVarFromNPObject::~PPVarFromNPObject() {
PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var_);
}
// NPObjectAccessorWithIdentifier ----------------------------------------------
NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier(
NPObject* object,
NPIdentifier identifier,
bool allow_integer_identifier)
: object_(PluginObject::FromNPObject(object)),
identifier_(PP_MakeUndefined()) {
if (object_) {
identifier_ = NPIdentifierToPPVar(identifier);
if (identifier_.type == PP_VARTYPE_INT32 && !allow_integer_identifier)
identifier_.type = PP_VARTYPE_UNDEFINED; // Mark it invalid.
}
}
NPObjectAccessorWithIdentifier::~NPObjectAccessorWithIdentifier() {
PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(identifier_);
}
// TryCatch --------------------------------------------------------------------
TryCatch::TryCatch(PP_Var* exception)
: has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED),
exception_(exception) {
WebBindings::pushExceptionHandler(&TryCatch::Catch, this);
}
TryCatch::~TryCatch() { WebBindings::popExceptionHandler(); }
void TryCatch::SetException(const char* message) {
if (!has_exception()) {
has_exception_ = true;
if (exception_) {
if (!message)
message = "Unknown exception.";
*exception_ = ppapi::StringVar::StringToPPVar(message, strlen(message));
}
}
}
// static
void TryCatch::Catch(void* self, const char* message) {
static_cast<TryCatch*>(self)->SetException(message);
}
} // namespace content
// 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 CONTENT_RENDERER_PEPPER_NPAPI_GLUE_H_
#define CONTENT_RENDERER_PEPPER_NPAPI_GLUE_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "content/common/content_export.h"
#include "ppapi/c/pp_module.h"
#include "ppapi/c/pp_var.h"
struct NPObject;
typedef struct _NPVariant NPVariant;
typedef void* NPIdentifier;
namespace content {
class PepperPluginInstanceImpl;
class PluginObject;
// Utilities -------------------------------------------------------------------
// Converts the given PP_Var to an NPVariant, returning true on success.
// False means that the given variant is invalid. In this case, the result
// NPVariant will be set to a void one.
//
// The contents of the PP_Var will be copied unless the PP_Var corresponds to
// an object.
bool PPVarToNPVariant(PP_Var var, NPVariant* result);
// Returns a PP_Var that corresponds to the given NPVariant. The contents of
// the NPVariant will be copied unless the NPVariant corresponds to an
// object. This will handle all Variant types including POD, strings, and
// objects.
//
// The returned PP_Var will have a refcount of 1, this passing ownership of
// the reference to the caller. This is suitable for returning to a plugin.
PP_Var NPVariantToPPVar(PepperPluginInstanceImpl* instance,
const NPVariant* variant);
// Returns a NPIdentifier that corresponds to the given PP_Var. The contents
// of the PP_Var will be copied. Returns 0 if the given PP_Var is not a a
// string or integer type.
NPIdentifier PPVarToNPIdentifier(PP_Var var);
// Returns a PP_Var corresponding to the given identifier. In the case of
// a string identifier, the returned string will have a reference count of 1.
PP_Var NPIdentifierToPPVar(NPIdentifier id);
// Helper function to create a PP_Var of type object that contains the given
// NPObject for use byt he given module. Calling this function multiple times
// given the same module + NPObject results in the same PP_Var, assuming that
// there is still a PP_Var with a reference open to it from the previous
// call.
//
// The instance is necessary because we can have different instances pointing to
// the same NPObject, and we want to keep their refs separate.
//
// If no ObjectVar currently exists corresponding to the NPObject, one is
// created associated with the given module.
//
// Note: this could easily be changed to take a PP_Instance instead if that
// makes certain calls in the future easier. Currently all callers have a
// PluginInstance so that's what we use here.
CONTENT_EXPORT PP_Var
NPObjectToPPVar(PepperPluginInstanceImpl* instance, NPObject* object);
// This version creates a default v8::Context rather than using the one from
// the container of |instance|. It is only for use in unit tests, where we don't
// have a real container for |instance|.
CONTENT_EXPORT PP_Var NPObjectToPPVarForTest(PepperPluginInstanceImpl* instance,
NPObject* object);
// PPResultAndExceptionToNPResult ----------------------------------------------
// Convenience object for converting a PPAPI call that can throw an exception
// and optionally return a value, back to the NPAPI layer which expects a
// NPVariant as a result.
//
// Normal usage is that you will pass the result of exception() to the
// PPAPI function as the exception output parameter. Then you will either
// call SetResult with the result of the PPAPI call, or
// CheckExceptionForNoResult if the PPAPI call doesn't return a PP_Var.
//
// Both SetResult and CheckExceptionForNoResult will throw an exception to
// the JavaScript library if the plugin reported an exception. SetResult
// will additionally convert the result to an NPVariant and write it to the
// output parameter given in the constructor.
class PPResultAndExceptionToNPResult {
public:
// The object_var parameter is the object to associate any exception with.
// It may not be NULL.
//
// The np_result parameter is the NPAPI result output parameter. This may be
// NULL if there is no NPVariant result (like for HasProperty). If this is
// specified, you must call SetResult() to set it. If it is not, you must
// call CheckExceptionForNoResult to do the exception checking with no result
// conversion.
PPResultAndExceptionToNPResult(NPObject* object_var, NPVariant* np_result);
~PPResultAndExceptionToNPResult();
// Returns true if an exception has been set.
bool has_exception() const { return exception_.type != PP_VARTYPE_UNDEFINED; }
// Returns a pointer to the exception. You would pass this to the PPAPI
// function as the exception parameter. If it is set to non-void, this object
// will take ownership of destroying it.
PP_Var* exception() { return &exception_; }
// Returns true if everything succeeded with no exception. This is valid only
// after calling SetResult/CheckExceptionForNoResult.
bool success() const { return success_; }
// Call this with the return value of the PPAPI function. It will convert
// the result to the NPVariant output parameter and pass any exception on to
// the JS engine. It will update the success flag and return it.
bool SetResult(PP_Var result);
// Call this after calling a PPAPI function that could have set the
// exception. It will pass the exception on to the JS engine and update
// the success flag.
//
// The success flag will be returned.
bool CheckExceptionForNoResult();
// Call this to ignore any exception. This prevents the DCHECK from failing
// in the destructor.
void IgnoreException();
private:
// Throws the current exception to JS. The exception must be set.
void ThrowException();
NPObject* object_var_; // Non-owning ref (see constructor).
NPVariant* np_result_; // Output value, possibly NULL (see constructor).
PP_Var exception_; // Exception set by the PPAPI call. We own a ref to it.
bool success_; // See the success() function above.
bool checked_exception_; // SetResult/CheckExceptionForNoResult was called.
DISALLOW_COPY_AND_ASSIGN(PPResultAndExceptionToNPResult);
};
// PPVarArrayFromNPVariantArray ------------------------------------------------
// Converts an array of NPVariants to an array of PP_Var, and scopes the
// ownership of the PP_Var. This is used when converting argument lists from
// WebKit to the plugin.
class PPVarArrayFromNPVariantArray {
public:
PPVarArrayFromNPVariantArray(PepperPluginInstanceImpl* instance,
size_t size,
const NPVariant* variants);
~PPVarArrayFromNPVariantArray();
PP_Var* array() { return array_.get(); }
private:
size_t size_;
scoped_ptr<PP_Var[]> array_;
DISALLOW_COPY_AND_ASSIGN(PPVarArrayFromNPVariantArray);
};
// PPVarFromNPObject -----------------------------------------------------------
// Converts an NPObject tp PP_Var, and scopes the ownership of the PP_Var. This
// is used when converting 'this' pointer from WebKit to the plugin.
class PPVarFromNPObject {
public:
PPVarFromNPObject(PepperPluginInstanceImpl* instance, NPObject* object);
~PPVarFromNPObject();
PP_Var var() const { return var_; }
private:
const PP_Var var_;
DISALLOW_COPY_AND_ASSIGN(PPVarFromNPObject);
};
// NPObjectAccessorWithIdentifier ----------------------------------------------
// Helper class for our NPObject wrapper. This converts a call from WebKit
// where it gives us an NPObject and an NPIdentifier to an easily-accessible
// ObjectVar (corresponding to the NPObject) and PP_Var (corresponding to the
// NPIdentifier).
//
// If the NPObject or identifier is invalid, we'll set is_valid() to false.
// The caller should check is_valid() before doing anything with the class.
//
// JS can't have integer functions, so when dealing with these, we don't want
// to allow integer identifiers. The calling code can decode if it wants to
// allow integer identifiers (like for property access) or prohibit them
// (like for method calling) by setting |allow_integer_identifier|. If this
// is false and the identifier is an integer, we'll set is_valid() to false.
//
// Getting an integer identifier in this case should be impossible. V8
// shouldn't be allowing this, and the Pepper Var calls from the plugin are
// supposed to error out before calling into V8 (which will then call us back).
// Aside from an egregious error, the only time this could happen is an NPAPI
// plugin calling us.
class NPObjectAccessorWithIdentifier {
public:
NPObjectAccessorWithIdentifier(NPObject* object,
NPIdentifier identifier,
bool allow_integer_identifier);
~NPObjectAccessorWithIdentifier();
// Returns true if both the object and identifier are valid.
bool is_valid() const {
return object_ && identifier_.type != PP_VARTYPE_UNDEFINED;
}
PluginObject* object() { return object_; }
PP_Var identifier() const { return identifier_; }
private:
PluginObject* object_;
PP_Var identifier_;
DISALLOW_COPY_AND_ASSIGN(NPObjectAccessorWithIdentifier);
};
// TryCatch --------------------------------------------------------------------
// Instantiate this object on the stack to catch V8 exceptions and pass them
// to an optional out parameter supplied by the plugin.
class TryCatch {
public:
// The given exception may be NULL if the consumer isn't interested in
// catching exceptions. If non-NULL, the given var will be updated if any
// exception is thrown (so it must outlive the TryCatch object).
TryCatch(PP_Var* exception);
~TryCatch();
// Returns true is an exception has been thrown. This can be true immediately
// after construction if the var passed to the constructor is non-void.
bool has_exception() const { return has_exception_; }
// Sets the given exception. If an exception has been previously set, this
// function will do nothing (normally you want only the first exception).
void SetException(const char* message);
private:
static void Catch(void* self, const char* message);
// True if an exception has been thrown. Since the exception itself may be
// NULL if the plugin isn't interested in getting the exception, this will
// always indicate if SetException has been called, regardless of whether
// the exception itself has been stored.
bool has_exception_;
// May be null if the consumer isn't interesting in catching exceptions.
PP_Var* exception_;
};
} // namespace content
#endif // CONTENT_RENDERER_PEPPER_NPAPI_GLUE_H_
// 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.
#include "content/renderer/pepper/npobject_var.h"
#include "base/logging.h"
#include "content/renderer/pepper/host_globals.h"
#include "content/renderer/pepper/host_var_tracker.h"
#include "ppapi/c/pp_var.h"
#include "third_party/WebKit/public/web/WebBindings.h"
using blink::WebBindings;
namespace ppapi {
// NPObjectVar -----------------------------------------------------------------
NPObjectVar::NPObjectVar(PP_Instance instance, NPObject* np_object)
: pp_instance_(instance), np_object_(np_object) {
WebBindings::retainObject(np_object_);
content::HostGlobals::Get()->host_var_tracker()->AddNPObjectVar(this);
}
NPObjectVar::~NPObjectVar() {
if (pp_instance())
content::HostGlobals::Get()->host_var_tracker()->RemoveNPObjectVar(this);
WebBindings::releaseObject(np_object_);
}
NPObjectVar* NPObjectVar::AsNPObjectVar() { return this; }
PP_VarType NPObjectVar::GetType() const { return PP_VARTYPE_OBJECT; }
void NPObjectVar::InstanceDeleted() {
DCHECK(pp_instance_);
content::HostGlobals::Get()->host_var_tracker()->RemoveNPObjectVar(this);
pp_instance_ = 0;
}
// static
scoped_refptr<NPObjectVar> NPObjectVar::FromPPVar(PP_Var var) {
if (var.type != PP_VARTYPE_OBJECT)
return scoped_refptr<NPObjectVar>(NULL);
scoped_refptr<Var> var_object(
PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
if (!var_object.get())
return scoped_refptr<NPObjectVar>();
return scoped_refptr<NPObjectVar>(var_object->AsNPObjectVar());
}
} // namespace ppapi
// Copyright (c) 2012 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 CONTENT_RENDERER_PEPPER_NPOBJECT_VAR_H_
#define CONTENT_RENDERER_PEPPER_NPOBJECT_VAR_H_
#include <string>
#include "base/compiler_specific.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/shared_impl/var.h"
#include "content/common/content_export.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_Instance instance, NPObject* np_object);
// Var overrides.
virtual NPObjectVar* AsNPObjectVar() OVERRIDE;
virtual PP_VarType GetType() const 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.
CONTENT_EXPORT static scoped_refptr<NPObjectVar> FromPPVar(PP_Var var);
private:
virtual ~NPObjectVar();
// 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);
};
} // ppapi
#endif // CONTENT_RENDERER_PEPPER_NPOBJECT_VAR_H_
......@@ -23,7 +23,7 @@ namespace ppapi {
// Represents a JavaScript object Var. By itself, this represents random
// v8 objects that a given plugin (identified by the resource's module) wants to
// reference. If two different modules reference the same NPObject (like the
// reference. If two different modules reference the same v8 object (like the
// "window" object), then there will be different V8ObjectVar'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
......
......@@ -80,8 +80,6 @@ StringVar* Var::AsStringVar() { return NULL; }
ArrayBufferVar* Var::AsArrayBufferVar() { return NULL; }
NPObjectVar* Var::AsNPObjectVar() { return NULL; }
V8ObjectVar* Var::AsV8ObjectVar() { return NULL; }
ProxyObjectVar* Var::AsProxyObjectVar() { return NULL; }
......
......@@ -19,7 +19,6 @@ namespace ppapi {
class ArrayBufferVar;
class ArrayVar;
class DictionaryVar;
class NPObjectVar;
class ProxyObjectVar;
class ResourceVar;
class StringVar;
......@@ -36,7 +35,6 @@ class PPAPI_SHARED_EXPORT Var : public base::RefCounted<Var> {
virtual StringVar* AsStringVar();
virtual ArrayBufferVar* AsArrayBufferVar();
virtual NPObjectVar* AsNPObjectVar();
virtual V8ObjectVar* AsV8ObjectVar();
virtual ProxyObjectVar* AsProxyObjectVar();
virtual ArrayVar* AsArrayVar();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment