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

Side by Side Diff: content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc

Issue 61063003: Keep NaCl plugins used in app background pages alive when active. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ref counted compile warning Created 7 years, 1 month 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/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());
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() {
64 // Notify the filter so it won't foward messages to us.
65 message_filter_->OnHostDestroyed();
66
67 // Delete the host explicitly first. This shutdown will destroy the
68 // resources, which may want to do cleanup in their destructors and expect
69 // their pointers to us to be valid.
70 ppapi_host_.reset();
71 }
72
73 ppapi::host::PpapiHost* BrowserPpapiHostImpl::GetPpapiHost() { 68 ppapi::host::PpapiHost* BrowserPpapiHostImpl::GetPpapiHost() {
74 return ppapi_host_.get(); 69 return ppapi_host_.get();
75 } 70 }
76 71
77 base::ProcessHandle BrowserPpapiHostImpl::GetPluginProcessHandle() const { 72 base::ProcessHandle BrowserPpapiHostImpl::GetPluginProcessHandle() const {
78 // Handle should previously have been set before use. 73 // Handle should previously have been set before use.
79 DCHECK(plugin_process_handle_ != base::kNullProcessHandle); 74 DCHECK(plugin_process_handle_ != base::kNullProcessHandle);
80 return plugin_process_handle_; 75 return plugin_process_handle_;
81 } 76 }
82 77
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 130
136 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { 131 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) {
137 InstanceMap::iterator found = instance_map_.find(instance); 132 InstanceMap::iterator found = instance_map_.find(instance);
138 if (found == instance_map_.end()) { 133 if (found == instance_map_.end()) {
139 NOTREACHED(); 134 NOTREACHED();
140 return; 135 return;
141 } 136 }
142 instance_map_.erase(found); 137 instance_map_.erase(found);
143 } 138 }
144 139
140 void BrowserPpapiHostImpl::OnIdleState(bool idle) {
141 if (!delegate_)
142 return;
143
144 for (InstanceMap::iterator i = instance_map_.begin();
145 i != instance_map_.end();
146 ++i) {
147 RenderViewHost* render_view_host = RenderViewHost::FromID(
148 i->second.render_process_id, i->second.render_view_id);
149
150 delegate_->OnIdleState(idle, profile_data_directory_, render_view_host,
151 i->second.document_url);
152 }
153 }
154
155 BrowserPpapiHostImpl::~BrowserPpapiHostImpl() {
156 // Notify the filter so it won't foward messages to us.
157 message_filter_->OnHostDestroyed();
158
159 // Delete the host explicitly first. This shutdown will destroy the
160 // resources, which may want to do cleanup in their destructors and expect
161 // their pointers to us to be valid.
162 ppapi_host_.reset();
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,
yzshen1 2013/11/06 22:43:15 Important: BrowserPpapiHostImpl should be accessed
scheib 2013/11/15 01:22:17 Done.
191 browser_ppapi_host_impl_,
192 idle));
193 }
194 }
195
167 } // namespace content 196 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698