blob: f87bea4e0ff00c7aa959b82d3477579b2947ad90 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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.
#include "webkit/plugins/ppapi/npobject_var.h"
#include "base/logging.h"
#include "ppapi/c/pp_var.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
#include "webkit/plugins/ppapi/host_globals.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
using webkit::ppapi::HostGlobals;
using WebKit::WebBindings;
namespace ppapi {
// NPObjectVar -----------------------------------------------------------------
NPObjectVar::NPObjectVar(PP_Module module,
PP_Instance instance,
NPObject* np_object)
: Var(module),
pp_instance_(instance),
np_object_(np_object) {
WebBindings::retainObject(np_object_);
HostGlobals::Get()->host_resource_tracker()->AddNPObjectVar(this);
}
NPObjectVar::~NPObjectVar() {
if (pp_instance())
HostGlobals::Get()->host_resource_tracker()->RemoveNPObjectVar(this);
WebBindings::releaseObject(np_object_);
}
NPObjectVar* NPObjectVar::AsNPObjectVar() {
return this;
}
PP_Var NPObjectVar::GetPPVar() {
int32 id = GetOrCreateVarID();
if (!id)
return PP_MakeNull();
PP_Var result;
result.type = PP_VARTYPE_OBJECT;
result.value.as_id = id;
return result;
}
PP_VarType NPObjectVar::GetType() const {
return PP_VARTYPE_OBJECT;
}
void NPObjectVar::InstanceDeleted() {
DCHECK(pp_instance_);
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)
return scoped_refptr<NPObjectVar>();
return scoped_refptr<NPObjectVar>(var_object->AsNPObjectVar());
}
} // namespace ppapi
|