blob: c97401026a11d8e75aebf52ce3b5753ab1bec60b [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
Hans Wennborg708fa822020-04-27 17:23:1511#include "base/check.h"
[email protected]709a847e2010-11-10 01:16:1112#include "base/compiler_specific.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/singleton.h"
Hans Wennborg708fa822020-04-27 17:23:1514#include "base/notreached.h"
[email protected]9ca952d2010-11-11 20:43:5015#include "ppapi/proxy/ppapi_messages.h"
[email protected]c2932f5e2010-11-03 03:22:3316#include "ppapi/proxy/var_serialization_rules.h"
17
[email protected]74122042014-04-25 00:07:3018namespace IPC {
19class MessageFilter;
20}
21
[email protected]4d2efd22011-08-18 21:58:0222namespace ppapi {
[email protected]c2932f5e2010-11-03 03:22:3323namespace proxy {
24
[email protected]195d4cde2012-10-02 18:12:4125Dispatcher::Dispatcher(PP_GetInterface_Func local_get_interface,
26 const PpapiPermissions& permissions)
27 : local_get_interface_(local_get_interface),
28 permissions_(permissions) {
[email protected]c2932f5e2010-11-03 03:22:3329}
30
31Dispatcher::~Dispatcher() {
32}
33
[email protected]ac4b54d2011-10-20 23:09:2834InterfaceProxy* Dispatcher::GetInterfaceProxy(ApiID id) {
[email protected]5c966022011-09-13 18:09:3735 InterfaceProxy* proxy = proxies_[id].get();
36 if (!proxy) {
37 // Handle the first time for a given API by creating the proxy for it.
38 InterfaceProxy::Factory factory =
39 InterfaceList::GetInstance()->GetFactoryForID(id);
40 if (!factory) {
41 NOTREACHED();
42 return NULL;
43 }
44 proxy = factory(this);
45 DCHECK(proxy);
46 proxies_[id].reset(proxy);
47 }
48 return proxy;
49}
50
dmichael6b328f3d2014-09-29 23:49:0251void Dispatcher::AddIOThreadMessageFilter(
52 scoped_refptr<IPC::MessageFilter> filter) {
[email protected]8be45842012-04-13 19:49:2953 // Our filter is refcounted. The channel will call the destruct method on the
54 // filter when the channel is done with it, so the corresponding Release()
55 // happens there.
dmichael6b328f3d2014-09-29 23:49:0256 channel()->AddFilter(filter.get());
[email protected]5c966022011-09-13 18:09:3757}
58
[email protected]a95986a82010-12-24 06:19:2859bool Dispatcher::OnMessageReceived(const IPC::Message& msg) {
[email protected]ac4b54d2011-10-20 23:09:2860 if (msg.routing_id() <= 0 || msg.routing_id() >= API_ID_COUNT) {
[email protected]5c966022011-09-13 18:09:3761 OnInvalidMessageReceived();
62 return true;
63 }
[email protected]465faa22011-02-08 16:31:4664
[email protected]5c966022011-09-13 18:09:3765 InterfaceProxy* proxy = GetInterfaceProxy(
[email protected]ac4b54d2011-10-20 23:09:2866 static_cast<ApiID>(msg.routing_id()));
[email protected]5c966022011-09-13 18:09:3767 if (!proxy) {
68 NOTREACHED();
69 return true;
70 }
71 return proxy->OnMessageReceived(msg);
[email protected]465faa22011-02-08 16:31:4672}
73
[email protected]c2932f5e2010-11-03 03:22:3374void Dispatcher::SetSerializationRules(
75 VarSerializationRules* var_serialization_rules) {
[email protected]67600b92012-03-10 06:51:4876 serialization_rules_ = var_serialization_rules;
[email protected]c2932f5e2010-11-03 03:22:3377}
78
[email protected]5c966022011-09-13 18:09:3779void Dispatcher::OnInvalidMessageReceived() {
[email protected]c2932f5e2010-11-03 03:22:3380}
81
[email protected]c2932f5e2010-11-03 03:22:3382} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:0283} // namespace ppapi