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

Side by Side Diff: ppapi/host/ppapi_host.cc

Issue 15947004: Allow renderer to create pepper ResourceHosts in the browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months 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
« no previous file with comments | « ppapi/host/ppapi_host.h ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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
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());
(...skipping 28 matching lines...) Expand all
221 resources_.erase(found); 242 resources_.erase(found);
222 } 243 }
223 244
224 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const { 245 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const {
225 ResourceMap::const_iterator found = resources_.find(resource); 246 ResourceMap::const_iterator found = resources_.find(resource);
226 return found == resources_.end() ? NULL : found->second.get(); 247 return found == resources_.end() ? NULL : found->second.get();
227 } 248 }
228 249
229 } // namespace host 250 } // namespace host
230 } // namespace ppapi 251 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/host/ppapi_host.h ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698