This source file includes following definitions.
- Init
- DidChangeView
- DidChangeView
- DidChangeFocus
- HandleDocumentLoad
- HandleInputEvent
- HandleMessage
- BindGraphics
- BindGraphics
- IsFullFrame
- RequestInputEvents
- RequestFilteringInputEvents
- ClearInputEventRequest
- PostMessage
- LogToConsole
- LogToConsoleWithSource
- AddPerInstanceObject
- RemovePerInstanceObject
- RemovePerInstanceObject
- GetPerInstanceObject
#include "ppapi/cpp/instance.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_console.h"
#include "ppapi/c/ppb_input_event.h"
#include "ppapi/c/ppb_instance.h"
#include "ppapi/c/ppb_messaging.h"
#include "ppapi/cpp/graphics_2d.h"
#include "ppapi/cpp/graphics_3d.h"
#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/instance_handle.h"
#include "ppapi/cpp/logging.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
#include "ppapi/cpp/point.h"
#include "ppapi/cpp/resource.h"
#include "ppapi/cpp/var.h"
#include "ppapi/cpp/view.h"
namespace pp {
namespace {
template <> const char* interface_name<PPB_Console_1_0>() {
return PPB_CONSOLE_INTERFACE_1_0;
}
template <> const char* interface_name<PPB_InputEvent_1_0>() {
return PPB_INPUT_EVENT_INTERFACE_1_0;
}
template <> const char* interface_name<PPB_Instance_1_0>() {
return PPB_INSTANCE_INTERFACE_1_0;
}
template <> const char* interface_name<PPB_Messaging_1_0>() {
return PPB_MESSAGING_INTERFACE_1_0;
}
}
Instance::Instance(PP_Instance instance) : pp_instance_(instance) {
}
Instance::~Instance() {
}
bool Instance::Init(uint32_t , const char* [],
const char* []) {
return true;
}
void Instance::DidChangeView(const View& view) {
DidChangeView(view.GetRect(), view.GetClipRect());
}
void Instance::DidChangeView(const pp::Rect& ,
const pp::Rect& ) {
}
void Instance::DidChangeFocus(bool ) {
}
bool Instance::HandleDocumentLoad(const URLLoader& ) {
return false;
}
bool Instance::HandleInputEvent(const InputEvent& ) {
return false;
}
void Instance::HandleMessage(const Var& ) {
return;
}
bool Instance::BindGraphics(const Graphics2D& graphics) {
if (!has_interface<PPB_Instance_1_0>())
return false;
return PP_ToBool(get_interface<PPB_Instance_1_0>()->BindGraphics(
pp_instance(), graphics.pp_resource()));
}
bool Instance::BindGraphics(const Graphics3D& graphics) {
if (!has_interface<PPB_Instance_1_0>())
return false;
return PP_ToBool(get_interface<PPB_Instance_1_0>()->BindGraphics(
pp_instance(), graphics.pp_resource()));
}
bool Instance::IsFullFrame() {
if (!has_interface<PPB_Instance_1_0>())
return false;
return PP_ToBool(get_interface<PPB_Instance_1_0>()->IsFullFrame(
pp_instance()));
}
int32_t Instance::RequestInputEvents(uint32_t event_classes) {
if (!has_interface<PPB_InputEvent_1_0>())
return PP_ERROR_NOINTERFACE;
return get_interface<PPB_InputEvent_1_0>()->RequestInputEvents(pp_instance(),
event_classes);
}
int32_t Instance::RequestFilteringInputEvents(uint32_t event_classes) {
if (!has_interface<PPB_InputEvent_1_0>())
return PP_ERROR_NOINTERFACE;
return get_interface<PPB_InputEvent_1_0>()->RequestFilteringInputEvents(
pp_instance(), event_classes);
}
void Instance::ClearInputEventRequest(uint32_t event_classes) {
if (!has_interface<PPB_InputEvent_1_0>())
return;
get_interface<PPB_InputEvent_1_0>()->ClearInputEventRequest(pp_instance(),
event_classes);
}
void Instance::PostMessage(const Var& message) {
if (!has_interface<PPB_Messaging_1_0>())
return;
get_interface<PPB_Messaging_1_0>()->PostMessage(pp_instance(),
message.pp_var());
}
void Instance::LogToConsole(PP_LogLevel level, const Var& value) {
if (!has_interface<PPB_Console_1_0>())
return;
get_interface<PPB_Console_1_0>()->Log(
pp_instance(), level, value.pp_var());
}
void Instance::LogToConsoleWithSource(PP_LogLevel level,
const Var& source,
const Var& value) {
if (!has_interface<PPB_Console_1_0>())
return;
get_interface<PPB_Console_1_0>()->LogWithSource(
pp_instance(), level, source.pp_var(), value.pp_var());
}
void Instance::AddPerInstanceObject(const std::string& interface_name,
void* object) {
PP_DCHECK(interface_name_to_objects_.find(interface_name) ==
interface_name_to_objects_.end());
interface_name_to_objects_[interface_name] = object;
}
void Instance::RemovePerInstanceObject(const std::string& interface_name,
void* object) {
InterfaceNameToObjectMap::iterator found = interface_name_to_objects_.find(
interface_name);
if (found == interface_name_to_objects_.end()) {
PP_DCHECK(false);
return;
}
PP_DCHECK(found->second == object);
(void)object;
interface_name_to_objects_.erase(found);
}
void Instance::RemovePerInstanceObject(const InstanceHandle& instance,
const std::string& interface_name,
void* object) {
Instance* that = Module::Get()->InstanceForPPInstance(instance.pp_instance());
if (!that)
return;
that->RemovePerInstanceObject(interface_name, object);
}
void* Instance::GetPerInstanceObject(PP_Instance instance,
const std::string& interface_name) {
Instance* that = Module::Get()->InstanceForPPInstance(instance);
if (!that)
return NULL;
InterfaceNameToObjectMap::iterator found =
that->interface_name_to_objects_.find(interface_name);
if (found == that->interface_name_to_objects_.end())
return NULL;
return found->second;
}
}