OLD | NEW |
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/browser/renderer_host/pepper/browser_ppapi_host_impl.h" | 5 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" |
| 6 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" |
6 | 7 |
7 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
8 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
9 #include "ipc/ipc_message_macros.h" | 10 #include "ipc/ipc_message_macros.h" |
10 | 11 |
11 namespace content { | 12 namespace content { |
12 | 13 |
| 14 // static |
| 15 BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess( |
| 16 IPC::Sender* sender, |
| 17 ppapi::PpapiPermissions permissions, |
| 18 base::ProcessHandle plugin_child_process, |
| 19 IPC::ChannelProxy* channel, |
| 20 net::HostResolver* host_resolver, |
| 21 int render_process_id, |
| 22 int render_view_id) { |
| 23 BrowserPpapiHostImpl* browser_ppapi_host = |
| 24 new BrowserPpapiHostImpl(sender, permissions); |
| 25 browser_ppapi_host->set_plugin_process_handle(plugin_child_process); |
| 26 |
| 27 channel->AddFilter( |
| 28 new PepperMessageFilter(PepperMessageFilter::NACL, |
| 29 host_resolver, |
| 30 render_process_id, |
| 31 render_view_id)); |
| 32 |
| 33 return browser_ppapi_host; |
| 34 } |
| 35 |
13 BrowserPpapiHostImpl::BrowserPpapiHostImpl( | 36 BrowserPpapiHostImpl::BrowserPpapiHostImpl( |
14 IPC::Sender* sender, | 37 IPC::Sender* sender, |
15 const ppapi::PpapiPermissions& permissions) | 38 const ppapi::PpapiPermissions& permissions) |
16 : ppapi_host_(sender, permissions), | 39 : ppapi_host_(sender, permissions), |
17 plugin_process_handle_(base::kNullProcessHandle) { | 40 plugin_process_handle_(base::kNullProcessHandle) { |
| 41 message_filter_ = new HostMessageFilter(&ppapi_host_); |
18 ppapi_host_.AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( | 42 ppapi_host_.AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( |
19 new ContentBrowserPepperHostFactory(this))); | 43 new ContentBrowserPepperHostFactory(this))); |
20 } | 44 } |
21 | 45 |
22 BrowserPpapiHostImpl::~BrowserPpapiHostImpl() { | 46 BrowserPpapiHostImpl::~BrowserPpapiHostImpl() { |
23 } | 47 // Notify the filter so it won't foward messages to us. |
24 | 48 message_filter_->OnHostDestroyed(); |
25 bool BrowserPpapiHostImpl::OnMessageReceived(const IPC::Message& msg) { | |
26 /* TODO(brettw) when we add messages, here, the code should look like this: | |
27 bool handled = true; | |
28 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl, msg) | |
29 // Add necessary message handlers here. | |
30 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_.OnMessageReceived(msg)) | |
31 IPC_END_MESSAGE_MAP(); | |
32 return handled; | |
33 */ | |
34 return ppapi_host_.OnMessageReceived(msg); | |
35 } | 49 } |
36 | 50 |
37 ppapi::host::PpapiHost* BrowserPpapiHostImpl::GetPpapiHost() { | 51 ppapi::host::PpapiHost* BrowserPpapiHostImpl::GetPpapiHost() { |
38 return &ppapi_host_; | 52 return &ppapi_host_; |
39 } | 53 } |
40 | 54 |
41 base::ProcessHandle BrowserPpapiHostImpl::GetPluginProcessHandle() const { | 55 base::ProcessHandle BrowserPpapiHostImpl::GetPluginProcessHandle() const { |
42 // Handle should previously have been set before use. | 56 // Handle should previously have been set before use. |
43 DCHECK(plugin_process_handle_ != base::kNullProcessHandle); | 57 DCHECK(plugin_process_handle_ != base::kNullProcessHandle); |
44 return plugin_process_handle_; | 58 return plugin_process_handle_; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 91 |
78 void BrowserPpapiHostImpl::DeleteInstanceForView(PP_Instance instance) { | 92 void BrowserPpapiHostImpl::DeleteInstanceForView(PP_Instance instance) { |
79 InstanceToViewMap::iterator found = instance_to_view_.find(instance); | 93 InstanceToViewMap::iterator found = instance_to_view_.find(instance); |
80 if (found == instance_to_view_.end()) { | 94 if (found == instance_to_view_.end()) { |
81 NOTREACHED(); | 95 NOTREACHED(); |
82 return; | 96 return; |
83 } | 97 } |
84 instance_to_view_.erase(found); | 98 instance_to_view_.erase(found); |
85 } | 99 } |
86 | 100 |
| 101 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( |
| 102 const IPC::Message& msg) { |
| 103 // Don't forward messages if our owner object has been destroyed. |
| 104 if (!ppapi_host_) |
| 105 return false; |
| 106 |
| 107 /* TODO(brettw) when we add messages, here, the code should look like this: |
| 108 bool handled = true; |
| 109 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl, msg) |
| 110 // Add necessary message handlers here. |
| 111 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) |
| 112 IPC_END_MESSAGE_MAP(); |
| 113 return handled; |
| 114 */ |
| 115 return ppapi_host_->OnMessageReceived(msg); |
| 116 } |
| 117 |
| 118 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { |
| 119 DCHECK(ppapi_host_); |
| 120 ppapi_host_ = NULL; |
| 121 } |
| 122 |
87 } // namespace content | 123 } // namespace content |
OLD | NEW |