blob: 3ef2c270a39505f84a7ba9684b2eb9027c39d2a0 [file] [log] [blame]
[email protected]67600b92012-03-10 06:51:481// Copyright (c) 2012 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#include "ppapi/proxy/dispatcher.h"
6
7#include <string.h> // For memset.
8
9#include <map>
10
[email protected]709a847e2010-11-10 01:16:1111#include "base/compiler_specific.h"
[email protected]c2932f5e2010-11-03 03:22:3312#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/singleton.h"
[email protected]9ca952d2010-11-11 20:43:5014#include "ppapi/proxy/ppapi_messages.h"
[email protected]c2932f5e2010-11-03 03:22:3315#include "ppapi/proxy/var_serialization_rules.h"
16
[email protected]4d2efd22011-08-18 21:58:0217namespace ppapi {
[email protected]c2932f5e2010-11-03 03:22:3318namespace proxy {
19
[email protected]f0ecb552012-05-11 22:09:1120Dispatcher::Dispatcher(PP_GetInterface_Func local_get_interface)
21 : disallow_trusted_interfaces_(false), // TODO(brettw) make this settable.
[email protected]0f41c012011-10-21 19:49:2022 local_get_interface_(local_get_interface) {
[email protected]c2932f5e2010-11-03 03:22:3323}
24
25Dispatcher::~Dispatcher() {
26}
27
[email protected]4dec5802012-06-30 05:26:5228void Dispatcher::AddFilter(IPC::Listener* listener) {
29 filters_.push_back(listener);
30}
31
[email protected]ac4b54d2011-10-20 23:09:2832InterfaceProxy* Dispatcher::GetInterfaceProxy(ApiID id) {
[email protected]5c966022011-09-13 18:09:3733 InterfaceProxy* proxy = proxies_[id].get();
34 if (!proxy) {
35 // Handle the first time for a given API by creating the proxy for it.
36 InterfaceProxy::Factory factory =
37 InterfaceList::GetInstance()->GetFactoryForID(id);
38 if (!factory) {
39 NOTREACHED();
40 return NULL;
41 }
42 proxy = factory(this);
43 DCHECK(proxy);
44 proxies_[id].reset(proxy);
45 }
46 return proxy;
47}
48
49base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() {
50 return delegate()->GetIPCMessageLoop();
51}
52
53void Dispatcher::AddIOThreadMessageFilter(
54 IPC::ChannelProxy::MessageFilter* filter) {
[email protected]8be45842012-04-13 19:49:2955 // Our filter is refcounted. The channel will call the destruct method on the
56 // filter when the channel is done with it, so the corresponding Release()
57 // happens there.
[email protected]5c966022011-09-13 18:09:3758 channel()->AddFilter(filter);
59}
60
[email protected]a95986a82010-12-24 06:19:2861bool Dispatcher::OnMessageReceived(const IPC::Message& msg) {
[email protected]ac4b54d2011-10-20 23:09:2862 if (msg.routing_id() <= 0 || msg.routing_id() >= API_ID_COUNT) {
[email protected]5c966022011-09-13 18:09:3763 OnInvalidMessageReceived();
64 return true;
65 }
[email protected]465faa22011-02-08 16:31:4666
[email protected]5c966022011-09-13 18:09:3767 InterfaceProxy* proxy = GetInterfaceProxy(
[email protected]ac4b54d2011-10-20 23:09:2868 static_cast<ApiID>(msg.routing_id()));
[email protected]5c966022011-09-13 18:09:3769 if (!proxy) {
70 NOTREACHED();
71 return true;
72 }
73 return proxy->OnMessageReceived(msg);
[email protected]465faa22011-02-08 16:31:4674}
75
[email protected]c2932f5e2010-11-03 03:22:3376void Dispatcher::SetSerializationRules(
77 VarSerializationRules* var_serialization_rules) {
[email protected]67600b92012-03-10 06:51:4878 serialization_rules_ = var_serialization_rules;
[email protected]c2932f5e2010-11-03 03:22:3379}
80
[email protected]5c966022011-09-13 18:09:3781void Dispatcher::OnInvalidMessageReceived() {
[email protected]c2932f5e2010-11-03 03:22:3382}
83
[email protected]c2932f5e2010-11-03 03:22:3384} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:0285} // namespace ppapi