blob: 3c038a3906d8361d0623c62c74d88762a2c40483 [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]74122042014-04-25 00:07:3017namespace IPC {
18class MessageFilter;
19}
20
[email protected]4d2efd22011-08-18 21:58:0221namespace ppapi {
[email protected]c2932f5e2010-11-03 03:22:3322namespace proxy {
23
[email protected]195d4cde2012-10-02 18:12:4124Dispatcher::Dispatcher(PP_GetInterface_Func local_get_interface,
25 const PpapiPermissions& permissions)
26 : local_get_interface_(local_get_interface),
27 permissions_(permissions) {
[email protected]c2932f5e2010-11-03 03:22:3328}
29
30Dispatcher::~Dispatcher() {
31}
32
[email protected]ac4b54d2011-10-20 23:09:2833InterfaceProxy* Dispatcher::GetInterfaceProxy(ApiID id) {
[email protected]5c966022011-09-13 18:09:3734 InterfaceProxy* proxy = proxies_[id].get();
35 if (!proxy) {
36 // Handle the first time for a given API by creating the proxy for it.
37 InterfaceProxy::Factory factory =
38 InterfaceList::GetInstance()->GetFactoryForID(id);
39 if (!factory) {
40 NOTREACHED();
41 return NULL;
42 }
43 proxy = factory(this);
44 DCHECK(proxy);
45 proxies_[id].reset(proxy);
46 }
47 return proxy;
48}
49
dmichael6b328f3d2014-09-29 23:49:0250void Dispatcher::AddIOThreadMessageFilter(
51 scoped_refptr<IPC::MessageFilter> filter) {
[email protected]8be45842012-04-13 19:49:2952 // Our filter is refcounted. The channel will call the destruct method on the
53 // filter when the channel is done with it, so the corresponding Release()
54 // happens there.
dmichael6b328f3d2014-09-29 23:49:0255 channel()->AddFilter(filter.get());
[email protected]5c966022011-09-13 18:09:3756}
57
[email protected]a95986a82010-12-24 06:19:2858bool Dispatcher::OnMessageReceived(const IPC::Message& msg) {
[email protected]ac4b54d2011-10-20 23:09:2859 if (msg.routing_id() <= 0 || msg.routing_id() >= API_ID_COUNT) {
[email protected]5c966022011-09-13 18:09:3760 OnInvalidMessageReceived();
61 return true;
62 }
[email protected]465faa22011-02-08 16:31:4663
[email protected]5c966022011-09-13 18:09:3764 InterfaceProxy* proxy = GetInterfaceProxy(
[email protected]ac4b54d2011-10-20 23:09:2865 static_cast<ApiID>(msg.routing_id()));
[email protected]5c966022011-09-13 18:09:3766 if (!proxy) {
67 NOTREACHED();
68 return true;
69 }
70 return proxy->OnMessageReceived(msg);
[email protected]465faa22011-02-08 16:31:4671}
72
[email protected]c2932f5e2010-11-03 03:22:3373void Dispatcher::SetSerializationRules(
74 VarSerializationRules* var_serialization_rules) {
[email protected]67600b92012-03-10 06:51:4875 serialization_rules_ = var_serialization_rules;
[email protected]c2932f5e2010-11-03 03:22:3376}
77
[email protected]5c966022011-09-13 18:09:3778void Dispatcher::OnInvalidMessageReceived() {
[email protected]c2932f5e2010-11-03 03:22:3379}
80
[email protected]c2932f5e2010-11-03 03:22:3381} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:0282} // namespace ppapi