• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/cpp/private/instance_private.h"
6 
7 #include "ppapi/c/private/ppb_instance_private.h"
8 #include "ppapi/c/private/ppp_instance_private.h"
9 #include "ppapi/cpp/module_impl.h"
10 #include "ppapi/cpp/private/var_private.h"
11 
12 namespace pp {
13 
14 namespace {
15 
interface_name()16 template <> const char* interface_name<PPB_Instance_Private>() {
17   return PPB_INSTANCE_PRIVATE_INTERFACE;
18 }
19 
GetInstanceObject(PP_Instance pp_instance)20 PP_Var GetInstanceObject(PP_Instance pp_instance) {
21   Module* module_singleton = Module::Get();
22   if (!module_singleton)
23     return Var().Detach();
24   InstancePrivate* instance_private = static_cast<InstancePrivate*>(
25       module_singleton->InstanceForPPInstance(pp_instance));
26   if (!instance_private)
27     return Var().Detach();
28   return instance_private->GetInstanceObject().Detach();
29 }
30 
31 const PPP_Instance_Private ppp_instance_private = {
32   &GetInstanceObject
33 };
34 
35 }  // namespace
36 
InstancePrivate(PP_Instance instance)37 InstancePrivate::InstancePrivate(PP_Instance instance) : Instance(instance) {
38   // If at least 1 InstancePrivate is created, register the PPP_INSTANCE_PRIVATE
39   // interface.
40   Module::Get()->AddPluginInterface(PPP_INSTANCE_PRIVATE_INTERFACE,
41                                     &ppp_instance_private);
42 }
43 
~InstancePrivate()44 InstancePrivate::~InstancePrivate() {}
45 
GetInstanceObject()46 Var InstancePrivate::GetInstanceObject() {
47   return Var();
48 }
49 
GetWindowObject()50 VarPrivate InstancePrivate::GetWindowObject() {
51   if (!has_interface<PPB_Instance_Private>())
52     return VarPrivate();
53   return VarPrivate(PASS_REF,
54       get_interface<PPB_Instance_Private>()->GetWindowObject(pp_instance()));
55 }
56 
GetOwnerElementObject()57 VarPrivate InstancePrivate::GetOwnerElementObject() {
58   if (!has_interface<PPB_Instance_Private>())
59     return VarPrivate();
60   return VarPrivate(PASS_REF,
61       get_interface<PPB_Instance_Private>()->GetOwnerElementObject(
62           pp_instance()));
63 }
64 
ExecuteScript(const Var & script,Var * exception)65 VarPrivate InstancePrivate::ExecuteScript(const Var& script, Var* exception) {
66   if (!has_interface<PPB_Instance_Private>())
67     return VarPrivate();
68   return VarPrivate(PASS_REF,
69       get_interface<PPB_Instance_Private>()->ExecuteScript(
70           pp_instance(),
71           script.pp_var(),
72           VarPrivate::OutException(exception).get()));
73 }
74 
75 }  // namespace pp
76