This source file includes following definitions.
- InputEvent_HandleEvent
- Instance_DidCreate
- Instance_DidDestroy
- Instance_DidChangeView
- Instance_DidChangeFocus
- Instance_HandleDocumentLoad
- Messaging_HandleMessage
- core_
- Init
- GetPluginInterface
- GetBrowserInterface
- InstanceForPPInstance
- AddPluginInterface
- InternalInit
#include "ppapi/cpp/module.h"
#include <string.h>
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/c/ppp_input_event.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/c/ppp_messaging.h"
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/resource.h"
#include "ppapi/cpp/url_loader.h"
#include "ppapi/cpp/var.h"
#include "ppapi/cpp/view.h"
namespace pp {
PP_Bool InputEvent_HandleEvent(PP_Instance pp_instance, PP_Resource resource) {
Module* module_singleton = Module::Get();
if (!module_singleton)
return PP_FALSE;
Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
if (!instance)
return PP_FALSE;
return PP_FromBool(instance->HandleInputEvent(InputEvent(resource)));
}
const PPP_InputEvent input_event_interface = {
&InputEvent_HandleEvent
};
PP_Bool Instance_DidCreate(PP_Instance pp_instance,
uint32_t argc,
const char* argn[],
const char* argv[]) {
Module* module_singleton = Module::Get();
if (!module_singleton)
return PP_FALSE;
Instance* instance = module_singleton->CreateInstance(pp_instance);
if (!instance)
return PP_FALSE;
module_singleton->current_instances_[pp_instance] = instance;
return PP_FromBool(instance->Init(argc, argn, argv));
}
void Instance_DidDestroy(PP_Instance instance) {
Module* module_singleton = Module::Get();
if (!module_singleton)
return;
Module::InstanceMap::iterator found =
module_singleton->current_instances_.find(instance);
if (found == module_singleton->current_instances_.end())
return;
Instance* obj = found->second;
module_singleton->current_instances_.erase(found);
delete obj;
}
void Instance_DidChangeView(PP_Instance pp_instance,
PP_Resource view_resource) {
Module* module_singleton = Module::Get();
if (!module_singleton)
return;
Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
if (!instance)
return;
instance->DidChangeView(View(view_resource));
}
void Instance_DidChangeFocus(PP_Instance pp_instance, PP_Bool has_focus) {
Module* module_singleton = Module::Get();
if (!module_singleton)
return;
Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
if (!instance)
return;
instance->DidChangeFocus(PP_ToBool(has_focus));
}
PP_Bool Instance_HandleDocumentLoad(PP_Instance pp_instance,
PP_Resource pp_url_loader) {
Module* module_singleton = Module::Get();
if (!module_singleton)
return PP_FALSE;
Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
if (!instance)
return PP_FALSE;
return PP_FromBool(instance->HandleDocumentLoad(URLLoader(pp_url_loader)));
}
static PPP_Instance instance_interface = {
&Instance_DidCreate,
&Instance_DidDestroy,
&Instance_DidChangeView,
&Instance_DidChangeFocus,
&Instance_HandleDocumentLoad
};
void Messaging_HandleMessage(PP_Instance pp_instance, PP_Var var) {
Module* module_singleton = Module::Get();
if (!module_singleton)
return;
Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
if (!instance)
return;
instance->HandleMessage(Var(PASS_REF, var));
}
static PPP_Messaging instance_messaging_interface = {
&Messaging_HandleMessage
};
Module::Module() : pp_module_(0), get_browser_interface_(NULL), core_(NULL) {
}
Module::~Module() {
delete core_;
core_ = NULL;
}
bool Module::Init() {
return true;
}
const void* Module::GetPluginInterface(const char* interface_name) {
if (strcmp(interface_name, PPP_INPUT_EVENT_INTERFACE) == 0)
return &input_event_interface;
if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0)
return &instance_interface;
if (strcmp(interface_name, PPP_MESSAGING_INTERFACE) == 0)
return &instance_messaging_interface;
InterfaceMap::const_iterator found = additional_interfaces_.find(
std::string(interface_name));
if (found != additional_interfaces_.end())
return found->second;
return NULL;
}
const void* Module::GetBrowserInterface(const char* interface_name) {
return get_browser_interface_(interface_name);
}
Instance* Module::InstanceForPPInstance(PP_Instance instance) {
InstanceMap::iterator found = current_instances_.find(instance);
if (found == current_instances_.end())
return NULL;
return found->second;
}
void Module::AddPluginInterface(const std::string& interface_name,
const void* vtable) {
const void* existing_interface = GetPluginInterface(interface_name.c_str());
if (existing_interface) {
PP_DCHECK(vtable == existing_interface);
return;
}
additional_interfaces_[interface_name] = vtable;
}
bool Module::InternalInit(PP_Module mod,
PPB_GetInterface get_browser_interface) {
pp_module_ = mod;
get_browser_interface_ = get_browser_interface;
const PPB_Core* core = reinterpret_cast<const PPB_Core*>(GetBrowserInterface(
PPB_CORE_INTERFACE));
if (!core)
return false;
core_ = new Core(core);
return Init();
}
}