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.
5 #include "ppapi/cpp/private/instance_private.h"
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"
16 template <> const char* interface_name
<PPB_Instance_Private
>() {
17 return PPB_INSTANCE_PRIVATE_INTERFACE
;
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();
31 const PPP_Instance_Private ppp_instance_private
= {
37 InstancePrivate::InstancePrivate(PP_Instance instance
) : Instance(instance
) {
38 // If at least 1 InstancePrivate is created, register the PPP_INSTANCE_PRIVATE
40 Module::Get()->AddPluginInterface(PPP_INSTANCE_PRIVATE_INTERFACE
,
41 &ppp_instance_private
);
44 InstancePrivate::~InstancePrivate() {}
46 Var
InstancePrivate::GetInstanceObject() {
50 VarPrivate
InstancePrivate::GetWindowObject() {
51 if (!has_interface
<PPB_Instance_Private
>())
53 return VarPrivate(PASS_REF
,
54 get_interface
<PPB_Instance_Private
>()->GetWindowObject(pp_instance()));
57 VarPrivate
InstancePrivate::GetOwnerElementObject() {
58 if (!has_interface
<PPB_Instance_Private
>())
60 return VarPrivate(PASS_REF
,
61 get_interface
<PPB_Instance_Private
>()->GetOwnerElementObject(
65 VarPrivate
InstancePrivate::ExecuteScript(const Var
& script
, Var
* exception
) {
66 if (!has_interface
<PPB_Instance_Private
>())
68 return VarPrivate(PASS_REF
,
69 get_interface
<PPB_Instance_Private
>()->ExecuteScript(
72 VarPrivate::OutException(exception
).get()));