Revert of Use ExtensionRegistryObserver instead of deprecated extension notification...
[chromium-blink-merge.git] / ppapi / cpp / private / instance_private.cc
blobc55408a28cbe753d32d6b269e40fea098780d82f
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"
12 namespace pp {
14 namespace {
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 = {
32 &GetInstanceObject
35 } // namespace
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);
44 InstancePrivate::~InstancePrivate() {}
46 Var InstancePrivate::GetInstanceObject() {
47 return Var();
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()));
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()));
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()));
75 } // namespace pp