Chromium Code Reviews| Index: ppapi/cpp/private/instance_private.cc |
| diff --git a/ppapi/cpp/private/instance_private.cc b/ppapi/cpp/private/instance_private.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f66e492d8a0e286d6a2349064f057594a7575dd8 |
| --- /dev/null |
| +++ b/ppapi/cpp/private/instance_private.cc |
| @@ -0,0 +1,73 @@ |
| +// 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() {} |
| + |
| +VarPrivate InstancePrivate::GetWindowObject() { |
| + if (!has_interface<PPB_Instance_Private>()) |
| + return VarPrivate(); |
| + return VarPrivate(Var::PassRef(), |
| + get_interface<PPB_Instance_Private>()->GetWindowObject( |
|
brettw
2011/04/18 21:13:26
I'd indent these lines to 4 spaces from the left o
|
| + pp_instance())); |
| +} |
| + |
| +VarPrivate InstancePrivate::GetOwnerElementObject() { |
| + if (!has_interface<PPB_Instance_Private>()) |
| + return VarPrivate(); |
| + return VarPrivate(Var::PassRef(), |
| + get_interface<PPB_Instance_Private>()->GetOwnerElementObject( |
| + pp_instance())); |
| +} |
| + |
| +VarPrivate InstancePrivate::ExecuteScript(const VarPrivate& script, |
| + VarPrivate* exception) { |
| + if (!has_interface<PPB_Instance_Private>()) |
| + return VarPrivate(); |
| + return VarPrivate(Var::PassRef(), |
| + get_interface<PPB_Instance_Private>()->ExecuteScript( |
| + pp_instance(), |
| + script.pp_var(), |
| + VarPrivate::OutException(exception).get())); |
| +} |
| + |
| +} // namespace pp |