| 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 "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" | 9 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" |
| 10 #include "content/browser/tracing/trace_message_filter.h" | 10 #include "content/browser/tracing/trace_message_filter.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 return it->second->renderer_data.document_url; | 130 return it->second->renderer_data.document_url; |
| 131 } | 131 } |
| 132 | 132 |
| 133 GURL BrowserPpapiHostImpl::GetPluginURLForInstance(PP_Instance instance) { | 133 GURL BrowserPpapiHostImpl::GetPluginURLForInstance(PP_Instance instance) { |
| 134 auto it = instance_map_.find(instance); | 134 auto it = instance_map_.find(instance); |
| 135 if (it == instance_map_.end()) | 135 if (it == instance_map_.end()) |
| 136 return GURL(); | 136 return GURL(); |
| 137 return it->second->renderer_data.plugin_url; | 137 return it->second->renderer_data.plugin_url; |
| 138 } | 138 } |
| 139 | 139 |
| 140 void BrowserPpapiHostImpl::SetOnKeepaliveCallback( | |
| 141 const BrowserPpapiHost::OnKeepaliveCallback& callback) { | |
| 142 on_keepalive_callback_ = callback; | |
| 143 } | |
| 144 | |
| 145 bool BrowserPpapiHostImpl::IsPotentiallySecurePluginContext( | 140 bool BrowserPpapiHostImpl::IsPotentiallySecurePluginContext( |
| 146 PP_Instance instance) { | 141 PP_Instance instance) { |
| 147 auto it = instance_map_.find(instance); | 142 auto it = instance_map_.find(instance); |
| 148 if (it == instance_map_.end()) | 143 if (it == instance_map_.end()) |
| 149 return false; | 144 return false; |
| 150 return it->second->renderer_data.is_potentially_secure_plugin_context; | 145 return it->second->renderer_data.is_potentially_secure_plugin_context; |
| 151 } | 146 } |
| 152 | 147 |
| 153 void BrowserPpapiHostImpl::AddInstance( | 148 void BrowserPpapiHostImpl::AddInstance( |
| 154 PP_Instance instance, | 149 PP_Instance instance, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 196 |
| 202 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( | 197 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( |
| 203 const IPC::Message& msg) { | 198 const IPC::Message& msg) { |
| 204 // Don't forward messages if our owner object has been destroyed. | 199 // Don't forward messages if our owner object has been destroyed. |
| 205 if (!ppapi_host_) | 200 if (!ppapi_host_) |
| 206 return false; | 201 return false; |
| 207 | 202 |
| 208 bool handled = true; | 203 bool handled = true; |
| 209 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl::HostMessageFilter, msg) | 204 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl::HostMessageFilter, msg) |
| 210 // Add necessary message handlers here. | 205 // Add necessary message handlers here. |
| 211 IPC_MESSAGE_HANDLER(PpapiHostMsg_Keepalive, OnKeepalive) | |
| 212 IPC_MESSAGE_HANDLER(PpapiHostMsg_LogInterfaceUsage, | 206 IPC_MESSAGE_HANDLER(PpapiHostMsg_LogInterfaceUsage, |
| 213 OnHostMsgLogInterfaceUsage) | 207 OnHostMsgLogInterfaceUsage) |
| 214 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) | 208 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) |
| 215 IPC_END_MESSAGE_MAP() | 209 IPC_END_MESSAGE_MAP() |
| 216 return handled; | 210 return handled; |
| 217 } | 211 } |
| 218 | 212 |
| 219 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { | 213 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { |
| 220 DCHECK(ppapi_host_); | 214 DCHECK(ppapi_host_); |
| 221 ppapi_host_ = NULL; | 215 ppapi_host_ = NULL; |
| 222 browser_ppapi_host_impl_ = NULL; | 216 browser_ppapi_host_impl_ = NULL; |
| 223 } | 217 } |
| 224 | 218 |
| 225 BrowserPpapiHostImpl::HostMessageFilter::~HostMessageFilter() {} | 219 BrowserPpapiHostImpl::HostMessageFilter::~HostMessageFilter() {} |
| 226 | 220 |
| 227 void BrowserPpapiHostImpl::HostMessageFilter::OnKeepalive() { | |
| 228 if (browser_ppapi_host_impl_) | |
| 229 browser_ppapi_host_impl_->OnKeepalive(); | |
| 230 } | |
| 231 | |
| 232 void BrowserPpapiHostImpl::HostMessageFilter::OnHostMsgLogInterfaceUsage( | 221 void BrowserPpapiHostImpl::HostMessageFilter::OnHostMsgLogInterfaceUsage( |
| 233 int hash) const { | 222 int hash) const { |
| 234 UMA_HISTOGRAM_SPARSE_SLOWLY("Pepper.InterfaceUsed", hash); | 223 UMA_HISTOGRAM_SPARSE_SLOWLY("Pepper.InterfaceUsed", hash); |
| 235 } | 224 } |
| 236 | 225 |
| 237 BrowserPpapiHostImpl::InstanceData::InstanceData( | 226 BrowserPpapiHostImpl::InstanceData::InstanceData( |
| 238 const PepperRendererInstanceData& renderer_data) | 227 const PepperRendererInstanceData& renderer_data) |
| 239 : renderer_data(renderer_data), is_throttled(false) { | 228 : renderer_data(renderer_data), is_throttled(false) { |
| 240 } | 229 } |
| 241 | 230 |
| 242 BrowserPpapiHostImpl::InstanceData::~InstanceData() { | 231 BrowserPpapiHostImpl::InstanceData::~InstanceData() { |
| 243 } | 232 } |
| 244 | 233 |
| 245 void BrowserPpapiHostImpl::OnKeepalive() { | |
| 246 // An instance has been active. The on_keepalive_callback_ will be | |
| 247 // used to permit the content embedder to handle this, e.g. by tracking | |
| 248 // activity and shutting down processes that go idle. | |
| 249 // | |
| 250 // Currently embedders do not need to distinguish between instances having | |
| 251 // different idle state, and thus this implementation handles all instances | |
| 252 // for this module together. | |
| 253 | |
| 254 if (on_keepalive_callback_.is_null()) | |
| 255 return; | |
| 256 | |
| 257 BrowserPpapiHost::OnKeepaliveInstanceData instance_data(instance_map_.size()); | |
| 258 | |
| 259 auto instance = instance_map_.begin(); | |
| 260 int i = 0; | |
| 261 while (instance != instance_map_.end()) { | |
| 262 instance_data[i].render_process_id = | |
| 263 instance->second->renderer_data.render_process_id; | |
| 264 instance_data[i].render_frame_id = | |
| 265 instance->second->renderer_data.render_frame_id; | |
| 266 instance_data[i].document_url = | |
| 267 instance->second->renderer_data.document_url; | |
| 268 ++instance; | |
| 269 ++i; | |
| 270 } | |
| 271 on_keepalive_callback_.Run(instance_data, profile_data_directory_); | |
| 272 } | |
| 273 | |
| 274 } // namespace content | 234 } // namespace content |
| OLD | NEW |