1// Copyright (c) 2012 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.
4
5#include "ppapi/proxy/host_var_serialization_rules.h"
6
7#include "ppapi/shared_impl/ppapi_globals.h"
8#include "ppapi/shared_impl/var_tracker.h"
9
10using ppapi::PpapiGlobals;
11using ppapi::VarTracker;
12
13namespace ppapi {
14namespace proxy {
15
16HostVarSerializationRules::HostVarSerializationRules() {
17}
18
19HostVarSerializationRules::~HostVarSerializationRules() {
20}
21
22PP_Var HostVarSerializationRules::SendCallerOwned(const PP_Var& var) {
23  return var;
24}
25
26PP_Var HostVarSerializationRules::BeginReceiveCallerOwned(const PP_Var& var) {
27  return var;
28}
29
30void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) {
31  if (var.type != PP_VARTYPE_OBJECT && var.type >= PP_VARTYPE_STRING) {
32    // Release our reference to the local Var.
33    PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
34  }
35}
36
37PP_Var HostVarSerializationRules::ReceivePassRef(const PP_Var& var) {
38  // See PluginVarSerialization::BeginSendPassRef for an example.
39  if (var.type == PP_VARTYPE_OBJECT)
40    PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var);
41  return var;
42}
43
44PP_Var HostVarSerializationRules::BeginSendPassRef(const PP_Var& var) {
45  return var;
46}
47
48void HostVarSerializationRules::EndSendPassRef(const PP_Var& /* var */) {
49  // See PluginVarSerialization::ReceivePassRef for an example. We don't need
50  // to do anything here.
51}
52
53void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) {
54  PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
55}
56
57}  // namespace proxy
58}  // namespace ppapi
59