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/proxy/dispatcher.h"
7 #include <string.h> // For memset.
11 #include "base/compiler_specific.h"
12 #include "base/logging.h"
13 #include "base/memory/singleton.h"
14 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/proxy/var_serialization_rules.h"
20 Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle
,
21 GetInterfaceFunc local_get_interface
)
22 : ProxyChannel(remote_process_handle
),
23 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable.
24 local_get_interface_(local_get_interface
) {
27 Dispatcher::~Dispatcher() {
30 InterfaceProxy
* Dispatcher::GetInterfaceProxy(ApiID id
) {
31 InterfaceProxy
* proxy
= proxies_
[id
].get();
33 // Handle the first time for a given API by creating the proxy for it.
34 InterfaceProxy::Factory factory
=
35 InterfaceList::GetInstance()->GetFactoryForID(id
);
40 proxy
= factory(this);
42 proxies_
[id
].reset(proxy
);
47 base::MessageLoopProxy
* Dispatcher::GetIPCMessageLoop() {
48 return delegate()->GetIPCMessageLoop();
51 void Dispatcher::AddIOThreadMessageFilter(
52 IPC::ChannelProxy::MessageFilter
* filter
) {
53 channel()->AddFilter(filter
);
56 bool Dispatcher::OnMessageReceived(const IPC::Message
& msg
) {
57 if (msg
.routing_id() <= 0 || msg
.routing_id() >= API_ID_COUNT
) {
58 OnInvalidMessageReceived();
62 InterfaceProxy
* proxy
= GetInterfaceProxy(
63 static_cast<ApiID
>(msg
.routing_id()));
68 return proxy
->OnMessageReceived(msg
);
71 void Dispatcher::SetSerializationRules(
72 VarSerializationRules
* var_serialization_rules
) {
73 serialization_rules_
.reset(var_serialization_rules
);
76 void Dispatcher::OnInvalidMessageReceived() {