blob: 1fed704428e965f5f07fa56ebcd31c3d030e7526 [file] [log] [blame]
[email protected]84396dbc2011-04-14 06:33:421// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]c2932f5e2010-11-03 03:22:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef PPAPI_PROXY_INTERFACE_PROXY_H_
6#define PPAPI_PROXY_INTERFACE_PROXY_H_
7
8#include "base/basictypes.h"
9#include "ipc/ipc_channel.h"
10#include "ipc/ipc_message.h"
11#include "ppapi/c/pp_completion_callback.h"
12#include "ppapi/c/pp_resource.h"
13#include "ppapi/c/pp_var.h"
14#include "ppapi/proxy/interface_id.h"
15
[email protected]4d2efd22011-08-18 21:58:0216namespace ppapi {
[email protected]c2932f5e2010-11-03 03:22:3317namespace proxy {
18
19class Dispatcher;
20
21class InterfaceProxy : public IPC::Channel::Listener,
22 public IPC::Message::Sender {
23 public:
[email protected]465faa22011-02-08 16:31:4624 // Factory function type for interfaces. Ownership of the returned pointer
25 // is transferred to the caller.
26 typedef InterfaceProxy* (*Factory)(Dispatcher* dispatcher,
27 const void* target_interface);
28
29 // Information about the interface. Each interface has a static function to
30 // return its info, which allows either construction on the target side, and
31 // getting the proxied interface on the source side (see dispatcher.h for
32 // terminology).
33 struct Info {
[email protected]84396dbc2011-04-14 06:33:4234 const void* interface_ptr;
[email protected]465faa22011-02-08 16:31:4635
36 const char* name;
37 InterfaceID id;
38
39 bool is_trusted;
40
41 InterfaceProxy::Factory create_proxy;
42 };
43
[email protected]c2932f5e2010-11-03 03:22:3344 virtual ~InterfaceProxy();
45
[email protected]465faa22011-02-08 16:31:4646 // The actual implementation of the given interface in the current process.
[email protected]c2932f5e2010-11-03 03:22:3347 const void* target_interface() const { return target_interface_; }
48
[email protected]f56279c2011-02-02 18:12:3149 Dispatcher* dispatcher() const { return dispatcher_; }
[email protected]c2932f5e2010-11-03 03:22:3350
51 // IPC::Message::Sender implementation.
52 virtual bool Send(IPC::Message* msg);
53
[email protected]c2932f5e2010-11-03 03:22:3354 // Sub-classes must implement IPC::Channel::Listener which contains this:
[email protected]a95986a82010-12-24 06:19:2855 //virtual bool OnMessageReceived(const IPC::Message& msg);
[email protected]c2932f5e2010-11-03 03:22:3356
57 protected:
[email protected]465faa22011-02-08 16:31:4658 // Creates the given interface associated with the given dispatcher. The
59 // dispatcher manages our lifetime.
60 //
61 // The target interface pointer, when non-NULL, indicates that this is a
62 // target proxy (see dispatcher.h for a definition). In this case, the proxy
63 // will interpret this pointer to the actual implementation of the interface
64 // in the local process.
65 InterfaceProxy(Dispatcher* dispatcher, const void* target_interface);
66
[email protected]c2932f5e2010-11-03 03:22:3367 uint32 SendCallback(PP_CompletionCallback callback);
68 PP_CompletionCallback ReceiveCallback(uint32 serialized_callback);
69
70 private:
71 Dispatcher* dispatcher_;
72 const void* target_interface_;
73};
74
[email protected]c2932f5e2010-11-03 03:22:3375} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:0276} // namespace ppapi
[email protected]c2932f5e2010-11-03 03:22:3377
78#endif // PPAPI_PROXY_INTERFACE_PROXY_H_
79