Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / pepper / npobject_var.cc
blob50ccf87b4df24cb12429e5a4733a095b53504408
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 blink::WebBindings;
15 namespace ppapi {
17 // NPObjectVar -----------------------------------------------------------------
19 NPObjectVar::NPObjectVar(PP_Instance instance, NPObject* np_object)
20 : pp_instance_(instance), np_object_(np_object) {
21 WebBindings::retainObject(np_object_);
22 content::HostGlobals::Get()->host_var_tracker()->AddNPObjectVar(this);
25 NPObjectVar::~NPObjectVar() {
26 if (pp_instance())
27 content::HostGlobals::Get()->host_var_tracker()->RemoveNPObjectVar(this);
28 WebBindings::releaseObject(np_object_);
31 NPObjectVar* NPObjectVar::AsNPObjectVar() { return this; }
33 PP_VarType NPObjectVar::GetType() const { return PP_VARTYPE_OBJECT; }
35 void NPObjectVar::InstanceDeleted() {
36 DCHECK(pp_instance_);
37 content::HostGlobals::Get()->host_var_tracker()->RemoveNPObjectVar(this);
38 pp_instance_ = 0;
41 // static
42 scoped_refptr<NPObjectVar> NPObjectVar::FromPPVar(PP_Var var) {
43 if (var.type != PP_VARTYPE_OBJECT)
44 return scoped_refptr<NPObjectVar>(NULL);
45 scoped_refptr<Var> var_object(
46 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
47 if (!var_object.get())
48 return scoped_refptr<NPObjectVar>();
49 return scoped_refptr<NPObjectVar>(var_object->AsNPObjectVar());
52 } // namespace ppapi