| 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 "ppapi/host/ppapi_host.h" | 5 #include "ppapi/host/ppapi_host.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/host/host_factory.h" | 9 #include "ppapi/host/host_factory.h" |
| 10 #include "ppapi/host/host_message_context.h" | 10 #include "ppapi/host/host_message_context.h" |
| 11 #include "ppapi/host/instance_message_filter.h" | 11 #include "ppapi/host/instance_message_filter.h" |
| 12 #include "ppapi/host/resource_host.h" | 12 #include "ppapi/host/resource_host.h" |
| 13 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
| 14 #include "ppapi/proxy/resource_message_params.h" | 14 #include "ppapi/proxy/resource_message_params.h" |
| 15 #include "ppapi/shared_impl/host_resource.h" | 15 #include "ppapi/shared_impl/host_resource.h" |
| 16 #include "ppapi/shared_impl/ppapi_message_tracker.h" |
| 16 | 17 |
| 17 namespace ppapi { | 18 namespace ppapi { |
| 18 namespace host { | 19 namespace host { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // Put a cap on the maximum number of resources so we don't explode if the | 23 // Put a cap on the maximum number of resources so we don't explode if the |
| 23 // renderer starts spamming us. | 24 // renderer starts spamming us. |
| 24 const size_t kMaxResourcesPerPlugin = 1 << 14; | 25 const size_t kMaxResourcesPerPlugin = 1 << 14; |
| 25 | 26 |
| 26 } // namespace | 27 } // namespace |
| 27 | 28 |
| 28 PpapiHost::PpapiHost(IPC::Sender* sender, | 29 PpapiHost::PpapiHost(IPC::Sender* sender, |
| 29 HostFactory* host_factory, | 30 HostFactory* host_factory, |
| 30 const PpapiPermissions& perms) | 31 const PpapiPermissions& perms) |
| 31 : sender_(sender), | 32 : sender_(sender), |
| 32 host_factory_(host_factory), | 33 host_factory_(host_factory), |
| 33 permissions_(perms) { | 34 permissions_(perms) { |
| 34 } | 35 } |
| 35 | 36 |
| 36 PpapiHost::~PpapiHost() { | 37 PpapiHost::~PpapiHost() { |
| 37 // Delete these explicitly before destruction since then the host is still | 38 // Delete these explicitly before destruction since then the host is still |
| 38 // technically alive in case one of the filters accesses us from the | 39 // technically alive in case one of the filters accesses us from the |
| 39 // destructor. | 40 // destructor. |
| 40 instance_message_filters_.clear(); | 41 instance_message_filters_.clear(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 bool PpapiHost::Send(IPC::Message* msg) { | 44 bool PpapiHost::Send(IPC::Message* msg) { |
| 45 ScopedTrackPpapiMessage track_ppapi_message; |
| 44 return sender_->Send(msg); | 46 return sender_->Send(msg); |
| 45 } | 47 } |
| 46 | 48 |
| 47 bool PpapiHost::OnMessageReceived(const IPC::Message& msg) { | 49 bool PpapiHost::OnMessageReceived(const IPC::Message& msg) { |
| 50 ScopedTrackPpapiMessage track_ppapi_message; |
| 48 bool handled = true; | 51 bool handled = true; |
| 49 IPC_BEGIN_MESSAGE_MAP(PpapiHost, msg) | 52 IPC_BEGIN_MESSAGE_MAP(PpapiHost, msg) |
| 50 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCall, | 53 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCall, |
| 51 OnHostMsgResourceCall) | 54 OnHostMsgResourceCall) |
| 52 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreated, | 55 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreated, |
| 53 OnHostMsgResourceCreated) | 56 OnHostMsgResourceCreated) |
| 54 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceDestroyed, | 57 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceDestroyed, |
| 55 OnHostMsgResourceDestroyed) | 58 OnHostMsgResourceDestroyed) |
| 56 IPC_MESSAGE_UNHANDLED(handled = false) | 59 IPC_MESSAGE_UNHANDLED(handled = false) |
| 57 IPC_END_MESSAGE_MAP() | 60 IPC_END_MESSAGE_MAP() |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 resources_.erase(found); | 144 resources_.erase(found); |
| 142 } | 145 } |
| 143 | 146 |
| 144 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) { | 147 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) { |
| 145 ResourceMap::iterator found = resources_.find(resource); | 148 ResourceMap::iterator found = resources_.find(resource); |
| 146 return found == resources_.end() ? NULL : found->second.get(); | 149 return found == resources_.end() ? NULL : found->second.get(); |
| 147 } | 150 } |
| 148 | 151 |
| 149 } // namespace host | 152 } // namespace host |
| 150 } // namespace ppapi | 153 } // namespace ppapi |
| OLD | NEW |