1 // Copyright (c) 2011 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/c/pp_errors.h"
6 #include "ppapi/c/pp_input_event.h"
7 #include "ppapi/c/ppb_var.h"
8 #include "ppapi/c/trusted/ppb_instance_trusted.h"
9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/instance.h"
11 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/private/var_private.h"
14 class MyInstance
: public pp::Instance
{
16 MyInstance(PP_Instance instance
) : pp::Instance(instance
) {
17 factory_
.Initialize(this);
20 virtual ~MyInstance() {
23 virtual bool Init(uint32_t argc
, const char* argn
[], const char* argv
[]) {
27 virtual bool HandleInputEvent(const PP_InputEvent
& event
) {
29 case PP_INPUTEVENT_TYPE_MOUSEDOWN
:
30 pp::Module::Get()->core()->CallOnMainThread(100,
31 factory_
.NewCallback(&MyInstance::SayHello
));
33 case PP_INPUTEVENT_TYPE_MOUSEMOVE
:
35 case PP_INPUTEVENT_TYPE_KEYDOWN
:
43 void SayHello(int32_t) {
44 pp::Var
code("deletePlugin()");
46 When scripting is removed from instance, this is the code that will do the
48 const PPB_Instance_Trusted* inst =
49 (const PPB_Instance_Trusted*)pp::Module::Get()->GetBrowserInterface(
50 PPB_INSTANCE_TRUSTED_INTERFACE);
51 inst->ExecuteScript(pp_instance(), code.pp_var(), NULL);
56 pp::CompletionCallbackFactory
<MyInstance
> factory_
;
59 class MyModule
: public pp::Module
{
61 MyModule() : pp::Module() {}
62 virtual ~MyModule() {}
64 virtual pp::Instance
* CreateInstance(PP_Instance instance
) {
65 return new MyInstance(instance
);
71 // Factory function for your specialization of the Module object.
72 Module
* CreateModule() {
73 return new MyModule();