diff options
author | dmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-19 14:49:32 +0000 |
---|---|---|
committer | dmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-19 14:49:32 +0000 |
commit | 8cef2068010fa12968211e3721d60d4d5fd3d4e9 (patch) | |
tree | 63907b7fd8fc28fd2d9a343772edb66a79a4d19a /ppapi/cpp | |
parent | 304d682f570f60644c97fea6d86bc303ba6b2ac5 (diff) | |
download | chromium_src-8cef2068010fa12968211e3721d60d4d5fd3d4e9.zip chromium_src-8cef2068010fa12968211e3721d60d4d5fd3d4e9.tar.gz chromium_src-8cef2068010fa12968211e3721d60d4d5fd3d4e9.tar.bz2 |
Rename Instance_Trusted to Instance_Private, wire it up in Chrome.
Add C++ InstancePrivate.
BUG=None
TEST=PPAPI tests
Review URL: http://codereview.chromium.org/6871040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82104 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp')
-rw-r--r-- | ppapi/cpp/private/instance_private.cc | 72 | ||||
-rw-r--r-- | ppapi/cpp/private/instance_private.h | 60 | ||||
-rw-r--r-- | ppapi/cpp/private/var_private.cc | 4 | ||||
-rw-r--r-- | ppapi/cpp/private/var_private.h | 4 |
4 files changed, 137 insertions, 3 deletions
diff --git a/ppapi/cpp/private/instance_private.cc b/ppapi/cpp/private/instance_private.cc new file mode 100644 index 0000000..2a924a3 --- /dev/null +++ b/ppapi/cpp/private/instance_private.cc @@ -0,0 +1,72 @@ +// 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(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 diff --git a/ppapi/cpp/private/instance_private.h b/ppapi/cpp/private/instance_private.h new file mode 100644 index 0000000..226494c --- /dev/null +++ b/ppapi/cpp/private/instance_private.h @@ -0,0 +1,60 @@ +// 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. + +#ifndef PPAPI_CPP_PRIVATE_INSTANCE_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_INSTANCE_PRIVATE_H_ + +/** + * @file + * Defines the API ... + * + * @addtogroup CPP + * @{ + */ + +#include "ppapi/cpp/instance.h" + +/** The C++ interface to the Pepper API. */ +namespace pp { + +class VarPrivate; + +class InstancePrivate : public Instance { + public: + explicit InstancePrivate(PP_Instance instance); + virtual ~InstancePrivate(); + + // @{ + /// @name PPP_Instance_Private methods for the plugin to override: + + /// See PPP_Instance_Private.GetInstanceObject. + // TODO(dmichael): Put this virtual function here and remove the + // 'Var GetInstanceObject()' version from pp::Instance. + //virtual VarPrivate GetInstanceObject(); + + // @} + + // @{ + /// @name PPB_Instance_Private methods for querying the browser: + + /// See PPB_Instance_Private.GetWindowObject. + VarPrivate GetWindowObject(); + + /// See PPB_Instance_Private.GetOwnerElementObject. + VarPrivate GetOwnerElementObject(); + + /// See PPB_Instance.ExecuteScript. + VarPrivate ExecuteScript(const VarPrivate& script, + VarPrivate* exception = NULL); + + // @} +}; + +} // namespace pp + +/** + * @} + * End addtogroup CPP + */ +#endif // PPAPI_CPP_PRIVATE_INSTANCE_PRIVATE_H_ diff --git a/ppapi/cpp/private/var_private.cc b/ppapi/cpp/private/var_private.cc index c3da55d..5db0aa3 100644 --- a/ppapi/cpp/private/var_private.cc +++ b/ppapi/cpp/private/var_private.cc @@ -5,7 +5,7 @@ #include "ppapi/cpp/private/var_private.h" #include "ppapi/c/dev/ppb_var_deprecated.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/private/instance_private.h" #include "ppapi/cpp/logging.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/dev/scriptable_object_deprecated.h" @@ -22,7 +22,7 @@ template <> const char* interface_name<PPB_Var_Deprecated>() { using namespace deprecated; -VarPrivate::VarPrivate(Instance* instance, ScriptableObject* object) { +VarPrivate::VarPrivate(InstancePrivate* instance, ScriptableObject* object) { if (has_interface<PPB_Var_Deprecated>()) { var_ = get_interface<PPB_Var_Deprecated>()->CreateObject( instance->pp_instance(), object->GetClass(), object); diff --git a/ppapi/cpp/private/var_private.h b/ppapi/cpp/private/var_private.h index 55068bc..5ab1e07b 100644 --- a/ppapi/cpp/private/var_private.h +++ b/ppapi/cpp/private/var_private.h @@ -9,6 +9,8 @@ namespace pp { +class InstancePrivate; + // VarPrivate is a version of Var that exposes the private scripting API. // It's designed to be mostly interchangable with Var since most callers will // be dealing with Vars from various places. @@ -23,7 +25,7 @@ class VarPrivate : public Var { VarPrivate(const std::string& utf8_str) : Var(utf8_str) {} VarPrivate(PassRef, PP_Var var) : Var(PassRef(), var) {} VarPrivate(DontManage, PP_Var var) : Var(DontManage(), var) {} - VarPrivate(Instance* instance, deprecated::ScriptableObject* object); + VarPrivate(InstancePrivate* instance, deprecated::ScriptableObject* object); VarPrivate(const Var& other) : Var(other) {} virtual ~VarPrivate() {} |