Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: content/renderer/pepper/pepper_in_process_resource_creation.cc

Issue 10578043: Hook up content/renderer to the PPAPI host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments addressed Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "content/renderer/pepper/pepper_in_process_resource_creation.h"
6
7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop.h"
10 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h"
11 #include "ipc/ipc_message.h"
12 #include "ipc/ipc_message_macros.h"
13 #include "ppapi/host/ppapi_host.h"
14 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/shared_impl/ppapi_globals.h"
16 #include "ppapi/shared_impl/resource_tracker.h"
17
18 // Note that the code in the creation functions in this file should generally
19 // be the same as that in ppapi/proxy/resource_creation_proxy.cc. See
20 // pepper_in_process_resource_creation.h for what this file is for.
21
22 namespace content {
23
24 class PepperInProcessResourceCreation::PluginToHostRouter
25 : public IPC::Sender {
26 public:
27 PluginToHostRouter(RenderViewImpl* render_view,
28 IPC::Sender* host_to_plugin_sender);
29 virtual ~PluginToHostRouter() {}
30
31 // Sender implementation.
32 virtual bool Send(IPC::Message* msg) OVERRIDE;
33
34 private:
35 void DoSend(IPC::Message* msg);
36
37 base::WeakPtrFactory<PluginToHostRouter> weak_factory_;
38
39 ContentRendererPepperHostFactory factory_;
40 ppapi::host::PpapiHost host_;
41
42 DISALLOW_COPY_AND_ASSIGN(PluginToHostRouter);
43 };
44
45 PepperInProcessResourceCreation::PluginToHostRouter::PluginToHostRouter(
46 RenderViewImpl* render_view,
47 IPC::Sender* host_to_plugin_sender)
48 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
49 factory_(render_view),
50 host_(host_to_plugin_sender, &factory_) {
51 }
52
53 bool PepperInProcessResourceCreation::PluginToHostRouter::Send(
54 IPC::Message* msg) {
55 // Don't directly call into the message handler to avoid reentrancy. The IPC
56 // systen assumes everything is executed from the message loop, so emulate
57 // the same thing for in-process.
58 MessageLoop::current()->PostTask(FROM_HERE,
59 base::Bind(&PluginToHostRouter::DoSend, weak_factory_.GetWeakPtr(),
60 base::Owned(msg)));
61 return true;
62 }
63
64 void PepperInProcessResourceCreation::PluginToHostRouter::DoSend(
65 IPC::Message* msg) {
66 host_.OnMessageReceived(*msg);
67 }
68
69 // HostToPluginRouter ---------------------------------------------------------
70
71 class PepperInProcessResourceCreation::HostToPluginRouter
72 : public IPC::Sender {
73 public:
74 HostToPluginRouter();
75 virtual ~HostToPluginRouter() {}
76
77 // Sender implementation.
78 virtual bool Send(IPC::Message* msg) OVERRIDE;
79
80 private:
81 void DispatchMsg(IPC::Message* msg);
82
83 void OnMsgResourceReply(
84 const ppapi::proxy::ResourceMessageReplyParams& reply_params,
85 const IPC::Message& nested_msg);
86
87 base::WeakPtrFactory<HostToPluginRouter> weak_factory_;
88
89 DISALLOW_COPY_AND_ASSIGN(HostToPluginRouter);
90 };
91
92 PepperInProcessResourceCreation::HostToPluginRouter::HostToPluginRouter()
93 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
94 }
95
96 bool PepperInProcessResourceCreation::HostToPluginRouter::Send(
97 IPC::Message* msg) {
98 // As in the PluginToHostRouter, dispatch from the message loop.
99 MessageLoop::current()->PostTask(FROM_HERE,
100 base::Bind(&HostToPluginRouter::DispatchMsg,
101 weak_factory_.GetWeakPtr(),
102 base::Owned(msg)));
103 return true;
104 }
105
106 void PepperInProcessResourceCreation::HostToPluginRouter::DispatchMsg(
107 IPC::Message* msg) {
108 // Emulate the proxy by dispatching the relevant message here.
109 IPC_BEGIN_MESSAGE_MAP(HostToPluginRouter, *msg)
110 IPC_MESSAGE_HANDLER(PpapiPluginMsg_ResourceReply, OnMsgResourceReply)
111 IPC_END_MESSAGE_MAP()
112 }
113
114 void PepperInProcessResourceCreation::HostToPluginRouter::OnMsgResourceReply(
115 const ppapi::proxy::ResourceMessageReplyParams& reply_params,
116 const IPC::Message& nested_msg) {
117 ppapi::Resource* resource =
118 ppapi::PpapiGlobals::Get()->GetResourceTracker()->GetResource(
119 reply_params.pp_resource());
120 if (!resource) {
121 // The resource could have been destroyed while the async processing was
122 // pending. Just drop the message.
123 return;
124 }
125 resource->OnReplyReceived(reply_params.sequence(), reply_params.result(),
126 nested_msg);
127 }
128
129 // PepperInProcessResourceCreation --------------------------------------------
130
131 PepperInProcessResourceCreation::PepperInProcessResourceCreation(
132 RenderViewImpl* render_view,
133 webkit::ppapi::PluginInstance* instance)
134 : ResourceCreationImpl(instance),
135 host_to_plugin_router_(new HostToPluginRouter),
136 plugin_to_host_router_(
137 new PluginToHostRouter(render_view, host_to_plugin_router_.get())) {
138 }
139
140 PepperInProcessResourceCreation::~PepperInProcessResourceCreation() {
141 }
142
143 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_in_process_resource_creation.h ('k') | content/renderer/pepper/pepper_plugin_delegate_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698