| Index: ppapi/proxy/ppb_hello_proxy.cc
|
| diff --git a/ppapi/proxy/ppb_hello_proxy.cc b/ppapi/proxy/ppb_hello_proxy.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..79954e37e81c789aca832d85a44f42e9ff555a18
|
| --- /dev/null
|
| +++ b/ppapi/proxy/ppb_hello_proxy.cc
|
| @@ -0,0 +1,149 @@
|
| +// 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/proxy/ppb_hello_proxy.h"
|
| +
|
| +#include <stdio.h>
|
| +
|
| +#include "base/logging.h"
|
| +#include "build/build_config.h"
|
| +#include "ppapi/c/pp_errors.h"
|
| +#include "ppapi/c/pp_resource.h"
|
| +#include "ppapi/c/dev/ppb_hello_dev.h"
|
| +#include "ppapi/cpp/completion_callback.h"
|
| +#include "ppapi/proxy/host_dispatcher.h"
|
| +#include "ppapi/proxy/plugin_dispatcher.h"
|
| +#include "ppapi/proxy/ppapi_messages.h"
|
| +#include "ppapi/thunk/enter.h"
|
| +#include "ppapi/thunk/resource_creation_api.h"
|
| +#include "ppapi/thunk/thunk.h"
|
| +
|
| +using ppapi::thunk::PPB_Hello_API;
|
| +
|
| +namespace ppapi {
|
| +namespace proxy {
|
| +
|
| +class Hello : public Resource, public HelloImpl {
|
| + public:
|
| + Hello(const HostResource& hello_id);
|
| + virtual ~Hello();
|
| +
|
| + // Resource overrides.
|
| + virtual PPB_Hello_API* AsPPB_Hello_API();
|
| +
|
| + // PPB_Hello_API implementation.
|
| + virtual int32_t SayHello() OVERRIDE;
|
| + virtual void WhoAreYou(char* name, uint32_t size,
|
| + pp::CompletionCallback callback) OVERRIDE;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(Hello);
|
| +};
|
| +
|
| +Hello::Hello(const HostResource& hello) : Resource(hello) {
|
| + LOG(ERROR) << "Hello (constructor)";
|
| +}
|
| +
|
| +Hello::~Hello() {
|
| + LOG(ERROR) << "~Hello (destructor)";
|
| +}
|
| +
|
| +PPB_Hello_API* Hello::AsPPB_Hello_API() {
|
| + LOG(ERROR) << "AsPPB_Hello_API";
|
| + return this;
|
| +}
|
| +
|
| +int32_t Hello::SayHello() {
|
| + LOG(ERROR) << "SayHello";
|
| + HelloImpl();
|
| + PluginDispatcher::GetForResource(this)->Send(
|
| + new PpapiHostMsg_PPBHello_Hello(API_ID_PPB_HELLO, host_resource()));
|
| + return PP_OK;
|
| +}
|
| +
|
| +void Hello::WhoAreYou(char* name, uint32_t size,
|
| + pp::CompletionCallback callback) {
|
| + LOG(ERROR) << "WhoAreYou";
|
| + ReceiveSerializedVarReturnValue result;
|
| + PluginDispatcher::GetForResource(this)->Send(
|
| + new PpapiHostMsg_PPBHello_WhoAreYou(API_ID_PPB_HELLO, host_resource(),
|
| + &result));
|
| + //PP_Var var = result.Return(dispatcher);
|
| + // TODO: Copy var to name
|
| +}
|
| +
|
| +PPB_Hello_Proxy::PPB_Hello_Proxy(Dispatcher* dispatcher)
|
| + : InterfaceProxy(dispatcher) {
|
| + LOG(ERROR) << "PPB_Hello_Proxy";
|
| +}
|
| +
|
| +PPB_Hello_Proxy::~PPB_Hello_Proxy() {
|
| + LOG(ERROR) << "~PPB_Hello_Proxy";
|
| +}
|
| +
|
| +// static
|
| +PP_Resource PPB_Hello_Proxy::CreateProxyResource(PP_Instance instance) {
|
| + LOG(ERROR) << "CreateProxyResource";
|
| + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
|
| + if (!dispatcher) {
|
| + LOG(ERROR) << "Can not get dispatcher";
|
| + return 0;
|
| + }
|
| +
|
| + LOG(ERROR) << "dispatcher->Send...";
|
| + HostResource result;
|
| + dispatcher->Send(new PpapiHostMsg_PPBHello_Create(
|
| + API_ID_PPB_HELLO, instance, &result));
|
| + if (result.is_null()) {
|
| + LOG(ERROR) << "result is null";
|
| + return 0;
|
| + }
|
| +
|
| + return (new Hello(result))->GetReference();
|
| +}
|
| +
|
| +bool PPB_Hello_Proxy::OnMessageReceived(const IPC::Message& msg) {
|
| + //puts("OnMessageReceived");
|
| + LOG(ERROR) << "OnMessageReceived";
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(PPB_Hello_Proxy, msg)
|
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBHello_Create, OnMsgCreate)
|
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBHello_Hello, OnMsgHello)
|
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBHello_WhoAreYou, OnMsgWhoAreYou)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| + return handled;
|
| +}
|
| +
|
| +void PPB_Hello_Proxy::OnMsgCreate(PP_Instance instance, HostResource* result) {
|
| + LOG(ERROR) << "OnMsgCreate";
|
| + thunk::EnterFunction<thunk::ResourceCreationAPI> resource_creation(
|
| + instance, true);
|
| + if (resource_creation.failed())
|
| + return;
|
| +
|
| + LOG(ERROR) << "resource_creation";
|
| + if (resource_creation.failed())
|
| + return;
|
| +
|
| + LOG(ERROR) << "SetHostResource";
|
| + result->SetHostResource(
|
| + instance, resource_creation.functions()->CreateHello(instance));
|
| + if (result->is_null())
|
| + return;
|
| +}
|
| +
|
| +void PPB_Hello_Proxy::OnMsgHello(const HostResource& host_resource) {
|
| + LOG(ERROR) << "OnMsgHello";
|
| +}
|
| +
|
| +void PPB_Hello_Proxy::OnMsgWhoAreYou(const HostResource& host_resource,
|
| + SerializedVarReturnValue result) {
|
| + LOG(ERROR) << "OnMsgWhoAreYou";
|
| + PP_Var var = PP_MakeUndefined();
|
| + // TODO: Make String
|
| + result.Return(dispatcher(), var);
|
| +}
|
| +
|
| +} // namespace proxy
|
| +} // namespace ppapi
|
|
|