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

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

Issue 22300003: Move broker creation out of PepperHelperImpl to PPB_Broker_Impl in the effort to eliminate PepperHe… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 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_helper_impl.h" 5 #include "content/renderer/pepper/pepper_helper_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <cstddef> 8 #include <cstddef>
9 #include <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
(...skipping 20 matching lines...) Expand all
31 #include "content/public/common/page_zoom.h" 31 #include "content/public/common/page_zoom.h"
32 #include "content/public/common/referrer.h" 32 #include "content/public/common/referrer.h"
33 #include "content/public/common/webplugininfo.h" 33 #include "content/public/common/webplugininfo.h"
34 #include "content/public/renderer/content_renderer_client.h" 34 #include "content/public/renderer/content_renderer_client.h"
35 #include "content/renderer/gamepad_shared_memory_reader.h" 35 #include "content/renderer/gamepad_shared_memory_reader.h"
36 #include "content/renderer/media/media_stream_dispatcher.h" 36 #include "content/renderer/media/media_stream_dispatcher.h"
37 #include "content/renderer/p2p/socket_dispatcher.h" 37 #include "content/renderer/p2p/socket_dispatcher.h"
38 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" 38 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h"
39 #include "content/renderer/pepper/host_dispatcher_wrapper.h" 39 #include "content/renderer/pepper/host_dispatcher_wrapper.h"
40 #include "content/renderer/pepper/host_globals.h" 40 #include "content/renderer/pepper/host_globals.h"
41 #include "content/renderer/pepper/pepper_broker.h"
42 #include "content/renderer/pepper/pepper_browser_connection.h" 41 #include "content/renderer/pepper/pepper_browser_connection.h"
43 #include "content/renderer/pepper/pepper_file_system_host.h" 42 #include "content/renderer/pepper/pepper_file_system_host.h"
44 #include "content/renderer/pepper/pepper_graphics_2d_host.h" 43 #include "content/renderer/pepper/pepper_graphics_2d_host.h"
45 #include "content/renderer/pepper/pepper_hung_plugin_filter.h" 44 #include "content/renderer/pepper/pepper_hung_plugin_filter.h"
46 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" 45 #include "content/renderer/pepper/pepper_in_process_resource_creation.h"
47 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 46 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
48 #include "content/renderer/pepper/pepper_plugin_registry.h" 47 #include "content/renderer/pepper/pepper_plugin_registry.h"
49 #include "content/renderer/pepper/pepper_webplugin_impl.h" 48 #include "content/renderer/pepper/pepper_webplugin_impl.h"
50 #include "content/renderer/pepper/plugin_module.h" 49 #include "content/renderer/pepper/plugin_module.h"
51 #include "content/renderer/pepper/ppb_tcp_socket_private_impl.h" 50 #include "content/renderer/pepper/ppb_tcp_socket_private_impl.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 permissions, 194 permissions,
196 channel_handle, 195 channel_handle,
197 peer_pid, 196 peer_pid,
198 plugin_child_id, 197 plugin_child_id,
199 false)) // is_external = false 198 false)) // is_external = false
200 return scoped_refptr<PluginModule>(); 199 return scoped_refptr<PluginModule>();
201 200
202 return module; 201 return module;
203 } 202 }
204 203
205 scoped_refptr<PepperBroker> PepperHelperImpl::CreateBroker(
206 PluginModule* plugin_module) {
207 DCHECK(plugin_module);
208 DCHECK(!plugin_module->GetBroker());
209
210 // The broker path is the same as the plugin.
211 const base::FilePath& broker_path = plugin_module->path();
212
213 scoped_refptr<PepperBroker> broker = new PepperBroker(plugin_module, this);
214
215 int request_id =
216 pending_connect_broker_.Add(new scoped_refptr<PepperBroker>(broker));
217
218 // Have the browser start the broker process for us.
219 Send(new ViewHostMsg_OpenChannelToPpapiBroker(
220 routing_id(), request_id, broker_path));
221
222 return broker;
223 }
224
225 RendererPpapiHost* PepperHelperImpl::CreateOutOfProcessModule( 204 RendererPpapiHost* PepperHelperImpl::CreateOutOfProcessModule(
226 PluginModule* module, 205 PluginModule* module,
227 const base::FilePath& path, 206 const base::FilePath& path,
228 ppapi::PpapiPermissions permissions, 207 ppapi::PpapiPermissions permissions,
229 const IPC::ChannelHandle& channel_handle, 208 const IPC::ChannelHandle& channel_handle,
230 base::ProcessId peer_pid, 209 base::ProcessId peer_pid,
231 int plugin_child_id, 210 int plugin_child_id,
232 bool is_external) { 211 bool is_external) {
233 scoped_refptr<PepperHungPluginFilter> hung_filter( 212 scoped_refptr<PepperHungPluginFilter> hung_filter(
234 new PepperHungPluginFilter(path, routing_id(), plugin_child_id)); 213 new PepperHungPluginFilter(path, routing_id(), plugin_child_id));
(...skipping 12 matching lines...) Expand all
247 226
248 RendererPpapiHostImpl* host_impl = 227 RendererPpapiHostImpl* host_impl =
249 RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( 228 RendererPpapiHostImpl::CreateOnModuleForOutOfProcess(
250 module, dispatcher->dispatcher(), permissions); 229 module, dispatcher->dispatcher(), permissions);
251 render_view_->PpapiPluginCreated(host_impl); 230 render_view_->PpapiPluginCreated(host_impl);
252 231
253 module->InitAsProxied(dispatcher.release()); 232 module->InitAsProxied(dispatcher.release());
254 return host_impl; 233 return host_impl;
255 } 234 }
256 235
257 void PepperHelperImpl::OnPpapiBrokerChannelCreated(
258 int request_id,
259 base::ProcessId broker_pid,
260 const IPC::ChannelHandle& handle) {
261 scoped_refptr<PepperBroker>* broker_ptr =
262 pending_connect_broker_.Lookup(request_id);
263 if (broker_ptr) {
264 scoped_refptr<PepperBroker> broker = *broker_ptr;
265 pending_connect_broker_.Remove(request_id);
266 broker->OnBrokerChannelConnected(broker_pid, handle);
267 } else {
268 // There is no broker waiting for this channel. Close it so the broker can
269 // clean up and possibly exit.
270 // The easiest way to clean it up is to just put it in an object
271 // and then close them. This failure case is not performance critical.
272 PepperBrokerDispatcherWrapper temp_dispatcher;
273 temp_dispatcher.Init(broker_pid, handle);
274 }
275 }
276
277 // Iterates through pending_connect_broker_ to find the broker.
278 // Cannot use Lookup() directly because pending_connect_broker_ does not store
279 // the raw pointer to the broker. Assumes maximum of one copy of broker exists.
280 bool PepperHelperImpl::StopWaitingForBrokerConnection(
281 PepperBroker* broker) {
282 for (BrokerMap::iterator i(&pending_connect_broker_);
283 !i.IsAtEnd(); i.Advance()) {
284 if (i.GetCurrentValue()->get() == broker) {
285 pending_connect_broker_.Remove(i.GetCurrentKey());
286 return true;
287 }
288 }
289
290 return false;
291 }
292
293 void PepperHelperImpl::ViewWillInitiatePaint() { 236 void PepperHelperImpl::ViewWillInitiatePaint() {
294 // Notify all of our instances that we started painting. This is used for 237 // Notify all of our instances that we started painting. This is used for
295 // internal bookkeeping only, so we know that the set can not change under 238 // internal bookkeeping only, so we know that the set can not change under
296 // us. 239 // us.
297 for (std::set<PepperPluginInstanceImpl*>::iterator i = 240 for (std::set<PepperPluginInstanceImpl*>::iterator i =
298 active_instances_.begin(); 241 active_instances_.begin();
299 i != active_instances_.end(); ++i) 242 i != active_instances_.end(); ++i)
300 (*i)->ViewWillInitiatePaint(); 243 (*i)->ViewWillInitiatePaint();
301 } 244 }
302 245
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 PluginFocusChanged(instance, false); 455 PluginFocusChanged(instance, false);
513 456
514 if (!instance->module()->IsProxied()) { 457 if (!instance->module()->IsProxied()) {
515 PepperBrowserConnection* browser_connection = 458 PepperBrowserConnection* browser_connection =
516 PepperBrowserConnection::Get(render_view_); 459 PepperBrowserConnection::Get(render_view_);
517 browser_connection->DidDeleteInProcessInstance( 460 browser_connection->DidDeleteInProcessInstance(
518 instance->pp_instance()); 461 instance->pp_instance());
519 } 462 }
520 } 463 }
521 464
522 // If a broker has not already been created for this plugin, creates one.
523 PepperBroker* PepperHelperImpl::ConnectToBroker(
524 PPB_Broker_Impl* client) {
525 DCHECK(client);
526
527 PluginModule* plugin_module =
528 HostGlobals::Get()->GetInstance(client->pp_instance())->module();
529 if (!plugin_module)
530 return NULL;
531
532 scoped_refptr<PepperBroker> broker =
533 static_cast<PepperBroker*>(plugin_module->GetBroker());
534 if (!broker.get())
535 broker = CreateBroker(plugin_module);
536
537 int request_id = pending_permission_requests_.Add(
538 new base::WeakPtr<PPB_Broker_Impl>(client->AsWeakPtr()));
539 Send(new ViewHostMsg_RequestPpapiBrokerPermission(
540 routing_id(),
541 request_id,
542 client->GetDocumentUrl(),
543 plugin_module->path()));
544
545 // Adds a reference, ensuring that the broker is not deleted when
546 // |broker| goes out of scope.
547 broker->AddPendingConnect(client);
548
549 return broker.get();
550 }
551
552 void PepperHelperImpl::OnPpapiBrokerPermissionResult(int request_id,
553 bool result) {
554 scoped_ptr<base::WeakPtr<PPB_Broker_Impl> > client_ptr(
555 pending_permission_requests_.Lookup(request_id));
556 DCHECK(client_ptr.get());
557 pending_permission_requests_.Remove(request_id);
558 base::WeakPtr<PPB_Broker_Impl> client = *client_ptr;
559 if (!client.get())
560 return;
561
562 PluginModule* plugin_module =
563 HostGlobals::Get()->GetInstance(client->pp_instance())->module();
564 if (!plugin_module)
565 return;
566
567 PepperBroker* broker = static_cast<PepperBroker*>(plugin_module->GetBroker());
568 broker->OnBrokerPermissionResult(client.get(), result);
569 }
570
571 void PepperHelperImpl::OnSetFocus(bool has_focus) { 465 void PepperHelperImpl::OnSetFocus(bool has_focus) {
572 for (std::set<PepperPluginInstanceImpl*>::iterator i = 466 for (std::set<PepperPluginInstanceImpl*>::iterator i =
573 active_instances_.begin(); 467 active_instances_.begin();
574 i != active_instances_.end(); ++i) 468 i != active_instances_.end(); ++i)
575 (*i)->SetContentAreaFocus(has_focus); 469 (*i)->SetContentAreaFocus(has_focus);
576 } 470 }
577 471
578 void PepperHelperImpl::PageVisibilityChanged(bool is_visible) { 472 void PepperHelperImpl::PageVisibilityChanged(bool is_visible) {
579 for (std::set<PepperPluginInstanceImpl*>::iterator i = 473 for (std::set<PepperPluginInstanceImpl*>::iterator i =
580 active_instances_.begin(); 474 active_instances_.begin();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 PepperPluginInstanceImpl* instance) { 524 PepperPluginInstanceImpl* instance) {
631 last_mouse_event_target_ = instance; 525 last_mouse_event_target_ = instance;
632 } 526 }
633 527
634 void PepperHelperImpl::SampleGamepads(WebKit::WebGamepads* data) { 528 void PepperHelperImpl::SampleGamepads(WebKit::WebGamepads* data) {
635 if (!gamepad_shared_memory_reader_) 529 if (!gamepad_shared_memory_reader_)
636 gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader); 530 gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader);
637 gamepad_shared_memory_reader_->SampleGamepads(*data); 531 gamepad_shared_memory_reader_->SampleGamepads(*data);
638 } 532 }
639 533
640 bool PepperHelperImpl::OnMessageReceived(const IPC::Message& message) {
641 bool handled = true;
642 IPC_BEGIN_MESSAGE_MAP(PepperHelperImpl, message)
643 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
644 OnPpapiBrokerChannelCreated)
645 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult,
646 OnPpapiBrokerPermissionResult)
647 IPC_MESSAGE_UNHANDLED(handled = false)
648 IPC_END_MESSAGE_MAP()
649 return handled;
650 }
651
652 void PepperHelperImpl::OnDestruct() { 534 void PepperHelperImpl::OnDestruct() {
653 // Nothing to do here. Default implementation in RenderViewObserver does 535 // Nothing to do here. Default implementation in RenderViewObserver does
654 // 'delete this' but it's not suitable for PepperHelperImpl because 536 // 'delete this' but it's not suitable for PepperHelperImpl because
655 // it's non-pointer member in RenderViewImpl. 537 // it's non-pointer member in RenderViewImpl.
656 } 538 }
657 539
658 } // namespace content 540 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698