blob: 0b219f4468ee3f6dfd56059121216c8e0abdc620 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// 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.
#ifndef PPAPI_PROXY_PLUGIN_DISPATCHER_H_
#define PPAPI_PROXY_PLUGIN_DISPATCHER_H_
#include <string>
#include "base/hash_tables.h"
#include "base/process.h"
#include "base/scoped_ptr.h"
#include "build/build_config.h"
#include "ppapi/c/pp_rect.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/proxy/dispatcher.h"
class MessageLoop;
namespace base {
class WaitableEvent;
}
namespace pp {
namespace proxy {
// Used to keep track of per-instance data.
struct InstanceData {
PP_Rect position;
};
class PluginDispatcher : public Dispatcher {
public:
// Constructor for the plugin side. The init and shutdown functions will be
// will be automatically called when requested by the renderer side. The
// module ID will be set upon receipt of the InitializeModule message.
//
// You must call Dispatcher::InitWithChannel after the constructor.
PluginDispatcher(base::ProcessHandle remote_process_handle,
GetInterfaceFunc get_interface);
~PluginDispatcher();
// The plugin side maintains a mapping from PP_Instance to Dispatcher so
// that we can send the messages to the right channel if there are multiple
// renderers sharing the same plugin. This mapping is maintained by
// DidCreateInstance/DidDestroyInstance.
static PluginDispatcher* GetForInstance(PP_Instance instance);
static const void* GetInterfaceFromDispatcher(const char* interface);
// Dispatcher overrides.
virtual bool IsPlugin() const;
// IPC::Channel::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& msg);
virtual void OnChannelError();
// Keeps track of which dispatcher to use for each instance, active instances
// and tracks associated data like the current size.
void DidCreateInstance(PP_Instance instance);
void DidDestroyInstance(PP_Instance instance);
// Gets the data for an existing instance, or NULL if the instance id doesn't
// correspond to a known instance.
InstanceData* GetInstanceData(PP_Instance instance);
#if defined(OS_POSIX)
// See renderer_fd_ below.
int GetRendererFD();
void CloseRendererFD();
#endif
private:
friend class PluginDispatcherTest;
// Notifies all live instances that they're now closed. This is used when
// a renderer crashes or some other error is received.
void ForceFreeAllInstances();
// IPC message handlers.
void OnMsgSupportsInterface(const std::string& interface_name, bool* result);
#if defined(OS_POSIX)
// FD for the renderer end of the socket. It is closed when the IPC layer
// indicates that the channel is connected, proving that the renderer has
// access to its side of the socket.
int renderer_fd_;
#endif
// All target proxies currently created. These are ones that receive
// messages.
scoped_ptr<InterfaceProxy> target_proxies_[INTERFACE_ID_COUNT];
typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap;
InstanceDataMap instance_map_;
DISALLOW_COPY_AND_ASSIGN(PluginDispatcher);
};
} // namespace proxy
} // namespace pp
#endif // PPAPI_PROXY_PLUGIN_DISPATCHER_H_
|