Disable content detection tests on Android
[chromium-blink-merge.git] / webkit / plugins / ppapi / npobject_var.cc
blob5c892815459303b75626246ddfbf6f523ee9cd58
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 "webkit/plugins/ppapi/npobject_var.h"
7 #include "base/logging.h"
8 #include "ppapi/c/pp_var.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
10 #include "webkit/plugins/ppapi/host_globals.h"
11 #include "webkit/plugins/ppapi/host_var_tracker.h"
13 using webkit::ppapi::HostGlobals;
14 using WebKit::WebBindings;
16 namespace ppapi {
18 // NPObjectVar -----------------------------------------------------------------
20 NPObjectVar::NPObjectVar(PP_Instance instance,
21 NPObject* np_object)
22 : pp_instance_(instance),
23 np_object_(np_object) {
24 WebBindings::retainObject(np_object_);
25 HostGlobals::Get()->host_var_tracker()->AddNPObjectVar(this);
28 NPObjectVar::~NPObjectVar() {
29 if (pp_instance())
30 HostGlobals::Get()->host_var_tracker()->RemoveNPObjectVar(this);
31 WebBindings::releaseObject(np_object_);
34 NPObjectVar* NPObjectVar::AsNPObjectVar() {
35 return this;
38 PP_VarType NPObjectVar::GetType() const {
39 return PP_VARTYPE_OBJECT;
42 void NPObjectVar::InstanceDeleted() {
43 DCHECK(pp_instance_);
44 HostGlobals::Get()->host_var_tracker()->RemoveNPObjectVar(this);
45 pp_instance_ = 0;
48 // static
49 scoped_refptr<NPObjectVar> NPObjectVar::FromPPVar(PP_Var var) {
50 if (var.type != PP_VARTYPE_OBJECT)
51 return scoped_refptr<NPObjectVar>(NULL);
52 scoped_refptr<Var> var_object(
53 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
54 if (!var_object)
55 return scoped_refptr<NPObjectVar>();
56 return scoped_refptr<NPObjectVar>(var_object->AsNPObjectVar());
59 } // namespace ppapi