summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/private/instance_private.cc
blob: 4e381149d7d3b50a388db2145b331a1f4de4e798 (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
72
73
74
75
// 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 "ppapi/cpp/private/instance_private.h"

#include "ppapi/c/private/ppb_instance_private.h"
#include "ppapi/c/private/ppp_instance_private.h"
#include "ppapi/cpp/module_impl.h"
#include "ppapi/cpp/private/var_private.h"

namespace pp {

namespace {

template <> const char* interface_name<PPB_Instance_Private>() {
  return PPB_INSTANCE_PRIVATE_INTERFACE;
}

PP_Var GetInstanceObject(PP_Instance pp_instance) {
  Module* module_singleton = Module::Get();
  if (!module_singleton)
    return Var().Detach();
  InstancePrivate* instance_private = static_cast<InstancePrivate*>(
      module_singleton->InstanceForPPInstance(pp_instance));
  if (!instance_private)
    return Var().Detach();
  return instance_private->GetInstanceObject().Detach();
}

const PPP_Instance_Private ppp_instance_private = {
  &GetInstanceObject
};

}  // namespace

InstancePrivate::InstancePrivate(PP_Instance instance) : Instance(instance) {
  // If at least 1 InstancePrivate is created, register the PPP_INSTANCE_PRIVATE
  // interface.
  Module::Get()->AddPluginInterface(PPP_INSTANCE_PRIVATE_INTERFACE,
                                    &ppp_instance_private);
}

InstancePrivate::~InstancePrivate() {}

Var InstancePrivate::GetInstanceObject() {
  return Var();
}

VarPrivate InstancePrivate::GetWindowObject() {
  if (!has_interface<PPB_Instance_Private>())
    return VarPrivate();
  return VarPrivate(PASS_REF,
      get_interface<PPB_Instance_Private>()->GetWindowObject(pp_instance()));
}

VarPrivate InstancePrivate::GetOwnerElementObject() {
  if (!has_interface<PPB_Instance_Private>())
    return VarPrivate();
  return VarPrivate(PASS_REF,
      get_interface<PPB_Instance_Private>()->GetOwnerElementObject(
          pp_instance()));
}

VarPrivate InstancePrivate::ExecuteScript(const Var& script, Var* exception) {
  if (!has_interface<PPB_Instance_Private>())
    return VarPrivate();
  return VarPrivate(PASS_REF,
             get_interface<PPB_Instance_Private>()->ExecuteScript(
                 pp_instance(),
                 script.pp_var(),
                 VarPrivate::OutException(exception).get()));
}

}  // namespace pp