Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/pepper_renderer_connection.h" | 5 #include "content/browser/renderer_host/pepper/pepper_renderer_connection.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/memory/ref_counted.h" | |
| 7 #include "content/browser/browser_child_process_host_impl.h" | 9 #include "content/browser/browser_child_process_host_impl.h" |
| 8 #include "content/browser/ppapi_plugin_process_host.h" | 10 #include "content/browser/ppapi_plugin_process_host.h" |
| 9 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" | 11 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" |
| 10 #include "content/common/pepper_renderer_instance_data.h" | 12 #include "content/common/pepper_renderer_instance_data.h" |
| 11 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 12 #include "content/browser/renderer_host/pepper/pepper_file_ref_host.h" | 14 #include "content/browser/renderer_host/pepper/pepper_file_ref_host.h" |
| 13 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h " | 15 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h " |
| 14 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
| 15 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
| 16 #include "ipc/ipc_message_macros.h" | 18 #include "ipc/ipc_message_macros.h" |
| 17 #include "ppapi/host/resource_host.h" | 19 #include "ppapi/host/resource_host.h" |
| 18 #include "ppapi/proxy/ppapi_message_utils.h" | 20 #include "ppapi/proxy/ppapi_message_utils.h" |
| 19 #include "ppapi/proxy/ppapi_messages.h" | 21 #include "ppapi/proxy/ppapi_messages.h" |
| 20 #include "ppapi/proxy/ppapi_message_utils.h" | 22 #include "ppapi/proxy/ppapi_message_utils.h" |
| 21 #include "ppapi/proxy/resource_message_params.h" | 23 #include "ppapi/proxy/resource_message_params.h" |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 24 | 26 |
| 27 namespace { | |
| 28 | |
| 29 // Responsible for creating the pending resource hosts, holding their IDs until | |
| 30 // all of them have been created for a single message, and sending the reply to | |
| 31 // say that the hosts have been created. | |
| 32 class PendingHostCreator | |
| 33 : public base::RefCountedThreadSafe<PendingHostCreator> { | |
|
yzshen1
2013/11/01 22:27:39
ThreadSafe is not needed. This code won't be run o
Matt Giuca
2013/11/01 23:19:47
It will be passed to another thread, then passed b
yzshen1
2013/11/02 00:25:07
If the ref needs to be manipulated by multiple thr
Matt Giuca
2013/11/02 00:51:45
I agree. RefCounted seems fine.
| |
| 34 public: | |
| 35 PendingHostCreator(int routing_id, | |
| 36 int sequence_id, | |
| 37 BrowserPpapiHostImpl* host, | |
| 38 int nested_msgs_size, | |
|
yzshen1
2013/11/01 22:27:39
size_t, please.
nit, optional: maybe it is better
Matt Giuca
2013/11/01 23:19:47
Done. I agree.
| |
| 39 BrowserMessageFilter* connection); | |
| 40 | |
| 41 // Adds the given resource host as a pending one. The host is remembered as | |
| 42 // host number |index|, and will ultimately be sent to the plugin to be | |
| 43 // attached to a real resource. | |
| 44 void AddPendingResourceHost( | |
| 45 size_t index, | |
| 46 scoped_ptr<ppapi::host::ResourceHost> resource_host); | |
| 47 | |
| 48 private: | |
| 49 friend class base::RefCountedThreadSafe<PendingHostCreator>; | |
| 50 | |
| 51 // When the last reference to this class is released, all of the resource | |
| 52 // hosts would have been added. This destructor sends the message to the | |
| 53 // plugin to tell it to attach real hosts to all of the pending hosts that | |
| 54 // have been added by this object. | |
| 55 ~PendingHostCreator(); | |
| 56 | |
| 57 int routing_id_; | |
| 58 int sequence_id_; | |
| 59 BrowserPpapiHostImpl* host_; | |
| 60 std::vector<int> pending_resource_host_ids_; | |
| 61 BrowserMessageFilter* connection_; | |
| 62 }; | |
| 63 | |
| 64 PendingHostCreator::PendingHostCreator(int routing_id, | |
| 65 int sequence_id, | |
| 66 BrowserPpapiHostImpl* host, | |
| 67 int nested_msgs_size, | |
| 68 BrowserMessageFilter* connection) | |
| 69 : routing_id_(routing_id), | |
| 70 sequence_id_(sequence_id), | |
| 71 host_(host), | |
| 72 pending_resource_host_ids_(nested_msgs_size, 0), | |
| 73 connection_(connection) {} | |
| 74 | |
| 75 void PendingHostCreator::AddPendingResourceHost( | |
| 76 size_t index, | |
| 77 scoped_ptr<ppapi::host::ResourceHost> resource_host) { | |
| 78 pending_resource_host_ids_[index] = | |
| 79 host_->GetPpapiHost()->AddPendingResourceHost(resource_host.Pass()); | |
| 80 } | |
| 81 | |
| 82 PendingHostCreator::~PendingHostCreator() { | |
| 83 connection_->Send(new PpapiHostMsg_CreateResourceHostsFromHostReply( | |
|
yzshen1
2013/11/01 22:27:39
Is it possible that something has failed and we ha
Matt Giuca
2013/11/01 23:19:47
No more possible than it already was. (That is, I'
yzshen1
2013/11/02 00:25:07
I think it is possible: The FileSystem resource ho
Matt Giuca
2013/11/02 01:05:21
Had a chat with Yuzhu. I agree, there is a very ra
| |
| 84 routing_id_, sequence_id_, pending_resource_host_ids_)); | |
| 85 } | |
| 86 | |
| 87 } // namespace | |
| 88 | |
| 25 PepperRendererConnection::PepperRendererConnection(int render_process_id) | 89 PepperRendererConnection::PepperRendererConnection(int render_process_id) |
| 26 : render_process_id_(render_process_id) { | 90 : render_process_id_(render_process_id) { |
| 27 // Only give the renderer permission for stable APIs. | 91 // Only give the renderer permission for stable APIs. |
| 28 in_process_host_.reset(new BrowserPpapiHostImpl(this, | 92 in_process_host_.reset(new BrowserPpapiHostImpl(this, |
| 29 ppapi::PpapiPermissions(), | 93 ppapi::PpapiPermissions(), |
| 30 "", | 94 "", |
| 31 base::FilePath(), | 95 base::FilePath(), |
| 32 base::FilePath(), | 96 base::FilePath(), |
| 33 true /* in_process */, | 97 true /* in_process */, |
| 34 false /* external_plugin */)); | 98 false /* external_plugin */)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 return handled; | 150 return handled; |
| 87 } | 151 } |
| 88 | 152 |
| 89 void PepperRendererConnection::OnMsgCreateResourceHostsFromHost( | 153 void PepperRendererConnection::OnMsgCreateResourceHostsFromHost( |
| 90 int routing_id, | 154 int routing_id, |
| 91 int child_process_id, | 155 int child_process_id, |
| 92 const ppapi::proxy::ResourceMessageCallParams& params, | 156 const ppapi::proxy::ResourceMessageCallParams& params, |
| 93 PP_Instance instance, | 157 PP_Instance instance, |
| 94 const std::vector<IPC::Message>& nested_msgs) { | 158 const std::vector<IPC::Message>& nested_msgs) { |
| 95 BrowserPpapiHostImpl* host = GetHostForChildProcess(child_process_id); | 159 BrowserPpapiHostImpl* host = GetHostForChildProcess(child_process_id); |
| 160 scoped_refptr<PendingHostCreator> creator = | |
| 161 new PendingHostCreator( | |
| 162 routing_id, params.sequence(), host, nested_msgs.size(), this); | |
| 96 | 163 |
| 97 std::vector<int> pending_resource_host_ids(nested_msgs.size(), 0); | |
| 98 if (!host) { | 164 if (!host) { |
| 99 DLOG(ERROR) << "Invalid plugin process ID."; | 165 DLOG(ERROR) << "Invalid plugin process ID."; |
| 100 } else { | 166 } else { |
| 101 for (size_t i = 0; i < nested_msgs.size(); ++i) { | 167 for (size_t i = 0; i < nested_msgs.size(); ++i) { |
| 102 const IPC::Message& nested_msg = nested_msgs[i]; | 168 const IPC::Message& nested_msg = nested_msgs[i]; |
| 103 scoped_ptr<ppapi::host::ResourceHost> resource_host; | 169 scoped_ptr<ppapi::host::ResourceHost> resource_host; |
| 104 if (host->IsValidInstance(instance)) { | 170 if (host->IsValidInstance(instance)) { |
| 105 if (nested_msg.type() == PpapiHostMsg_FileRef_CreateExternal::ID) { | 171 if (nested_msg.type() == PpapiHostMsg_FileRef_CreateExternal::ID) { |
| 106 // FileRef_CreateExternal is only permitted from the renderer. Because | 172 // FileRef_CreateExternal is only permitted from the renderer. Because |
| 107 // of this, we handle this message here and not in | 173 // of this, we handle this message here and not in |
| 108 // content_browser_pepper_host_factory.cc. | 174 // content_browser_pepper_host_factory.cc. |
| 109 base::FilePath external_path; | 175 base::FilePath external_path; |
| 110 if (ppapi::UnpackMessage<PpapiHostMsg_FileRef_CreateExternal>( | 176 if (ppapi::UnpackMessage<PpapiHostMsg_FileRef_CreateExternal>( |
| 111 nested_msg, &external_path)) { | 177 nested_msg, &external_path)) { |
| 112 resource_host.reset(new PepperFileRefHost( | 178 resource_host.reset(new PepperFileRefHost( |
| 113 host, instance, params.pp_resource(), external_path)); | 179 host, instance, params.pp_resource(), external_path)); |
| 114 } | 180 } |
| 115 } else if (nested_msg.type() == | 181 } else if (nested_msg.type() == |
| 116 PpapiHostMsg_FileSystem_CreateFromRenderer::ID) { | 182 PpapiHostMsg_FileSystem_CreateFromRenderer::ID) { |
| 117 // Similarly, FileSystem_CreateFromRenderer is only permitted from the | 183 // Similarly, FileSystem_CreateFromRenderer is only permitted from the |
| 118 // renderer. | 184 // renderer. |
| 119 std::string root_url; | 185 std::string root_url; |
| 120 PP_FileSystemType file_system_type; | 186 PP_FileSystemType file_system_type; |
| 121 if (ppapi::UnpackMessage<PpapiHostMsg_FileSystem_CreateFromRenderer>( | 187 if (ppapi::UnpackMessage<PpapiHostMsg_FileSystem_CreateFromRenderer>( |
| 122 nested_msg, &root_url, &file_system_type)) { | 188 nested_msg, &root_url, &file_system_type)) { |
| 123 resource_host.reset( | 189 PepperFileSystemBrowserHost* browser_host = |
| 124 new PepperFileSystemBrowserHost(host, | 190 new PepperFileSystemBrowserHost(host, |
| 125 instance, | 191 instance, |
| 126 params.pp_resource(), | 192 params.pp_resource(), |
| 127 GURL(root_url), | 193 file_system_type); |
| 128 file_system_type)); | 194 resource_host.reset(browser_host); |
| 195 // Open the file system resource host. This is an asynchronous | |
| 196 // operation, and we must only add the pending resource host and | |
| 197 // send the message once it completes. | |
| 198 browser_host->OpenExisting( | |
| 199 GURL(root_url), | |
| 200 base::Bind( | |
| 201 &PendingHostCreator::AddPendingResourceHost, | |
|
dmichael (off chromium)
2013/11/01 17:33:52
The idea of this being asynchronous is pretty scar
teravest
2013/11/01 19:57:24
Dave's right-- you should definitely call AddPendi
yzshen1
2013/11/01 21:23:12
(Not saying that it is incorrect, just try to unde
Matt Giuca
2013/11/01 21:41:54
Hey,
I'm not sure I understand how this is a prob
dmichael (off chromium)
2013/11/01 21:44:26
Yeah, I realize now that the sender of CreateFromR
| |
| 202 creator, | |
| 203 i, | |
| 204 base::Passed(&resource_host))); | |
| 205 // Do not fall through; the fall-through case adds the pending | |
| 206 // resource host to the list. We must do this asynchronously. | |
| 207 continue; | |
|
dmichael (off chromium)
2013/11/01 17:33:52
I think it might be better to structure this diffe
Matt Giuca
2013/11/01 23:19:47
That's messy. The case currently at the bottom is
| |
| 129 } | 208 } |
| 130 } | 209 } |
| 131 } | 210 } |
| 132 | 211 |
| 133 if (!resource_host.get()) { | 212 if (!resource_host.get()) { |
| 134 resource_host = host->GetPpapiHost()->CreateResourceHost( | 213 resource_host = host->GetPpapiHost()->CreateResourceHost( |
| 135 params, instance, nested_msg); | 214 params, instance, nested_msg); |
| 136 } | 215 } |
| 137 | 216 |
| 138 if (resource_host.get()) { | 217 if (resource_host.get()) |
| 139 pending_resource_host_ids[i] = | 218 creator->AddPendingResourceHost(i, resource_host.Pass()); |
| 140 host->GetPpapiHost()->AddPendingResourceHost(resource_host.Pass()); | |
| 141 } | |
| 142 } | 219 } |
| 143 } | 220 } |
| 144 | 221 |
| 145 Send(new PpapiHostMsg_CreateResourceHostsFromHostReply( | 222 // Note: All of the pending host IDs that were added as part of this |
| 146 routing_id, params.sequence(), pending_resource_host_ids)); | 223 // operation will automatically be send to the plugin when |creator| is |
|
dmichael (off chromium)
2013/11/01 17:33:52
nit: s/send/sent
Matt Giuca
2013/11/01 23:19:47
Done.
| |
| 224 // released. This may happen immediately, or (if there are asynchronous | |
| 225 // requests to create resource hosts), once all of them complete. | |
| 147 } | 226 } |
| 148 | 227 |
| 149 void PepperRendererConnection::OnMsgDidCreateInProcessInstance( | 228 void PepperRendererConnection::OnMsgDidCreateInProcessInstance( |
| 150 PP_Instance instance, | 229 PP_Instance instance, |
| 151 const PepperRendererInstanceData& instance_data) { | 230 const PepperRendererInstanceData& instance_data) { |
| 152 PepperRendererInstanceData data = instance_data; | 231 PepperRendererInstanceData data = instance_data; |
| 153 data.render_process_id = render_process_id_; | 232 data.render_process_id = render_process_id_; |
| 154 in_process_host_->AddInstance(instance, data); | 233 in_process_host_->AddInstance(instance, data); |
| 155 } | 234 } |
| 156 | 235 |
| 157 void PepperRendererConnection::OnMsgDidDeleteInProcessInstance( | 236 void PepperRendererConnection::OnMsgDidDeleteInProcessInstance( |
| 158 PP_Instance instance) { | 237 PP_Instance instance) { |
| 159 in_process_host_->DeleteInstance(instance); | 238 in_process_host_->DeleteInstance(instance); |
| 160 } | 239 } |
| 161 | 240 |
| 162 } // namespace content | 241 } // namespace content |
| OLD | NEW |