1 // Copyright (c) 2012 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 "base/callback.h"
6 #include "base/basictypes.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/weak_ptr.h"
9 #include "ppapi/proxy/connection.h"
10 #include "ppapi/proxy/resource_message_params.h"
14 class MessageReplyDeserializer
;
19 class RendererPpapiHostImpl
;
21 // This class fakes an IPC channel so that we can take the new resources with
22 // IPC backends and run them in-process.
24 // (See pepper_in_process_resource_creation.h for more background.)
26 // This class just provides the fake routing for in-process plugins.
27 // Asynchronous messages are converted into an asynchronous execution of the
28 // message receiver on the opposite end. Synchronous messages just call right
31 // The resources in ppapi/proxy assume that there is an IPC connection to
32 // both the renderer and the browser processes. They take a connection object
33 // that includes both of these channels. However, in-process plugins don't
34 // have a BrowserPpapiHost on the browser side to receive these messages.
36 // As a result, we can't support resources that rely on sending messages to the
37 // browser process. Since this class is a stopgap until all interfaces are
38 // converted and all plugins are run out-of-procss, we just choose not to
39 // support faking IPC channels for resources that send messages directly to the
40 // browser process. These resources will just have to use the "old" in-process
41 // implementation until the conversion is complete and all this code can be
44 // To keep things consistent, we provide an IPC::Sender for the browser channel
45 // in the connection object supplied to resources. This dummy browser channel
46 // will just assert and delete the message if anything is ever sent over it.
48 // There are two restrictions for in-process resource calls:
49 // Sync messages can only be sent from the plugin to the host.
50 // The host must handle sync messages synchronously.
51 class PepperInProcessRouter
{
53 // The given host parameter owns this class and must outlive us.
54 PepperInProcessRouter(RendererPpapiHostImpl
* host_impl
);
55 ~PepperInProcessRouter();
57 // Returns the dummy sender for the cooresponding end of the in-process
59 IPC::Sender
* GetPluginToRendererSender();
60 IPC::Sender
* GetRendererToPluginSender();
62 // Returns a connection pair for use by a resource proxy. This includes
63 // the plugin->renderer sender as well as a dummy sender to the browser
64 // process. See the class comment above about the dummy sender.
65 ppapi::proxy::Connection
GetPluginConnection();
68 bool SendToHost(IPC::Message
*msg
);
69 bool SendToPlugin(IPC::Message
*msg
);
70 void DispatchPluginMsg(IPC::Message
* msg
);
71 bool DummySendTo(IPC::Message
*msg
);
73 // Handles resource reply messages from the host.
75 const ppapi::proxy::ResourceMessageReplyParams
& reply_params
,
76 const IPC::Message
& nested_msg
);
78 RendererPpapiHostImpl
* host_impl_
;
81 scoped_ptr
<Channel
> dummy_browser_channel_
;
83 // Renderer -> plugin channel.
84 scoped_ptr
<Channel
> host_to_plugin_router_
;
86 // Plugin -> renderer channel.
87 scoped_ptr
<Channel
> plugin_to_host_router_
;
89 // Pending sync message id.
90 int pending_message_id_
;
92 // Reply deserializer of the pending sync message.
93 scoped_ptr
<IPC::MessageReplyDeserializer
> reply_deserializer_
;
95 // Reply result of the pending sync message.
98 base::WeakPtrFactory
<PepperInProcessRouter
> weak_factory_
;
100 DISALLOW_COPY_AND_ASSIGN(PepperInProcessRouter
);
103 } // namespace content