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" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 void PpapiHost::SendUnsolicitedReply(PP_Resource resource, | 92 void PpapiHost::SendUnsolicitedReply(PP_Resource resource, |
93 const IPC::Message& msg) { | 93 const IPC::Message& msg) { |
94 TRACE_EVENT2("ppapi proxy", "PpapiHost::SendUnsolicitedReply", | 94 TRACE_EVENT2("ppapi proxy", "PpapiHost::SendUnsolicitedReply", |
95 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), | 95 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), |
96 "Line", IPC_MESSAGE_ID_LINE(msg.type())); | 96 "Line", IPC_MESSAGE_ID_LINE(msg.type())); |
97 DCHECK(resource); // If this fails, host is probably pending. | 97 DCHECK(resource); // If this fails, host is probably pending. |
98 proxy::ResourceMessageReplyParams params(resource, 0); | 98 proxy::ResourceMessageReplyParams params(resource, 0); |
99 Send(new PpapiPluginMsg_ResourceReply(params, msg)); | 99 Send(new PpapiPluginMsg_ResourceReply(params, msg)); |
100 } | 100 } |
101 | 101 |
102 scoped_ptr<ResourceHost> PpapiHost::CreateResourceHost( | |
103 const proxy::ResourceMessageCallParams& params, | |
104 PP_Instance instance, | |
105 const IPC::Message& nested_msg) { | |
106 scoped_ptr<ResourceHost> resource_host; | |
107 DCHECK(!host_factory_filters_.empty()); // Caller forgot to add a factory. | |
108 for (size_t i = 0; i < host_factory_filters_.size(); i++) { | |
109 resource_host = host_factory_filters_[i]->CreateResourceHost( | |
110 this, params, instance, nested_msg).Pass(); | |
111 if (resource_host.get()) | |
112 break; | |
113 } | |
114 return resource_host.Pass(); | |
115 } | |
116 | |
102 int PpapiHost::AddPendingResourceHost(scoped_ptr<ResourceHost> resource_host) { | 117 int PpapiHost::AddPendingResourceHost(scoped_ptr<ResourceHost> resource_host) { |
103 // The resource ID should not be assigned. | 118 // The resource ID should not be assigned. |
104 DCHECK(resource_host->pp_resource() == 0); | 119 if (!resource_host.get() || resource_host->pp_resource() != 0) { |
120 NOTREACHED(); | |
121 return 0; | |
122 } | |
123 | |
124 if (pending_resource_hosts_.size() + resources_.size() | |
125 >= kMaxResourcesPerPlugin) { | |
126 return 0; | |
127 } | |
105 | 128 |
106 int pending_id = next_pending_resource_host_id_++; | 129 int pending_id = next_pending_resource_host_id_++; |
107 pending_resource_hosts_[pending_id] = | 130 pending_resource_hosts_[pending_id] = |
108 linked_ptr<ResourceHost>(resource_host.release()); | 131 linked_ptr<ResourceHost>(resource_host.release()); |
109 return pending_id; | 132 return pending_id; |
110 } | 133 } |
111 | 134 |
112 void PpapiHost::AddHostFactoryFilter(scoped_ptr<HostFactory> filter) { | 135 void PpapiHost::AddHostFactoryFilter(scoped_ptr<HostFactory> filter) { |
113 host_factory_filters_.push_back(filter.release()); | 136 host_factory_filters_.push_back(filter.release()); |
114 } | 137 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 } | 184 } |
162 } | 185 } |
163 | 186 |
164 void PpapiHost::OnHostMsgResourceCreated( | 187 void PpapiHost::OnHostMsgResourceCreated( |
165 const proxy::ResourceMessageCallParams& params, | 188 const proxy::ResourceMessageCallParams& params, |
166 PP_Instance instance, | 189 PP_Instance instance, |
167 const IPC::Message& nested_msg) { | 190 const IPC::Message& nested_msg) { |
168 TRACE_EVENT2("ppapi proxy", "PpapiHost::OnHostMsgResourceCreated", | 191 TRACE_EVENT2("ppapi proxy", "PpapiHost::OnHostMsgResourceCreated", |
169 "Class", IPC_MESSAGE_ID_CLASS(nested_msg.type()), | 192 "Class", IPC_MESSAGE_ID_CLASS(nested_msg.type()), |
170 "Line", IPC_MESSAGE_ID_LINE(nested_msg.type())); | 193 "Line", IPC_MESSAGE_ID_LINE(nested_msg.type())); |
171 if (resources_.size() >= kMaxResourcesPerPlugin) | 194 |
195 if (pending_resource_hosts_.size() + resources_.size() | |
196 >= kMaxResourcesPerPlugin) { | |
172 return; | 197 return; |
198 } | |
173 | 199 |
174 // Run through all filters until one grabs this message. | 200 // Run through all filters until one grabs this message. |
175 scoped_ptr<ResourceHost> resource_host; | 201 scoped_ptr<ResourceHost> resource_host = CreateResourceHost(params, instance, |
176 DCHECK(!host_factory_filters_.empty()); // Caller forgot to add a factory. | 202 nested_msg); |
177 for (size_t i = 0; i < host_factory_filters_.size(); i++) { | 203 |
178 resource_host = host_factory_filters_[i]->CreateResourceHost( | |
179 this, params, instance, nested_msg).Pass(); | |
180 if (resource_host.get()) | |
181 break; | |
182 } | |
183 if (!resource_host.get()) { | 204 if (!resource_host.get()) { |
184 NOTREACHED(); | 205 NOTREACHED(); |
185 return; | 206 return; |
186 } | 207 } |
187 | 208 |
188 // Resource should have been assigned a nonzero PP_Resource. | 209 // Resource should have been assigned a nonzero PP_Resource. |
189 DCHECK(resource_host->pp_resource()); | 210 DCHECK(resource_host->pp_resource()); |
190 | 211 |
191 resources_[params.pp_resource()] = | 212 resources_[params.pp_resource()] = |
192 linked_ptr<ResourceHost>(resource_host.release()); | 213 linked_ptr<ResourceHost>(resource_host.release()); |
193 } | 214 } |
194 | 215 |
195 void PpapiHost::OnHostMsgAttachToPendingHost(PP_Resource pp_resource, | 216 void PpapiHost::OnHostMsgAttachToPendingHost(PP_Resource pp_resource, |
196 int pending_host_id) { | 217 int pending_host_id) { |
197 PendingHostResourceMap::iterator found = | 218 PendingHostResourceMap::iterator found = |
198 pending_resource_hosts_.find(pending_host_id); | 219 pending_resource_hosts_.find(pending_host_id); |
199 if (found == pending_resource_hosts_.end()) { | 220 if (found == pending_resource_hosts_.end()) { |
200 // Plugin sent a bad ID. | 221 // Plugin sent a bad ID. |
201 NOTREACHED(); | 222 NOTREACHED(); |
202 return; | 223 return; |
203 } | 224 } |
204 found->second->SetPPResourceForPendingHost(pp_resource); | 225 found->second->SetPPResourceForPendingHost(pp_resource); |
226 if (resources_.size() >= kMaxResourcesPerPlugin) | |
227 return; | |
teravest
2013/05/29 15:19:36
What should callers of AttachToPendingHost() do to
raymes
2013/05/29 15:53:03
Oops this shouldn't be here. I already added the c
| |
205 resources_[pp_resource] = found->second; | 228 resources_[pp_resource] = found->second; |
206 pending_resource_hosts_.erase(found); | 229 pending_resource_hosts_.erase(found); |
207 } | 230 } |
208 | 231 |
209 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) { | 232 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) { |
210 ResourceMap::iterator found = resources_.find(resource); | 233 ResourceMap::iterator found = resources_.find(resource); |
211 if (found == resources_.end()) { | 234 if (found == resources_.end()) { |
212 NOTREACHED(); | 235 NOTREACHED(); |
213 return; | 236 return; |
214 } | 237 } |
215 // Invoking the HostResource destructor might result in looking up the | 238 // Invoking the HostResource destructor might result in looking up the |
216 // PP_Resource in resources_. std::map is not well specified as to whether the | 239 // PP_Resource in resources_. std::map is not well specified as to whether the |
217 // element will be there or not. Therefore, we delay destruction of the | 240 // element will be there or not. Therefore, we delay destruction of the |
218 // HostResource until after we've made sure the map no longer contains | 241 // HostResource until after we've made sure the map no longer contains |
219 // |resource|. | 242 // |resource|. |
220 linked_ptr<ResourceHost> delete_at_end_of_scope(found->second); | 243 linked_ptr<ResourceHost> delete_at_end_of_scope(found->second); |
221 resources_.erase(found); | 244 resources_.erase(found); |
222 } | 245 } |
223 | 246 |
224 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const { | 247 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const { |
225 ResourceMap::const_iterator found = resources_.find(resource); | 248 ResourceMap::const_iterator found = resources_.find(resource); |
226 return found == resources_.end() ? NULL : found->second.get(); | 249 return found == resources_.end() ? NULL : found->second.get(); |
227 } | 250 } |
228 | 251 |
229 } // namespace host | 252 } // namespace host |
230 } // namespace ppapi | 253 } // namespace ppapi |
OLD | NEW |