1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/pepper/npobject_var.h"
7 #include "base/logging.h"
8 #include "content/renderer/pepper/host_globals.h"
9 #include "content/renderer/pepper/host_var_tracker.h"
10 #include "ppapi/c/pp_var.h"
11 #include "third_party/WebKit/public/web/WebBindings.h"
13 using WebKit::WebBindings;
17 // NPObjectVar -----------------------------------------------------------------
19 NPObjectVar::NPObjectVar(PP_Instance instance,
21 : pp_instance_(instance),
22 np_object_(np_object) {
23 WebBindings::retainObject(np_object_);
24 content::HostGlobals::Get()->host_var_tracker()->AddNPObjectVar(this);
27 NPObjectVar::~NPObjectVar() {
29 content::HostGlobals::Get()->host_var_tracker()->RemoveNPObjectVar(this);
30 WebBindings::releaseObject(np_object_);
33 NPObjectVar* NPObjectVar::AsNPObjectVar() {
37 PP_VarType NPObjectVar::GetType() const {
38 return PP_VARTYPE_OBJECT;
41 void NPObjectVar::InstanceDeleted() {
43 content::HostGlobals::Get()->host_var_tracker()->RemoveNPObjectVar(this);
48 scoped_refptr<NPObjectVar> NPObjectVar::FromPPVar(PP_Var var) {
49 if (var.type != PP_VARTYPE_OBJECT)
50 return scoped_refptr<NPObjectVar>(NULL);
51 scoped_refptr<Var> var_object(
52 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
53 if (!var_object.get())
54 return scoped_refptr<NPObjectVar>();
55 return scoped_refptr<NPObjectVar>(var_object->AsNPObjectVar());