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

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

Issue 10815073: Refactoring of new IPC-only pepper implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" 5 #include "content/renderer/pepper/pepper_in_process_resource_creation.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "content/renderer/render_view_impl.h" 10 #include "content/renderer/render_view_impl.h"
11 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" 11 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
12 #include "content/renderer/pepper/pepper_in_process_router.h"
12 #include "ipc/ipc_message.h" 13 #include "ipc/ipc_message.h"
13 #include "ipc/ipc_message_macros.h" 14 #include "ipc/ipc_message_macros.h"
14 #include "ppapi/host/ppapi_host.h" 15 #include "ppapi/host/ppapi_host.h"
15 #include "ppapi/proxy/file_chooser_resource.h" 16 #include "ppapi/proxy/file_chooser_resource.h"
16 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
17 #include "ppapi/shared_impl/ppapi_globals.h" 18 #include "ppapi/shared_impl/ppapi_globals.h"
18 #include "ppapi/shared_impl/ppapi_permissions.h" 19 #include "ppapi/shared_impl/ppapi_permissions.h"
19 #include "ppapi/shared_impl/resource_tracker.h" 20 #include "ppapi/shared_impl/resource_tracker.h"
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
21 22
22 // Note that the code in the creation functions in this file should generally 23 // Note that the code in the creation functions in this file should generally
23 // be the same as that in ppapi/proxy/resource_creation_proxy.cc. See 24 // be the same as that in ppapi/proxy/resource_creation_proxy.cc. See
24 // pepper_in_process_resource_creation.h for what this file is for. 25 // pepper_in_process_resource_creation.h for what this file is for.
25 26
26 namespace content { 27 namespace content {
27 28
28 // PluginResources take a plugin->browser channel in their constructor. When
29 // in process, we don't have a per-plugin-module object in the browser. We
30 // currently just don't support these resource objects in-process.
31 //
32 // But to keep things linking, we provide this dummy browser channel. It will
33 // just assert if anything attempts to actually send a message.
34 class PepperInProcessResourceCreation::DummyBrowserChannel
35 : public IPC::Sender {
36 public:
37 DummyBrowserChannel() {}
38 ~DummyBrowserChannel() {}
39
40 // Sender implementation.
41 virtual bool Send(IPC::Message* msg) OVERRIDE {
42 NOTREACHED();
43 delete msg;
44 return false;
45 }
46 };
47
48 class PepperInProcessResourceCreation::PluginToHostRouter
49 : public IPC::Sender {
50 public:
51 PluginToHostRouter(RenderViewImpl* render_view,
52 PepperInstanceStateAccessor* state,
53 IPC::Sender* host_to_plugin_sender,
54 const ppapi::PpapiPermissions& perms);
55 virtual ~PluginToHostRouter() {}
56
57 ppapi::host::PpapiHost& host() { return host_; }
58
59 // Sender implementation.
60 virtual bool Send(IPC::Message* msg) OVERRIDE;
61
62 private:
63 void DoSend(IPC::Message* msg);
64
65 base::WeakPtrFactory<PluginToHostRouter> weak_factory_;
66
67 ContentRendererPepperHostFactory factory_;
68 ppapi::host::PpapiHost host_;
69
70 DISALLOW_COPY_AND_ASSIGN(PluginToHostRouter);
71 };
72
73 PepperInProcessResourceCreation::PluginToHostRouter::PluginToHostRouter(
74 RenderViewImpl* render_view,
75 PepperInstanceStateAccessor* state,
76 IPC::Sender* host_to_plugin_sender,
77 const ppapi::PpapiPermissions& perms)
78 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
79 factory_(render_view, perms, state),
80 host_(host_to_plugin_sender, &factory_, perms) {
81 }
82
83 bool PepperInProcessResourceCreation::PluginToHostRouter::Send(
84 IPC::Message* msg) {
85 // Don't directly call into the message handler to avoid reentrancy. The IPC
86 // systen assumes everything is executed from the message loop, so emulate
87 // the same thing for in-process.
88 MessageLoop::current()->PostTask(FROM_HERE,
89 base::Bind(&PluginToHostRouter::DoSend, weak_factory_.GetWeakPtr(),
90 base::Owned(msg)));
91 return true;
92 }
93
94 void PepperInProcessResourceCreation::PluginToHostRouter::DoSend(
95 IPC::Message* msg) {
96 host_.OnMessageReceived(*msg);
97 }
98
99 // HostToPluginRouter ---------------------------------------------------------
100
101 class PepperInProcessResourceCreation::HostToPluginRouter
102 : public IPC::Sender {
103 public:
104 HostToPluginRouter();
105 virtual ~HostToPluginRouter() {}
106
107 // Sender implementation.
108 virtual bool Send(IPC::Message* msg) OVERRIDE;
109
110 private:
111 void DispatchMsg(IPC::Message* msg);
112
113 void OnMsgResourceReply(
114 const ppapi::proxy::ResourceMessageReplyParams& reply_params,
115 const IPC::Message& nested_msg);
116
117 base::WeakPtrFactory<HostToPluginRouter> weak_factory_;
118
119 DISALLOW_COPY_AND_ASSIGN(HostToPluginRouter);
120 };
121
122 PepperInProcessResourceCreation::HostToPluginRouter::HostToPluginRouter()
123 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
124 }
125
126 bool PepperInProcessResourceCreation::HostToPluginRouter::Send(
127 IPC::Message* msg) {
128 // As in the PluginToHostRouter, dispatch from the message loop.
129 MessageLoop::current()->PostTask(FROM_HERE,
130 base::Bind(&HostToPluginRouter::DispatchMsg,
131 weak_factory_.GetWeakPtr(),
132 base::Owned(msg)));
133 return true;
134 }
135
136 void PepperInProcessResourceCreation::HostToPluginRouter::DispatchMsg(
137 IPC::Message* msg) {
138 // Emulate the proxy by dispatching the relevant message here.
139 IPC_BEGIN_MESSAGE_MAP(HostToPluginRouter, *msg)
140 IPC_MESSAGE_HANDLER(PpapiPluginMsg_ResourceReply, OnMsgResourceReply)
141 IPC_END_MESSAGE_MAP()
142 }
143
144 void PepperInProcessResourceCreation::HostToPluginRouter::OnMsgResourceReply(
145 const ppapi::proxy::ResourceMessageReplyParams& reply_params,
146 const IPC::Message& nested_msg) {
147 ppapi::Resource* resource =
148 ppapi::PpapiGlobals::Get()->GetResourceTracker()->GetResource(
149 reply_params.pp_resource());
150 if (!resource) {
151 // The resource could have been destroyed while the async processing was
152 // pending. Just drop the message.
153 return;
154 }
155 resource->OnReplyReceived(reply_params, nested_msg);
156 }
157
158 // PepperInProcessResourceCreation -------------------------------------------- 29 // PepperInProcessResourceCreation --------------------------------------------
159 30
160 PepperInProcessResourceCreation::PepperInProcessResourceCreation( 31 PepperInProcessResourceCreation::PepperInProcessResourceCreation(
161 RenderViewImpl* render_view, 32 RendererPpapiHostImpl* host_impl,
162 webkit::ppapi::PluginInstance* instance, 33 webkit::ppapi::PluginInstance* instance)
163 const ppapi::PpapiPermissions& perms)
164 : ResourceCreationImpl(instance), 34 : ResourceCreationImpl(instance),
165 instance_state_(instance->module()), 35 host_impl_(host_impl) {
166 dummy_browser_channel_(new DummyBrowserChannel),
167 host_to_plugin_router_(new HostToPluginRouter),
168 plugin_to_host_router_(
169 new PluginToHostRouter(render_view, &instance_state_,
170 host_to_plugin_router_.get(),
171 perms)) {
172 render_view->PpapiPluginCreated(&plugin_to_host_router_->host());
173 } 36 }
174 37
175 PepperInProcessResourceCreation::~PepperInProcessResourceCreation() { 38 PepperInProcessResourceCreation::~PepperInProcessResourceCreation() {
176 } 39 }
177 40
178 PP_Resource PepperInProcessResourceCreation::CreateFileChooser( 41 PP_Resource PepperInProcessResourceCreation::CreateFileChooser(
179 PP_Instance instance, 42 PP_Instance instance,
180 PP_FileChooserMode_Dev mode, 43 PP_FileChooserMode_Dev mode,
181 const char* accept_types) { 44 const char* accept_types) {
182 return (new ppapi::proxy::FileChooserResource( 45 return (new ppapi::proxy::FileChooserResource(
183 GetConnection(), 46 host_impl_->in_process_router()->GetPluginConnection(),
184 instance, mode, accept_types))->GetReference(); 47 instance, mode, accept_types))->GetReference();
185 } 48 }
186 49
187 ppapi::proxy::Connection PepperInProcessResourceCreation::GetConnection() {
188 return ppapi::proxy::Connection(dummy_browser_channel_.get(),
189 plugin_to_host_router_.get());
190 }
191
192 } // namespace content 50 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698