| 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 | 16 |
| 17 namespace ppapi { | 17 namespace ppapi { |
| 18 namespace host { | 18 namespace host { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Put a cap on the maximum number of resources so we don't explode if the | 22 // Put a cap on the maximum number of resources so we don't explode if the |
| 23 // renderer starts spamming us. | 23 // renderer starts spamming us. |
| 24 const size_t kMaxResourcesPerPlugin = 1 << 14; | 24 const size_t kMaxResourcesPerPlugin = 1 << 14; |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 PpapiHost::PpapiHost(IPC::Sender* sender, | 28 PpapiHost::PpapiHost(IPC::Sender* sender, |
| 29 HostFactory* host_factory, | |
| 30 const PpapiPermissions& perms) | 29 const PpapiPermissions& perms) |
| 31 : sender_(sender), | 30 : sender_(sender), |
| 32 host_factory_(host_factory), | |
| 33 permissions_(perms) { | 31 permissions_(perms) { |
| 34 } | 32 } |
| 35 | 33 |
| 36 PpapiHost::~PpapiHost() { | 34 PpapiHost::~PpapiHost() { |
| 37 // Delete these explicitly before destruction since then the host is still | 35 // Delete these explicitly before destruction since then the host is still |
| 38 // technically alive in case one of the filters accesses us from the | 36 // technically alive in case one of the filters accesses us from the |
| 39 // destructor. | 37 // destructor. |
| 40 instance_message_filters_.clear(); | 38 instance_message_filters_.clear(); |
| 41 } | 39 } |
| 42 | 40 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 66 } | 64 } |
| 67 | 65 |
| 68 return handled; | 66 return handled; |
| 69 } | 67 } |
| 70 | 68 |
| 71 void PpapiHost::SendReply(const proxy::ResourceMessageReplyParams& params, | 69 void PpapiHost::SendReply(const proxy::ResourceMessageReplyParams& params, |
| 72 const IPC::Message& msg) { | 70 const IPC::Message& msg) { |
| 73 Send(new PpapiPluginMsg_ResourceReply(params, msg)); | 71 Send(new PpapiPluginMsg_ResourceReply(params, msg)); |
| 74 } | 72 } |
| 75 | 73 |
| 74 void PpapiHost::AddHostFactoryFilter(scoped_ptr<HostFactory> filter) { |
| 75 host_factory_filters_.push_back(filter.release()); |
| 76 } |
| 76 | 77 |
| 77 void PpapiHost::AddInstanceMessageFilter( | 78 void PpapiHost::AddInstanceMessageFilter( |
| 78 scoped_ptr<InstanceMessageFilter> filter) { | 79 scoped_ptr<InstanceMessageFilter> filter) { |
| 79 instance_message_filters_.push_back(filter.release()); | 80 instance_message_filters_.push_back(filter.release()); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void PpapiHost::OnHostMsgResourceCall( | 83 void PpapiHost::OnHostMsgResourceCall( |
| 83 const proxy::ResourceMessageCallParams& params, | 84 const proxy::ResourceMessageCallParams& params, |
| 84 const IPC::Message& nested_msg) { | 85 const IPC::Message& nested_msg) { |
| 85 HostMessageContext context(params); | 86 HostMessageContext context(params); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 114 SendReply(reply_params, context.reply_msg); | 115 SendReply(reply_params, context.reply_msg); |
| 115 } | 116 } |
| 116 | 117 |
| 117 void PpapiHost::OnHostMsgResourceCreated( | 118 void PpapiHost::OnHostMsgResourceCreated( |
| 118 const proxy::ResourceMessageCallParams& params, | 119 const proxy::ResourceMessageCallParams& params, |
| 119 PP_Instance instance, | 120 PP_Instance instance, |
| 120 const IPC::Message& nested_msg) { | 121 const IPC::Message& nested_msg) { |
| 121 if (resources_.size() >= kMaxResourcesPerPlugin) | 122 if (resources_.size() >= kMaxResourcesPerPlugin) |
| 122 return; | 123 return; |
| 123 | 124 |
| 124 scoped_ptr<ResourceHost> resource_host( | 125 // Run through all filters until one grabs this message. |
| 125 host_factory_->CreateResourceHost(this, params, instance, nested_msg)); | 126 scoped_ptr<ResourceHost> resource_host; |
| 127 DCHECK(!host_factory_filters_.empty()); // Caller forgot to add a factory. |
| 128 for (size_t i = 0; i < host_factory_filters_.size(); i++) { |
| 129 resource_host = host_factory_filters_[i]->CreateResourceHost( |
| 130 this, params, instance, nested_msg).Pass(); |
| 131 if (resource_host.get()) |
| 132 break; |
| 133 } |
| 126 if (!resource_host.get()) { | 134 if (!resource_host.get()) { |
| 127 NOTREACHED(); | 135 NOTREACHED(); |
| 128 return; | 136 return; |
| 129 } | 137 } |
| 130 | 138 |
| 131 resources_[params.pp_resource()] = | 139 resources_[params.pp_resource()] = |
| 132 linked_ptr<ResourceHost>(resource_host.release()); | 140 linked_ptr<ResourceHost>(resource_host.release()); |
| 133 } | 141 } |
| 134 | 142 |
| 135 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) { | 143 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) { |
| 136 ResourceMap::iterator found = resources_.find(resource); | 144 ResourceMap::iterator found = resources_.find(resource); |
| 137 if (found == resources_.end()) { | 145 if (found == resources_.end()) { |
| 138 NOTREACHED(); | 146 NOTREACHED(); |
| 139 return; | 147 return; |
| 140 } | 148 } |
| 141 resources_.erase(found); | 149 resources_.erase(found); |
| 142 } | 150 } |
| 143 | 151 |
| 144 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) { | 152 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) { |
| 145 ResourceMap::iterator found = resources_.find(resource); | 153 ResourceMap::iterator found = resources_.find(resource); |
| 146 return found == resources_.end() ? NULL : found->second.get(); | 154 return found == resources_.end() ? NULL : found->second.get(); |
| 147 } | 155 } |
| 148 | 156 |
| 149 } // namespace host | 157 } // namespace host |
| 150 } // namespace ppapi | 158 } // namespace ppapi |
| OLD | NEW |