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 | 6 |
7 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" | 7 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" |
8 #include "content/browser/tracing/trace_message_filter.h" | 8 #include "content/browser/tracing/trace_message_filter.h" |
9 #include "content/common/pepper_renderer_instance_data.h" | 9 #include "content/common/pepper_renderer_instance_data.h" |
10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
11 #include "content/public/browser/site_instance.h" | |
11 #include "content/public/common/process_type.h" | 12 #include "content/public/common/process_type.h" |
12 #include "ipc/ipc_message_macros.h" | 13 #include "ipc/ipc_message_macros.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 | 17 |
16 // static | 18 // static |
17 BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess( | 19 scoped_refptr<BrowserPpapiHost> BrowserPpapiHost::CreateExternalPluginProcess( |
20 BrowserPpapiHost::Delegate* delegate, | |
18 IPC::Sender* sender, | 21 IPC::Sender* sender, |
19 ppapi::PpapiPermissions permissions, | 22 ppapi::PpapiPermissions permissions, |
20 base::ProcessHandle plugin_child_process, | 23 base::ProcessHandle plugin_child_process, |
21 IPC::ChannelProxy* channel, | 24 IPC::ChannelProxy* channel, |
22 int render_process_id, | 25 int render_process_id, |
23 int render_view_id, | 26 int render_view_id, |
24 const base::FilePath& profile_directory) { | 27 const base::FilePath& profile_directory) { |
25 // The plugin name and path shouldn't be needed for external plugins. | 28 // The plugin name and path shouldn't be needed for external plugins. |
26 BrowserPpapiHostImpl* browser_ppapi_host = | 29 scoped_refptr<BrowserPpapiHostImpl> browser_ppapi_host = |
27 new BrowserPpapiHostImpl(sender, permissions, std::string(), | 30 new BrowserPpapiHostImpl(delegate, sender, permissions, std::string(), |
28 base::FilePath(), profile_directory, | 31 base::FilePath(), profile_directory, |
29 false /* in_process */, | 32 false /* in_process */, |
30 true /* external_plugin */); | 33 true /* external_plugin */); |
31 browser_ppapi_host->set_plugin_process_handle(plugin_child_process); | 34 browser_ppapi_host->set_plugin_process_handle(plugin_child_process); |
32 | 35 |
33 scoped_refptr<PepperMessageFilter> pepper_message_filter( | 36 scoped_refptr<PepperMessageFilter> pepper_message_filter( |
34 new PepperMessageFilter()); | 37 new PepperMessageFilter()); |
35 channel->AddFilter(pepper_message_filter->GetFilter()); | 38 channel->AddFilter(pepper_message_filter->GetFilter()); |
36 channel->AddFilter(browser_ppapi_host->message_filter()); | 39 channel->AddFilter(browser_ppapi_host->message_filter()); |
37 channel->AddFilter((new TraceMessageFilter())->GetFilter()); | 40 channel->AddFilter((new TraceMessageFilter())->GetFilter()); |
38 | 41 |
39 return browser_ppapi_host; | 42 return browser_ppapi_host; |
40 } | 43 } |
41 | 44 |
42 BrowserPpapiHostImpl::BrowserPpapiHostImpl( | 45 BrowserPpapiHostImpl::BrowserPpapiHostImpl( |
46 BrowserPpapiHost::Delegate* delegate, | |
43 IPC::Sender* sender, | 47 IPC::Sender* sender, |
44 const ppapi::PpapiPermissions& permissions, | 48 const ppapi::PpapiPermissions& permissions, |
45 const std::string& plugin_name, | 49 const std::string& plugin_name, |
46 const base::FilePath& plugin_path, | 50 const base::FilePath& plugin_path, |
47 const base::FilePath& profile_data_directory, | 51 const base::FilePath& profile_data_directory, |
48 bool in_process, | 52 bool in_process, |
49 bool external_plugin) | 53 bool external_plugin) |
50 : ppapi_host_(new ppapi::host::PpapiHost(sender, permissions)), | 54 : delegate_(delegate), |
55 ppapi_host_(new ppapi::host::PpapiHost(sender, permissions)), | |
51 plugin_process_handle_(base::kNullProcessHandle), | 56 plugin_process_handle_(base::kNullProcessHandle), |
52 plugin_name_(plugin_name), | 57 plugin_name_(plugin_name), |
53 plugin_path_(plugin_path), | 58 plugin_path_(plugin_path), |
54 profile_data_directory_(profile_data_directory), | 59 profile_data_directory_(profile_data_directory), |
55 in_process_(in_process), | 60 in_process_(in_process), |
56 external_plugin_(external_plugin), | 61 external_plugin_(external_plugin), |
57 ssl_context_helper_(new SSLContextHelper()) { | 62 ssl_context_helper_(new SSLContextHelper()) { |
58 message_filter_ = new HostMessageFilter(ppapi_host_.get()); | 63 message_filter_ = new HostMessageFilter(this, ppapi_host_.get()); |
dmichael (off chromium)
2013/11/06 22:39:21
Maybe you should give the HostMessageFilter a call
scheib
2013/11/15 01:22:17
Done.
| |
59 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( | 64 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( |
60 new ContentBrowserPepperHostFactory(this))); | 65 new ContentBrowserPepperHostFactory(this))); |
61 } | 66 } |
62 | 67 |
63 BrowserPpapiHostImpl::~BrowserPpapiHostImpl() { | 68 BrowserPpapiHostImpl::~BrowserPpapiHostImpl() { |
64 // Notify the filter so it won't foward messages to us. | 69 // Notify the filter so it won't foward messages to us. |
65 message_filter_->OnHostDestroyed(); | 70 message_filter_->OnHostDestroyed(); |
66 | 71 |
67 // Delete the host explicitly first. This shutdown will destroy the | 72 // Delete the host explicitly first. This shutdown will destroy the |
68 // resources, which may want to do cleanup in their destructors and expect | 73 // resources, which may want to do cleanup in their destructors and expect |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 | 140 |
136 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { | 141 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { |
137 InstanceMap::iterator found = instance_map_.find(instance); | 142 InstanceMap::iterator found = instance_map_.find(instance); |
138 if (found == instance_map_.end()) { | 143 if (found == instance_map_.end()) { |
139 NOTREACHED(); | 144 NOTREACHED(); |
140 return; | 145 return; |
141 } | 146 } |
142 instance_map_.erase(found); | 147 instance_map_.erase(found); |
143 } | 148 } |
144 | 149 |
150 void BrowserPpapiHostImpl::OnIdleState(bool idle) { | |
151 if (!delegate_) | |
152 return; | |
153 | |
154 for (InstanceMap::iterator i = instance_map_.begin(); | |
dmichael (off chromium)
2013/11/06 22:39:21
Hmm... it might be nice if this code was more ins
scheib
2013/11/07 01:06:42
Comment certainly warranted. I'm not a fan of tra
scheib
2013/11/15 01:22:17
I have moved the for loop to the handler in chrome
| |
155 i != instance_map_.end(); | |
156 ++i) { | |
157 RenderViewHost* render_view_host = RenderViewHost::FromID( | |
158 i->second.render_process_id, i->second.render_view_id); | |
159 | |
160 delegate_->OnIdleState(idle, profile_data_directory_, render_view_host, | |
161 i->second.document_url); | |
162 } | |
163 } | |
164 | |
145 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( | 165 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( |
146 const IPC::Message& msg) { | 166 const IPC::Message& msg) { |
147 // Don't forward messages if our owner object has been destroyed. | 167 // Don't forward messages if our owner object has been destroyed. |
148 if (!ppapi_host_) | 168 if (!ppapi_host_) |
149 return false; | 169 return false; |
150 | 170 |
151 /* TODO(brettw) when we add messages, here, the code should look like this: | |
152 bool handled = true; | 171 bool handled = true; |
153 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl, msg) | 172 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl::HostMessageFilter, msg) |
154 // Add necessary message handlers here. | 173 // Add necessary message handlers here. |
174 IPC_MESSAGE_HANDLER(PpapiHostMsg_IdleState, | |
175 OnIdleState) | |
155 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) | 176 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) |
156 IPC_END_MESSAGE_MAP(); | 177 IPC_END_MESSAGE_MAP(); |
157 return handled; | 178 return handled; |
158 */ | |
159 return ppapi_host_->OnMessageReceived(msg); | |
160 } | 179 } |
161 | 180 |
162 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { | 181 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { |
182 browser_ppapi_host_impl_ = NULL; | |
163 DCHECK(ppapi_host_); | 183 DCHECK(ppapi_host_); |
164 ppapi_host_ = NULL; | 184 ppapi_host_ = NULL; |
165 } | 185 } |
166 | 186 |
187 void BrowserPpapiHostImpl::HostMessageFilter::OnIdleState(bool idle) { | |
188 if (browser_ppapi_host_impl_) { | |
189 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
190 base::Bind(&BrowserPpapiHostImpl::OnIdleState, | |
191 browser_ppapi_host_impl_, | |
192 idle)); | |
193 } | |
194 } | |
195 | |
167 } // namespace content | 196 } // namespace content |
OLD | NEW |